Skip to content

Data

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."""

    PRIVATE = "private"
    GROUP = "group"
    SUPERGROUP = "supergroup"
    CHANNEL = "channel"

WebAppChat dataclass

Represents a Telegram chat.

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.

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: str
    signature: str
    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

WebAppUser dataclass

Represents a Telegram user.

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