Aiogram Telegram Bot Object

Bot object

Low level API

Subclass of this class used only for splitting network interface from all of API methods.classaiogram.bot.base.BaseBot(token: Stringloop: Optional[Union[BaseEventLoop, AbstractEventLoop]] = Noneconnections_limit: Optional[Integer] = Noneproxy: Optional[String] = Noneproxy_auth: Optional[BasicAuth] = Nonevalidate_token: Optional[Boolean] = Trueparse_mode: Optional[String] = Nonedisable_web_page_preview: Optional[Boolean] = Noneprotect_content: Optional[Boolean] = Nonetimeout: Optional[Union[Integer, Float, ClientTimeout]] = Noneserver: TelegramAPIServer = TelegramAPIServer(base=’https://api.telegram.org/bot{token}/{method}’, file=’https://api.telegram.org/file/bot{token}/{path}’))[source]

Bases: object

Base class for bot. It’s raw bot.

Instructions how to get Bot token is found here: https://core.telegram.org/bots#3-how-do-i-create-a-botParameters

  • token (str) – token from @BotFather
  • loop (Optional Union asyncio.BaseEventLoopasyncio.AbstractEventLoop) – event loop
  • connections_limit (int) – connections limit for aiohttp.ClientSession
  • proxy (str) – HTTP proxy URL
  • proxy_auth (Optional aiohttp.BasicAuth) – Authentication information
  • validate_token (bool) – Validate token.
  • parse_mode (str) – You can set default parse mode
  • disable_web_page_preview (bool) – You can set default disable web page preview parameter
  • protect_content (typing.Optional[base.Boolean]) – Protects the contents of sent messages from forwarding and saving
  • timeout (typing.Optional[typing.Union[base.Integer, base.Float, aiohttp.ClientTimeout]]) – Request timeout
  • server (TelegramAPIServer) – Telegram Bot API Server endpoint.

Raise

when token is invalid throw an aiogram.utils.exceptions.ValidationErrorrequest_timeout(timeout: Union[Integer, Float, ClientTimeout])[source]

Context manager implements opportunity to change request timeout in current contextParameters

timeout (typing.Optional[typing.Union[base.Integer, base.Float, aiohttp.ClientTimeout]]) – Request timeoutReturnsclose()[source]

Close all client sessionsasyncrequest(method: Stringdata: Optional[Dict] = Nonefiles: Optional[Dict] = None**kwargs)→ Union[List, Dict, Boolean][source]

Make an request to Telegram Bot API

https://core.telegram.org/bots/api#making-requestsParameters
  • method (str) – API method
  • data (dict) – request parameters
  • files (dict) – files

Returns

resultReturn type

Union[List, Dict]Raise

aiogram.exceptions.TelegramApiErrorasyncdownload_file(file_path: ~aiogram.types.base.Stringdestination: ~typing.Optional[~typing.Union[~aiogram.types.base.InputFile~pathlib.Path]] = Nonetimeout: ~typing.Optional[~aiogram.types.base.Integer] = <object object>chunk_size: ~typing.Optional[~aiogram.types.base.Integer] = 65536seek: ~typing.Optional[~aiogram.types.base.Boolean] = Truedestination_dir: ~typing.Optional[~typing.Union[str~pathlib.Path]] = Nonemake_dirs: ~typing.Optional[~aiogram.types.base.Boolean] = True)→ Union[BytesIO, FileIO][source]

Download file by file_path to destination file or directory

if You want to automatically create destination (io.BytesIO) use default value of destination and handle result of this method.

At most one of these parameters can be used: :param destination:, :param destination_dir:Parameters

  • file_path (str) – file path on telegram server (You can get it from aiogram.types.File)
  • destination – filename or instance of io.IOBase. For e. g. io.BytesIO
  • timeout – Integer
  • chunk_size – Integer
  • seek – Boolean – go to start of file when downloading is finished.
  • destination_dir – directory for saving files
  • make_dirs – Make dirs if not exist

Returns

destinationasyncsend_file(file_typemethodfilepayload)→ Union[Dict, Boolean][source]

Send file

https://core.telegram.org/bots/api#inputfileParameters
  • file_type – field name
  • method – API method
  • file – String or io.IOBase
  • payload – request payload

Returns

response

Telegram Bot

This class based on aiogram.bot.base.BaseBotclassaiogram.bot.bot.Bot(token: Stringloop: Optional[Union[BaseEventLoop, AbstractEventLoop]] = Noneconnections_limit: Optional[Integer] = Noneproxy: Optional[String] = Noneproxy_auth: Optional[BasicAuth] = Nonevalidate_token: Optional[Boolean] = Trueparse_mode: Optional[String] = Nonedisable_web_page_preview: Optional[Boolean] = Noneprotect_content: Optional[Boolean] = Nonetimeout: Optional[Union[Integer, Float, ClientTimeout]] = Noneserver: TelegramAPIServer = TelegramAPIServer(base=’https://api.telegram.org/bot{token}/{method}’, file=’https://api.telegram.org/file/bot{token}/{path}’))[source]

Bases: BaseBotDataMixinContextInstanceMixin

Base bot class

Instructions how to get Bot token is found here: https://core.telegram.org/bots#3-how-do-i-create-a-botParameters

  • token (str) – token from @BotFather
  • loop (Optional Union asyncio.BaseEventLoopasyncio.AbstractEventLoop) – event loop
  • connections_limit (int) – connections limit for aiohttp.ClientSession
  • proxy (str) – HTTP proxy URL
  • proxy_auth (Optional aiohttp.BasicAuth) – Authentication information
  • validate_token (bool) – Validate token.
  • parse_mode (str) – You can set default parse mode
  • disable_web_page_preview (bool) – You can set default disable web page preview parameter
  • protect_content (typing.Optional[base.Boolean]) – Protects the contents of sent messages from forwarding and saving
  • timeout (typing.Optional[typing.Union[base.Integer, base.Float, aiohttp.ClientTimeout]]) – Request timeout
  • server (TelegramAPIServer) – Telegram Bot API Server endpoint.

Raise

when token is invalid throw an aiogram.utils.exceptions.ValidationErrorpropertymeUser

Alias for self.get_me() but lazy and with caching.Returns

aiogram.types.Userasyncdownload_file_by_id(file_id: base.Stringdestination: Optional[base.InputFile, pathlib.Path] = Nonetimeout: base.Integer = 30chunk_size: base.Integer = 65536seek: base.Boolean = Truedestination_dir: Optional[Union[str, pathlib.Path]] = Nonemake_dirs: Optional[base.Boolean] = True)[source]

Download file by file_id to destination file or directory

if You want to automatically create destination (io.BytesIO) use default value of destination and handle result of this method.

At most one of these parameters can be used: :param destination:, :param destination_dir:Parameters

  • file_id – str
  • destination – filename or instance of io.IOBase. For e. g. io.BytesIO
  • timeout – int
  • chunk_size – int
  • seek – bool – go to start of file when downloading is finished
  • destination_dir – directory for saving files
  • make_dirs – Make dirs if not exist

Returns

destinationasyncget_updates(offset: Optional[Integer] = Nonelimit: Optional[Integer] = Nonetimeout: Optional[Integer] = Noneallowed_updates: Optional[List[String]] = None)→ List[Update][source]

Use this method to receive incoming updates using long polling (wiki).

Notes 1. This method will not work if an outgoing webhook is set up. 2. In order to avoid getting duplicate updates, recalculate offset after each server response.

Source: https://core.telegram.org/bots/api#getupdatesParameters

  • offset (typing.Optional[base.Integer]) – Identifier of the first update to be returned
  • limit (typing.Optional[base.Integer]) – Limits the number of updates to be retrieved
  • timeout (typing.Optional[base.Integer]) – Timeout in seconds for long polling
  • allowed_updates (typing.Union[typing.List[base.String], None]) – List the types of updates you want your bot to receive

Returns

An Array of Update objects is returnedReturn type

typing.List[types.Update]asyncset_webhook(url: Stringcertificate: Optional[InputFile] = Noneip_address: Optional[String] = Nonemax_connections: Optional[Integer] = Noneallowed_updates: Optional[List[String]] = Nonedrop_pending_updates: Optional[Boolean] = Nonesecret_token: Optional[str] = None)→ Boolean[source]

Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts. Returns True on success.

If you’d like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL, e.g. https://www.example.com/<token>. Since nobody else knows your bot’s token, you can be pretty sure it’s us.

Source: https://core.telegram.org/bots/api#setwebhookParameters

  • url (base.String) – HTTPS url to send updates to. Use an empty string to remove webhook integration
  • certificate (typing.Optional[base.InputFile]) – Upload your public key certificate so that the root certificate in use can be checked. See our self-signed guide for details: https://core.telegram.org/bots/self-signed
  • ip_address (typing.Optional[base.String]) – The fixed IP address which will be used to send webhook requests instead of the IP address resolved through DNS
  • max_connections (typing.Optional[base.Integer]) – 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.
  • allowed_updates (typing.Optional[typing.List[base.String]]) – 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 Update for a complete list of available update types. Specify an empty list to receive all updates regardless of type (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 setWebhook, so unwanted updates may be received for a short period of time.
  • drop_pending_updates (typing.Optional[base.Boolean]) – Pass True to drop all pending updates
  • secret_token (typing.Optional[str]) – 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.

Returns

Returns trueReturn type

base.Booleanasyncdelete_webhook(drop_pending_updates: Optional[Boolean] = None)→ Boolean[source]

Use this method to remove webhook integration if you decide to switch back to getUpdates. Returns True on success.

Source: https://core.telegram.org/bots/api#deletewebhookParameters

drop_pending_updates (typing.Optional[base.Boolean]) – Pass True to drop all pending updatesReturns

Returns True on successReturn type

base.Booleanasyncget_webhook_info()→ WebhookInfo[source]

Use this method to get current webhook status. Requires no parameters.

If the bot is using getUpdates, will return an object with the url field empty.

Source: https://core.telegram.org/bots/api#getwebhookinfoReturns

On success, returns a WebhookInfo objectReturn type

types.WebhookInfoasyncget_me()→ User[source]

A simple method for testing your bot’s auth token. Requires no parameters.

Source: https://core.telegram.org/bots/api#getmeReturns

Returns basic information about the bot in form of a User objectReturn type

types.Userasynclog_out()→ Boolean[source]

Use this method to log out from the cloud Bot API server before launching the bot locally. You must log out the bot before running it locally, otherwise there is no guarantee that the bot will receive updates. After a successful call, you will not be able to log in again using the same token for 10 minutes. Returns True on success. Requires no parameters.

Source: https://core.telegram.org/bots/api#logoutReturns

Returns True on successReturn type

base.Booleanclose_bot()→ Boolean[source]

Use this method to close the bot instance before moving it from one local server to another. You need to delete the webhook before calling this method to ensure that the bot isn’t launched again after server restart. The method will return error 429 in the first 10 minutes after the bot is launched. Returns True on success. Requires no parameters.

Source: https://core.telegram.org/bots/api#closeReturns

Returns True on successReturn type

base.Booleanasyncsend_message(chat_id: Union[Integer, String]text: Stringparse_mode: Optional[String] = Noneentities: Optional[List[MessageEntity]] = Nonedisable_web_page_preview: Optional[Boolean] = Nonedisable_notification: Optional[Boolean] = Noneprotect_content: Optional[Boolean] = Nonereply_to_message_id: Optional[Integer] = Noneallow_sending_without_reply: Optional[Boolean] = Nonereply_markup: Optional[Union[InlineKeyboardMarkupReplyKeyboardMarkupReplyKeyboardRemoveForceReply]] = None)→ Message[source]

Use this method to send text messages.

Source: https://core.telegram.org/bots/api#sendmessageParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel
  • text (base.String) – Text of the message to be sent
  • parse_mode (typing.Optional[base.String]) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.
  • entities (typing.Optional[typing.List[types.MessageEntity]]) – List of special entities that appear in message text, which can be specified instead of parse_mode
  • disable_web_page_preview (typing.Optional[base.Boolean]) – Disables link previews for links in this message
  • disable_notification (typing.Optional[base.Boolean]) – Sends the message silently. Users will receive a notification with no sound
  • protect_content (typing.Optional[base.Boolean]) – Protects the contents of sent messages from forwarding and saving
  • reply_to_message_id (typing.Optional[base.Integer]) – If the message is a reply, ID of the original message
  • allow_sending_without_reply (typing.Optional[base.Boolean]) – Pass True, if the message should be sent even if the specified replied-to message is not found
  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, 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

Returns

On success, the sent Message is returnedReturn type

types.Messageasyncforward_message(chat_id: Union[Integer, String]from_chat_id: Union[Integer, String]message_id: Integerdisable_notification: Optional[Boolean] = Noneprotect_content: Optional[Boolean] = None)→ Message[source]

Use this method to forward messages of any kind.

Source: https://core.telegram.org/bots/api#forwardmessageParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel
  • from_chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the chat where the original message was sent
  • disable_notification (typing.Optional[base.Boolean]) – Sends the message silently. Users will receive a notification with no sound
  • protect_content (typing.Optional[base.Boolean]) – Protects the contents of the forwarded message from forwarding and saving
  • message_id (base.Integer) – Message identifier in the chat specified in from_chat_id

Returns

On success, the sent Message is returnedReturn type

types.Messageasynccopy_message(chat_id: Union[Integer, String]from_chat_id: Union[Integer, String]message_id: Integercaption: Optional[String] = Noneparse_mode: Optional[String] = Nonecaption_entities: Optional[List[MessageEntity]] = Nonedisable_notification: Optional[Boolean] = Noneprotect_content: Optional[Boolean] = Nonereply_to_message_id: Optional[Integer] = Noneallow_sending_without_reply: Optional[Boolean] = Nonereply_markup: Optional[Union[InlineKeyboardMarkupReplyKeyboardMarkupReplyKeyboardRemoveForceReply]] = None)→ MessageId[source]

Use this method to copy messages of any kind. The method is analogous to the method forwardMessages, but the copied message doesn’t have a link to the original message. Returns the MessageId of the sent message on success.

Source: https://core.telegram.org/bots/api#copymessageParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
  • from_chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)
  • message_id (base.Integer) – Message identifier in the chat specified in from_chat_id
  • caption (typing.Optional[base.String]) – New caption for media, 0-1024 characters after entities parsing. If not specified, the original caption is kept
  • parse_mode (typing.Optional[base.String]) – Mode for parsing entities in the new caption. See formatting options for more details: https://core.telegram.org/bots/api#formatting-options
  • caption_entities (typing.Optional[typing.List[types.MessageEntity]]) – List of special entities that appear in the new caption, which can be specified instead of parse_mode
  • disable_notification (typing.Optional[base.Boolean]) – Sends the message silently. Users will receive a notification with no sound
  • protect_content (typing.Optional[base.Boolean]) – Protects the contents of sent messages from forwarding and saving
  • reply_to_message_id (typing.Optional[base.Integer]) – If the message is a reply, ID of the original message
  • allow_sending_without_reply (typing.Optional[base.Boolean]) – Pass True, if the message should be sent even if the specified replied-to message is not found
  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, 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.

Returns

On success, the sent Message is returnedReturn type

types.Messageasyncsend_photo(chat_id: Union[Integer, String]photo: Union[InputFile, String]caption: Optional[String] = Noneparse_mode: Optional[String] = Nonecaption_entities: Optional[List[MessageEntity]] = Nonedisable_notification: Optional[Boolean] = Noneprotect_content: Optional[Boolean] = Nonereply_to_message_id: Optional[Integer] = Noneallow_sending_without_reply: Optional[Boolean] = Nonereply_markup: Optional[Union[InlineKeyboardMarkupReplyKeyboardMarkupReplyKeyboardRemoveForceReply]] = None)→ Message[source]

Use this method to send photos.

Source: https://core.telegram.org/bots/api#sendphotoParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel
  • photo (typing.Union[base.InputFile, base.String]) – Photo to send
  • caption (typing.Optional[base.String]) – Photo caption (may also be used when resending photos by file_id), 0-1024 characters
  • parse_mode (typing.Optional[base.String]) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.
  • caption_entities (typing.Optional[typing.List[types.MessageEntity]]) – List of special entities that appear in message text, which can be specified instead of parse_mode
  • disable_notification (typing.Optional[base.Boolean]) – Sends the message silently. Users will receive a notification with no sound
  • protect_content (typing.Optional[base.Boolean]) – Protects the contents of sent messages from forwarding and saving
  • reply_to_message_id (typing.Optional[base.Integer]) – If the message is a reply, ID of the original message
  • allow_sending_without_reply (typing.Optional[base.Boolean]) – Pass True, if the message should be sent even if the specified replied-to message is not found
  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, 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

Returns

On success, the sent Message is returnedReturn type

types.Messageasyncsend_audio(chat_id: Union[Integer, String]audio: Union[InputFile, String]caption: Optional[String] = Noneparse_mode: Optional[String] = Nonecaption_entities: Optional[List[MessageEntity]] = Noneduration: Optional[Integer] = Noneperformer: Optional[String] = Nonetitle: Optional[String] = Nonethumb: Optional[Union[InputFile, String]] = Nonedisable_notification: Optional[Boolean] = Noneprotect_content: Optional[Boolean] = Nonereply_to_message_id: Optional[Integer] = Noneallow_sending_without_reply: Optional[Boolean] = Nonereply_markup: Optional[Union[InlineKeyboardMarkupReplyKeyboardMarkupReplyKeyboardRemoveForceReply]] = None)→ Message[source]

Use this method to send audio files, if you want Telegram clients to display them in the music player. Your audio must be in the .mp3 format.

For sending voice messages, use the sendVoice method instead.

Source: https://core.telegram.org/bots/api#sendaudioParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel
  • audio (typing.Union[base.InputFile, base.String]) – Audio file to send
  • caption (typing.Optional[base.String]) – Audio caption, 0-1024 characters
  • parse_mode (typing.Optional[base.String]) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.
  • caption_entities (typing.Optional[typing.List[types.MessageEntity]]) – List of special entities that appear in message text, which can be specified instead of parse_mode
  • duration (typing.Optional[base.Integer]) – Duration of the audio in seconds
  • performer (typing.Optional[base.String]) – Performer
  • title (typing.Optional[base.String]) – Track name
  • thumb (typing.Union[base.InputFile, base.String, None]) – Thumbnail of the file sent
  • disable_notification (typing.Optional[base.Boolean]) – Sends the message silently. Users will receive a notification with no sound
  • protect_content (typing.Optional[base.Boolean]) – Protects the contents of sent messages from forwarding and saving
  • reply_to_message_id (typing.Optional[base.Integer]) – If the message is a reply, ID of the original message
  • allow_sending_without_reply (typing.Optional[base.Boolean]) – Pass True, if the message should be sent even if the specified replied-to message is not found
  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, 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

Returns

On success, the sent Message is returnedReturn type

types.Messageasyncsend_document(chat_id: Union[Integer, String]document: Union[InputFile, String]thumb: Optional[Union[InputFile, String]] = Nonecaption: Optional[String] = Noneparse_mode: Optional[String] = Nonecaption_entities: Optional[List[MessageEntity]] = Nonedisable_content_type_detection: Optional[Boolean] = Nonedisable_notification: Optional[Boolean] = Noneprotect_content: Optional[Boolean] = Nonereply_to_message_id: Optional[Integer] = Noneallow_sending_without_reply: Optional[Boolean] = Nonereply_markup: Optional[Union[InlineKeyboardMarkupReplyKeyboardMarkupReplyKeyboardRemoveForceReply]] = None)→ Message[source]

Use this method to send general files. On success, the sent Message is returned. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.

Source: https://core.telegram.org/bots/api#senddocumentParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel
  • document (typing.Union[base.InputFile, base.String]) – File to send
  • thumb (typing.Union[base.InputFile, base.String, None]) – Thumbnail of the file sent
  • caption (typing.Optional[base.String]) – Document caption (may also be used when resending documents by file_id), 0-1024 characters
  • disable_content_type_detection (typing.Optional[base.Boolean]) – Disables automatic server-side content type detection for files uploaded using multipart/form-data
  • parse_mode (typing.Optional[base.String]) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.
  • caption_entities (typing.Optional[typing.List[types.MessageEntity]]) – List of special entities that appear in message text, which can be specified instead of parse_mode
  • disable_notification (typing.Optional[base.Boolean]) – Sends the message silently. Users will receive a notification with no sound
  • protect_content (typing.Optional[base.Boolean]) – Protects the contents of sent messages from forwarding and saving
  • reply_to_message_id (typing.Optional[base.Integer]) – If the message is a reply, ID of the original message
  • allow_sending_without_reply (typing.Optional[base.Boolean]) – Pass True, if the message should be sent even if the specified replied-to message is not found
  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply], 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

Returns

On success, the sent Message is returnedReturn type

types.Messageasyncsend_video(chat_id: Union[Integer, String]video: Union[InputFile, String]duration: Optional[Integer] = Nonewidth: Optional[Integer] = Noneheight: Optional[Integer] = Nonethumb: Optional[Union[InputFile, String]] = Nonecaption: Optional[String] = Noneparse_mode: Optional[String] = Nonecaption_entities: Optional[List[MessageEntity]] = Nonesupports_streaming: Optional[Boolean] = Nonedisable_notification: Optional[Boolean] = Noneprotect_content: Optional[Boolean] = Nonereply_to_message_id: Optional[Integer] = Noneallow_sending_without_reply: Optional[Boolean] = Nonereply_markup: Optional[Union[InlineKeyboardMarkupReplyKeyboardMarkupReplyKeyboardRemoveForceReply]] = None)→ Message[source]

Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document).

Source: https://core.telegram.org/bots/api#sendvideoParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel
  • video (typing.Union[base.InputFile, base.String]) – Video to send
  • duration (typing.Optional[base.Integer]) – Duration of sent video in seconds
  • width (typing.Optional[base.Integer]) – Video width
  • height (typing.Optional[base.Integer]) – Video height
  • thumb (typing.Union[base.InputFile, base.String, None]) – Thumbnail of the file sent
  • caption (typing.Optional[base.String]) – Video caption (may also be used when resending videos by file_id), 0-1024 characters
  • parse_mode (typing.Optional[base.String]) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.
  • caption_entities (typing.Optional[typing.List[types.MessageEntity]]) – List of special entities that appear in message text, which can be specified instead of parse_mode
  • supports_streaming (typing.Optional[base.Boolean]) – Pass True, if the uploaded video is suitable for streaming
  • disable_notification (typing.Optional[base.Boolean]) – Sends the message silently. Users will receive a notification with no sound
  • protect_content (typing.Optional[base.Boolean]) – Protects the contents of sent messages from forwarding and saving
  • reply_to_message_id (typing.Optional[base.Integer]) – If the message is a reply, ID of the original message
  • allow_sending_without_reply (typing.Optional[base.Boolean]) – Pass True, if the message should be sent even if the specified replied-to message is not found
  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, 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

Returns

On success, the sent Message is returnedReturn type

types.Messageasyncsend_animation(chat_id: Union[Integer, String]animation: Union[InputFile, String]duration: Optional[Integer] = Nonewidth: Optional[Integer] = Noneheight: Optional[Integer] = Nonethumb: Optional[Union[InputFile, String]] = Nonecaption: Optional[String] = Noneparse_mode: Optional[String] = Nonecaption_entities: Optional[List[MessageEntity]] = Nonedisable_notification: Optional[Boolean] = Noneprotect_content: Optional[Boolean] = Nonereply_to_message_id: Optional[Integer] = Noneallow_sending_without_reply: Optional[Boolean] = Nonereply_markup: Optional[Union[InlineKeyboardMarkupReplyKeyboardMarkupReplyKeyboardRemoveForceReply]] = None)→ Message[source]

Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound).

On success, the sent Message is returned. Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future.

Source https://core.telegram.org/bots/api#sendanimationParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
  • animation (typing.Union[base.InputFile, base.String]) – Animation to send. Pass a file_id as String to send an animation that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an animation from the Internet, or upload a new animation using multipart/form-data
  • duration (typing.Optional[base.Integer]) – Duration of sent animation in seconds
  • width (typing.Optional[base.Integer]) – Animation width
  • height (typing.Optional[base.Integer]) – Animation height
  • thumb (typing.Union[typing.Union[base.InputFile, base.String], None]) – Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnail‘s width and height should not exceed 320.
  • caption (typing.Optional[base.String]) – Animation caption (may also be used when resending animation by file_id), 0-1024 characters
  • parse_mode (typing.Optional[base.String]) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption
  • caption_entities (typing.Optional[typing.List[types.MessageEntity]]) – List of special entities that appear in message text, which can be specified instead of parse_mode
  • disable_notification (typing.Optional[base.Boolean]) – Sends the message silently. Users will receive a notification with no sound
  • protect_content (typing.Optional[base.Boolean]) – Protects the contents of sent messages from forwarding and saving
  • reply_to_message_id (typing.Optional[base.Integer]) – If the message is a reply, ID of the original message
  • allow_sending_without_reply (typing.Optional[base.Boolean]) – Pass True, if the message should be sent even if the specified replied-to message is not found
  • reply_markup (typing.Union[typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply], 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

Returns

On success, the sent Message is returnedReturn type

types.Messageasyncsend_voice(chat_id: Union[Integer, String]voice: Union[InputFile, String]caption: Optional[String] = Noneparse_mode: Optional[String] = Nonecaption_entities: Optional[List[MessageEntity]] = Noneduration: Optional[Integer] = Nonedisable_notification: Optional[Boolean] = Noneprotect_content: Optional[Boolean] = Nonereply_to_message_id: Optional[Integer] = Noneallow_sending_without_reply: Optional[Boolean] = Nonereply_markup: Optional[Union[InlineKeyboardMarkupReplyKeyboardMarkupReplyKeyboardRemoveForceReply]] = None)→ Message[source]

Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message.

For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Audio or Document).

Source: https://core.telegram.org/bots/api#sendvoiceParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel
  • voice (typing.Union[base.InputFile, base.String]) – Audio file to send
  • caption (typing.Optional[base.String]) – Voice message caption, 0-1024 characters
  • parse_mode (typing.Optional[base.String]) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.
  • caption_entities (typing.Optional[typing.List[types.MessageEntity]]) – List of special entities that appear in message text, which can be specified instead of parse_mode
  • duration (typing.Optional[base.Integer]) – Duration of the voice message in seconds
  • disable_notification (typing.Optional[base.Boolean]) – Sends the message silently. Users will receive a notification with no sound
  • protect_content (typing.Optional[base.Boolean]) – Protects the contents of sent messages from forwarding and saving
  • reply_to_message_id (typing.Optional[base.Integer]) – If the message is a reply, ID of the original message
  • allow_sending_without_reply (typing.Optional[base.Boolean]) – Pass True, if the message should be sent even if the specified replied-to message is not found
  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, 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

Returns

On success, the sent Message is returnedReturn type

types.Messageasyncsend_video_note(chat_id: Union[Integer, String]video_note: Union[InputFile, String]duration: Optional[Integer] = Nonelength: Optional[Integer] = Nonethumb: Optional[Union[InputFile, String]] = Nonedisable_notification: Optional[Boolean] = Noneprotect_content: Optional[Boolean] = Nonereply_to_message_id: Optional[Integer] = Noneallow_sending_without_reply: Optional[Boolean] = Nonereply_markup: Optional[Union[InlineKeyboardMarkupReplyKeyboardMarkupReplyKeyboardRemoveForceReply]] = None)→ Message[source]

As of v.4.0, Telegram clients support rounded square mp4 videos of up to 1 minute long. Use this method to send video messages.

Source: https://core.telegram.org/bots/api#sendvideonoteParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel
  • video_note (typing.Union[base.InputFile, base.String]) – Video note to send
  • duration (typing.Optional[base.Integer]) – Duration of sent video in seconds
  • length (typing.Optional[base.Integer]) – Video width and height
  • thumb (typing.Union[base.InputFile, base.String, None]) – Thumbnail of the file sent
  • disable_notification (typing.Optional[base.Boolean]) – Sends the message silently. Users will receive a notification with no sound
  • protect_content (typing.Optional[base.Boolean]) – Protects the contents of sent messages from forwarding and saving
  • reply_to_message_id (typing.Optional[base.Integer]) – If the message is a reply, ID of the original message
  • allow_sending_without_reply (typing.Optional[base.Boolean]) – Pass True, if the message should be sent even if the specified replied-to message is not found
  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, 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

Returns

On success, the sent Message is returnedReturn type

types.Messageasyncsend_media_group(chat_id: Union[Integer, String]media: Union[MediaGroup, List]disable_notification: Optional[Boolean] = Noneprotect_content: Optional[Boolean] = Nonereply_to_message_id: Optional[Integer] = Noneallow_sending_without_reply: Optional[Boolean] = None)→ List[Message][source]

Use this method to send a group of photos, videos, documents or audios as an album. Documents and audio files can be only group in an album with messages of the same type. On success, an array of Messages that were sent is returned.

Source: https://core.telegram.org/bots/api#sendmediagroupParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
  • media (typing.Union[types.MediaGroup, typing.List]) – A JSON-serialized array describing messages to be sent, must include 2-10 items
  • disable_notification (typing.Optional[base.Boolean]) – Sends messages silently. Users will receive a notification with no sound.
  • protect_content (typing.Optional[base.Boolean]) – Protects the contents of sent messages from forwarding and saving
  • reply_to_message_id (typing.Optional[base.Integer]) – If the messages are a reply, ID of the original message
  • allow_sending_without_reply (typing.Optional[base.Boolean]) – Pass True, if the message should be sent even if the specified replied-to message is not found

Returns

On success, an array of the sent Messages is returnedReturn type

List[types.Message]asyncsend_location(chat_id: Union[Integer, String]latitude: Floatlongitude: Floathorizontal_accuracy: Optional[Float] = Nonelive_period: Optional[Integer] = Noneheading: Optional[Integer] = Noneproximity_alert_radius: Optional[Integer] = Nonedisable_notification: Optional[Boolean] = Noneprotect_content: Optional[Boolean] = Nonereply_to_message_id: Optional[Integer] = Noneallow_sending_without_reply: Optional[Boolean] = Nonereply_markup: Optional[Union[InlineKeyboardMarkupReplyKeyboardMarkupReplyKeyboardRemoveForceReply]] = None)→ Message[source]

Use this method to send point on the map.

Source: https://core.telegram.org/bots/api#sendlocationParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel
  • latitude (base.Float) – Latitude of the location
  • longitude (base.Float) – Longitude of the location
  • horizontal_accuracy (typing.Optional[base.Float]) – The radius of uncertainty for the location, measured in meters; 0-1500
  • live_period (typing.Optional[base.Integer]) – Period in seconds for which the location will be updated
  • heading (typing.Optional[base.Integer]) – For live locations, a direction in which the user is moving, in degrees. Must be between 1 and 360 if specified.
  • proximity_alert_radius (typing.Optional[base.Integer]) – For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified.
  • disable_notification (typing.Optional[base.Boolean]) – Sends the message silently. Users will receive a notification with no sound
  • protect_content (typing.Optional[base.Boolean]) – Protects the contents of sent messages from forwarding and saving
  • reply_to_message_id (typing.Optional[base.Integer]) – If the message is a reply, ID of the original message
  • allow_sending_without_reply (typing.Optional[base.Boolean]) – Pass True, if the message should be sent even if the specified replied-to message is not found
  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, 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

Returns

On success, the sent Message is returnedReturn type

types.Messageasyncedit_message_live_location(latitude: Floatlongitude: Floatchat_id: Optional[Union[Integer, String]] = Nonemessage_id: Optional[Integer] = Noneinline_message_id: Optional[String] = Nonehorizontal_accuracy: Optional[Float] = Noneheading: Optional[Integer] = Noneproximity_alert_radius: Optional[Integer] = Nonereply_markup: Optional[InlineKeyboardMarkup] = None)→ Message[source]

Use this method to edit live location messages sent by the bot or via the bot (for inline bots). A location can be edited until its live_period expires or editing is explicitly disabled by a call to stopMessageLiveLocation.

Source: https://core.telegram.org/bots/api#editmessagelivelocationParameters

  • chat_id (typing.Union[base.Integer, base.String, None]) – Required if inline_message_id is not specified
  • message_id (typing.Optional[base.Integer]) – Required if inline_message_id is not specified. Identifier of the sent message
  • inline_message_id (typing.Optional[base.String]) – Required if chat_id and message_id are not specified. Identifier of the inline message
  • latitude (base.Float) – Latitude of new location
  • longitude (base.Float) – Longitude of new location
  • horizontal_accuracy (typing.Optional[base.Float]) – The radius of uncertainty for the location, measured in meters; 0-1500
  • heading (typing.Optional[base.Integer]) – Direction in which the user is moving, in degrees. Must be between 1 and 360 if specified.
  • proximity_alert_radius (typing.Optional[base.Integer]) – For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified.
  • reply_markup (typing.Optional[types.InlineKeyboardMarkup]) – A JSON-serialized object for a new inline keyboard

Returns

On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned.Return type

typing.Union[types.Message, base.Boolean]asyncstop_message_live_location(chat_id: Optional[Union[Integer, String]] = Nonemessage_id: Optional[Integer] = Noneinline_message_id: Optional[String] = Nonereply_markup: Optional[InlineKeyboardMarkup] = None)→ Message[source]

Use this method to stop updating a live location message sent by the bot or via the bot (for inline bots) before live_period expires.

Source: https://core.telegram.org/bots/api#stopmessagelivelocationParameters

  • chat_id (typing.Union[base.Integer, base.String, None]) – Required if inline_message_id is not specified
  • message_id (typing.Optional[base.Integer]) – Required if inline_message_id is not specified. Identifier of the sent message
  • inline_message_id (typing.Optional[base.String]) – Required if chat_id and message_id are not specified. Identifier of the inline message
  • reply_markup (typing.Optional[types.InlineKeyboardMarkup]) – A JSON-serialized object for a new inline keyboard

Returns

On success, if the message was sent by the bot, the sent Message is returned, otherwise True is returned.Return type

typing.Union[types.Message, base.Boolean]asyncsend_venue(chat_id: Union[Integer, String]latitude: Floatlongitude: Floattitle: Stringaddress: Stringfoursquare_id: Optional[String] = Nonefoursquare_type: Optional[String] = Nonegoogle_place_id: Optional[String] = Nonegoogle_place_type: Optional[String] = Nonedisable_notification: Optional[Boolean] = Noneprotect_content: Optional[Boolean] = Nonereply_to_message_id: Optional[Integer] = Noneallow_sending_without_reply: Optional[Boolean] = Nonereply_markup: Optional[Union[InlineKeyboardMarkupReplyKeyboardMarkupReplyKeyboardRemoveForceReply]] = None)→ Message[source]

Use this method to send information about a venue.

Source: https://core.telegram.org/bots/api#sendvenueParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
  • latitude (base.Float) – Latitude of the venue
  • longitude (base.Float) – Longitude of the venue
  • title (base.String) – Name of the venue
  • address (base.String) – Address of the venue
  • foursquare_id (typing.Optional[base.String]) – Foursquare identifier of the venue
  • foursquare_type (typing.Optional[base.String]) – Foursquare type of the venue, if known
  • google_place_id (typing.Optional[base.String]) – Google Places identifier of the venue
  • google_place_type (typing.Optional[base.String]) – Google Places type of the venue. See supported types: https://developers.google.com/places/web-service/supported_types
  • disable_notification (typing.Optional[base.Boolean]) – Sends the message silently. Users will receive a notification with no sound
  • protect_content (typing.Optional[base.Boolean]) – Protects the contents of sent messages from forwarding and saving
  • reply_to_message_id (typing.Optional[base.Integer]) – If the message is a reply, ID of the original message
  • allow_sending_without_reply (typing.Optional[base.Boolean]) – Pass True, if the message should be sent even if the specified replied-to message is not found
  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, 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

Returns

On success, the sent Message is returnedReturn type

types.Messageasyncsend_contact(chat_id: Union[Integer, String]phone_number: Stringfirst_name: Stringlast_name: Optional[String] = Nonevcard: Optional[String] = Nonedisable_notification: Optional[Boolean] = Noneprotect_content: Optional[Boolean] = Nonereply_to_message_id: Optional[Integer] = Noneallow_sending_without_reply: Optional[Boolean] = Nonereply_markup: Optional[Union[InlineKeyboardMarkupReplyKeyboardMarkupReplyKeyboardRemoveForceReply]] = None)→ Message[source]

Use this method to send phone contacts.

Source: https://core.telegram.org/bots/api#sendcontactParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel
  • phone_number (base.String) – Contact’s phone number
  • first_name (base.String) – Contact’s first name
  • last_name (typing.Optional[base.String]) – Contact’s last name
  • vcard (typing.Optional[base.String]) – vcard
  • disable_notification (typing.Optional[base.Boolean]) – Sends the message silently. Users will receive a notification with no sound
  • protect_content (typing.Optional[base.Boolean]) – Protects the contents of sent messages from forwarding and saving
  • reply_to_message_id (typing.Optional[base.Integer]) – If the message is a reply, ID of the original message
  • allow_sending_without_reply (typing.Optional[base.Boolean]) – Pass True, if the message should be sent even if the specified replied-to message is not found
  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, 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

Returns

On success, the sent Message is returnedReturn type

types.Messageasyncsend_poll(chat_id: Union[Integer, String]question: Stringoptions: List[String]is_anonymous: Optional[Boolean] = Nonetype: Optional[String] = Noneallows_multiple_answers: Optional[Boolean] = Nonecorrect_option_id: Optional[Integer] = Noneexplanation: Optional[String] = Noneexplanation_parse_mode: Optional[String] = Noneexplanation_entities: Optional[List[MessageEntity]] = Noneopen_period: Optional[Integer] = Noneclose_date: Optional[Union[Integer, datetime, timedelta]] = Noneis_closed: Optional[Boolean] = Nonedisable_notification: Optional[Boolean] = Noneprotect_content: Optional[Boolean] = Nonereply_to_message_id: Optional[Integer] = Noneallow_sending_without_reply: Optional[Boolean] = Nonereply_markup: Optional[Union[InlineKeyboardMarkupReplyKeyboardMarkupReplyKeyboardRemoveForceReply]] = None)→ Message[source]

Use this method to send a native poll. On success, the sent Message is returned.

Source: https://core.telegram.org/bots/api#sendpollParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
  • question (base.String) – Poll question, 1-300 characters
  • options (typing.List[base.String]) – A list of answer options, 2-10 strings 1-100 characters each
  • is_anonymous (typing.Optional[base.Boolean]) – True, if the poll needs to be anonymous, defaults to True
  • type (typing.Optional[base.String]) – Poll type, “quiz” or “regular”, defaults to “regular”
  • allows_multiple_answers (typing.Optional[base.Boolean]) – True, if the poll allows multiple answers, ignored for polls in quiz mode, defaults to False
  • correct_option_id (typing.Optional[base.Integer]) – 0-based identifier of the correct answer option, required for polls in quiz mode
  • explanation (typing.Optional[base.String]) – Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters with at most 2 line feeds after entities parsing
  • explanation_parse_mode (typing.Optional[base.String]) – Mode for parsing entities in the explanation. See formatting options for more details.
  • explanation_entities (typing.Optional[typing.List[types.MessageEntity]]) – List of special entities that appear in message text, which can be specified instead of parse_mode
  • open_period (typing.Optional[base.Integer]) – Amount of time in seconds the poll will be active after creation, 5-600. Can’t be used together with close_date.
  • close_date (typing.Union[base.Integer, datetime.datetime, datetime.timedelta, None]) –Point in time (Unix timestamp) when the poll will be automatically closed. Must be at least 5 and no more than 600 seconds inthe future. Can’t be used together with open_period.
  • is_closed (typing.Optional[base.Boolean]) – Pass True, if the poll needs to be immediately closed
  • disable_notification (typing.Optional[Boolean]) – Sends the message silently. Users will receive a notification with no sound.
  • protect_content (typing.Optional[base.Boolean]) – Protects the contents of sent messages from forwarding and saving
  • reply_to_message_id (typing.Optional[Integer]) – If the message is a reply, ID of the original message
  • allow_sending_without_reply (typing.Optional[base.Boolean]) – Pass True, if the message should be sent even if the specified replied-to message is not found
  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, 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

Returns

On success, the sent Message is returnedReturn type

types.Messageasyncsend_dice(chat_id: Union[Integer, String]disable_notification: Optional[Boolean] = Noneprotect_content: Optional[Boolean] = Noneemoji: Optional[String] = Nonereply_to_message_id: Optional[Integer] = Noneallow_sending_without_reply: Optional[Boolean] = Nonereply_markup: Optional[Union[InlineKeyboardMarkupReplyKeyboardMarkupReplyKeyboardRemoveForceReply]] = None)→ Message[source]

Use this method to send an animated emoji that will display a random value. On success, the sent Message is returned.

Source: https://core.telegram.org/bots/api#senddiceParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
  • emoji (typing.Optional[base.String]) – Emoji on which the dice throw animation is based. Currently, must be one of “🎲”, “🎯”, “🏀”, “⚽”, or “🎰”. Dice can have values 1-6 for “🎲” and “🎯”, values 1-5 for “🏀” and “⚽”, and values 1-64 for “🎰”. Defaults to “🎲”
  • disable_notification (typing.Optional[base.Boolean]) – Sends the message silently. Users will receive a notification with no sound
  • protect_content (typing.Optional[base.Boolean]) – Protects the contents of sent messages from forwarding and saving
  • reply_to_message_id (typing.Optional[base.Integer]) – If the message is a reply, ID of the original message
  • allow_sending_without_reply (typing.Optional[base.Boolean]) – Pass True, if the message should be sent even if the specified replied-to message is not found
  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, 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

Returns

On success, the sent Message is returnedReturn type

types.Messageasyncsend_chat_action(chat_id: Union[Integer, String]action: String)→ Boolean[source]

Use this method when you need to tell the user that something is happening on the bot’s side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). Returns True on success.

Example: The ImageBot needs some time to process a request and upload the image. Instead of sending a text message along the lines of “Retrieving image, please wait…”, the bot may use sendChatAction with action = upload_photo. The user will see a “sending photo” status for the bot.

We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive.

Source: https://core.telegram.org/bots/api#sendchatactionParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
  • action (base.String) – Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_voice or upload_voice for voice notes, upload_document for general files, find_location for location data, record_video_note or upload_video_note for video notes.

Returns

Returns True on successReturn type

base.Booleanasyncget_user_profile_photos(user_id: Integeroffset: Optional[Integer] = Nonelimit: Optional[Integer] = None)→ UserProfilePhotos[source]

Use this method to get a list of profile pictures for a user. Returns a UserProfilePhotos object.

Source: https://core.telegram.org/bots/api#getuserprofilephotosParameters

  • user_id (base.Integer) – Unique identifier of the target user
  • offset (typing.Optional[base.Integer]) – Sequential number of the first photo to be returned. By default, all photos are returned
  • limit (typing.Optional[base.Integer]) – Limits the number of photos to be retrieved. Values between 1—100 are accepted. Defaults to 100

Returns

Returns a UserProfilePhotos objectReturn type

types.UserProfilePhotosasyncget_file(file_id: String)→ File[source]

Use this method to get basic info about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size.

Note: This function may not preserve the original file name and MIME type. You should save the file’s MIME type and name (if available) when the File object is received.

Source: https://core.telegram.org/bots/api#getfileParameters

file_id (base.String) – File identifier to get info aboutReturns

On success, a File object is returnedReturn type

types.Fileasyncban_chat_member(chat_id: Union[Integer, String]user_id: Integeruntil_date: Optional[Union[Integer, datetime, timedelta]] = Nonerevoke_messages: Optional[Boolean] = None)→ Boolean[source]

Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless unbanned first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success.

Source: https://core.telegram.org/bots/api#banchatmemberParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target group or username of the target supergroup or channel (in the format @channelusername)
  • user_id (base.Integer) – Unique identifier of the target user
  • until_date (typing.Union[base.Integer, datetime.datetime, datetime.timedelta, None]) – Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever. Applied for supergroups and channels only.
  • revoke_messages (typing.Optional[base.Boolean]) – Pass True to delete all messages from the chat for the user that is being removed. If False, the user will be able to see messages in the group that were sent before the user was removed. Always True for supergroups and channels.

Returns

Returns True on successReturn type

base.Booleanasynckick_chat_member(chat_id: Union[Integer, String]user_id: Integeruntil_date: Optional[Union[Integer, datetime, timedelta]] = Nonerevoke_messages: Optional[Boolean] = None)→ Boolean[source]

Renamed to ban_chat_member.asyncunban_chat_member(chat_id: Union[Integer, String]user_id: Integeronly_if_banned: Optional[Boolean] = None)→ Boolean[source]

Use this method to unban a previously kicked user in a supergroup or channel. The user will not return to the group or channel automatically, but will be able to join via link, etc. The bot must be an administrator for this to work. By default, this method guarantees that after the call the user is not a member of the chat, but will be able to join it. So if the user is a member of the chat they will also be removed from the chat. If you don’t want this, use the parameter only_if_banned. Returns True on success.

Source: https://core.telegram.org/bots/api#unbanchatmemberParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target group or username of the target supergroup or channel (in the format @username)
  • user_id (base.Integer) – Unique identifier of the target user
  • only_if_banned (typing.Optional[base.Boolean]) – Do nothing if the user is not banned

Returns

Returns True on successReturn type

base.Booleanasyncrestrict_chat_member(chat_id: Union[Integer, String]user_id: Integerpermissions: Optional[ChatPermissions] = Noneuntil_date: Optional[Union[Integer, datetime, timedelta]] = Nonecan_send_messages: Optional[Boolean] = Nonecan_send_media_messages: Optional[Boolean] = Nonecan_send_other_messages: Optional[Boolean] = Nonecan_add_web_page_previews: Optional[Boolean] = None)→ Boolean[source]

Use this method to restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. Pass True for all boolean parameters to lift restrictions from a user.

Source: https://core.telegram.org/bots/api#restrictchatmemberParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target supergroup
  • user_id (base.Integer) – Unique identifier of the target user
  • permissions (ChatPermissions) – New user permissions
  • until_date (typing.Optional[base.Integer]) – Date when restrictions will be lifted for the user, unix time
  • can_send_messages (typing.Optional[base.Boolean]) – Pass True, if the user can send text messages, contacts, locations and venues
  • can_send_media_messages (typing.Optional[base.Boolean]) – Pass True, if the user can send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages
  • can_send_other_messages (typing.Optional[base.Boolean]) – Pass True, if the user can send animations, games, stickers and use inline bots, implies can_send_media_messages
  • can_add_web_page_previews (typing.Optional[base.Boolean]) – Pass True, if the user may add web page previews to their messages, implies can_send_media_messages

Returns

Returns True on successReturn type

base.Booleanasyncpromote_chat_member(chat_id: Union[Integer, String]user_id: Integeris_anonymous: Optional[Boolean] = Nonecan_manage_chat: Optional[Boolean] = Nonecan_change_info: Optional[Boolean] = Nonecan_post_messages: Optional[Boolean] = Nonecan_edit_messages: Optional[Boolean] = Nonecan_delete_messages: Optional[Boolean] = Nonecan_manage_voice_chats: Optional[Boolean] = Nonecan_invite_users: Optional[Boolean] = Nonecan_restrict_members: Optional[Boolean] = Nonecan_pin_messages: Optional[Boolean] = Nonecan_promote_members: Optional[Boolean] = Nonecan_manage_video_chats: Optional[Boolean] = None)→ Boolean[source]

Use this method to promote or demote a user in a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Pass False for all boolean parameters to demote a user.

Source: https://core.telegram.org/bots/api#promotechatmemberParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel
  • user_id (base.Integer) – Unique identifier of the target user
  • is_anonymous (typing.Optional[base.Boolean]) – Pass True, if the administrator’s presence in the chat is hidden
  • can_manage_chat (typing.Optional[base.Boolean]) – Pass True, if the administrator can access the chat event log, chat statistics, message statistics in channels, see channel members, see anonymous administrators in supergroups and ignore slow mode. Implied by any other administrator privilege
  • can_change_info (typing.Optional[base.Boolean]) – Pass True, if the administrator can change chat title, photo and other settings
  • can_post_messages (typing.Optional[base.Boolean]) – Pass True, if the administrator can create channel posts, channels only
  • can_edit_messages (typing.Optional[base.Boolean]) – Pass True, if the administrator can edit messages of other users, channels only
  • can_delete_messages (typing.Optional[base.Boolean]) – Pass True, if the administrator can delete messages of other users
  • can_manage_voice_chats (typing.Optional[base.Boolean]) – Pass True, if the administrator can manage voice chats, supergroups only
  • can_invite_users (typing.Optional[base.Boolean]) – Pass True, if the administrator can invite new users to the chat
  • can_restrict_members (typing.Optional[base.Boolean]) – Pass True, if the administrator can restrict, ban or unban chat members
  • can_pin_messages (typing.Optional[base.Boolean]) – Pass True, if the administrator can pin messages, supergroups only
  • can_promote_members (typing.Optional[base.Boolean]) – Pass True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by him)
  • can_manage_video_chats – Pass True, if the administrator can manage video chats

Returns

Returns True on successReturn type

base.Booleanasyncset_chat_administrator_custom_title(chat_id: Union[Integer, String]user_id: Integercustom_title: String)→ Boolean[source]

Use this method to set a custom title for an administrator in a supergroup promoted by the bot.

Returns True on success.

Source: https://core.telegram.org/bots/api#setchatadministratorcustomtitleParameters

  • chat_id – Unique identifier for the target chat or username of the target supergroup
  • user_id – Unique identifier of the target user
  • custom_title – New custom title for the administrator; 0-16 characters, emoji are not allowed

Returns

True on success.asyncban_chat_sender_chat(chat_id: Union[Integer, String]sender_chat_id: Integer)[source]

Ban a channel chat in a supergroup or a channel.

Until the chat is unbanned, the owner of the banned chat won’t be able to send messages on behalf of any of their channels. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on success.

Source: https://core.telegram.org/bots/api#banchatsenderchatParameters

  • chat_id – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
  • sender_chat_id – Unique identifier of the target sender chat

asyncunban_chat_sender_chat(chat_id: Union[Integer, String]sender_chat_id: Integer)[source]

Unban a previously banned channel chat in a supergroup or channel.

The bot must be an administrator for this to work and must have the appropriate administrator rights. Returns True on success.

Source: https://core.telegram.org/bots/api#unbanchatsenderchatParameters

  • chat_id – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
  • sender_chat_id – Unique identifier of the target sender chat

asyncset_chat_permissions(chat_id: Union[Integer, String]permissions: ChatPermissions)→ Boolean[source]

Use this method to set default chat permissions for all members. The bot must be an administrator in the group or a supergroup for this to work and must have the can_restrict_members admin rights.

Returns True on success.Parameters

  • chat_id – Unique identifier for the target chat or username of the target supergroup
  • permissions – New default chat permissions

Returns

True on success.asyncexport_chat_invite_link(chat_id: Union[Integer, String])→ String[source]

Use this method to generate a new invite link for a chat; any previously generated link is revoked. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

Source: https://core.telegram.org/bots/api#exportchatinvitelinkParameters

chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channelReturns

Returns exported invite link as String on successReturn type

base.Stringasynccreate_chat_invite_link(chat_id: Union[Integer, String]expire_date: Optional[Union[Integer, datetime, timedelta]] = Nonemember_limit: Optional[Integer] = Nonename: Optional[String] = Nonecreates_join_request: Optional[Boolean] = None)→ ChatInviteLink[source]

Use this method to create an additional invite link for a chat. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. The link can be revoked using the method revokeChatInviteLink.

Source: https://core.telegram.org/bots/api#createchatinvitelinkParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
  • expire_date (typing.Union[base.Integer, datetime.datetime, datetime.timedelta, None]) – Point in time when the link will expire
  • member_limit (typing.Optional[base.Integer]) – Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999
  • name (typing.Optional[base.String]) – Invite link name; 0-32 characters
  • creates_join_request (typing.Optional[base.Boolean]) – True, if users joining the chat via the link need to be approved by chat administrators. If True, member_limit can’t be specified

Returns

the new invite link as ChatInviteLink object.Return type

types.ChatInviteLinkasyncedit_chat_invite_link(chat_id: Union[Integer, String]invite_link: Stringexpire_date: Optional[Union[Integer, datetime, timedelta]] = Nonemember_limit: Optional[Integer] = Nonename: Optional[String] = Nonecreates_join_request: Optional[Boolean] = None)→ ChatInviteLink[source]

Use this method to edit a non-primary invite link created by the bot. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

Source: https://core.telegram.org/bots/api#editchatinvitelinkParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
  • invite_link (base.String) – The invite link to edit
  • expire_date (typing.Union[base.Integer, datetime.datetime, datetime.timedelta, None]) – Point in time (Unix timestamp) when the link will expire
  • member_limit (typing.Optional[base.Integer]) – Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999
  • name (typing.Optional[base.String]) – Invite link name; 0-32 characters
  • creates_join_request (typing.Optional[base.Boolean]) – True, if users joining the chat via the link need to be approved by chat administrators. If True, member_limit can’t be specified

Returns

edited invite link as a ChatInviteLink object.asyncrevoke_chat_invite_link(chat_id: Union[Integer, String]invite_link: String)→ ChatInviteLink[source]

Use this method to revoke an invite link created by the bot. If the primary link is revoked, a new link is automatically generated. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

Source: https://core.telegram.org/bots/api#revokechatinvitelinkParameters

  • chat_id – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
  • invite_link – The invite link to revoke

Returns

the revoked invite link as ChatInviteLink objectasyncapprove_chat_join_request(chat_id: Union[Integer, String]user_id: Integer)→ Boolean[source]

Use this method to approve a chat join request. The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right.

Returns True on success.

Source: https://core.telegram.org/bots/api#approvechatjoinrequestParameters

  • chat_id (Union[base.Integerbase.String]) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
  • user_id (base.Integer) – Unique identifier of the target user

Returnsasyncdecline_chat_join_request(chat_id: Union[Integer, String]user_id: Integer)→ Boolean[source]

Use this method to decline a chat join request. The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right. Returns True on success.

Returns True on success.

Source: https://core.telegram.org/bots/api#declinechatjoinrequestParameters

  • chat_id (Union[base.Integerbase.String]) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
  • user_id (base.Integer) – Unique identifier of the target user

Returnsasyncset_chat_photo(chat_id: Union[Integer, String]photo: InputFile)→ Boolean[source]

Use this method to set a new profile photo for the chat. Photos can’t be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

Note: In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’ setting is off in the target group.

Source: https://core.telegram.org/bots/api#setchatphotoParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel
  • photo (base.InputFile) – New chat photo, uploaded using multipart/form-data

Returns

Returns True on successReturn type

base.Booleanasyncdelete_chat_photo(chat_id: Union[Integer, String])→ Boolean[source]

Use this method to delete a chat photo. Photos can’t be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

Note: In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’ setting is off in the target group.

Source: https://core.telegram.org/bots/api#deletechatphotoParameters

chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channelReturns

Returns True on successReturn type

base.Booleanasyncset_chat_title(chat_id: Union[Integer, String]title: String)→ Boolean[source]

Use this method to change the title of a chat. Titles can’t be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

Note: In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’ setting is off in the target group.

Source: https://core.telegram.org/bots/api#setchattitleParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel
  • title (base.String) – New chat title, 1-255 characters

Returns

Returns True on successReturn type

base.Booleanasyncset_chat_description(chat_id: Union[Integer, String]description: Optional[String] = None)→ Boolean[source]

Use this method to change the description of a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

Source: https://core.telegram.org/bots/api#setchatdescriptionParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel
  • description (typing.Optional[base.String]) – New chat description, 0-255 characters

Returns

Returns True on successReturn type

base.Booleanasyncpin_chat_message(chat_id: Union[Integer, String]message_id: Integerdisable_notification: Optional[Boolean] = None)→ Boolean[source]

Use this method to add a message to the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the ‘can_pin_messages’ admin right in a supergroup or ‘can_edit_messages’ admin right in a channel. Returns True on success.

Source: https://core.telegram.org/bots/api#pinchatmessageParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
  • message_id (base.Integer) – Identifier of a message to pin
  • disable_notification (typing.Optional[base.Boolean]) – Pass True, if it is not necessary to send a notification to all group members about the new pinned message

Returns

Returns True on successReturn type

base.Booleanasyncunpin_chat_message(chat_id: Union[Integer, String]message_id: Optional[Integer] = None)→ Boolean[source]

Use this method to remove a message from the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the ‘can_pin_messages’ admin right in a supergroup or ‘can_edit_messages’ admin right in a channel. Returns True on success.

Source: https://core.telegram.org/bots/api#unpinchatmessageParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
  • message_id (typing.Optional[base.Integer]) – Identifier of a message to unpin. If not specified, the most recent pinned message (by sending date) will be unpinned.

Returns

Returns True on successReturn type

base.Booleanasyncunpin_all_chat_messages(chat_id: Union[Integer, String])→ Boolean[source]

Use this method to clear the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the ‘can_pin_messages’ admin right in a supergroup or ‘can_edit_messages’ admin right in a channel. Returns True on success.

Source: https://core.telegram.org/bots/api#unpinallchatmessagesParameters

chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)Returns

Returns True on successReturn type

base.Booleanasyncleave_chat(chat_id: Union[Integer, String])→ Boolean[source]

Use this method for your bot to leave a group, supergroup or channel.

Source: https://core.telegram.org/bots/api#leavechatParameters

chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target supergroup or channelReturns

Returns True on successReturn type

base.Booleanasyncget_chat(chat_id: Union[Integer, String])→ Chat[source]

Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.).

Source: https://core.telegram.org/bots/api#getchatParameters

chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target supergroup or channelReturns

Returns a Chat object on successReturn type

types.Chatasyncget_chat_administrators(chat_id: Union[Integer, String])→ List[Union[ChatMemberOwner, ChatMemberAdministrator]][source]

Use this method to get a list of administrators in a chat.

Source: https://core.telegram.org/bots/api#getchatadministratorsParameters

chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target supergroup or channelReturns

On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots. If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned.Return type

typing.List[types.ChatMember]asyncget_chat_member_count(chat_id: Union[Integer, String])→ Integer[source]

Use this method to get the number of members in a chat.

Source: https://core.telegram.org/bots/api#getchatmembercountParameters

chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target supergroup or channelReturns

Returns Int on successReturn type

base.Integerasyncget_chat_members_count(chat_id: Union[Integer, String])→ Integer[source]

Renamed to get_chat_member_count.asyncget_chat_member(chat_id: Union[Integer, String]user_id: Integer)→ ChatMember[source]

Use this method to get information about a member of a chat.

Source: https://core.telegram.org/bots/api#getchatmemberParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target supergroup or channel
  • user_id (base.Integer) – Unique identifier of the target user

Returns

Returns a ChatMember object on successReturn type

types.ChatMemberasyncset_chat_sticker_set(chat_id: Union[Integer, String]sticker_set_name: String)→ Boolean[source]

Use this method to set a new group sticker set for a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method.

Source: https://core.telegram.org/bots/api#setchatstickersetParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target supergroup
  • sticker_set_name (base.String) – Name of the sticker set to be set as the group sticker set

Returns

Returns True on successReturn type

base.Booleanasyncdelete_chat_sticker_set(chat_id: Union[Integer, String])→ Boolean[source]

Use this method to delete a group sticker set from a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method.

Source: https://core.telegram.org/bots/api#deletechatstickersetParameters

chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target supergroupReturns

Returns True on successReturn type

base.Booleanasyncanswer_callback_query(callback_query_id: Stringtext: Optional[String] = Noneshow_alert: Optional[Boolean] = Noneurl: Optional[String] = Nonecache_time: Optional[Integer] = None)→ Boolean[source]

Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert.

Alternatively, the user can be redirected to the specified Game URL. For this option to work, you must first create a game for your bot via @Botfather and accept the terms. Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.

Source: https://core.telegram.org/bots/api#answercallbackqueryParameters

  • callback_query_id (base.String) – Unique identifier for the query to be answered
  • text (typing.Optional[base.String]) – Text of the notification. If not specified, nothing will be shown to the user, 0-1024 characters
  • show_alert (typing.Optional[base.Boolean]) – If true, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false.
  • url (typing.Optional[base.String]) – URL that will be opened by the user’s client
  • cache_time (typing.Optional[base.Integer]) – The maximum amount of time in seconds that the result of the callback query may be cached client-side.

Returns

On success, True is returnedReturn type

base.Booleanasyncset_my_commands(commands: List[BotCommand]scope: Optional[BotCommandScope] = Nonelanguage_code: Optional[String] = None)→ Boolean[source]

Use this method to change the list of the bot’s commands.

Source: https://core.telegram.org/bots/api#setmycommandsParameters

  • commands – A JSON-serialized list of bot commands to be set as the list of the bot’s commands. At most 100 commands can be specified.
  • scope – A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault.
  • language_code – A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands

Returns

Returns True on success.Return type

base.Booleanasyncdelete_my_commands(scope: Optional[BotCommandScope] = Nonelanguage_code: Optional[String] = None)→ Boolean[source]

Use this method to delete the list of the bot’s commands for the given scope and user language. After deletion, higher level commands will be shown to affected users.

Source: https://core.telegram.org/bots/api#deletemycommandsParameters

  • scope – A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault.
  • language_code – A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands

Returns

Returns True on success.Return type

base.Booleanasyncget_my_commands(scope: Optional[BotCommandScope] = Nonelanguage_code: Optional[String] = None)→ List[BotCommand][source]

Use this method to get the current list of the bot’s commands for the given scope and user language. Returns Array of BotCommand on success. If commands aren’t set, an empty list is returned.

Source: https://core.telegram.org/bots/api#getmycommandsParameters

  • scope – A JSON-serialized object, describing scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault.
  • language_code – A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands

Returns

Returns Array of BotCommand on success or empty list.Return type

typing.List[types.BotCommand]asyncset_chat_menu_button(chat_id: Optional[Integer] = Nonemenu_button: Optional[MenuButton] = None)→ bool[source]

Use this method to change bot’s menu button in a private chat, or the default menu button.

Returns True on success.

Source https://core.telegram.org/bots/api#setchatmenubuttonParameters

  • chat_id – Unique identifier for the target private chat. If not specified, default bot’s menu button will be changed
  • menu_button – A JSON-serialized object for the new bot’s menu button. Defaults to MenuButtonDefault

Returns

Returns True on success.asyncget_chat_menu_button(chat_id: Optional[Integer] = None)→ Union[types.MenuButtonCommands, types.MenuButtonDefault, types.MenuButtonWebApp][source]

Use this method to get the current value of the bot’s menu button in a private chat, or the default menu button.

Returns MenuButton on success.

Source https://core.telegram.org/bots/api#getchatmenuParameters

chat_id – Unique identifier for the target private chat. If not specified, default bot’s menu button will be returnedReturns

Returns MenuButton on success.asyncset_my_default_administrator_rights(rights: Optional[ChatAdministratorRights] = Nonefor_channels: Optional[Boolean] = None)→ Boolean[source]

Use this method to change default administrator rights of the bot for adding it as an administrator to groups or channels. Returns True on success.

Source: https://core.telegram.org/bots/api#setmydefaultadministratorrightsParameters

  • rights – A JSON-serialized object, describing new default administrator rights. If not specified, the default administrator rights will be cleared.
  • for_channels – Pass True to change default administrator rights of the bot in channels. Otherwise, default administrator rights of the bot for groups and supergroups will be changed.

Returns

Returns True on success.asyncget_my_default_administrator_rights(for_channels: Optional[Boolean] = None)→ ChatAdministratorRights[source]

Use this method to get the current default administrator rights of the bot. Returns ChatAdministratorRights on success.

Source: https://core.telegram.org/bots/api#getmydefaultadministratorrightsParameters

for_channels – Pass True to get default administrator rights of the bot in channels. Otherwise, default administrator rights of the bot for groups and supergroups will be returned.Returnsasyncedit_message_text(text: Stringchat_id: Optional[Union[Integer, String]] = Nonemessage_id: Optional[Integer] = Noneinline_message_id: Optional[String] = Noneparse_mode: Optional[String] = Noneentities: Optional[List[MessageEntity]] = Nonedisable_web_page_preview: Optional[Boolean] = Nonereply_markup: Optional[InlineKeyboardMarkup] = None)→ Message[source]

Use this method to edit text and game messages sent by the bot or via the bot (for inline bots).

Source: https://core.telegram.org/bots/api#editmessagetextParameters

  • chat_id (typing.Union[base.Integer, base.String, None]) – Required if inline_message_id is not specified Unique identifier for the target chat or username of the target channel
  • message_id (typing.Optional[base.Integer]) – Required if inline_message_id is not specified. Identifier of the sent message
  • inline_message_id (typing.Optional[base.String]) – Required if chat_id and message_id are not specified. Identifier of the inline message
  • text (base.String) – New text of the message
  • parse_mode (typing.Optional[base.String]) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.
  • entities (typing.Optional[typing.List[types.MessageEntity]]) – List of special entities that appear in message text, which can be specified instead of parse_mode
  • disable_web_page_preview (typing.Optional[base.Boolean]) – Disables link previews for links in this message
  • reply_markup (typing.Optional[types.InlineKeyboardMarkup]) – A JSON-serialized object for an inline keyboard

Returns

On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.Return type

typing.Union[types.Message, base.Boolean]asyncedit_message_caption(chat_id: Optional[Union[Integer, String]] = Nonemessage_id: Optional[Integer] = Noneinline_message_id: Optional[String] = Nonecaption: Optional[String] = Noneparse_mode: Optional[String] = Nonecaption_entities: Optional[List[MessageEntity]] = Nonereply_markup: Optional[InlineKeyboardMarkup] = None)→ Message[source]

Use this method to edit captions of messages sent by the bot or via the bot (for inline bots).

Source: https://core.telegram.org/bots/api#editmessagecaptionParameters

  • chat_id (typing.Union[base.Integer, base.String, None]) – Required if inline_message_id is not specified Unique identifier for the target chat or username of the target channel
  • message_id (typing.Optional[base.Integer]) – Required if inline_message_id is not specified. Identifier of the sent message
  • inline_message_id (typing.Optional[base.String]) – Required if chat_id and message_id are not specified. Identifier of the inline message
  • caption (typing.Optional[base.String]) – New caption of the message
  • parse_mode (typing.Optional[base.String]) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.
  • caption_entities (typing.Optional[typing.List[types.MessageEntity]]) – List of special entities that appear in message text, which can be specified instead of parse_mode
  • reply_markup (typing.Optional[types.InlineKeyboardMarkup]) – A JSON-serialized object for an inline keyboard

Returns

On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.Return type

typing.Union[types.Message, base.Boolean]asyncedit_message_media(media: InputMediachat_id: Optional[Union[Integer, String]] = Nonemessage_id: Optional[Integer] = Noneinline_message_id: Optional[String] = Nonereply_markup: Optional[InlineKeyboardMarkup] = None)→ Union[Message, Boolean][source]

Use this method to edit audio, document, photo, or video messages. If a message is a part of a message album, then it can be edited only to a photo or a video. Otherwise, message type can be changed arbitrarily. When inline message is edited, new file can’t be uploaded. Use previously uploaded file via its file_id or specify a URL.

On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned.

Source https://core.telegram.org/bots/api#editmessagemediaParameters

  • chat_id (typing.Union[typing.Union[base.Integer, base.String], None]) – Required if inline_message_id is not specified
  • message_id (typing.Optional[base.Integer]) – Required if inline_message_id is not specified. Identifier of the sent message
  • inline_message_id (typing.Optional[base.String]) – Required if chat_id and message_id are not specified. Identifier of the inline message
  • media (types.InputMedia) – A JSON-serialized object for a new media content of the message
  • reply_markup (typing.Optional[types.InlineKeyboardMarkup]) – A JSON-serialized object for a new inline keyboard

Returns

On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returnedReturn type

typing.Union[types.Message, base.Boolean]asyncedit_message_reply_markup(chat_id: Optional[Union[Integer, String]] = Nonemessage_id: Optional[Integer] = Noneinline_message_id: Optional[String] = Nonereply_markup: Optional[InlineKeyboardMarkup] = None)→ Message[source]

Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots).

Source: https://core.telegram.org/bots/api#editmessagereplymarkupParameters

  • chat_id (typing.Union[base.Integer, base.String, None]) – Required if inline_message_id is not specified Unique identifier for the target chat or username of the target channel
  • message_id (typing.Optional[base.Integer]) – Required if inline_message_id is not specified. Identifier of the sent message
  • inline_message_id (typing.Optional[base.String]) – Required if chat_id and message_id are not specified. Identifier of the inline message
  • reply_markup (typing.Optional[types.InlineKeyboardMarkup]) – A JSON-serialized object for an inline keyboard

Returns

On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.Return type

typing.Union[types.Message, base.Boolean]asyncstop_poll(chat_id: Union[String, Integer]message_id: Integerreply_markup: Optional[InlineKeyboardMarkup] = None)→ Poll[source]

Use this method to stop a poll which was sent by the bot. On success, the stopped Poll with the final results is returned.Parameters

  • chat_id (typing.Union[base.String, base.Integer]) – Unique identifier for the target chat or username of the target channel
  • message_id (base.Integer) – Identifier of the original message with the poll
  • reply_markup (typing.Optional[types.InlineKeyboardMarkup]) – A JSON-serialized object for a new message inline keyboard.

Returns

On success, the stopped Poll with the final results is returned.Return type

types.Pollasyncdelete_message(chat_id: Union[Integer, String]message_id: Integer)→ Boolean[source]

Use this method to delete a message, including service messages, with the following limitations: – A message can only be deleted if it was sent less than 48 hours ago. – Bots can delete outgoing messages in private chats, groups, and supergroups. – Bots can delete incoming messages in private chats. – Bots granted can_post_messages permissions can delete outgoing messages in channels. – If the bot is an administrator of a group, it can delete any message there. – If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there.

Source: https://core.telegram.org/bots/api#deletemessageParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel
  • message_id (base.Integer) – Identifier of the message to delete

Returns

Returns True on successReturn type

base.Booleanasyncsend_sticker(chat_id: Union[Integer, String]sticker: Union[InputFile, String]disable_notification: Optional[Boolean] = Noneprotect_content: Optional[Boolean] = Nonereply_to_message_id: Optional[Integer] = Noneallow_sending_without_reply: Optional[Boolean] = Nonereply_markup: Optional[Union[InlineKeyboardMarkupReplyKeyboardMarkupReplyKeyboardRemoveForceReply]] = None)→ Message[source]

Use this method to send .webp stickers.

Source: https://core.telegram.org/bots/api#sendstickerParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel
  • sticker (typing.Union[base.InputFile, base.String]) – Sticker to send
  • disable_notification (typing.Optional[base.Boolean]) – Sends the message silently. Users will receive a notification with no sound
  • protect_content (typing.Optional[base.Boolean]) – Protects the contents of sent messages from forwarding and saving
  • reply_to_message_id (typing.Optional[base.Integer]) – If the message is a reply, ID of the original message
  • allow_sending_without_reply (typing.Optional[base.Boolean]) – Pass True, if the message should be sent even if the specified replied-to message is not found
  • reply_markup (typing.Union[types.InlineKeyboardMarkup, types.ReplyKeyboardMarkup, types.ReplyKeyboardRemove, types.ForceReply, 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

Returns

On success, the sent Message is returnedReturn type

types.Messageasyncget_sticker_set(name: String)→ StickerSet[source]

Use this method to get a sticker set.

Source: https://core.telegram.org/bots/api#getstickersetParameters

name (base.String) – Name of the sticker setReturns

On success, a StickerSet object is returnedReturn type

types.StickerSetasyncupload_sticker_file(user_id: Integerpng_sticker: InputFile)→ File[source]

Use this method to upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet methods (can be used multiple times).

Source: https://core.telegram.org/bots/api#uploadstickerfileParameters

  • user_id (base.Integer) – User identifier of sticker file owner
  • png_sticker (base.InputFile) – Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px.

Returns

Returns the uploaded File on successReturn type

types.Fileasyncget_custom_emoji_stickers(custom_emoji_ids: List[String])→ List[Sticker][source]

Use this method to get information about custom emoji stickers by their identifiers.

Source: https://core.telegram.org/bots/api#uploadstickerfileParameters

custom_emoji_ids (typing.List[base.String]) – User identifier of sticker file ownerReturns

Returns an Array of Sticker objects.Return type

typing.List[types.Sticker]asynccreate_new_sticker_set(user_id: Integername: Stringtitle: Stringemojis: Stringpng_sticker: Optional[Union[InputFile, String]] = Nonetgs_sticker: Optional[InputFile] = Nonewebm_sticker: Optional[InputFile] = Nonecontains_masks: Optional[Boolean] = Nonesticker_type: Optional[String] = Nonemask_position: Optional[MaskPosition] = None)→ Boolean[source]

Use this method to create a new sticker set owned by a user. The bot will be able to edit the sticker set thus created. You must use exactly one of the fields png_sticker or tgs_sticker.

Source: https://core.telegram.org/bots/api#createnewstickersetParameters

  • user_id (base.Integer) – User identifier of created sticker set owner
  • name (base.String) – Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g., animals). Can contain only english letters, digits and underscores. Must begin with a letter, can’t contain consecutive underscores and must end in “_by_<bot username>”. <bot_username> is case insensitive. 1-64 characters.
  • title (base.String) – Sticker set title, 1-64 characters
  • png_sticker (typing.Union[base.InputFile, base.String]) – PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. Pass a file_id as a String to send a file that already exists on the Telegram servers, 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. More info on https://core.telegram.org/bots/api#sending-files
  • tgs_sticker (base.InputFile) – TGS animation with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements
  • webm_sticker (base.String) – WEBM video with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/stickers#video-sticker-requirements for technical requirements
  • sticker_type (base.InputFile) – Type of stickers in the set, pass “regular” or “mask”. Custom emoji sticker sets can’t be created via the Bot API at the moment. By default, a regular sticker set is created.
  • emojis (base.String) – One or more emoji corresponding to the sticker
  • contains_masks (typing.Optional[base.Boolean]) – Pass True, if a set of mask stickers should be created
  • mask_position (typing.Optional[types.MaskPosition]) – A JSON-serialized object for position where the mask should be placed on faces

Returns

Returns True on successReturn type

base.Booleanasyncadd_sticker_to_set(user_id: Integername: Stringemojis: Stringpng_sticker: Optional[Union[InputFile, String]] = Nonetgs_sticker: Optional[InputFile] = Nonewebm_sticker: Optional[InputFile] = Nonemask_position: Optional[MaskPosition] = None)→ Boolean[source]

Use this method to add a new sticker to a set created by the bot. You must use exactly one of the fields png_sticker or tgs_sticker. Animated stickers can be added to animated sticker sets and only to them. Animated sticker sets can have up to 50 stickers. Static sticker sets can have up to 120 stickers.

Source: https://core.telegram.org/bots/api#addstickertosetParameters

  • user_id (base.Integer) – User identifier of sticker set owner
  • name (base.String) – Sticker set name
  • png_sticker (typing.Union[base.InputFile, base.String]) – PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. Pass a file_id as a String to send a file that already exists on the Telegram servers, 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. More info on https://core.telegram.org/bots/api#sending-files
  • tgs_sticker (base.InputFile) – TGS animation with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements
  • webm_sticker (base.InputFile) – WEBM video with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/stickers#video-sticker-requirements for technical requirements
  • emojis (base.String) – One or more emoji corresponding to the sticker
  • mask_position (typing.Optional[types.MaskPosition]) – A JSON-serialized object for position where the mask should be placed on faces

Returns

Returns True on successReturn type

base.Booleanasyncset_sticker_position_in_set(sticker: Stringposition: Integer)→ Boolean[source]

Use this method to move a sticker in a set created by the bot to a specific position.

Source: https://core.telegram.org/bots/api#setstickerpositioninsetParameters

  • sticker (base.String) – File identifier of the sticker
  • position (base.Integer) – New sticker position in the set, zero-based

Returns

Returns True on successReturn type

base.Booleanasyncdelete_sticker_from_set(sticker: String)→ Boolean[source]

Use this method to delete a sticker from a set created by the bot.

Source: https://core.telegram.org/bots/api#deletestickerfromsetParameters

sticker (base.String) – File identifier of the stickerReturns

Returns True on successReturn type

base.Booleanasyncset_sticker_set_thumb(name: Stringuser_id: Integerthumb: Optional[Union[InputFile, String]] = None)→ Boolean[source]

Use this method to set the thumbnail of a sticker set. Animated thumbnails can be set for animated sticker sets only.

Source: https://core.telegram.org/bots/api#setstickersetthumbParameters

  • name (base.String) – Sticker set name
  • user_id (base.Integer) – User identifier of the sticker set owner
  • thumb (typing.Union[base.InputFile, base.String]) – A PNG image with the thumbnail, must be up to 128 kilobytes in size and have width and height exactly 100px, or a TGS animation with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/stickers#animated-sticker-requirements for animated sticker technical requirements, or a WEBM video with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/stickers#video-sticker-requirements for video sticker technical requirements. Pass a file_id as a String to send a file that already exists on the Telegram servers, 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. More info on https://core.telegram.org/bots/api#sending-files. Animated sticker set thumbnail can’t be uploaded via HTTP URL.

Returns

Returns True on successReturn type

base.Booleanasyncanswer_inline_query(inline_query_id: Stringresults: List[InlineQueryResult]cache_time: Optional[Integer] = Noneis_personal: Optional[Boolean] = Nonenext_offset: Optional[String] = Noneswitch_pm_text: Optional[String] = Noneswitch_pm_parameter: Optional[String] = None)→ Boolean[source]

Use this method to send answers to an inline query. No more than 50 results per query are allowed.

Source: https://core.telegram.org/bots/api#answerinlinequeryParameters

  • inline_query_id (base.String) – Unique identifier for the answered query
  • results (typing.List[types.InlineQueryResult]) – A JSON-serialized array of results for the inline query
  • cache_time (typing.Optional[base.Integer]) – The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300.
  • is_personal (typing.Optional[base.Boolean]) – Pass True, if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query
  • next_offset (typing.Optional[base.String]) – Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don‘t support pagination. Offset length can’t exceed 64 bytes.
  • switch_pm_text (typing.Optional[base.String]) – If passed, clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter switch_pm_parameter
  • switch_pm_parameter (typing.Optional[base.String]) – Deep-linking parameter for the /start message sent to the bot when user presses the switch button. 1-64 characters, only A-Z, a-z, 0-9, _ and – are allowed.

Returns

On success, True is returnedReturn type

base.Booleanasyncanswer_web_app_query(web_app_query_id: Stringresult: InlineQueryResult)→ SentWebAppMessage[source]

Use this method to set result of interaction with web app and send corresponding message on behalf of the user to the chat from which the query originated. On success, SentWebAppMessage is returned.

Source https://core.telegram.org/bots/api#answerwebappqueryParameters

  • web_app_query_id – Unique identifier for the answered query
  • result – A JSON-serialized object with a description of the message to send

Returns

On success, SentWebAppMessage is returned.asyncsend_invoice(chat_id: Union[Integer, String]title: Stringdescription: Stringpayload: Stringprovider_token: Stringcurrency: Stringprices: List[LabeledPrice]max_tip_amount: Optional[Integer] = Nonesuggested_tip_amounts: Optional[List[Integer]] = Nonestart_parameter: Optional[String] = Noneprovider_data: Optional[Dict] = Nonephoto_url: Optional[String] = Nonephoto_size: Optional[Integer] = Nonephoto_width: Optional[Integer] = Nonephoto_height: Optional[Integer] = Noneneed_name: Optional[Boolean] = Noneneed_phone_number: Optional[Boolean] = Noneneed_email: Optional[Boolean] = Noneneed_shipping_address: Optional[Boolean] = Nonesend_phone_number_to_provider: Optional[Boolean] = Nonesend_email_to_provider: Optional[Boolean] = Noneis_flexible: Optional[Boolean] = Nonedisable_notification: Optional[Boolean] = Noneprotect_content: Optional[Boolean] = Nonereply_to_message_id: Optional[Integer] = Noneallow_sending_without_reply: Optional[Boolean] = Nonereply_markup: Optional[InlineKeyboardMarkup] = None)→ Message[source]

Use this method to send invoices.

Source: https://core.telegram.org/bots/api#sendinvoiceParameters

  • chat_id (typing.Union[base.Integer, base.String]) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)
  • title (base.String) – Product name, 1-32 characters
  • description (base.String) – Product description, 1-255 characters
  • payload (base.String) – Bot-defined invoice payload, 1-128 bytes This will not be displayed to the user, use for your internal processes.
  • provider_token (base.String) – Payments provider token, obtained via Botfather
  • currency (base.String) – Three-letter ISO 4217 currency code, see more on currencies
  • prices (typing.List[types.LabeledPrice]) – Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
  • max_tip_amount (typing.Optional[base.Integer]) – The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0
  • suggested_tip_amounts (typing.Optional[typing.List[base.Integer]]) – A JSON-serialized array of suggested amounts of tips in the smallest units of the currency (integer, not float/double). At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount.
  • start_parameter (typing.Optional[base.String]) – Unique deep-linking parameter. If left empty, forwarded copies of the sent message will have a Pay button, allowing multiple users to pay directly from the forwarded message, using the same invoice. If non-empty, forwarded copies of the sent message will have a URL button with a deep link to the bot (instead of a Pay button), with the value used as the start parameter
  • provider_data (typing.Optional[typing.Dict]) – JSON-encoded data about the invoice, which will be shared with the payment provider
  • photo_url (typing.Optional[base.String]) – URL of the product photo for the invoice
  • photo_size (typing.Optional[base.Integer]) – Photo size
  • photo_width (typing.Optional[base.Integer]) – Photo width
  • photo_height (typing.Optional[base.Integer]) – Photo height
  • need_name (typing.Optional[base.Boolean]) – Pass True, if you require the user’s full name to complete the order
  • need_phone_number (typing.Optional[base.Boolean]) – Pass True, if you require the user’s phone number to complete the order
  • need_email (typing.Optional[base.Boolean]) – Pass True, if you require the user’s email to complete the order
  • need_shipping_address (typing.Optional[base.Boolean]) – Pass True, if you require the user’s shipping address to complete the order
  • send_phone_number_to_provider (typing.Optional[base.Boolean]) – Pass True, if user’s phone number should be sent to provider
  • send_email_to_provider (typing.Optional[base.Boolean]) – Pass True, if user’s email address should be sent to provider
  • is_flexible (typing.Optional[base.Boolean]) – Pass True, if the final price depends on the shipping method
  • disable_notification (typing.Optional[base.Boolean]) – Sends the message silently. Users will receive a notification with no sound
  • protect_content (typing.Optional[base.Boolean]) – Protects the contents of sent messages from forwarding and saving
  • reply_to_message_id (typing.Optional[base.Integer]) – If the message is a reply, ID of the original message
  • allow_sending_without_reply (typing.Optional[base.Boolean]) – Pass True, if the message should be sent even if the specified replied-to message is not found
  • reply_markup (typing.Optional[types.InlineKeyboardMarkup]) – A JSON-serialized object for an inline keyboard If empty, one ‘Pay total price’ button will be shown. If not empty, the first button must be a Pay button.

Returns

On success, the sent Message is returnedReturn type

types.Messageasynccreate_invoice_link(title: Stringdescription: Stringpayload: Stringprovider_token: Stringcurrency: Stringprices: List[LabeledPrice]max_tip_amount: Optional[int] = Nonesuggested_tip_amounts: Optional[List[int]] = Noneprovider_data: Optional[String] = Nonephoto_url: Optional[str] = Nonephoto_size: Optional[int] = Nonephoto_width: Optional[int] = Nonephoto_height: Optional[int] = Noneneed_name: Optional[bool] = Noneneed_phone_number: Optional[bool] = Noneneed_email: Optional[bool] = Noneneed_shipping_address: Optional[bool] = Nonesend_phone_number_to_provider: Optional[bool] = Nonesend_email_to_provider: Optional[bool] = Noneis_flexible: Optional[bool] = None)→ str[source]

Use this method to create a link for an invoice. On success, the created link is returned.

Source: https://core.telegram.org/bots/api#createinvoicelinkParameters

  • title – Product name, 1-32 characters
  • description – Product description, 1-255 characters
  • payload – Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
  • provider_token – Payment provider token, obtained via BotFather
  • currency – Three-letter ISO 4217 currency code, see more on currencies
  • prices – Price breakdown, a JSON-serialized list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
  • max_tip_amount – The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0
  • suggested_tip_amounts – A JSON-serialized array of suggested amounts of tips in the smallest units of the currency (integer, not float/double). At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount.
  • provider_data – JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider.
  • photo_url – URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service.
  • photo_size – Photo size in bytes
  • photo_width – Photo width
  • photo_height – Photo height
  • need_name – Pass True, if you require the user’s full name to complete the order
  • need_phone_number – Pass True, if you require the user’s phone number to complete the order
  • need_email – Pass True, if you require the user’s email address to complete the order
  • need_shipping_address – Pass True, if you require the user’s shipping address to complete the order
  • send_phone_number_to_provider – Pass True, if the user’s phone number should be sent to the provider
  • send_email_to_provider – Pass True, if the user’s email address should be sent to the provider
  • is_flexible – Pass True, if the final price depends on the shipping method

Returnsasyncanswer_shipping_query(shipping_query_id: Stringok: Booleanshipping_options: Optional[List[ShippingOption]] = Noneerror_message: Optional[String] = None)→ Boolean[source]

If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API will send an Update with a shipping_query field to the bot.

Source: https://core.telegram.org/bots/api#answershippingqueryParameters

  • shipping_query_id (base.String) – Unique identifier for the query to be answered
  • ok (base.Boolean) – Specify True if delivery to the specified address is possible and False if there are any problems (for example, if delivery to the specified address is not possible)
  • shipping_options (typing.Union[typing.List[types.ShippingOption], None]) – Required if ok is True. A JSON-serialized array of available shipping options
  • error_message (typing.Optional[base.String]) – Required if ok is False Error message in human readable form that explains why it is impossible to complete the order (e.g. “Sorry, delivery to your desired address is unavailable’). Telegram will display this message to the user.

Returns

On success, True is returnedReturn type

base.Booleanasyncanswer_pre_checkout_query(pre_checkout_query_id: Stringok: Booleanerror_message: Optional[String] = None)→ Boolean[source]

Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the field pre_checkout_query. Use this method to respond to such pre-checkout queries.

Source: https://core.telegram.org/bots/api#answerprecheckoutqueryParameters

  • pre_checkout_query_id (base.String) – Unique identifier for the query to be answered
  • ok (base.Boolean) – Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems.
  • error_message (typing.Optional[base.String]) – Required if ok is False Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. “Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!”). Telegram will display this message to the user.

Returns

On success, True is returnedReturn type

base.Booleanasyncset_passport_data_errors(user_id: Integererrors: List[PassportElementError])→ Boolean[source]

Informs a user that some of the Telegram Passport elements they provided contains errors. The user will not be able to re-submit their Passport to you until the errors are fixed (the contents of the field for which you returned the error must change). Returns True on success.

Use this if the data submitted by the user doesn’t satisfy the standards your service requires for any reason. For example, if a birthday date seems invalid, a submitted document is blurry, a scan shows evidence of tampering, etc. Supply some details in the error message to make sure the user knows how to correct the issues.

Source https://core.telegram.org/bots/api#setpassportdataerrorsParameters

  • user_id (base.Integer) – User identifier
  • errors (typing.List[types.PassportElementError]) – A JSON-serialized array describing the errors

Returns

Returns True on successReturn type

base.Booleanasyncsend_game(chat_id: Integergame_short_name: Stringdisable_notification: Optional[Boolean] = Noneprotect_content: Optional[Boolean] = Nonereply_to_message_id: Optional[Integer] = Noneallow_sending_without_reply: Optional[Boolean] = Nonereply_markup: Optional[InlineKeyboardMarkup] = None)→ Message[source]

Use this method to send a game.

Source: https://core.telegram.org/bots/api#sendgameParameters

  • chat_id (base.Integer) – Unique identifier for the target chat
  • game_short_name (base.String) – Short name of the game, serves as the unique identifier for the game. Set up your games via Botfather.
  • disable_notification (typing.Optional[base.Boolean]) – Sends the message silently. Users will receive a notification with no sound
  • protect_content (typing.Optional[base.Boolean]) – Protects the contents of sent messages from forwarding and saving
  • reply_to_message_id (typing.Optional[base.Integer]) – If the message is a reply, ID of the original message
  • allow_sending_without_reply (typing.Optional[base.Boolean]) – Pass True, if the message should be sent even if the specified replied-to message is not found
  • reply_markup (typing.Optional[types.InlineKeyboardMarkup]) – A JSON-serialized object for an inline keyboard If empty, one ‘Play game_title’ button will be shown. If not empty, the first button must launch the game.

Returns

On success, the sent Message is returnedReturn type

types.Messageasyncset_game_score(user_id: Integerscore: Integerforce: Optional[Boolean] = Nonedisable_edit_message: Optional[Boolean] = Nonechat_id: Optional[Integer] = Nonemessage_id: Optional[Integer] = Noneinline_message_id: Optional[String] = None)→ Message[source]

Use this method to set the score of the specified user in a game.

Source: https://core.telegram.org/bots/api#setgamescoreParameters

  • user_id (base.Integer) – User identifier
  • score (base.Integer) – New score, must be non-negative
  • force (typing.Optional[base.Boolean]) – Pass True, if the high score is allowed to decrease This can be useful when fixing mistakes or banning cheaters
  • disable_edit_message (typing.Optional[base.Boolean]) – Pass True, if the game message should not be automatically edited to include the current scoreboard
  • chat_id (typing.Optional[base.Integer]) – Required if inline_message_id is not specified. Unique identifier for the target chat
  • message_id (typing.Optional[base.Integer]) – Required if inline_message_id is not specified. Identifier of the sent message
  • inline_message_id (typing.Optional[base.String]) – Required if chat_id and message_id are not specified. Identifier of the inline message

Returns

On success, if the message was sent by the bot, returns the edited Message, otherwise returns True Returns an error, if the new score is not greater than the user’s current score in the chat and force is False.Return type

typing.Union[types.Message, base.Boolean]asyncget_game_high_scores(user_id: Integerchat_id: Optional[Integer] = Nonemessage_id: Optional[Integer] = Noneinline_message_id: Optional[String] = None)→ List[GameHighScore][source]

Use this method to get data for high score tables.

This method will currently return scores for the target user, plus two of his closest neighbors on each side. Will also return the top three users if the user and his neighbors are not among them. Please note that this behavior is subject to change.

Source: https://core.telegram.org/bots/api#getgamehighscoresParameters

  • user_id (base.Integer) – Target user id
  • chat_id (typing.Optional[base.Integer]) – Required if inline_message_id is not specified. Unique identifier for the target chat
  • message_id (typing.Optional[base.Integer]) – Required if inline_message_id is not specified. Identifier of the sent message
  • inline_message_id (typing.Optional[base.String]) – Required if chat_id and message_id are not specified. Identifier of the inline message

Returns

Will return the score of the specified user and several of his neighbors in a game On success, returns an Array of GameHighScore objects. This method will currently return scores for the target user, plus two of his closest neighbors on each side. Will also return the top three users if the user and his neighbors are not among them.Return type

typing.List[types.GameHighScore]

API Helpers

classaiogram.bot.api.TelegramAPIServer(base: strfile: str)[source]

Bases: object

Base config for API Endpointsapi_url(token: strmethod: str)→ str[source]

Generate URL for API methodsParameters

  • token – Bot token
  • method – API method name (case insensitive)

Returns

URLfile_url(token: strpath: str)→ str[source]

Generate URL for downloading filesParameters

  • token – Bot token
  • path – file path

Returns

URLaiogram.bot.api.check_token(token: str)→ bool[source]

Validate BOT tokenParameters

token –Returnsaiogram.bot.api.check_result(method_name: strcontent_type: strstatus_code: intbody: str)[source]

Checks whether result is a valid API response. A result is considered invalid if: – The server returned an HTTP response code other than 200 – The content of the result is invalid JSON. – The method call was unsuccessful (The JSON ‘ok’ field equals False)Parameters

  • method_name – The name of the method called
  • status_code – status code
  • content_type – content type of result
  • body – result body

Returns

The result parsed to a JSON dictionaryRaises

ApiException – if one of the above listed cases is applicableaiogram.bot.api.guess_filename(obj)[source]

Get file name from objectParameters

obj –Returnsaiogram.bot.api.compose_data(params=Nonefiles=None)[source]

Prepare request dataParameters

  • params –
  • files –

Returnsclassaiogram.bot.api.Methods[source]

Bases: Helper

Helper for Telegram API Methods listed on https://core.telegram.org/bots/api