CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-python-telegram-bot

A pure Python, asynchronous interface for the Telegram Bot API with comprehensive wrapper and high-level framework for building sophisticated Telegram bots

Pending
Overview
Eval results
Files

telegram-types.mddocs/

Telegram Types

Complete type system covering all Telegram Bot API objects including messages, users, chats, files, and update structures.

Capabilities

Update Structure

Container for all incoming updates from Telegram.

class Update:
    update_id: int
    message: Message | None
    edited_message: Message | None
    channel_post: Message | None
    edited_channel_post: Message | None
    business_connection: BusinessConnection | None
    business_message: Message | None
    edited_business_message: Message | None
    deleted_business_messages: BusinessMessagesDeleted | None
    message_reaction: MessageReactionUpdated | None
    message_reaction_count: MessageReactionCountUpdated | None
    inline_query: InlineQuery | None
    chosen_inline_result: ChosenInlineResult | None
    callback_query: CallbackQuery | None
    shipping_query: ShippingQuery | None
    pre_checkout_query: PreCheckoutQuery | None
    purchased_paid_media: PaidMediaPurchased | None
    poll: Poll | None
    poll_answer: PollAnswer | None
    my_chat_member: ChatMemberUpdated | None
    chat_member: ChatMemberUpdated | None
    chat_join_request: ChatJoinRequest | None
    chat_boost: ChatBoostUpdated | None
    removed_chat_boost: ChatBoostRemoved | None
    
    def effective_message(self) -> Message | None: ...
    def effective_chat(self) -> Chat | None: ...
    def effective_user(self) -> User | None: ...

Message Types

Core message structure and related types.

class Message:
    message_id: int
    message_thread_id: int | None
    from_user: User | None
    sender_chat: Chat | None
    sender_boost_count: int | None
    sender_business_bot: User | None
    date: datetime.datetime
    business_connection_id: str | None
    chat: Chat
    forward_origin: MessageOrigin | None
    is_topic_message: bool | None
    is_automatic_forward: bool | None
    reply_to_message: 'Message' | None
    external_reply: ExternalReplyInfo | None
    quote: TextQuote | None
    reply_to_story: Story | None
    via_bot: User | None
    edit_date: datetime.datetime | None
    has_protected_content: bool | None
    is_from_offline: bool | None
    media_group_id: str | None
    author_signature: str | None
    text: str | None
    entities: list[MessageEntity] | None
    link_preview_options: LinkPreviewOptions | None
    effect_id: str | None
    animation: Animation | None
    audio: Audio | None
    document: Document | None
    paid_media: PaidMediaInfo | None
    photo: list[PhotoSize] | None
    sticker: Sticker | None
    story: Story | None
    video: Video | None
    video_note: VideoNote | None
    voice: Voice | None
    caption: str | None
    caption_entities: list[MessageEntity] | None
    show_caption_above_media: bool | None
    has_media_spoiler: bool | None
    contact: Contact | None
    dice: Dice | None
    game: Game | None
    poll: Poll | None
    venue: Venue | None
    location: Location | None
    new_chat_members: list[User] | None
    left_chat_member: User | None
    new_chat_title: str | None
    new_chat_photo: list[PhotoSize] | None
    delete_chat_photo: bool | None
    group_chat_created: bool | None
    supergroup_chat_created: bool | None
    channel_chat_created: bool | None
    message_auto_delete_timer_changed: MessageAutoDeleteTimerChanged | None
    migrate_to_chat_id: int | None
    migrate_from_chat_id: int | None
    pinned_message: MaybeInaccessibleMessage | None
    invoice: Invoice | None
    successful_payment: SuccessfulPayment | None
    refunded_payment: RefundedPayment | None
    users_shared: UsersShared | None
    chat_shared: ChatShared | None
    connected_website: str | None
    write_access_allowed: WriteAccessAllowed | None
    passport_data: PassportData | None
    proximity_alert_triggered: ProximityAlertTriggered | None
    boost_added: ChatBoostAdded | None
    chat_background_set: ChatBackground | None
    forum_topic_created: ForumTopicCreated | None
    forum_topic_edited: ForumTopicEdited | None
    forum_topic_closed: ForumTopicClosed | None
    forum_topic_reopened: ForumTopicReopened | None
    general_forum_topic_hidden: GeneralForumTopicHidden | None
    general_forum_topic_unhidden: GeneralForumTopicUnhidden | None
    giveaway_created: GiveawayCreated | None
    giveaway: Giveaway | None
    giveaway_winners: GiveawayWinners | None
    giveaway_completed: GiveawayCompleted | None
    video_chat_scheduled: VideoChatScheduled | None
    video_chat_started: VideoChatStarted | None
    video_chat_ended: VideoChatEnded | None
    video_chat_participants_invited: VideoChatParticipantsInvited | None
    web_app_data: WebAppData | None
    reply_markup: InlineKeyboardMarkup | None
    
    async def reply_text(self, text: str, **kwargs) -> 'Message': ...
    async def reply_photo(self, photo: InputFile | str, **kwargs) -> 'Message': ...
    async def reply_audio(self, audio: InputFile | str, **kwargs) -> 'Message': ...
    async def reply_document(self, document: InputFile | str, **kwargs) -> 'Message': ...
    async def reply_video(self, video: InputFile | str, **kwargs) -> 'Message': ...
    async def reply_animation(self, animation: InputFile | str, **kwargs) -> 'Message': ...
    async def reply_sticker(self, sticker: InputFile | str, **kwargs) -> 'Message': ...
    async def reply_video_note(self, video_note: InputFile | str, **kwargs) -> 'Message': ...
    async def reply_voice(self, voice: InputFile | str, **kwargs) -> 'Message': ...
    async def reply_location(self, latitude: float, longitude: float, **kwargs) -> 'Message': ...
    async def reply_venue(self, latitude: float, longitude: float, title: str, address: str, **kwargs) -> 'Message': ...
    async def reply_contact(self, phone_number: str, first_name: str, **kwargs) -> 'Message': ...
    async def reply_poll(self, question: str, options: list[str], **kwargs) -> 'Message': ...
    async def reply_dice(self, emoji: str = None, **kwargs) -> 'Message': ...
    async def edit_text(self, text: str, **kwargs) -> 'Message' | bool: ...
    async def edit_caption(self, caption: str = None, **kwargs) -> 'Message' | bool: ...
    async def edit_media(self, media: InputMedia, **kwargs) -> 'Message' | bool: ...
    async def edit_reply_markup(self, reply_markup: InlineKeyboardMarkup = None, **kwargs) -> 'Message' | bool: ...
    async def delete(self, **kwargs) -> bool: ...
    async def pin(self, **kwargs) -> bool: ...
    async def unpin(self, **kwargs) -> bool: ...
    async def forward(self, chat_id: int | str, **kwargs) -> 'Message': ...
    async def copy(self, chat_id: int | str, **kwargs) -> MessageId: ...
    
    def parse_entity(self, entity: MessageEntity) -> str: ...
    def parse_entities(self, types: list[str] = None) -> dict[MessageEntity, str]: ...
    def parse_caption_entity(self, entity: MessageEntity) -> str: ...
    def parse_caption_entities(self, types: list[str] = None) -> dict[MessageEntity, str]: ...

class InaccessibleMessage:
    chat: Chat
    message_id: int
    date: int

MaybeInaccessibleMessage = Message | InaccessibleMessage

class MessageId:
    message_id: int

class MessageEntity:
    type: str
    offset: int
    length: int
    url: str | None
    user: User | None
    language: str | None
    custom_emoji_id: str | None

User and Chat Types

User information and chat details.

class User:
    id: int
    is_bot: bool
    first_name: str
    last_name: str | None
    username: str | None
    language_code: str | None
    is_premium: bool | None
    added_to_attachment_menu: bool | None
    can_join_groups: bool | None
    can_read_all_group_messages: bool | None
    supports_inline_queries: bool | None
    can_connect_to_business: bool | None
    has_main_web_app: bool | None
    
    def full_name(self) -> str: ...
    def name(self) -> str: ...
    def mention_markdown(self, name: str = None) -> str: ...
    def mention_html(self, name: str = None) -> str: ...

class Chat:
    id: int
    type: str
    title: str | None
    username: str | None
    first_name: str | None
    last_name: str | None
    is_forum: bool | None
    
    def full_name(self) -> str: ...
    def name(self) -> str: ...
    async def leave(self, **kwargs) -> bool: ...
    async def get_administrators(self, **kwargs) -> list[ChatMember]: ...
    async def get_member_count(self, **kwargs) -> int: ...
    async def get_member(self, user_id: int, **kwargs) -> ChatMember: ...
    async def ban_member(self, user_id: int, **kwargs) -> bool: ...
    async def unban_member(self, user_id: int, **kwargs) -> bool: ...
    async def restrict_member(self, user_id: int, permissions: ChatPermissions, **kwargs) -> bool: ...
    async def promote_member(self, user_id: int, **kwargs) -> bool: ...
    async def set_permissions(self, permissions: ChatPermissions, **kwargs) -> bool: ...
    async def set_administrator_custom_title(self, user_id: int, custom_title: str, **kwargs) -> bool: ...
    async def pin_message(self, message_id: int, **kwargs) -> bool: ...
    async def unpin_message(self, message_id: int = None, **kwargs) -> bool: ...
    async def unpin_all_messages(self, **kwargs) -> bool: ...
    async def send_message(self, text: str, **kwargs) -> Message: ...
    # ... (all Bot send methods available as Chat methods)

class ChatFullInfo(Chat):
    accent_color_id: int | None
    max_reaction_count: int | None
    photo: ChatPhoto | None
    active_usernames: list[str] | None
    birthdate: Birthdate | None
    business_intro: BusinessIntro | None
    business_location: BusinessLocation | None
    business_opening_hours: BusinessOpeningHours | None
    personal_chat: Chat | None
    available_reactions: list[ReactionType] | None
    background_custom_emoji_id: str | None
    profile_accent_color_id: int | None
    profile_background_custom_emoji_id: str | None
    emoji_status_custom_emoji_id: str | None
    emoji_status_expiration_date: datetime.datetime | None
    bio: str | None
    has_private_forwards: bool | None
    has_restricted_voice_and_video_messages: bool | None
    join_to_send_messages: bool | None
    join_by_request: bool | None
    description: str | None
    invite_link: str | None
    pinned_message: Message | None
    permissions: ChatPermissions | None
    can_send_paid_media: bool | None
    slow_mode_delay: int | None
    unrestrict_boost_count: int | None
    message_auto_delete_time: int | None
    has_aggressive_anti_spam_enabled: bool | None
    has_hidden_members: bool | None
    has_protected_content: bool | None
    has_visible_history: bool | None
    sticker_set_name: str | None
    can_set_sticker_set: bool | None
    custom_emoji_sticker_set_name: str | None
    linked_chat_id: int | None
    location: ChatLocation | None

class ChatMember:
    user: User
    status: str
    until_date: datetime.datetime | None

class ChatMemberOwner(ChatMember):
    is_anonymous: bool
    custom_title: str | None

class ChatMemberAdministrator(ChatMember):
    can_be_edited: bool
    can_manage_chat: bool
    can_post_messages: bool | None
    can_edit_messages: bool | None
    can_delete_messages: bool
    can_manage_video_chats: bool
    can_restrict_members: bool
    can_promote_members: bool
    can_change_info: bool
    can_invite_users: bool
    can_pin_messages: bool | None
    can_manage_topics: bool | None
    is_anonymous: bool
    custom_title: str | None

class ChatMemberMember(ChatMember):
    until_date: datetime.datetime | None

class ChatMemberRestricted(ChatMember):
    is_member: bool
    can_send_messages: bool
    can_send_audios: bool
    can_send_documents: bool
    can_send_photos: bool
    can_send_videos: bool
    can_send_video_notes: bool
    can_send_voice_notes: bool
    can_send_polls: bool
    can_send_other_messages: bool
    can_add_web_page_previews: bool
    can_change_info: bool
    can_invite_users: bool
    can_pin_messages: bool
    can_manage_topics: bool
    until_date: datetime.datetime | None

class ChatMemberLeft(ChatMember):
    pass

class ChatMemberBanned(ChatMember):
    until_date: datetime.datetime | None

class ChatPermissions:
    can_send_messages: bool | None
    can_send_audios: bool | None
    can_send_documents: bool | None
    can_send_photos: bool | None
    can_send_videos: bool | None
    can_send_video_notes: bool | None
    can_send_voice_notes: bool | None
    can_send_polls: bool | None
    can_send_other_messages: bool | None
    can_add_web_page_previews: bool | None
    can_change_info: bool | None
    can_invite_users: bool | None
    can_pin_messages: bool | None
    can_manage_topics: bool | None

File Types

Media and file representations.

class PhotoSize:
    file_id: str
    file_unique_id: str
    width: int
    height: int
    file_size: int | None
    
    async def get_file(self, **kwargs) -> File: ...

class Audio:
    file_id: str
    file_unique_id: str
    duration: int
    performer: str | None
    title: str | None
    file_name: str | None
    mime_type: str | None
    file_size: int | None
    thumbnail: PhotoSize | None
    
    async def get_file(self, **kwargs) -> File: ...

class Document:
    file_id: str
    file_unique_id: str
    thumbnail: PhotoSize | None
    file_name: str | None
    mime_type: str | None
    file_size: int | None
    
    async def get_file(self, **kwargs) -> File: ...

class Video:
    file_id: str
    file_unique_id: str
    width: int
    height: int
    duration: int
    thumbnail: PhotoSize | None
    file_name: str | None
    mime_type: str | None
    file_size: int | None
    
    async def get_file(self, **kwargs) -> File: ...

class Animation:
    file_id: str
    file_unique_id: str
    width: int
    height: int
    duration: int
    thumbnail: PhotoSize | None
    file_name: str | None
    mime_type: str | None
    file_size: int | None
    
    async def get_file(self, **kwargs) -> File: ...

class Voice:
    file_id: str
    file_unique_id: str
    duration: int
    mime_type: str | None
    file_size: int | None
    
    async def get_file(self, **kwargs) -> File: ...

class VideoNote:
    file_id: str
    file_unique_id: str
    length: int
    duration: int
    thumbnail: PhotoSize | None
    file_size: int | None
    
    async def get_file(self, **kwargs) -> File: ...

class Contact:
    phone_number: str
    first_name: str
    last_name: str | None
    user_id: int | None
    vcard: str | None

class Location:
    longitude: float
    latitude: float
    horizontal_accuracy: float | None
    live_period: int | None
    heading: int | None
    proximity_alert_radius: int | None

class Venue:
    location: Location
    title: str
    address: str
    foursquare_id: str | None
    foursquare_type: str | None
    google_place_id: str | None
    google_place_type: str | None

class File:
    file_id: str
    file_unique_id: str
    file_size: int | None
    file_path: str | None
    
    async def download_to_drive(self, custom_path: str = None) -> str: ...
    async def download_as_bytearray(self) -> bytearray: ...

Callback and Inline Types

Callback queries and inline query handling.

class CallbackQuery:
    id: str
    from_user: User
    message: MaybeInaccessibleMessage | None
    inline_message_id: str | None
    chat_instance: str
    data: str | None
    game_short_name: str | None
    
    async def answer(self, text: str = None, show_alert: bool = None, url: str = None, cache_time: int = None, **kwargs) -> bool: ...
    async def edit_message_text(self, text: str, **kwargs) -> Message | bool: ...
    async def edit_message_caption(self, caption: str = None, **kwargs) -> Message | bool: ...
    async def edit_message_reply_markup(self, reply_markup: InlineKeyboardMarkup = None, **kwargs) -> Message | bool: ...
    async def delete_message(self, **kwargs) -> bool: ...

class InlineQuery:
    id: str
    from_user: User
    query: str
    offset: str
    chat_type: str | None
    location: Location | None
    
    async def answer(self, results: list[InlineQueryResult], **kwargs) -> bool: ...

class ChosenInlineResult:
    result_id: str
    from_user: User
    location: Location | None
    inline_message_id: str | None
    query: str

Poll Types

Poll and voting structures.

class Poll:
    id: str
    question: str
    question_entities: list[MessageEntity] | None
    options: list[PollOption]
    total_voter_count: int
    is_closed: bool
    is_anonymous: bool
    type: str
    allows_multiple_answers: bool
    correct_option_id: int | None
    explanation: str | None
    explanation_entities: list[MessageEntity] | None
    open_period: int | None
    close_date: datetime.datetime | None

class PollOption:
    text: str
    text_entities: list[MessageEntity] | None
    voter_count: int
    special_entities: list[MessageEntity] | None

class PollAnswer:
    poll_id: str
    option_ids: list[int]
    voter_chat: Chat | None
    user: User | None

Type Hierarchies

Message Origin Types

class MessageOrigin:
    type: str
    date: datetime.datetime

class MessageOriginUser(MessageOrigin):
    sender_user: User

class MessageOriginHiddenUser(MessageOrigin):
    sender_user_name: str

class MessageOriginChat(MessageOrigin):
    sender_chat: Chat
    author_signature: str | None

class MessageOriginChannel(MessageOrigin):
    chat: Chat
    message_id: int
    author_signature: str | None

Reaction Types

class ReactionType:
    type: str

class ReactionTypeEmoji(ReactionType):
    emoji: str

class ReactionTypeCustomEmoji(ReactionType):
    custom_emoji_id: str

class ReactionTypePaid(ReactionType):
    pass

Background Types

class BackgroundFill:
    type: str

class BackgroundFillSolid(BackgroundFill):
    color: int

class BackgroundFillGradient(BackgroundFill):
    top_color: int
    bottom_color: int
    rotation_angle: int

class BackgroundFillFreeformGradient(BackgroundFill):
    colors: list[int]

class BackgroundType:
    type: str

class BackgroundTypeFill(BackgroundType):
    fill: BackgroundFill
    dark_theme_dimming: int

class BackgroundTypeWallpaper(BackgroundType):
    document: Document
    dark_theme_dimming: int
    is_blurred: bool | None
    is_moving: bool | None

class BackgroundTypePattern(BackgroundType):
    document: Document
    fill: BackgroundFill
    intensity: int
    is_inverted: bool | None
    is_moving: bool | None

class BackgroundTypeChatTheme(BackgroundType):
    theme_name: str

class ChatBackground:
    type: BackgroundType

Transaction Types

class TransactionPartner:
    type: str

class TransactionPartnerUser(TransactionPartner):
    user: User
    invoice_payload: str | None
    subscription_period: int | None
    paid_media: list[PaidMedia] | None
    paid_media_payload: str | None

class TransactionPartnerFragment(TransactionPartner):
    withdrawal_state: RevenueWithdrawalState | None

class TransactionPartnerTelegramAds(TransactionPartner):
    pass

class TransactionPartnerTelegramApi(TransactionPartner):
    request_count: int

class TransactionPartnerOther(TransactionPartner):
    pass

class TransactionPartnerChat(TransactionPartner):
    chat: Chat
    invoice_payload: str | None

class TransactionPartnerAffiliateProgram(TransactionPartner):
    commission_per_mille: int

class AffiliateInfo:
    affiliate_user: User | None
    affiliate_chat: Chat | None
    commission_per_mille: int
    amount: int
    nanostar_amount: int | None

class StarTransaction:
    id: str
    amount: int
    nanostar_amount: int | None
    date: datetime.datetime
    source: TransactionPartner | None
    receiver: TransactionPartner | None

class StarTransactions:
    transactions: list[StarTransaction]

class RevenueWithdrawalState:
    type: str

class RevenueWithdrawalStatePending(RevenueWithdrawalState):
    pass

class RevenueWithdrawalStateSucceeded(RevenueWithdrawalState):
    date: datetime.datetime
    url: str

class RevenueWithdrawalStateFailed(RevenueWithdrawalState):
    pass

Business Types

class BusinessConnection:
    id: str
    user: User
    user_chat_id: int
    date: datetime.datetime
    can_reply: bool
    is_enabled: bool

class BusinessIntro:
    title: str | None
    message: str | None
    sticker: Sticker | None

class BusinessLocation:
    address: str
    location: Location | None

class BusinessOpeningHours:
    time_zone_name: str
    opening_hours: list[BusinessOpeningHoursInterval]

class BusinessOpeningHoursInterval:
    opening_minute: int
    closing_minute: int

class BusinessMessagesDeleted:
    business_connection_id: str
    chat: Chat
    message_ids: list[int]

Gift Types

class Gift:
    id: str
    sticker: Sticker
    star_count: int
    total_count: int | None
    remaining_count: int | None

class Gifts:
    gifts: list[Gift]

Birthdate Type

class Birthdate:
    day: int
    month: int
    year: int | None

Install with Tessl CLI

npx tessl i tessl/pypi-python-telegram-bot

docs

advanced-features.md

application-framework.md

bot-api.md

files.md

filters.md

handlers.md

index.md

keyboards.md

telegram-types.md

tile.json