Data Models
Validated Telegram data is returned as dataclasses from telegram_webapp_auth.data.
Use these models for typed access to users, chats, and launch metadata after validation succeeds. Unknown top-level Telegram fields are preserved in WebAppInitData.extra.
This module contains data structures used in the Telegram Web Apps API.
ChatType
Bases: str, Enum
Represents the type of Telegram chat.
Source code in telegram_webapp_auth/data.py
| class ChatType(str, enum.Enum):
"""Represents the type of Telegram chat."""
SENDER = "sender"
PRIVATE = "private"
GROUP = "group"
SUPERGROUP = "supergroup"
CHANNEL = "channel"
|
WebAppChat dataclass
Represents a Telegram chat.
Links
https://core.telegram.org/bots/webapps#webappchat
Source code in telegram_webapp_auth/data.py
| @dataclasses.dataclass
class WebAppChat:
"""Represents a Telegram chat.
Links:
https://core.telegram.org/bots/webapps#webappchat
"""
id: int
type: ChatType
title: str
username: typing.Optional[str] = None
photo_url: typing.Optional[str] = None
|
WebAppInitData dataclass
Represents the data that the webapp receives from Telegram.
Links
https://core.telegram.org/bots/webapps#webappinitdata
Source code in telegram_webapp_auth/data.py
| @dataclasses.dataclass
class WebAppInitData:
"""Represents the data that the webapp receives from Telegram.
Links:
https://core.telegram.org/bots/webapps#webappinitdata
"""
auth_date: int
hash: typing.Optional[str] = None
signature: typing.Optional[str] = None
query_id: typing.Optional[str] = None
user: typing.Optional[WebAppUser] = None
receiver: typing.Optional[WebAppUser] = None
chat: typing.Optional[WebAppChat] = None
chat_type: typing.Optional[ChatType] = None
chat_instance: typing.Optional[str] = None
start_param: typing.Optional[str] = None
can_send_after: typing.Optional[int] = None
extra: dict[str, str] = dataclasses.field(default_factory=dict)
|
WebAppUser dataclass
Represents a Telegram user.
Links
https://core.telegram.org/bots/webapps#webappuser
Source code in telegram_webapp_auth/data.py
| @dataclasses.dataclass
class WebAppUser:
"""Represents a Telegram user.
Links:
https://core.telegram.org/bots/webapps#webappuser
"""
id: int
first_name: str
is_bot: typing.Optional[bool] = None
last_name: typing.Optional[str] = None
username: typing.Optional[str] = None
language_code: typing.Optional[str] = None
is_premium: typing.Optional[bool] = None
added_to_attachment_menu: typing.Optional[bool] = None
allows_write_to_pm: typing.Optional[bool] = None
photo_url: typing.Optional[str] = None
|