Skip to content

Types

The data models for Bot API objects. Each keeps the original response in a raw dict, so fields that are not yet modelled stay reachable.

Typed models for Bot API objects.

Each type keeps the original response in a raw dict, so fields that are not yet modelled stay reachable (for example message.raw["photo"]).

The Bot API sender field is named "from", a Python keyword, so it is exposed as from_user.

User dataclass

send_message async

send_message(text: str, **kwargs: Any) -> 'Message'

Send a direct message to this user.

Chat dataclass

send_message async

send_message(text: str, **kwargs: Any) -> 'Message'

Send a text message to this chat.

send_photo async

send_photo(photo: 'FileInput', **kwargs: Any) -> 'Message'

Send a photo to this chat.

MaskPosition dataclass

Where a mask sticker is placed on a face (sent and received).

InputSticker dataclass

A sticker to add to a set (sent).

sticker is a file_id, an HTTP URL, or "attach://" for an uploaded file; format is one of "static", "animated", or "video".

Message dataclass

reply_text async

reply_text(text: str, **kwargs: Any) -> 'Message'

Send a text message to this message's chat.

reply_photo async

reply_photo(photo: FileInput, **kwargs: Any) -> 'Message'

Send a photo to this message's chat.

reply_document async

reply_document(document: FileInput, **kwargs: Any) -> 'Message'

Send a document to this message's chat.

edit_text async

edit_text(text: str, **kwargs: Any) -> Message | bool

Edit this message's text.

delete async

delete() -> bool

Delete this message.

forward async

forward(chat_id: int | str, **kwargs: Any) -> 'Message'

Forward this message to another chat.

copy async

copy(chat_id: int | str, **kwargs: Any) -> MessageId

Copy this message to another chat.

CallbackQuery dataclass

An incoming callback query from a button on an inline keyboard.

answer async

answer(text: Optional[str] = None, *, show_alert: Optional[bool] = None, **kwargs: Any) -> bool

Answer this callback query with an optional toast or alert.

edit_message_text async

edit_message_text(text: str, **kwargs: Any) -> Message | bool

Edit the message this query's button is attached to.

InlineQuery dataclass

An incoming inline query (the inline_query update).

answer async

answer(results: 'list[InlineQueryResult]', **kwargs: Any) -> bool

Answer this inline query with a list of results.

ChosenInlineResult dataclass

A result the user chose from inline query results.

Update dataclass

effective_message property

effective_message: Optional[Message]

The incoming message of this update, whatever message kind it is.

effective_chat_id property

effective_chat_id: Optional[int]

The chat this update concerns, if any.

effective_user_id property

effective_user_id: Optional[int]

The user who caused this update, if any.

set_bot

set_bot(bot: 'Bot') -> None

Bind a Bot onto this update and its children, enabling shortcuts.

WebhookInfo dataclass

The current webhook status, as returned by getWebhookInfo.

ChatPermissions dataclass

The actions a non-admin member may take in a chat (used to restrict).

ChatAdministratorRights dataclass

An administrator's rights in a chat.

Sent to set_my_default_administrator_rights and returned by get_my_default_administrator_rights. Unset (None) rights are dropped when sent, which Telegram treats as not granted.

ChatJoinRequest dataclass

A request to join a chat (the chat_join_request update).

approve async

approve() -> bool

Approve this join request.

decline async

decline() -> bool

Decline this join request.

ShippingQuery dataclass

An incoming shipping query (the shipping_query update).

Sent for invoices with is_flexible set, once the user picks a shipping address. Reply with answer() to offer delivery options or report an error.

answer async

answer(ok: bool, *, shipping_options: 'Optional[list[ShippingOption]]' = None, error_message: Optional[str] = None) -> bool

Reply with delivery options (ok=True) or an error (ok=False).

PreCheckoutQuery dataclass

An incoming pre-checkout query (the pre_checkout_query update).

The final confirmation before payment. Telegram expects answer() within 10 seconds; pass ok=False with an error_message to abort the checkout.

answer async

answer(ok: bool, *, error_message: Optional[str] = None) -> bool

Confirm (ok=True) or reject (ok=False, with error_message) checkout.

BotCommand dataclass

A bot command shown in the client's command menu.

ReplyParameters dataclass

How a sent message replies to an earlier one.

Pass this as reply_parameters to a send method. Reply to a normal message with message_id, or to an ephemeral message with ephemeral_message_id; exactly one of the two identifies the target. quote_entities, when given, is a list of already-serialized MessageEntity dicts.

LinkPreviewOptions dataclass

How the link preview for a message is generated.

Pass this as link_preview_options to send_message or edit_message_text. Set is_disabled to suppress the preview entirely, url to preview a link other than the first one in the text, and prefer_small_media or prefer_large_media to override the preview's default size.

SuggestedPostPrice dataclass

The price asked for publishing a suggested post.

amount is in the currency's smallest units, like LabeledPrice.

SuggestedPostParameters dataclass

Terms of a post suggested to a direct messages chat.

price is what the sender asks to be paid for publishing the post, and send_date is a Unix timestamp for when it should go out. Omitting both suggests the post with no price and no fixed schedule.

InputPollOption dataclass

One answer option of a poll being sent.

send_poll also accepts plain strings, so this is only needed when an option carries its own formatting (text_parse_mode, text_entities) or media.

ReplyKeyboardRemove dataclass

Removes the custom reply keyboard and restores the letter keyboard.

Pass this as reply_markup. Set selective to remove the keyboard only for the users the message replies to or mentions.

ForceReply dataclass

Shows a reply interface to the user as if they tapped Reply.

Pass this as reply_markup to collect a private one-off answer without needing the user to reply manually.

LabeledPrice dataclass

One labeled line item in an invoice price breakdown.

amount is in the currency's smallest units (for example cents), so LabeledPrice("Total", 500) is 5.00 of a two-decimal currency.

ShippingOption dataclass

A delivery option offered in reply to a shipping query.

InputMediaPhoto dataclass

A photo for a media group or editMessageMedia (media is a file_id or URL).

InputMediaVideo dataclass

A video for a media group or editMessageMedia (media is a file_id or URL).

InputMediaAudio dataclass

An audio file for a media group or editMessageMedia.

InputMediaDocument dataclass

A general file for a media group or editMessageMedia.

InputMediaAnimation dataclass

An animation for a media group or editMessageMedia.

InputMediaVoiceNote dataclass

A voice message to be sent, used inside a rich message.

Unlike the other InputMedia types this is not part of the InputMedia union accepted by send_media_group or edit_message_media; it appears only in a rich message's media list and in the voice-note rich block.

ReactionTypeEmoji dataclass

An emoji reaction, e.g. ReactionTypeEmoji("👍").

ReactionTypeCustomEmoji dataclass

A custom emoji reaction, identified by its custom_emoji_id.

ReactionTypePaid dataclass

A paid (Telegram Star) reaction. It carries no extra fields.

InputFile

A local file to upload: raw bytes, a filesystem path, or a binary file object.

The contents are read once at construction. Pass this as the media argument to send_photo, send_document, and similar to upload a new file; pass a plain string to reuse a file_id or to have Telegram fetch a URL.

InlineKeyboardButton dataclass

A button on an inline keyboard. Set exactly one action (callback_data or url).

style colors the button: "primary", "success", or "danger" (Bot API 9.4). icon_custom_emoji_id puts a custom emoji on the button.

InlineKeyboardMarkup dataclass

An inline keyboard: rows of InlineKeyboardButton attached to a message.

KeyboardButton dataclass

A button on a custom reply keyboard.

style colors the button: "primary", "success", or "danger" (Bot API 9.4). icon_custom_emoji_id puts a custom emoji on the button.

ReplyKeyboardMarkup dataclass

A custom reply keyboard shown in place of the user's letter keyboard.

InputTextMessageContent dataclass

Text content for an inline query result's sent message.

InlineQueryResultArticle dataclass

An inline result linking to an article or web page.

InlineQueryResultPhoto dataclass

An inline result: a link to a photo (photo_url plus thumbnail_url).

InlineQueryResultDocument dataclass

An inline result: a link to a file (document_url plus mime_type).

InlineQueryResultVideo dataclass

An inline result: a link to a video (video_url, mime_type, thumbnail_url).

InlineQueryResultCachedPhoto dataclass

An inline result: a photo stored on Telegram (photo_file_id).

InlineQueryResultCachedDocument dataclass

An inline result: a file stored on Telegram (document_file_id).

InlineQueryResultCachedVideo dataclass

An inline result: a video stored on Telegram (video_file_id).

InlineQueryResultCachedSticker dataclass

An inline result: a sticker stored on Telegram (sticker_file_id).