Методы Tg API

pydantic model tg_api.tg_methods.BaseTgRequest[source]

Base class representing a request to the Telegram Bot API.

Provides utility methods for making both asynchronous and synchronous requests to the API.

Typically used as a parent class for specific request types which include their data fields and possibly override or extend the base methods to customize behavior.

async apost_as_json(api_method)[source]

Send a request to the Telegram Bot API asynchronously using a JSON payload.

Parameters:

api_method (str) – The Telegram Bot API method to call.

Returns:

The response from the Telegram Bot API as a byte string.

Return type:

bytes

async apost_multipart_form_data(api_method, content, files)[source]

Send a request to the Telegram Bot API asynchronously using the “multipart/form-data” format.

Parameters:
  • api_method (str) – The Telegram Bot API method to call.

  • content (dict) – A dictionary containing the content to be sent.

  • files (dict) – A dictionary containing files to be sent.

Returns:

The response from the Telegram Bot API as a byte string.

Return type:

bytes

post_as_json(api_method)[source]

Send a request to the Telegram Bot API synchronously using a JSON payload.

Parameters:

api_method (str) – The Telegram Bot API method to call.

Returns:

The response from the Telegram Bot API as a byte string.

Return type:

bytes

post_multipart_form_data(api_method, content, files)[source]

Send a request to the Telegram Bot API synchronously using the “multipart/form-data” format.

Parameters:
  • api_method (str) – The Telegram Bot API method name.

  • content (dict) – A dictionary containing the content to be sent.

  • files (dict) – A dictionary containing files to be sent.

Returns:

The response from the Telegram Bot API as a byte string.

Return type:

bytes

pydantic model tg_api.tg_methods.BaseTgResponse[source]

Represents the base structure of a response from the Telegram Bot API.

Every response from the Telegram Bot API contains certain common attributes, which are captured in this base model. Specific response types might extend this base structure.

field description: str = ''

A string value that can contain additional description of the result of the operation or the cause of the error. If the operation was successful, the value will be empty.

field error_code: int | None = None

An integer or None value that contains the error code if the operation fails. If the operation was successful, the value will be None.

field ok: bool [Required]

A Boolean value indicating the success of the operation.

field parameters: ResponseParameters | None = None

An optional field that represents additional parameters associated with the response.

field result: Any = None

Any value that represents the specific result of an operation. The value type may depend on the specific Telegram Bot API response type.

pydantic model tg_api.tg_methods.SendMessageResponse[source]

Represents an extended response structure from the Telegram Bot API.

field result: Message [Required]

Result of sending a message.

pydantic model tg_api.tg_methods.SendMessageRequest[source]

Object encapsulates data for calling Telegram Bot API endpoint sendMessage.

See here https://core.telegram.org/bots/api#sendmessage

field allow_sending_without_reply: bool | None = None

Pass True if the message should be sent even if the specified replied-to message is not found.

field chat_id: int [Required]

Unique identifier for the target chat or username of the target channel (in the format @channelusername).

field disable_notification: bool | None = None

Sends the message silently. Users will receive a notification with no sound.

field disable_web_page_preview: bool | None = None

Disables link previews for links in this message.

field entities: list[MessageEntity] | None = None

A JSON-serialized list of special entities that appear in message text, which can be specified instead of parse_mode.

field message_thread_id: bool | None = None

Unique identifier for the target message thread (topic) of the forum; for forum supergroups only.

field parse_mode: ParseMode | None = None

Mode for parsing entities in the message text. See formatting options for more details.

field protect_content: bool | None = None

Protects the contents of the sent message from forwarding and saving.

field reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None

Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

field text: str [Required]

Text of the message to be sent, 1-4096 characters after entities parsing.

Constraints:
  • maxLength = 4096

  • minLength = 1

async asend()[source]

Send HTTP request to sendMessage Telegram Bot API endpoint asynchronously and parse response.

Return type:

SendMessageResponse

send()[source]

Send HTTP request to sendMessage Telegram Bot API endpoint synchronously and parse response.

Return type:

SendMessageResponse

pydantic model tg_api.tg_methods.SendLocationResponse[source]

Represents an extended response structure from the Telegram Bot API.

field result: Message [Required]

Result of sending a message.

pydantic model tg_api.tg_methods.SendLocationRequest[source]

Object encapsulates data for calling Telegram Bot API endpoint sendLocation.

See here https://core.telegram.org/bots/api#sendlocation

field chat_id: int [Required]

Unique identifier for the target chat or username of the target channel (in the format @channelusername).

field disable_notification: bool | None = None

Sends the message silently. Users will receive a notification with no sound.

field heading: int | None = None

For live locations, a direction in which the user is moving, in degrees. Must be between 1 and 360 if specified.

Constraints:
  • minimum = 0

  • maximum = 360

field horizontal_accuracy: float | None = None

The radius of uncertainty for the location, measured in meters; 0-1500.

Constraints:
  • minimum = 0

  • maximum = 1500

field latitude: float [Required]

Latitude of the location.

field live_period: int | None = None

Period in seconds for which the location will be updated (see Live Locations, should be between 60 and 86400).

Constraints:
  • minimum = 60

  • maximum = 86400

field longitude: float [Required]

Longitude of the location.

field message_thread_id: int | None = None

Unique identifier for the target message thread (topic) of the forum; for forum supergroups only.

field protect_content: bool | None = None

Protects the contents of the sent message from forwarding and saving.

field proximity_alert_radius: int | None = None

For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified.

Constraints:
  • minimum = 1

  • maximum = 100000

field reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None

Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

async asend()[source]

Send HTTP request to sendLocation Telegram Bot API endpoint asynchronously and parse response.

Return type:

SendLocationResponse

send()[source]

Send HTTP request to sendLocation Telegram Bot API endpoint synchronously and parse response.

Return type:

SendLocationResponse

pydantic model tg_api.tg_methods.SendPhotoResponse[source]

Represents an extended response structure from the Telegram Bot API.

field result: Message [Required]

Result of sending a photo.

pydantic model tg_api.tg_methods.SendBytesPhotoRequest[source]

Object encapsulates data for calling Telegram Bot API endpoint sendPhoto.

See here https://core.telegram.org/bots/api#sendphoto

field allow_sending_without_reply: bool | None = None

Pass True if the message should be sent even if the specified replied-to message is not found.

field caption: str | None = None

Photo caption (may also be used when resending photos by file_id), 0-1024 characters after entities parsing.

Constraints:
  • maxLength = 1024

field caption_entities: list[MessageEntity] | None = None

A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode.

field chat_id: int [Required]

Unique identifier for the target chat or username of the target channel (in the format @channelusername).

field disable_notification: bool | None = None

Sends the message silently. Users will receive a notification with no sound.

field filename: str | None = None
field has_spoiler: bool | None = None

Pass True if the photo needs to be covered with a spoiler animation.

field message_thread_id: int | None = None

Unique identifier for the target message thread (topic) of the forum; for forum supergroups only.

field parse_mode: str | None = None

Mode for parsing entities in the photo caption. See formatting options for more details.

field photo: bytes [Required]

Photo to send. Pass a file_id as String to send a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload a new photo using multipart/form-data. The photo must be at most 10 MB in size. The photo’s width and height must not exceed 10000 in total. Width and height ratio must be at most 20.

field protect_content: bool | None = None

Protects the contents of the sent message from forwarding and saving.

field reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None

Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

field reply_to_message_id: int | None = None

If the message is a reply, ID of the original message.

async asend()[source]

Send HTTP request to sendPhoto Telegram Bot API endpoint asynchronously and parse response.

Return type:

SendPhotoResponse

send()[source]

Send HTTP request to sendPhoto Telegram Bot API endpoint synchronously and parse response.

Return type:

SendPhotoResponse

pydantic model tg_api.tg_methods.SendUrlPhotoRequest[source]

Object encapsulates data for calling Telegram Bot API endpoint sendPhoto.

See here https://core.telegram.org/bots/api#sendphoto

field allow_sending_without_reply: bool | None = None

Pass True if the message should be sent even if the specified replied-to message is not found.

field caption: str | None = None

Photo caption (may also be used when resending photos by file_id), 0-1024 characters after entities parsing.

Constraints:
  • maxLength = 1024

field caption_entities: list[MessageEntity] | None = None

A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode.

field chat_id: int [Required]

Unique identifier for the target chat or username of the target channel (in the format @channelusername).

field disable_notification: bool | None = None

Sends the message silently. Users will receive a notification with no sound.

field filename: str | None = None
field has_spoiler: bool | None = None

Pass True if the photo needs to be covered with a spoiler animation.

field message_thread_id: int | None = None

Unique identifier for the target message thread (topic) of the forum; for forum supergroups only.

field parse_mode: str | None = None

Mode for parsing entities in the photo caption. See formatting options for more details.

field photo: str [Required]

Photo to send. Pass a file_id as String to send a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload a new photo using multipart/form-data. The photo must be at most 10 MB in size. The photo’s width and height must not exceed 10000 in total. Width and height ratio must be at most 20.

field protect_content: bool | None = None

Protects the contents of the sent message from forwarding and saving.

field reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None

Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

field reply_to_message_id: int | None = None

If the message is a reply, ID of the original message.

async asend()[source]

Send HTTP request to sendPhoto Telegram Bot API endpoint asynchronously and parse response.

Return type:

SendPhotoResponse

send()[source]

Send HTTP request to sendPhoto Telegram Bot API endpoint synchronously and parse response.

Return type:

SendPhotoResponse

pydantic model tg_api.tg_methods.SendDocumentResponse[source]

Represents an extended response structure from the Telegram Bot API.

field result: Message [Required]

Result of sending a document.

pydantic model tg_api.tg_methods.SendBytesDocumentRequest[source]

Object encapsulates data for calling Telegram Bot API endpoint sendDocument.

See here https://core.telegram.org/bots/api#senddocument

field allow_sending_without_reply: bool | None = None

Pass True if the message should be sent even if the specified replied-to message is not found.

field caption: str | None = None

Document caption (may also be used when resending documents by file_id), 0-1024 characters after entities parsing.

Constraints:
  • maxLength = 1024

field caption_entities: list[MessageEntity] | None = None

A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode.

field chat_id: int [Required]

Unique identifier for the target chat or username of the target channel (in the format @channelusername).

field disable_content_type_detection: bool | None = None

Disables automatic server-side content type detection for files uploaded using multipart/form-data.

field disable_notification: bool | None = None

Sends the message silently. Users will receive a notification with no sound.

field document: bytes [Required]

File to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data.

field filename: str | None = None
field message_thread_id: int | None = None

Unique identifier for the target message thread (topic) of the forum; for forum supergroups only.

field parse_mode: str | None = None

Mode for parsing entities in the document caption. See formatting options for more details.

field protect_content: bool | None = None

Protects the contents of the sent message from forwarding and saving.

field reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None

Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

field reply_to_message_id: int | None = None

If the message is a reply, ID of the original message.

field thumbnail: bytes | str | None = None

Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail’s width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.

async asend()[source]

Send HTTP request to sendDocument Telegram Bot API endpoint asynchronously and parse response.

Return type:

SendDocumentResponse

send()[source]

Send HTTP request to sendDocument Telegram Bot API endpoint synchronously and parse response.

Return type:

SendDocumentResponse

pydantic model tg_api.tg_methods.SendUrlDocumentRequest[source]

Object encapsulates data for calling Telegram Bot API endpoint sendDocument.

See here https://core.telegram.org/bots/api#senddocument

field allow_sending_without_reply: bool | None = None

Pass True if the message should be sent even if the specified replied-to message is not found.

field caption: str | None = None

Document caption (may also be used when resending documents by file_id), 0-1024 characters after entities parsing.

Constraints:
  • maxLength = 1024

field caption_entities: list[MessageEntity] | None = None

A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode.

field chat_id: int [Required]

Unique identifier for the target chat or username of the target channel (in the format @channelusername).

field disable_content_type_detection: bool | None = None

Disables automatic server-side content type detection for files uploaded using multipart/form-data.

field disable_notification: bool | None = None

Sends the message silently. Users will receive a notification with no sound.

field document: str [Required]

File to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data.

field filename: str | None = None
field message_thread_id: int | None = None

Unique identifier for the target message thread (topic) of the forum; for forum supergroups only.

field parse_mode: str | None = None

Mode for parsing entities in the document caption. See formatting options for more details.

field protect_content: bool | None = None

Protects the contents of the sent message from forwarding and saving.

field reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None

Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

field reply_to_message_id: int | None = None

If the message is a reply, ID of the original message.

field thumbnail: bytes | str | None = None

Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail’s width and height should not exceed 320. Ignored if the file is not uploaded using multipart/form-data. Thumbnails can’t be reused and can be only uploaded as a new file, so you can pass “attach://<file_attach_name>” if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.

async asend()[source]

Send HTTP request to sendDocument Telegram Bot API endpoint asynchronously and parse response.

Return type:

SendDocumentResponse

send()[source]

Send HTTP request to sendDocument Telegram Bot API endpoint synchronously and parse response.

Return type:

SendDocumentResponse

pydantic model tg_api.tg_methods.DeleteMessageResponse[source]

Represents an extended response structure from the Telegram Bot API.

field result: bool [Required]

Message deletion result.

pydantic model tg_api.tg_methods.DeleteMessageRequest[source]

Object encapsulates data for calling Telegram Bot API endpoint deleteMessage.

See here https://core.telegram.org/bots/api#deletemessage

field chat_id: int [Required]

Unique identifier for the target chat or username of the target channel (in the format @channelusername).

field message_id: int [Required]

Identifier of the message to delete.

async asend()[source]

Send HTTP request to deleteMessage Telegram Bot API endpoint asynchronously and parse response.

Return type:

DeleteMessageResponse

send()[source]

Send HTTP request to deleteMessage Telegram Bot API endpoint synchronously and parse response.

Return type:

DeleteMessageResponse

pydantic model tg_api.tg_methods.EditMessageTextResponse[source]

Represents an extended response structure from the Telegram Bot API.

field result: Message | bool [Required]

Message editing result.

pydantic model tg_api.tg_methods.EditMessageTextRequest[source]

Object encapsulates data for calling Telegram Bot API endpoint editMessageText.

See here https://core.telegram.org/bots/api#editmessagetext

field chat_id: int | None = None

Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername).

field disable_web_page_preview: bool | None = None

Disables link previews for links in this message.

field entities: list[MessageEntity] | None = None

A JSON-serialized list of special entities that appear in message text, which can be specified instead of parse_mode.

field inline_message_id: str | None = None

Required if chat_id and message_id are not specified. Identifier of the inline message.

field message_id: int | None = None

Required if inline_message_id is not specified. Identifier of the message to edit.

field parse_mode: str | None = None

Mode for parsing entities in the message text. See formatting options for more details.

field reply_markup: InlineKeyboardMarkup | None = None

A JSON-serialized object for an inline keyboard.

field text: str [Required]

New text of the message, 1-4096 characters after entities parsing.

Constraints:
  • maxLength = 4096

  • minLength = 1

async asend()[source]

Send HTTP request to editmessagetext Telegram Bot API endpoint asynchronously and parse response.

Return type:

EditMessageTextResponse

send()[source]

Send HTTP request to editmessagetext Telegram Bot API endpoint synchronously and parse response.

Return type:

EditMessageTextResponse

pydantic model tg_api.tg_methods.EditMessageReplyMarkupResponse[source]

Represents an extended response structure from the Telegram Bot API.

field result: Message | bool [Required]

The result of editing a ReplyMarkup message.

pydantic model tg_api.tg_methods.EditMessageReplyMarkupRequest[source]

Object encapsulates data for calling Telegram Bot API endpoint editMessageReplyMarkup.

See here https://core.telegram.org/bots/api#editmessagereplymarkup

field chat_id: int | None = None

Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername).

field inline_message_id: str | None = None

Required if chat_id and message_id are not specified. Identifier of the inline message.

field message_id: int | None = None

Required if inline_message_id is not specified. Identifier of the message to edit.

field reply_markup: InlineKeyboardMarkup | None = None

A JSON-serialized object for an inline keyboard.

async asend()[source]

Send HTTP request to editmessagereplymarkup Telegram Bot API endpoint asynchronously and parse response.

Return type:

EditMessageReplyMarkupResponse

send()[source]

Send HTTP request to editmessagereplymarkup Telegram Bot API endpoint synchronously and parse response.

Return type:

EditMessageReplyMarkupResponse

pydantic model tg_api.tg_methods.EditMessageCaptionResponse[source]

Represents an extended response structure from the Telegram Bot API.

field result: Message | bool [Required]

The result of editing a caption.

pydantic model tg_api.tg_methods.EditMessageCaptionRequest[source]

Object encapsulates data for calling Telegram Bot API endpoint editMessageCaption.

See here https://core.telegram.org/bots/api#editmessagecaption

field caption: str | None = None

New caption of the message, 0-1024 characters after entities parsing.

Constraints:
  • maxLength = 1024

field caption_entities: list[MessageEntity] | None = None

A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode.

field chat_id: int | None = None

Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername).

field inline_message_id: str | None = None

Required if chat_id and message_id are not specified. Identifier of the inline message.

field message_id: int | None = None

Required if inline_message_id is not specified. Identifier of the message to edit.

field parse_mode: str | None = None

Mode for parsing entities in the message caption. See formatting options for more details.

field reply_markup: InlineKeyboardMarkup | None = None

A JSON-serialized object for an inline keyboard.

async asend()[source]

Send HTTP request to editmessagecaption Telegram Bot API endpoint asynchronously and parse response.

Return type:

EditMessageCaptionResponse

send()[source]

Send HTTP request to editmessagecaption Telegram Bot API endpoint synchronously and parse response.

Return type:

EditMessageCaptionResponse

pydantic model tg_api.tg_methods.EditMessageMediaResponse[source]

Represents an extended response structure from the Telegram Bot API.

field result: Message | bool [Required]

The result of editing a media message.

pydantic model tg_api.tg_methods.EditBytesMessageMediaRequest[source]

Object encapsulates data for calling Telegram Bot API endpoint editmessagemedia.

See here https://core.telegram.org/bots/api#editmessagemedia

field chat_id: int | None = None

Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername).

field inline_message_id: str | None = None

Required if chat_id and message_id are not specified. Identifier of the inline message.

field media: InputMediaBytesDocument | InputMediaBytesPhoto [Required]

A JSON-serialized object for a new media content of the message.

field message_id: int | None = None

Required if inline_message_id is not specified. Identifier of the message to edit.

field reply_markup: InlineKeyboardMarkup | None = None

A JSON-serialized object for a new inline keyboard.

async asend()[source]

Send HTTP request to editmessagemedia Telegram Bot API endpoint asynchronously and parse response.

Return type:

EditMessageMediaResponse

send()[source]

Send HTTP request to editmessagemedia Telegram Bot API endpoint synchronously and parse response.

Return type:

EditMessageMediaResponse

pydantic model tg_api.tg_methods.EditUrlMessageMediaRequest[source]

Object encapsulates data for calling Telegram Bot API endpoint editmessagemedia.

See here https://core.telegram.org/bots/api#editmessagemedia

field chat_id: int | None = None

Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername).

field inline_message_id: str | None = None

Required if chat_id and message_id are not specified. Identifier of the inline message.

field media: InputMediaUrlDocument | InputMediaUrlPhoto [Required]

A JSON-serialized object for a new media content of the message.

field message_id: int | None = None

Required if inline_message_id is not specified. Identifier of the message to edit.

field reply_markup: InlineKeyboardMarkup | None = None

A JSON-serialized object for a new inline keyboard.

async asend()[source]

Send HTTP request to editmessagemedia Telegram Bot API endpoint asynchronously and parse response.

Return type:

EditMessageMediaResponse

send()[source]

Send HTTP request to editmessagemedia Telegram Bot API endpoint synchronously and parse response.

Return type:

EditMessageMediaResponse

pydantic model tg_api.tg_methods.WebhookInfoResponse[source]

Represents an extended response structure from the Telegram Bot API.

field result: WebhookInfo [Required]

Webhook info.

pydantic model tg_api.tg_methods.WebhookInfoRequest[source]

Get current webhook status.

See https://core.telegram.org/bots/api#getwebhookinfo

async asend()[source]

Get the webhook info (async).

Return type:

WebhookInfoResponse

send()[source]

Get the webhook info (sync).

Return type:

WebhookInfoResponse

pydantic model tg_api.tg_methods.SetWebhookResponse[source]

Represents an extended response structure from the Telegram Bot API.

field result: bool [Required]

Set webhook result.

pydantic model tg_api.tg_methods.SetWebhookRequest[source]

Specify a URL for receiving updates via an outgoing webhook.

See https://core.telegram.org/bots/api#setwebhook

field allowed_updates: list[str] | None = None

A JSON-serialized list of the update types you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types.

field certificate: bytes | None = None

Upload your public key certificate so that the root certificate in use can be checked. See the self-signed guide for details: https://core.telegram.org/bots/self-signed

field drop_pending_updates: bool | None = None

Pass True to drop all pending updates

field ip_address: str | None = None

The fixed IP address which will be used to send webhook requests instead of the IP address resolved through DNS

field max_connections: int | None = None

The maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. Use lower values to limit the load on your bot’s server, and higher values to increase your bot’s throughput.

field secret_token: str | None = None

A secret token to be sent in a header “X-Telegram-Bot-Api-Secret-Token” in every webhook request, 1-256 characters. Only characters A-Z, a-z, 0-9, _ and - are allowed. The header is useful to ensure that the request comes from a webhook set by you.

field url: str [Required]

HTTPS URL to send updates to. Use an empty string to remove webhook integration

async asend()[source]

Set a webhook (async).

Return type:

SetWebhookResponse

send()[source]

Set the webhook (sync).

Return type:

SetWebhookResponse

pydantic model tg_api.tg_methods.DeleteWebhookResponse[source]

Represents an extended response structure from the Telegram Bot API.

field result: bool [Required]

Delete webhook result.

pydantic model tg_api.tg_methods.DeleteWebhookRequest[source]

Remove webhook integration.

See https://core.telegram.org/bots/api#deletewebhook

field drop_pending_updates: bool | None = None

Pass True to drop all pending updates

async asend()[source]

Delete a webhook (async).

Return type:

DeleteWebhookResponse

send()[source]

Delete a webhook (sync).

Return type:

DeleteWebhookResponse

pydantic model tg_api.tg_methods.GetUpdatesResponse[source]

Represents an extended response structure from the Telegram Bot API.

field result: list[Update] [Required]

Get updates result.

pydantic model tg_api.tg_methods.GetUpdatesRequest[source]

Get updates.

Object encapsulates data for calling Telegram Bot API endpoint getUpdates.

See here https://core.telegram.org/bots/api#getupdates

Validators:
field allowed_updates: list[str] | None = None

Optional. Specify a list of the update types you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See https://core.telegram.org/bots/api#update for a complete list of available update types. Specify an empty list to receive all update types except chat_member, message_reaction, and message_reaction_count (default). If not specified, the previous setting will be used. Please note that this parameter doesn’t affect updates created before the call to the getUpdates, so unwanted updates may be received for a short period of time.

Validated by:
field limit: int = 100

Optional. Limits the number of updates to be retrieved. Values between 1-100 are accepted. Defaults to 100.

Constraints:
  • minimum = 1

  • maximum = 100

field offset: int | None = None

Optional. Identifier of the first update to be returned. Must be greater by one than the highest among the identifiers of previously received updates. By default, updates starting with the earliest unconfirmed update are returned. An update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id. The negative offset can be specified to retrieve updates starting from -offset update from the end of the updates queue. All previous updates will be forgotten.

field timeout: int | None = 0

Optional. Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be positive, short polling should be used for testing purposes only.

Constraints:
  • minimum = 0

async alisten_to_updates()[source]

Listen to updates - async.

Yield updates in an endless loop

Return type:

AsyncGenerator[Update, None]

validator allowed_updates_match  »  allowed_updates[source]
Parameters:

v (list[str]) –

Return type:

None

async asend()[source]

Get Telegram updates - async.

Return type:

GetUpdatesResponse

listen_to_updates()[source]

Listen to updates - sync.

Yield updates in an endless loop

Return type:

Generator[Update, None, None]

send()[source]

Get Telegram updates - sync.

Return type:

GetUpdatesResponse

pydantic model tg_api.tg_methods.AnswerCallbackQueryResponse[source]

Represents an extended response structure from the Telegram Bot API.

field result: bool [Required]

Result of answering to CallbackQuery.

pydantic model tg_api.tg_methods.AnswerCallbackQueryRequest[source]

Answer to CallbackQuery.

Object encapsulates data for calling Telegram Bot API endpoint answercallbackquery.

See here https://core.telegram.org/bots/api#answercallbackquery

field cache_time: int | None = 0

The maximum amount of time in seconds that the result of the callback query may be cached client-side.

field callback_query_id: str [Required]

Unique identifier for the query to be answered.

field show_alert: bool | None = False

Should an alert be shown by the client instead of a notification or not.

field text: str | None = None

Text of the notification.

Constraints:
  • maxLength = 200

field url: str | None = None

URL that will be opened by the user’s client.

async asend(raise_for_invalid_query=False)[source]

Answer CallbackQuery (async).

Parameters:

raise_for_invalid_query (bool | None) – Defines if TgHttpStatusError should be raised on the ‘query is too old or invalid’ error. By default this type of Telegram error will be ignored.

Raises:

TgHttpStatusError – Exception raised if Telegram responds with error. By default the ‘query is too old or invalid’ error will be ignored and cause no exception.

Return type:

AnswerCallbackQueryResponse

send(raise_for_invalid_query=False)[source]

Answer CallbackQuery (sync).

Parameters:

raise_for_invalid_query (bool | None) – Defines if TgHttpStatusError should be raised on the ‘query is too old or invalid’ error. By default this type of Telegram error will be ignored.

Raises:

TgHttpStatusError – Exception raised if Telegram responds with error. By default the ‘query is too old or invalid’ error will be ignored and cause no exception.

Return type:

AnswerCallbackQueryResponse