Bot object
Low level API
Subclass of this class used only for splitting network interface from all of API methods.
- class aiogram.bot.base.BaseBot(token: String, loop: Optional[Union[BaseEventLoop, AbstractEventLoop]] = None, connections_limit: Optional[Integer] = None, proxy: Optional[String] = None, proxy_auth: Optional[BasicAuth] = None, validate_token: Optional[Boolean] = True, parse_mode: Optional[String] = None, disable_web_page_preview: Optional[Boolean] = None, protect_content: Optional[Boolean] = None, timeout: Optional[Union[Integer, Float, ClientTimeout]] = None, server: 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-bot
- Parameters
token (
str
) – token from @BotFatherloop (Optional Union
asyncio.BaseEventLoop
,asyncio.AbstractEventLoop
) – event loopconnections_limit (
int
) – connections limit for aiohttp.ClientSessionproxy (
str
) – HTTP proxy URLproxy_auth (Optional
aiohttp.BasicAuth
) – Authentication informationvalidate_token (
bool
) – Validate token.parse_mode (
str
) – You can set default parse modedisable_web_page_preview (
bool
) – You can set default disable web page preview parameterprotect_content (
typing.Optional[base.Boolean]
) – Protects the contents of sent messages from forwarding and savingtimeout (
typing.Optional[typing.Union[base.Integer, base.Float, aiohttp.ClientTimeout]]
) – Request timeoutserver (
TelegramAPIServer
) – Telegram Bot API Server endpoint.
- Raise
when token is invalid throw an
aiogram.utils.exceptions.ValidationError
- request_timeout(timeout: Union[Integer, Float, ClientTimeout])[source]
Context manager implements opportunity to change request timeout in current context
- Parameters
timeout (
typing.Optional[typing.Union[base.Integer, base.Float, aiohttp.ClientTimeout]]
) – Request timeout- Returns
- async request(method: String, data: Optional[Dict] = None, files: Optional[Dict] = None, **kwargs) Union[List, Dict, Boolean] [source]
Make an request to Telegram Bot API
https://core.telegram.org/bots/api#making-requests
- Parameters
method (
str
) – API methoddata (
dict
) – request parametersfiles (
dict
) – files
- Returns
result
- Return type
Union[List, Dict]
- Raise
aiogram.exceptions.TelegramApiError
- async download_file(file_path: ~aiogram.types.base.String, destination: ~typing.Optional[~typing.Union[~aiogram.types.base.InputFile, ~pathlib.Path]] = None, timeout: ~typing.Optional[~aiogram.types.base.Integer] = <object object>, chunk_size: ~typing.Optional[~aiogram.types.base.Integer] = 65536, seek: ~typing.Optional[~aiogram.types.base.Boolean] = True, destination_dir: ~typing.Optional[~typing.Union[str, ~pathlib.Path]] = None, make_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 fromaiogram.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
destination
- async send_file(file_type, method, file, payload) Union[Dict, Boolean] [source]
Send file
https://core.telegram.org/bots/api#inputfile
- Parameters
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.BaseBot
- class aiogram.bot.bot.Bot(token: String, loop: Optional[Union[BaseEventLoop, AbstractEventLoop]] = None, connections_limit: Optional[Integer] = None, proxy: Optional[String] = None, proxy_auth: Optional[BasicAuth] = None, validate_token: Optional[Boolean] = True, parse_mode: Optional[String] = None, disable_web_page_preview: Optional[Boolean] = None, protect_content: Optional[Boolean] = None, timeout: Optional[Union[Integer, Float, ClientTimeout]] = None, server: TelegramAPIServer = TelegramAPIServer(base='https://api.telegram.org/bot{token}/{method}', file='https://api.telegram.org/file/bot{token}/{path}'))[source]
Bases:
BaseBot
,DataMixin
,ContextInstanceMixin
Base bot class
Instructions how to get Bot token is found here: https://core.telegram.org/bots#3-how-do-i-create-a-bot
- Parameters
token (
str
) – token from @BotFatherloop (Optional Union
asyncio.BaseEventLoop
,asyncio.AbstractEventLoop
) – event loopconnections_limit (
int
) – connections limit for aiohttp.ClientSessionproxy (
str
) – HTTP proxy URLproxy_auth (Optional
aiohttp.BasicAuth
) – Authentication informationvalidate_token (
bool
) – Validate token.parse_mode (
str
) – You can set default parse modedisable_web_page_preview (
bool
) – You can set default disable web page preview parameterprotect_content (
typing.Optional[base.Boolean]
) – Protects the contents of sent messages from forwarding and savingtimeout (
typing.Optional[typing.Union[base.Integer, base.Float, aiohttp.ClientTimeout]]
) – Request timeoutserver (
TelegramAPIServer
) – Telegram Bot API Server endpoint.
- Raise
when token is invalid throw an
aiogram.utils.exceptions.ValidationError
- async download_file_by_id(file_id: base.String, destination: Optional[base.InputFile, pathlib.Path] = None, timeout: base.Integer = 30, chunk_size: base.Integer = 65536, seek: base.Boolean = True, destination_dir: Optional[Union[str, pathlib.Path]] = None, make_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
destination
- async get_updates(offset: Optional[Integer] = None, limit: Optional[Integer] = None, timeout: Optional[Integer] = None, allowed_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#getupdates
- Parameters
offset (
typing.Optional[base.Integer]
) – Identifier of the first update to be returnedlimit (
typing.Optional[base.Integer]
) – Limits the number of updates to be retrievedtimeout (
typing.Optional[base.Integer]
) – Timeout in seconds for long pollingallowed_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 returned
- Return type
typing.List[types.Update]
- async set_webhook(url: String, certificate: Optional[InputFile] = None, ip_address: Optional[String] = None, max_connections: Optional[Integer] = None, allowed_updates: Optional[List[String]] = None, drop_pending_updates: Optional[Boolean] = None, secret_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#setwebhook
- Parameters
url (
base.String
) – HTTPS url to send updates to. Use an empty string to remove webhook integrationcertificate (
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-signedip_address (
typing.Optional[base.String]
) – The fixed IP address which will be used to send webhook requests instead of the IP address resolved through DNSmax_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 updatessecret_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 true
- Return type
base.Boolean
- async delete_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#deletewebhook
- Parameters
drop_pending_updates (
typing.Optional[base.Boolean]
) – Pass True to drop all pending updates- Returns
Returns True on success
- Return type
base.Boolean
- async get_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#getwebhookinfo
- Returns
On success, returns a WebhookInfo object
- Return type
types.WebhookInfo
- async get_me() User [source]
A simple method for testing your bot’s auth token. Requires no parameters.
Source: https://core.telegram.org/bots/api#getme
- Returns
Returns basic information about the bot in form of a User object
- Return type
types.User
- async log_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#logout
- Returns
Returns True on success
- Return type
base.Boolean
- close_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#close
- Returns
Returns True on success
- Return type
base.Boolean
- async send_message(chat_id: Union[Integer, String], text: String, parse_mode: Optional[String] = None, entities: Optional[List[MessageEntity]] = None, disable_web_page_preview: Optional[Boolean] = None, message_thread_id: Optional[Integer] = None, disable_notification: Optional[Boolean] = None, protect_content: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, allow_sending_without_reply: Optional[Boolean] = None, reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None) Message [source]
Use this method to send text messages.
Source: https://core.telegram.org/bots/api#sendmessage
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target channelmessage_thread_id (
typing.Optional[base.Integer]
) – Unique identifier for the target message thread (topic) of the forum; for forum supergroups onlytext (
base.String
) – Text of the message to be sentparse_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_modedisable_web_page_preview (
typing.Optional[base.Boolean]
) – Disables link previews for links in this messagedisable_notification (
typing.Optional[base.Boolean]
) – Sends the message silently. Users will receive a notification with no soundprotect_content (
typing.Optional[base.Boolean]
) – Protects the contents of sent messages from forwarding and savingreply_to_message_id (
typing.Optional[base.Integer]
) – If the message is a reply, ID of the original messageallow_sending_without_reply (
typing.Optional[base.Boolean]
) – Pass True, if the message should be sent even if the specified replied-to message is not foundreply_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 returned
- Return type
types.Message
- async forward_message(chat_id: Union[Integer, String], from_chat_id: Union[Integer, String], message_id: Integer, message_thread_id: Optional[Integer] = None, disable_notification: Optional[Boolean] = None, protect_content: Optional[Boolean] = None) Message [source]
Use this method to forward messages of any kind.
Source: https://core.telegram.org/bots/api#forwardmessage
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target channelmessage_thread_id (
typing.Optional[base.Integer]
) – Unique identifier for the target message thread (topic) of the forum; for forum supergroups onlyfrom_chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the chat where the original message was sentdisable_notification (
typing.Optional[base.Boolean]
) – Sends the message silently. Users will receive a notification with no soundprotect_content (
typing.Optional[base.Boolean]
) – Protects the contents of the forwarded message from forwarding and savingmessage_id (
base.Integer
) – Message identifier in the chat specified in from_chat_id
- Returns
On success, the sent Message is returned
- Return type
types.Message
- async copy_message(chat_id: Union[Integer, String], from_chat_id: Union[Integer, String], message_id: Integer, caption: Optional[String] = None, parse_mode: Optional[String] = None, caption_entities: Optional[List[MessageEntity]] = None, message_thread_id: Optional[Integer] = None, disable_notification: Optional[Boolean] = None, protect_content: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, allow_sending_without_reply: Optional[Boolean] = None, reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = 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#copymessage
- Parameters
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_thread_id (
typing.Optional[base.Integer]
) – Unique identifier for the target message thread (topic) of the forum; for forum supergroups onlyfrom_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_idcaption (
typing.Optional[base.String]
) – New caption for media, 0-1024 characters after entities parsing. If not specified, the original caption is keptparse_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-optionscaption_entities (
typing.Optional[typing.List[types.MessageEntity]]
) – List of special entities that appear in the new caption, which can be specified instead of parse_modedisable_notification (
typing.Optional[base.Boolean]
) – Sends the message silently. Users will receive a notification with no soundprotect_content (
typing.Optional[base.Boolean]
) – Protects the contents of sent messages from forwarding and savingreply_to_message_id (
typing.Optional[base.Integer]
) – If the message is a reply, ID of the original messageallow_sending_without_reply (
typing.Optional[base.Boolean]
) – Pass True, if the message should be sent even if the specified replied-to message is not foundreply_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 returned
- Return type
types.Message
- async send_photo(chat_id: Union[Integer, String], photo: Union[InputFile, String], caption: Optional[String] = None, parse_mode: Optional[String] = None, caption_entities: Optional[List[MessageEntity]] = None, message_thread_id: Optional[Integer] = None, disable_notification: Optional[Boolean] = None, protect_content: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, allow_sending_without_reply: Optional[Boolean] = None, reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None, has_spoiler: Optional[Boolean] = None) Message [source]
Use this method to send photos.
Source: https://core.telegram.org/bots/api#sendphoto
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target channelmessage_thread_id (
typing.Optional[base.Integer]
) – Unique identifier for the target message thread (topic) of the forum; for forum supergroups onlyphoto (
typing.Union[base.InputFile, base.String]
) – Photo to sendcaption (
typing.Optional[base.String]
) – Photo caption (may also be used when resending photos by file_id), 0-1024 charactersparse_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_modedisable_notification (
typing.Optional[base.Boolean]
) – Sends the message silently. Users will receive a notification with no soundprotect_content (
typing.Optional[base.Boolean]
) – Protects the contents of sent messages from forwarding and savingreply_to_message_id (
typing.Optional[base.Integer]
) – If the message is a reply, ID of the original messageallow_sending_without_reply (
typing.Optional[base.Boolean]
) – Pass True, if the message should be sent even if the specified replied-to message is not foundreply_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 userhas_spoiler (
typing.Optional[base.Boolean]
) – Pass True if the photo needs to be covered with a spoiler animation
- Returns
On success, the sent Message is returned
- Return type
types.Message
- async send_audio(chat_id: Union[Integer, String], audio: Union[InputFile, String], caption: Optional[String] = None, parse_mode: Optional[String] = None, caption_entities: Optional[List[MessageEntity]] = None, duration: Optional[Integer] = None, performer: Optional[String] = None, title: Optional[String] = None, thumb: Optional[Union[InputFile, String]] = None, message_thread_id: Optional[Integer] = None, disable_notification: Optional[Boolean] = None, protect_content: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, allow_sending_without_reply: Optional[Boolean] = None, reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = 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#sendaudio
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target channelmessage_thread_id (
typing.Optional[base.Integer]
) – Unique identifier for the target message thread (topic) of the forum; for forum supergroups onlyaudio (
typing.Union[base.InputFile, base.String]
) – Audio file to sendcaption (
typing.Optional[base.String]
) – Audio caption, 0-1024 charactersparse_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_modeduration (
typing.Optional[base.Integer]
) – Duration of the audio in secondsperformer (
typing.Optional[base.String]
) – Performertitle (
typing.Optional[base.String]
) – Track namethumb (
typing.Union[base.InputFile, base.String, None]
) – Thumbnail of the file sentdisable_notification (
typing.Optional[base.Boolean]
) – Sends the message silently. Users will receive a notification with no soundprotect_content (
typing.Optional[base.Boolean]
) – Protects the contents of sent messages from forwarding and savingreply_to_message_id (
typing.Optional[base.Integer]
) – If the message is a reply, ID of the original messageallow_sending_without_reply (
typing.Optional[base.Boolean]
) – Pass True, if the message should be sent even if the specified replied-to message is not foundreply_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 returned
- Return type
types.Message
- async send_document(chat_id: Union[Integer, String], document: Union[InputFile, String], thumb: Optional[Union[InputFile, String]] = None, caption: Optional[String] = None, parse_mode: Optional[String] = None, caption_entities: Optional[List[MessageEntity]] = None, disable_content_type_detection: Optional[Boolean] = None, message_thread_id: Optional[Integer] = None, disable_notification: Optional[Boolean] = None, protect_content: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, allow_sending_without_reply: Optional[Boolean] = None, reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = 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#senddocument
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target channelmessage_thread_id (
typing.Optional[base.Integer]
) – Unique identifier for the target message thread (topic) of the forum; for forum supergroups onlydocument (
typing.Union[base.InputFile, base.String]
) – File to sendthumb (
typing.Union[base.InputFile, base.String, None]
) – Thumbnail of the file sentcaption (
typing.Optional[base.String]
) – Document caption (may also be used when resending documents by file_id), 0-1024 charactersdisable_content_type_detection (
typing.Optional[base.Boolean]
) – Disables automatic server-side content type detection for files uploaded using multipart/form-dataparse_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_modedisable_notification (
typing.Optional[base.Boolean]
) – Sends the message silently. Users will receive a notification with no soundprotect_content (
typing.Optional[base.Boolean]
) – Protects the contents of sent messages from forwarding and savingreply_to_message_id (
typing.Optional[base.Integer]
) – If the message is a reply, ID of the original messageallow_sending_without_reply (
typing.Optional[base.Boolean]
) – Pass True, if the message should be sent even if the specified replied-to message is not foundreply_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 returned
- Return type
types.Message
- async send_video(chat_id: Union[Integer, String], video: Union[InputFile, String], duration: Optional[Integer] = None, width: Optional[Integer] = None, height: Optional[Integer] = None, thumb: Optional[Union[InputFile, String]] = None, caption: Optional[String] = None, parse_mode: Optional[String] = None, caption_entities: Optional[List[MessageEntity]] = None, supports_streaming: Optional[Boolean] = None, message_thread_id: Optional[Integer] = None, disable_notification: Optional[Boolean] = None, protect_content: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, allow_sending_without_reply: Optional[Boolean] = None, reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None, has_spoiler: Optional[Boolean] = 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#sendvideo
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target channelmessage_thread_id (
typing.Optional[base.Integer]
) – Unique identifier for the target message thread (topic) of the forum; for forum supergroups onlyvideo (
typing.Union[base.InputFile, base.String]
) – Video to sendduration (
typing.Optional[base.Integer]
) – Duration of sent video in secondswidth (
typing.Optional[base.Integer]
) – Video widthheight (
typing.Optional[base.Integer]
) – Video heightthumb (
typing.Union[base.InputFile, base.String, None]
) – Thumbnail of the file sentcaption (
typing.Optional[base.String]
) – Video caption (may also be used when resending videos by file_id), 0-1024 charactersparse_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_modesupports_streaming (
typing.Optional[base.Boolean]
) – Pass True, if the uploaded video is suitable for streamingdisable_notification (
typing.Optional[base.Boolean]
) – Sends the message silently. Users will receive a notification with no soundprotect_content (
typing.Optional[base.Boolean]
) – Protects the contents of sent messages from forwarding and savingreply_to_message_id (
typing.Optional[base.Integer]
) – If the message is a reply, ID of the original messageallow_sending_without_reply (
typing.Optional[base.Boolean]
) – Pass True, if the message should be sent even if the specified replied-to message is not foundreply_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 userhas_spoiler (
typing.Optional[base.Boolean]
) – Pass True if the video needs to be covered with a spoiler animation
- Returns
On success, the sent Message is returned
- Return type
types.Message
- async send_animation(chat_id: Union[Integer, String], animation: Union[InputFile, String], duration: Optional[Integer] = None, width: Optional[Integer] = None, height: Optional[Integer] = None, thumb: Optional[Union[InputFile, String]] = None, caption: Optional[String] = None, parse_mode: Optional[String] = None, caption_entities: Optional[List[MessageEntity]] = None, message_thread_id: Optional[Integer] = None, disable_notification: Optional[Boolean] = None, protect_content: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, allow_sending_without_reply: Optional[Boolean] = None, reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None, has_spoiler: Optional[Boolean] = 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#sendanimation
- Parameters
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_thread_id (
typing.Optional[base.Integer]
) – Unique identifier for the target message thread (topic) of the forum; for forum supergroups onlyanimation (
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-dataduration (
typing.Optional[base.Integer]
) – Duration of sent animation in secondswidth (
typing.Optional[base.Integer]
) – Animation widthheight (
typing.Optional[base.Integer]
) – Animation heightthumb (
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 charactersparse_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 captioncaption_entities (
typing.Optional[typing.List[types.MessageEntity]]
) – List of special entities that appear in message text, which can be specified instead of parse_modedisable_notification (
typing.Optional[base.Boolean]
) – Sends the message silently. Users will receive a notification with no soundprotect_content (
typing.Optional[base.Boolean]
) – Protects the contents of sent messages from forwarding and savingreply_to_message_id (
typing.Optional[base.Integer]
) – If the message is a reply, ID of the original messageallow_sending_without_reply (
typing.Optional[base.Boolean]
) – Pass True, if the message should be sent even if the specified replied-to message is not foundreply_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 userhas_spoiler (
typing.Optional[base.Boolean]
) – Pass True if the animation needs to be covered with a spoiler animation
- Returns
On success, the sent Message is returned
- Return type
types.Message
- async send_voice(chat_id: Union[Integer, String], voice: Union[InputFile, String], caption: Optional[String] = None, parse_mode: Optional[String] = None, caption_entities: Optional[List[MessageEntity]] = None, duration: Optional[Integer] = None, message_thread_id: Optional[Integer] = None, disable_notification: Optional[Boolean] = None, protect_content: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, allow_sending_without_reply: Optional[Boolean] = None, reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = 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#sendvoice
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target channelmessage_thread_id (
typing.Optional[base.Integer]
) – Unique identifier for the target message thread (topic) of the forum; for forum supergroups onlyvoice (
typing.Union[base.InputFile, base.String]
) – Audio file to sendcaption (
typing.Optional[base.String]
) – Voice message caption, 0-1024 charactersparse_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_modeduration (
typing.Optional[base.Integer]
) – Duration of the voice message in secondsdisable_notification (
typing.Optional[base.Boolean]
) – Sends the message silently. Users will receive a notification with no soundprotect_content (
typing.Optional[base.Boolean]
) – Protects the contents of sent messages from forwarding and savingreply_to_message_id (
typing.Optional[base.Integer]
) – If the message is a reply, ID of the original messageallow_sending_without_reply (
typing.Optional[base.Boolean]
) – Pass True, if the message should be sent even if the specified replied-to message is not foundreply_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 returned
- Return type
types.Message
- async send_video_note(chat_id: Union[Integer, String], video_note: Union[InputFile, String], duration: Optional[Integer] = None, length: Optional[Integer] = None, thumb: Optional[Union[InputFile, String]] = None, message_thread_id: Optional[Integer] = None, disable_notification: Optional[Boolean] = None, protect_content: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, allow_sending_without_reply: Optional[Boolean] = None, reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = 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#sendvideonote
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target channelmessage_thread_id (
typing.Optional[base.Integer]
) – Unique identifier for the target message thread (topic) of the forum; for forum supergroups onlyvideo_note (
typing.Union[base.InputFile, base.String]
) – Video note to sendduration (
typing.Optional[base.Integer]
) – Duration of sent video in secondslength (
typing.Optional[base.Integer]
) – Video width and heightthumb (
typing.Union[base.InputFile, base.String, None]
) – Thumbnail of the file sentdisable_notification (
typing.Optional[base.Boolean]
) – Sends the message silently. Users will receive a notification with no soundprotect_content (
typing.Optional[base.Boolean]
) – Protects the contents of sent messages from forwarding and savingreply_to_message_id (
typing.Optional[base.Integer]
) – If the message is a reply, ID of the original messageallow_sending_without_reply (
typing.Optional[base.Boolean]
) – Pass True, if the message should be sent even if the specified replied-to message is not foundreply_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 returned
- Return type
types.Message
- async send_media_group(chat_id: Union[Integer, String], media: Union[MediaGroup, List], message_thread_id: Optional[Integer] = None, disable_notification: Optional[Boolean] = None, protect_content: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, allow_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#sendmediagroup
- Parameters
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_thread_id (
typing.Optional[base.Integer]
) – Unique identifier for the target message thread (topic) of the forum; for forum supergroups onlymedia (
typing.Union[types.MediaGroup, typing.List]
) – A JSON-serialized array describing messages to be sent, must include 2-10 itemsdisable_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 savingreply_to_message_id (
typing.Optional[base.Integer]
) – If the messages are a reply, ID of the original messageallow_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 returned
- Return type
List[types.Message]
- async send_location(chat_id: Union[Integer, String], latitude: Float, longitude: Float, horizontal_accuracy: Optional[Float] = None, live_period: Optional[Integer] = None, heading: Optional[Integer] = None, proximity_alert_radius: Optional[Integer] = None, message_thread_id: Optional[Integer] = None, disable_notification: Optional[Boolean] = None, protect_content: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, allow_sending_without_reply: Optional[Boolean] = None, reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None) Message [source]
Use this method to send point on the map.
Source: https://core.telegram.org/bots/api#sendlocation
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target channelmessage_thread_id (
typing.Optional[base.Integer]
) – Unique identifier for the target message thread (topic) of the forum; for forum supergroups onlylatitude (
base.Float
) – Latitude of the locationlongitude (
base.Float
) – Longitude of the locationhorizontal_accuracy (
typing.Optional[base.Float]
) – The radius of uncertainty for the location, measured in meters; 0-1500live_period (
typing.Optional[base.Integer]
) – Period in seconds for which the location will be updatedheading (
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 soundprotect_content (
typing.Optional[base.Boolean]
) – Protects the contents of sent messages from forwarding and savingreply_to_message_id (
typing.Optional[base.Integer]
) – If the message is a reply, ID of the original messageallow_sending_without_reply (
typing.Optional[base.Boolean]
) – Pass True, if the message should be sent even if the specified replied-to message is not foundreply_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 returned
- Return type
types.Message
- async edit_message_live_location(latitude: Float, longitude: Float, chat_id: Optional[Union[Integer, String]] = None, message_id: Optional[Integer] = None, inline_message_id: Optional[String] = None, horizontal_accuracy: Optional[Float] = None, heading: Optional[Integer] = None, proximity_alert_radius: Optional[Integer] = None, reply_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#editmessagelivelocation
- Parameters
chat_id (
typing.Union[base.Integer, base.String, None]
) – Required if inline_message_id is not specifiedmessage_id (
typing.Optional[base.Integer]
) – Required if inline_message_id is not specified. Identifier of the sent messageinline_message_id (
typing.Optional[base.String]
) – Required if chat_id and message_id are not specified. Identifier of the inline messagelatitude (
base.Float
) – Latitude of new locationlongitude (
base.Float
) – Longitude of new locationhorizontal_accuracy (
typing.Optional[base.Float]
) – The radius of uncertainty for the location, measured in meters; 0-1500heading (
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]
- async stop_message_live_location(chat_id: Optional[Union[Integer, String]] = None, message_id: Optional[Integer] = None, inline_message_id: Optional[String] = None, reply_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#stopmessagelivelocation
- Parameters
chat_id (
typing.Union[base.Integer, base.String, None]
) – Required if inline_message_id is not specifiedmessage_id (
typing.Optional[base.Integer]
) – Required if inline_message_id is not specified. Identifier of the sent messageinline_message_id (
typing.Optional[base.String]
) – Required if chat_id and message_id are not specified. Identifier of the inline messagereply_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]
- async send_venue(chat_id: Union[Integer, String], latitude: Float, longitude: Float, title: String, address: String, foursquare_id: Optional[String] = None, foursquare_type: Optional[String] = None, google_place_id: Optional[String] = None, google_place_type: Optional[String] = None, message_thread_id: Optional[Integer] = None, disable_notification: Optional[Boolean] = None, protect_content: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, allow_sending_without_reply: Optional[Boolean] = None, reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None) Message [source]
Use this method to send information about a venue.
Source: https://core.telegram.org/bots/api#sendvenue
- Parameters
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_thread_id (
typing.Optional[base.Integer]
) – Unique identifier for the target message thread (topic) of the forum; for forum supergroups onlylatitude (
base.Float
) – Latitude of the venuelongitude (
base.Float
) – Longitude of the venuetitle (
base.String
) – Name of the venueaddress (
base.String
) – Address of the venuefoursquare_id (
typing.Optional[base.String]
) – Foursquare identifier of the venuefoursquare_type (
typing.Optional[base.String]
) – Foursquare type of the venue, if knowngoogle_place_id (
typing.Optional[base.String]
) – Google Places identifier of the venuegoogle_place_type (
typing.Optional[base.String]
) – Google Places type of the venue. See supported types: https://developers.google.com/places/web-service/supported_typesdisable_notification (
typing.Optional[base.Boolean]
) – Sends the message silently. Users will receive a notification with no soundprotect_content (
typing.Optional[base.Boolean]
) – Protects the contents of sent messages from forwarding and savingreply_to_message_id (
typing.Optional[base.Integer]
) – If the message is a reply, ID of the original messageallow_sending_without_reply (
typing.Optional[base.Boolean]
) – Pass True, if the message should be sent even if the specified replied-to message is not foundreply_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 returned
- Return type
types.Message
- async send_contact(chat_id: Union[Integer, String], phone_number: String, first_name: String, last_name: Optional[String] = None, vcard: Optional[String] = None, message_thread_id: Optional[Integer] = None, disable_notification: Optional[Boolean] = None, protect_content: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, allow_sending_without_reply: Optional[Boolean] = None, reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None) Message [source]
Use this method to send phone contacts.
Source: https://core.telegram.org/bots/api#sendcontact
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target channelmessage_thread_id (
typing.Optional[base.Integer]
) – Unique identifier for the target message thread (topic) of the forum; for forum supergroups onlyphone_number (
base.String
) – Contact’s phone numberfirst_name (
base.String
) – Contact’s first namelast_name (
typing.Optional[base.String]
) – Contact’s last namevcard (
typing.Optional[base.String]
) – vcarddisable_notification (
typing.Optional[base.Boolean]
) – Sends the message silently. Users will receive a notification with no soundprotect_content (
typing.Optional[base.Boolean]
) – Protects the contents of sent messages from forwarding and savingreply_to_message_id (
typing.Optional[base.Integer]
) – If the message is a reply, ID of the original messageallow_sending_without_reply (
typing.Optional[base.Boolean]
) – Pass True, if the message should be sent even if the specified replied-to message is not foundreply_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 returned
- Return type
types.Message
- async send_poll(chat_id: Union[Integer, String], question: String, options: List[String], is_anonymous: Optional[Boolean] = None, type: Optional[String] = None, allows_multiple_answers: Optional[Boolean] = None, correct_option_id: Optional[Integer] = None, explanation: Optional[String] = None, explanation_parse_mode: Optional[String] = None, explanation_entities: Optional[List[MessageEntity]] = None, open_period: Optional[Integer] = None, close_date: Optional[Union[Integer, datetime, timedelta]] = None, is_closed: Optional[Boolean] = None, message_thread_id: Optional[Integer] = None, disable_notification: Optional[Boolean] = None, protect_content: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, allow_sending_without_reply: Optional[Boolean] = None, reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = 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#sendpoll
- Parameters
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_thread_id (
typing.Optional[base.Integer]
) – Unique identifier for the target message thread (topic) of the forum; for forum supergroups onlyquestion (
base.String
) – Poll question, 1-300 charactersoptions (
typing.List[base.String]
) – A list of answer options, 2-10 strings 1-100 characters eachis_anonymous (
typing.Optional[base.Boolean]
) – True, if the poll needs to be anonymous, defaults to Truetype (
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 Falsecorrect_option_id (
typing.Optional[base.Integer]
) – 0-based identifier of the correct answer option, required for polls in quiz modeexplanation (
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 parsingexplanation_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_modeopen_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 in
the future. Can’t be used together with open_period.
is_closed (
typing.Optional[base.Boolean]
) – Pass True, if the poll needs to be immediately closeddisable_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 savingreply_to_message_id (
typing.Optional[Integer]
) – If the message is a reply, ID of the original messageallow_sending_without_reply (
typing.Optional[base.Boolean]
) – Pass True, if the message should be sent even if the specified replied-to message is not foundreply_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 returned
- Return type
types.Message
- async send_dice(chat_id: Union[Integer, String], message_thread_id: Optional[Integer] = None, disable_notification: Optional[Boolean] = None, protect_content: Optional[Boolean] = None, emoji: Optional[String] = None, reply_to_message_id: Optional[Integer] = None, allow_sending_without_reply: Optional[Boolean] = None, reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = 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#senddice
- Parameters
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_thread_id (
typing.Optional[base.Integer]
) – Unique identifier for the target message thread (topic) of the forum; for forum supergroups onlyemoji (
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 soundprotect_content (
typing.Optional[base.Boolean]
) – Protects the contents of sent messages from forwarding and savingreply_to_message_id (
typing.Optional[base.Integer]
) – If the message is a reply, ID of the original messageallow_sending_without_reply (
typing.Optional[base.Boolean]
) – Pass True, if the message should be sent even if the specified replied-to message is not foundreply_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 returned
- Return type
types.Message
- async send_chat_action(chat_id: Union[Integer, String], action: String, message_thread_id: Optional[Integer] = None) 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#sendchataction
- Parameters
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.message_thread_id (
typing.Optional[base.Integer]
) – Unique identifier for the target message thread; supergroups only
- Returns
Returns True on success
- Return type
base.Boolean
- async get_user_profile_photos(user_id: Integer, offset: Optional[Integer] = None, limit: 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#getuserprofilephotos
- Parameters
user_id (
base.Integer
) – Unique identifier of the target useroffset (
typing.Optional[base.Integer]
) – Sequential number of the first photo to be returned. By default, all photos are returnedlimit (
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 object
- Return type
types.UserProfilePhotos
- async get_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#getfile
- Parameters
file_id (
base.String
) – File identifier to get info about- Returns
On success, a File object is returned
- Return type
types.File
- async ban_chat_member(chat_id: Union[Integer, String], user_id: Integer, until_date: Optional[Union[Integer, datetime, timedelta]] = None, revoke_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#banchatmember
- Parameters
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 useruntil_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 success
- Return type
base.Boolean
- async kick_chat_member(chat_id: Union[Integer, String], user_id: Integer, until_date: Optional[Union[Integer, datetime, timedelta]] = None, revoke_messages: Optional[Boolean] = None) Boolean [source]
Renamed to ban_chat_member.
- async unban_chat_member(chat_id: Union[Integer, String], user_id: Integer, only_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#unbanchatmember
- Parameters
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 useronly_if_banned (
typing.Optional[base.Boolean]
) – Do nothing if the user is not banned
- Returns
Returns True on success
- Return type
base.Boolean
- async restrict_chat_member(chat_id: Union[Integer, String], user_id: Integer, permissions: Optional[ChatPermissions], use_independent_chat_permissions: Optional[Boolean] = None, until_date: Optional[Union[Integer, datetime, timedelta]] = None, can_send_messages: Optional[Boolean] = None, can_send_media_messages: Optional[Boolean] = None, can_send_other_messages: Optional[Boolean] = None, can_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#restrictchatmember
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target supergroupuser_id (
base.Integer
) – Unique identifier of the target userpermissions (
ChatPermissions
) – New user permissionsuse_independent_chat_permissions (
typing.Optional[base.Boolean]
) – Pass True if chat permissions are set independently. Otherwise, the can_send_other_messages and can_add_web_page_previews permissions will imply the can_send_messages, can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, and can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission.until_date (
typing.Optional[base.Integer]
) – Date when restrictions will be lifted for the user, unix timecan_send_messages (
typing.Optional[base.Boolean]
) – Pass True, if the user can send text messages, contacts, locations and venuescan_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_messagescan_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_messagescan_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 success
- Return type
base.Boolean
- async promote_chat_member(chat_id: Union[Integer, String], user_id: Integer, is_anonymous: Optional[Boolean] = None, can_manage_chat: Optional[Boolean] = None, can_change_info: Optional[Boolean] = None, can_post_messages: Optional[Boolean] = None, can_edit_messages: Optional[Boolean] = None, can_delete_messages: Optional[Boolean] = None, can_manage_voice_chats: Optional[Boolean] = None, can_invite_users: Optional[Boolean] = None, can_restrict_members: Optional[Boolean] = None, can_pin_messages: Optional[Boolean] = None, can_promote_members: Optional[Boolean] = None, can_manage_video_chats: Optional[Boolean] = None, can_manage_topics: 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#promotechatmember
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target channeluser_id (
base.Integer
) – Unique identifier of the target useris_anonymous (
typing.Optional[base.Boolean]
) – Pass True, if the administrator’s presence in the chat is hiddencan_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 privilegecan_change_info (
typing.Optional[base.Boolean]
) – Pass True, if the administrator can change chat title, photo and other settingscan_post_messages (
typing.Optional[base.Boolean]
) – Pass True, if the administrator can create channel posts, channels onlycan_edit_messages (
typing.Optional[base.Boolean]
) – Pass True, if the administrator can edit messages of other users, channels onlycan_delete_messages (
typing.Optional[base.Boolean]
) – Pass True, if the administrator can delete messages of other userscan_manage_voice_chats (
typing.Optional[base.Boolean]
) – Pass True, if the administrator can manage voice chats, supergroups onlycan_invite_users (
typing.Optional[base.Boolean]
) – Pass True, if the administrator can invite new users to the chatcan_restrict_members (
typing.Optional[base.Boolean]
) – Pass True, if the administrator can restrict, ban or unban chat memberscan_pin_messages (
typing.Optional[base.Boolean]
) – Pass True, if the administrator can pin messages, supergroups onlycan_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
can_manage_topics (
typing.Optional[base.Boolean]
) – Pass True if the user is allowed to create, rename, close, and reopen forum topics, supergroups only
- Returns
Returns True on success
- Return type
base.Boolean
- async set_chat_administrator_custom_title(chat_id: Union[Integer, String], user_id: Integer, custom_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#setchatadministratorcustomtitle
- Parameters
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.
- async ban_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#banchatsenderchat
- Parameters
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
- async unban_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#unbanchatsenderchat
- Parameters
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
- async set_chat_permissions(chat_id: Union[Integer, String], permissions: ChatPermissions, use_independent_chat_permissions: Optional[Boolean] = None) 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
use_independent_chat_permissions (
typing.Optional[base.Boolean]
) – Pass True if chat permissions are set independently. Otherwise, the can_send_other_messages and can_add_web_page_previews permissions will imply the can_send_messages, can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, and can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission.
- Returns
True on success.
- async export_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#exportchatinvitelink
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target channel- Returns
Returns exported invite link as String on success
- Return type
base.String
- async create_chat_invite_link(chat_id: Union[Integer, String], expire_date: Optional[Union[Integer, datetime, timedelta]] = None, member_limit: Optional[Integer] = None, name: Optional[String] = None, creates_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#createchatinvitelink
- Parameters
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 expiremember_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-99999name (
typing.Optional[base.String]
) – Invite link name; 0-32 characterscreates_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.ChatInviteLink
- async edit_chat_invite_link(chat_id: Union[Integer, String], invite_link: String, expire_date: Optional[Union[Integer, datetime, timedelta]] = None, member_limit: Optional[Integer] = None, name: Optional[String] = None, creates_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#editchatinvitelink
- Parameters
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 editexpire_date (
typing.Union[base.Integer, datetime.datetime, datetime.timedelta, None]
) – Point in time (Unix timestamp) when the link will expiremember_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-99999name (
typing.Optional[base.String]
) – Invite link name; 0-32 characterscreates_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.
- async revoke_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#revokechatinvitelink
- Parameters
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 object
- async approve_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#approvechatjoinrequest
- Parameters
chat_id (Union[base.Integer, base.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
- Returns
- async decline_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#declinechatjoinrequest
- Parameters
chat_id (Union[base.Integer, base.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
- Returns
- async set_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#setchatphoto
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target channelphoto (
base.InputFile
) – New chat photo, uploaded using multipart/form-data
- Returns
Returns True on success
- Return type
base.Boolean
- async delete_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#deletechatphoto
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target channel- Returns
Returns True on success
- Return type
base.Boolean
- async set_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#setchattitle
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target channeltitle (
base.String
) – New chat title, 1-255 characters
- Returns
Returns True on success
- Return type
base.Boolean
- async set_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#setchatdescription
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target channeldescription (
typing.Optional[base.String]
) – New chat description, 0-255 characters
- Returns
Returns True on success
- Return type
base.Boolean
- async pin_chat_message(chat_id: Union[Integer, String], message_id: Integer, disable_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#pinchatmessage
- Parameters
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 pindisable_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 success
- Return type
base.Boolean
- async unpin_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#unpinchatmessage
- Parameters
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 success
- Return type
base.Boolean
- async unpin_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#unpinallchatmessages
- Parameters
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 success
- Return type
base.Boolean
- async close_general_forum_topic(chat_id: Union[Integer, String]) Boolean [source]
Use this method to close an open ‘General’ topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights.
Returns
True
on success.- Parameters
chat_id – Unique identifier for the target chat or username of the target supergroup (in the format
@supergroupusername
)- Returns
Returns
True
on success.
- async edit_general_forum_topic(chat_id: Union[Integer, String], name: String) Boolean [source]
Use this method to edit the name of the ‘General’ topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights.
Returns
True
on success.- Parameters
chat_id – Unique identifier for the target chat or username of the target supergroup (in the format
@supergroupusername
)name – New topic name, 1-128 characters
- Returns
Returns
True
on success.
- async hide_general_forum_topic(chat_id: Union[Integer, String]) Boolean [source]
Use this method to hide the ‘General’ topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights.
The topic will be automatically closed if it was open. Returns
True
on success.- Parameters
chat_id – Unique identifier for the target chat or username of the target supergroup (in the format
@supergroupusername
)- Returns
Returns
True
on success.
- async reopen_general_forum_topic(chat_id: Union[Integer, String]) Boolean [source]
Use this method to reopen a closed ‘General’ topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. The topic will be automatically unhidden if it was hidden. Returns
True
on success.- Parameters
chat_id – Unique identifier for the target chat or username of the target supergroup (in the format
@supergroupusername
)- Returns
Returns
True
on success.
- async unhide_general_forum_topic(chat_id: Union[Integer, String]) Boolean [source]
Use this method to unhide the ‘General’ topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights.
Returns
True
on success.- Parameters
chat_id – Unique identifier for the target chat or username of the target supergroup (in the format
@supergroupusername
)- Returns
Returns
True
on success.
- async leave_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#leavechat
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target supergroup or channel- Returns
Returns True on success
- Return type
base.Boolean
- async get_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#getchat
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target supergroup or channel- Returns
Returns a Chat object on success
- Return type
types.Chat
- async get_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#getchatadministrators
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target supergroup or channel- Returns
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]
- async get_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#getchatmembercount
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target supergroup or channel- Returns
Returns Int on success
- Return type
base.Integer
- async get_chat_members_count(chat_id: Union[Integer, String]) Integer [source]
Renamed to get_chat_member_count.
- async get_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#getchatmember
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target supergroup or channeluser_id (
base.Integer
) – Unique identifier of the target user
- Returns
Returns a ChatMember object on success
- Return type
types.ChatMember
- async set_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#setchatstickerset
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target supergroupsticker_set_name (
base.String
) – Name of the sticker set to be set as the group sticker set
- Returns
Returns True on success
- Return type
base.Boolean
- async delete_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#deletechatstickerset
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target supergroup- Returns
Returns True on success
- Return type
base.Boolean
- async get_forum_topic_icon_stickers() List[Sticker] [source]
Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user. Requires no parameters.
Returns an Array of Sticker objects.
Source: https://core.telegram.org/bots/api#getforumtopiciconstickers
- Returns
Returns an Array of Sticker objects.
- async create_forum_topic(chat_id: Union[int, str], name: String, icon_color: Optional[Integer] = None, icon_custom_emoji_id: Optional[String] = None) ForumTopic [source]
Use this method to create a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights.
Returns information about the created topic as a ForumTopic object.
Source: https://core.telegram.org/bots/api#createforumtopic
- Parameters
chat_id – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
name – Topic name, 1-128 characters
icon_color – Color of the topic icon in RGB format. Currently, must be one of 0x6FB9F0, 0xFFD67E, 0xCB86DB, 0x8EEE98, 0xFF93B2, or 0xFB6F5F
icon_custom_emoji_id – Unique identifier of the custom emoji shown as the topic icon. Use getForumTopicIconStickers to get all allowed custom emoji identifiers.
- Returns
Returns information about the created topic as a ForumTopic object.
- async edit_forum_topic(chat_id: Union[int, str], name: Optional[String] = None, message_thread_id: Optional[Integer] = None, icon_custom_emoji_id: Optional[String] = None) Boolean [source]
Use this method to edit name and icon of a topic in a forum supergroup chat.
The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights, unless it is the creator of the topic.
Returns True on success.
Source: https://core.telegram.org/bots/api#editforumtopic
- Parameters
chat_id – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
name – Unique identifier for the target message thread of the forum topic
message_thread_id – New topic name, 1-128 characters
icon_custom_emoji_id – New unique identifier of the custom emoji shown as the topic icon. Use getForumTopicIconStickers to get all allowed custom emoji identifiers
- Returns
Returns True on success.
- async close_forum_topic(chat_id: Union[int, str], message_thread_id: Optional[Integer] = None) Boolean [source]
Use this method to close an open topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic.
Returns True on success.
- Parameters
chat_id – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
message_thread_id – Unique identifier for the target message thread of the forum topic
- Returns
Returns True on success.
- async reopen_forum_topic(chat_id: Union[int, str], message_thread_id: Optional[Integer] = None) Boolean [source]
Use this method to reopen a closed topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic.
Returns True on success.
Source: https://core.telegram.org/bots/api#reopenforumtopic
- Parameters
chat_id – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
message_thread_id – Unique identifier for the target message thread of the forum topic
- Returns
Returns True on success.
- async delete_forum_topic(chat_id: Union[int, str], message_thread_id: Optional[Integer] = None) Boolean [source]
Use this method to delete a forum topic along with all its messages in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_delete_messages administrator rights.
Returns True on success.
Source: https://core.telegram.org/bots/api#deleteforumtopic
- Parameters
chat_id – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
message_thread_id – Unique identifier for the target message thread of the forum topic
- Returns
Returns True on success.
- async unpin_all_forum_topic_messages(chat_id: Union[int, str], message_thread_id: Optional[Integer] = None) Boolean [source]
Use this method to clear the list of pinned messages in a forum topic. The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup.
Returns True on success.
Source: https://core.telegram.org/bots/api#unpinallforumtopicmessages
- Parameters
chat_id – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
message_thread_id – Unique identifier for the target message thread of the forum topic
- Returns
Returns True on success.
- async answer_callback_query(callback_query_id: String, text: Optional[String] = None, show_alert: Optional[Boolean] = None, url: Optional[String] = None, cache_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#answercallbackquery
- Parameters
callback_query_id (
base.String
) – Unique identifier for the query to be answeredtext (
typing.Optional[base.String]
) – Text of the notification. If not specified, nothing will be shown to the user, 0-1024 charactersshow_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 clientcache_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 returned
- Return type
base.Boolean
- async set_my_commands(commands: List[BotCommand], scope: Optional[BotCommandScope] = None, language_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#setmycommands
- Parameters
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.Boolean
- async delete_my_commands(scope: Optional[BotCommandScope] = None, language_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#deletemycommands
- Parameters
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.Boolean
- async get_my_commands(scope: Optional[BotCommandScope] = None, language_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#getmycommands
- Parameters
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]
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#setchatmenubutton
- Parameters
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.
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#getchatmenu
- Parameters
chat_id – Unique identifier for the target private chat. If not specified, default bot’s menu button will be returned
- Returns
Returns MenuButton on success.
- async set_my_default_administrator_rights(rights: Optional[ChatAdministratorRights] = None, for_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#setmydefaultadministratorrights
- Parameters
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.
- async get_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#getmydefaultadministratorrights
- Parameters
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.
- Returns
- async edit_message_text(text: String, chat_id: Optional[Union[Integer, String]] = None, message_id: Optional[Integer] = None, inline_message_id: Optional[String] = None, parse_mode: Optional[String] = None, entities: Optional[List[MessageEntity]] = None, disable_web_page_preview: Optional[Boolean] = None, reply_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#editmessagetext
- Parameters
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 channelmessage_id (
typing.Optional[base.Integer]
) – Required if inline_message_id is not specified. Identifier of the sent messageinline_message_id (
typing.Optional[base.String]
) – Required if chat_id and message_id are not specified. Identifier of the inline messagetext (
base.String
) – New text of the messageparse_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_modedisable_web_page_preview (
typing.Optional[base.Boolean]
) – Disables link previews for links in this messagereply_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]
- async edit_message_caption(chat_id: Optional[Union[Integer, String]] = None, message_id: Optional[Integer] = None, inline_message_id: Optional[String] = None, caption: Optional[String] = None, parse_mode: Optional[String] = None, caption_entities: Optional[List[MessageEntity]] = None, reply_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#editmessagecaption
- Parameters
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 channelmessage_id (
typing.Optional[base.Integer]
) – Required if inline_message_id is not specified. Identifier of the sent messageinline_message_id (
typing.Optional[base.String]
) – Required if chat_id and message_id are not specified. Identifier of the inline messagecaption (
typing.Optional[base.String]
) – New caption of the messageparse_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_modereply_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]
- async edit_message_media(media: InputMedia, chat_id: Optional[Union[Integer, String]] = None, message_id: Optional[Integer] = None, inline_message_id: Optional[String] = None, reply_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#editmessagemedia
- Parameters
chat_id (
typing.Union[typing.Union[base.Integer, base.String], None]
) – Required if inline_message_id is not specifiedmessage_id (
typing.Optional[base.Integer]
) – Required if inline_message_id is not specified. Identifier of the sent messageinline_message_id (
typing.Optional[base.String]
) – Required if chat_id and message_id are not specified. Identifier of the inline messagemedia (
types.InputMedia
) – A JSON-serialized object for a new media content of the messagereply_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]
- async edit_message_reply_markup(chat_id: Optional[Union[Integer, String]] = None, message_id: Optional[Integer] = None, inline_message_id: Optional[String] = None, reply_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#editmessagereplymarkup
- Parameters
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 channelmessage_id (
typing.Optional[base.Integer]
) – Required if inline_message_id is not specified. Identifier of the sent messageinline_message_id (
typing.Optional[base.String]
) – Required if chat_id and message_id are not specified. Identifier of the inline messagereply_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]
- async stop_poll(chat_id: Union[String, Integer], message_id: Integer, reply_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 channelmessage_id (
base.Integer
) – Identifier of the original message with the pollreply_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.Poll
- async delete_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#deletemessage
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target channelmessage_id (
base.Integer
) – Identifier of the message to delete
- Returns
Returns True on success
- Return type
base.Boolean
- async send_sticker(chat_id: Union[Integer, String], sticker: Union[InputFile, String], message_thread_id: Optional[Integer] = None, disable_notification: Optional[Boolean] = None, protect_content: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, allow_sending_without_reply: Optional[Boolean] = None, reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove, ForceReply]] = None) Message [source]
Use this method to send .webp stickers.
Source: https://core.telegram.org/bots/api#sendsticker
- Parameters
chat_id (
typing.Union[base.Integer, base.String]
) – Unique identifier for the target chat or username of the target channelmessage_thread_id (
typing.Optional[base.Integer]
) – Unique identifier for the target message thread (topic) of the forum; for forum supergroups onlysticker (
typing.Union[base.InputFile, base.String]
) – Sticker to senddisable_notification (
typing.Optional[base.Boolean]
) – Sends the message silently. Users will receive a notification with no soundprotect_content (
typing.Optional[base.Boolean]
) – Protects the contents of sent messages from forwarding and savingreply_to_message_id (
typing.Optional[base.Integer]
) – If the message is a reply, ID of the original messageallow_sending_without_reply (
typing.Optional[base.Boolean]
) – Pass True, if the message should be sent even if the specified replied-to message is not foundreply_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 returned
- Return type
types.Message
- async get_sticker_set(name: String) StickerSet [source]
Use this method to get a sticker set.
Source: https://core.telegram.org/bots/api#getstickerset
- Parameters
name (
base.String
) – Name of the sticker set- Returns
On success, a StickerSet object is returned
- Return type
types.StickerSet
- async upload_sticker_file(user_id: Integer, png_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#uploadstickerfile
- Parameters
user_id (
base.Integer
) – User identifier of sticker file ownerpng_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 success
- Return type
types.File
- async get_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#getcustomemojistickers
- Parameters
custom_emoji_ids (
typing.List[base.String]
) – List of custom emoji identifiers. At most 200 custom emoji identifiers can be specified.- Returns
Returns an Array of Sticker objects.
- Return type
typing.List[types.Sticker]
- async create_new_sticker_set(user_id: Integer, name: String, title: String, emojis: String, png_sticker: Optional[Union[InputFile, String]] = None, tgs_sticker: Optional[InputFile] = None, webm_sticker: Optional[InputFile] = None, contains_masks: Optional[Boolean] = None, sticker_type: Optional[String] = None, mask_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#createnewstickerset
- Parameters
user_id (
base.Integer
) – User identifier of created sticker set ownername (
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 characterspng_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-filestgs_sticker (
base.InputFile
) – TGS animation with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/animated_stickers#technical-requirements for technical requirementswebm_sticker (
base.String
) – WEBM video with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/stickers#video-sticker-requirements for technical requirementssticker_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 stickercontains_masks (
typing.Optional[base.Boolean]
) – Pass True, if a set of mask stickers should be createdmask_position (
typing.Optional[types.MaskPosition]
) – A JSON-serialized object for position where the mask should be placed on faces
- Returns
Returns True on success
- Return type
base.Boolean
- async add_sticker_to_set(user_id: Integer, name: String, emojis: String, png_sticker: Optional[Union[InputFile, String]] = None, tgs_sticker: Optional[InputFile] = None, webm_sticker: Optional[InputFile] = None, mask_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#addstickertoset
- Parameters
user_id (
base.Integer
) – User identifier of sticker set ownername (
base.String
) – Sticker set namepng_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-filestgs_sticker (
base.InputFile
) – TGS animation with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/animated_stickers#technical-requirements for technical requirementswebm_sticker (
base.InputFile
) – WEBM video with the sticker, uploaded using multipart/form-data. See https://core.telegram.org/stickers#video-sticker-requirements for technical requirementsemojis (
base.String
) – One or more emoji corresponding to the stickermask_position (
typing.Optional[types.MaskPosition]
) – A JSON-serialized object for position where the mask should be placed on faces
- Returns
Returns True on success
- Return type
base.Boolean
- async set_sticker_position_in_set(sticker: String, position: 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#setstickerpositioninset
- Parameters
sticker (
base.String
) – File identifier of the stickerposition (
base.Integer
) – New sticker position in the set, zero-based
- Returns
Returns True on success
- Return type
base.Boolean
- async delete_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#deletestickerfromset
- Parameters
sticker (
base.String
) – File identifier of the sticker- Returns
Returns True on success
- Return type
base.Boolean
- async set_sticker_set_thumb(name: String, user_id: Integer, thumb: 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#setstickersetthumb
- Parameters
name (
base.String
) – Sticker set nameuser_id (
base.Integer
) – User identifier of the sticker set ownerthumb (
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 success
- Return type
base.Boolean
- async answer_inline_query(inline_query_id: String, results: List[InlineQueryResult], cache_time: Optional[Integer] = None, is_personal: Optional[Boolean] = None, next_offset: Optional[String] = None, switch_pm_text: Optional[String] = None, switch_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#answerinlinequery
- Parameters
inline_query_id (
base.String
) – Unique identifier for the answered queryresults (
typing.List[types.InlineQueryResult]
) – A JSON-serialized array of results for the inline querycache_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 querynext_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_parameterswitch_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 returned
- Return type
base.Boolean
- async answer_web_app_query(web_app_query_id: String, result: 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#answerwebappquery
- Parameters
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.
- async send_invoice(chat_id: Union[Integer, String], title: String, description: String, payload: String, provider_token: String, currency: String, prices: List[LabeledPrice], max_tip_amount: Optional[Integer] = None, suggested_tip_amounts: Optional[List[Integer]] = None, start_parameter: Optional[String] = None, provider_data: Optional[Dict] = None, photo_url: Optional[String] = None, photo_size: Optional[Integer] = None, photo_width: Optional[Integer] = None, photo_height: Optional[Integer] = None, need_name: Optional[Boolean] = None, need_phone_number: Optional[Boolean] = None, need_email: Optional[Boolean] = None, need_shipping_address: Optional[Boolean] = None, send_phone_number_to_provider: Optional[Boolean] = None, send_email_to_provider: Optional[Boolean] = None, is_flexible: Optional[Boolean] = None, message_thread_id: Optional[Integer] = None, disable_notification: Optional[Boolean] = None, protect_content: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, allow_sending_without_reply: Optional[Boolean] = None, reply_markup: Optional[InlineKeyboardMarkup] = None) Message [source]
Use this method to send invoices.
Source: https://core.telegram.org/bots/api#sendinvoice
- Parameters
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_thread_id (
typing.Optional[base.Integer]
) – Unique identifier for the target message thread (topic) of the forum; for forum supergroups onlytitle (
base.String
) – Product name, 1-32 charactersdescription (
base.String
) – Product description, 1-255 characterspayload (
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 Botfathercurrency (
base.String
) – Three-letter ISO 4217 currency code, see more on currenciesprices (
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 0suggested_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 parameterprovider_data (
typing.Optional[typing.Dict]
) – JSON-encoded data about the invoice, which will be shared with the payment providerphoto_url (
typing.Optional[base.String]
) – URL of the product photo for the invoicephoto_size (
typing.Optional[base.Integer]
) – Photo sizephoto_width (
typing.Optional[base.Integer]
) – Photo widthphoto_height (
typing.Optional[base.Integer]
) – Photo heightneed_name (
typing.Optional[base.Boolean]
) – Pass True, if you require the user’s full name to complete the orderneed_phone_number (
typing.Optional[base.Boolean]
) – Pass True, if you require the user’s phone number to complete the orderneed_email (
typing.Optional[base.Boolean]
) – Pass True, if you require the user’s email to complete the orderneed_shipping_address (
typing.Optional[base.Boolean]
) – Pass True, if you require the user’s shipping address to complete the ordersend_phone_number_to_provider (
typing.Optional[base.Boolean]
) – Pass True, if user’s phone number should be sent to providersend_email_to_provider (
typing.Optional[base.Boolean]
) – Pass True, if user’s email address should be sent to provideris_flexible (
typing.Optional[base.Boolean]
) – Pass True, if the final price depends on the shipping methoddisable_notification (
typing.Optional[base.Boolean]
) – Sends the message silently. Users will receive a notification with no soundprotect_content (
typing.Optional[base.Boolean]
) – Protects the contents of sent messages from forwarding and savingreply_to_message_id (
typing.Optional[base.Integer]
) – If the message is a reply, ID of the original messageallow_sending_without_reply (
typing.Optional[base.Boolean]
) – Pass True, if the message should be sent even if the specified replied-to message is not foundreply_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 returned
- Return type
types.Message
- async create_invoice_link(title: String, description: String, payload: String, provider_token: String, currency: String, prices: List[LabeledPrice], max_tip_amount: Optional[int] = None, suggested_tip_amounts: Optional[List[int]] = None, provider_data: Optional[String] = None, photo_url: Optional[str] = None, photo_size: Optional[int] = None, photo_width: Optional[int] = None, photo_height: Optional[int] = None, need_name: Optional[bool] = None, need_phone_number: Optional[bool] = None, need_email: Optional[bool] = None, need_shipping_address: Optional[bool] = None, send_phone_number_to_provider: Optional[bool] = None, send_email_to_provider: Optional[bool] = None, is_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#createinvoicelink
- Parameters
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
- Returns
- async answer_shipping_query(shipping_query_id: String, ok: Boolean, shipping_options: Optional[List[ShippingOption]] = None, error_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#answershippingquery
- Parameters
shipping_query_id (
base.String
) – Unique identifier for the query to be answeredok (
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 optionserror_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 returned
- Return type
base.Boolean
- async answer_pre_checkout_query(pre_checkout_query_id: String, ok: Boolean, error_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#answerprecheckoutquery
- Parameters
pre_checkout_query_id (
base.String
) – Unique identifier for the query to be answeredok (
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 returned
- Return type
base.Boolean
- async set_passport_data_errors(user_id: Integer, errors: 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#setpassportdataerrors
- Parameters
user_id (
base.Integer
) – User identifiererrors (
typing.List[types.PassportElementError]
) – A JSON-serialized array describing the errors
- Returns
Returns True on success
- Return type
base.Boolean
- async send_game(chat_id: Integer, game_short_name: String, disable_notification: Optional[Boolean] = None, protect_content: Optional[Boolean] = None, reply_to_message_id: Optional[Integer] = None, allow_sending_without_reply: Optional[Boolean] = None, reply_markup: Optional[InlineKeyboardMarkup] = None) Message [source]
Use this method to send a game.
Source: https://core.telegram.org/bots/api#sendgame
- Parameters
chat_id (
base.Integer
) – Unique identifier for the target chatgame_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 soundprotect_content (
typing.Optional[base.Boolean]
) – Protects the contents of sent messages from forwarding and savingreply_to_message_id (
typing.Optional[base.Integer]
) – If the message is a reply, ID of the original messageallow_sending_without_reply (
typing.Optional[base.Boolean]
) – Pass True, if the message should be sent even if the specified replied-to message is not foundreply_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 returned
- Return type
types.Message
- async set_game_score(user_id: Integer, score: Integer, force: Optional[Boolean] = None, disable_edit_message: Optional[Boolean] = None, chat_id: Optional[Integer] = None, message_id: Optional[Integer] = None, inline_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#setgamescore
- Parameters
user_id (
base.Integer
) – User identifierscore (
base.Integer
) – New score, must be non-negativeforce (
typing.Optional[base.Boolean]
) – Pass True, if the high score is allowed to decrease This can be useful when fixing mistakes or banning cheatersdisable_edit_message (
typing.Optional[base.Boolean]
) – Pass True, if the game message should not be automatically edited to include the current scoreboardchat_id (
typing.Optional[base.Integer]
) – Required if inline_message_id is not specified. Unique identifier for the target chatmessage_id (
typing.Optional[base.Integer]
) – Required if inline_message_id is not specified. Identifier of the sent messageinline_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]
- async get_game_high_scores(user_id: Integer, chat_id: Optional[Integer] = None, message_id: Optional[Integer] = None, inline_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#getgamehighscores
- Parameters
user_id (
base.Integer
) – Target user idchat_id (
typing.Optional[base.Integer]
) – Required if inline_message_id is not specified. Unique identifier for the target chatmessage_id (
typing.Optional[base.Integer]
) – Required if inline_message_id is not specified. Identifier of the sent messageinline_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
- class aiogram.bot.api.TelegramAPIServer(base: str, file: str)[source]
Bases:
object
Base config for API Endpoints
- aiogram.bot.api.check_token(token: str) bool [source]
Validate BOT token
- Parameters
token –
- Returns
- aiogram.bot.api.check_result(method_name: str, content_type: str, status_code: int, body: 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 dictionary
- Raises
ApiException – if one of the above listed cases is applicable
- aiogram.bot.api.compose_data(params=None, files=None)[source]
Prepare request data
- Parameters
params –
files –
- Returns
- class aiogram.bot.api.Methods[source]
Bases:
Helper
Helper for Telegram API Methods listed on https://core.telegram.org/bots/api