telegram.bot module

This module contains an object that represents a Telegram Bot.

class telegram.bot.Bot(token, base_url=None, base_file_url=None, request=None)

Bases: telegram.base.TelegramObject

This object represents a Telegram Bot.

id

int – Unique identifier for this bot.

first_name

str – Bot’s first name.

last_name

str – Bot’s last name.

username

str – Bot’s username.

name

str – Bot’s @username.

Parameters:
  • token (str) – Bot’s unique authentication.
  • base_url (Optional[str]) – Telegram Bot API service URL.
  • base_file_url (Optional[str]) – Telegram Bot API file URL.
  • request (Optional[Request]) – Pre initialized Request class.
answerCallbackQuery(*args, **kwargs)

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.

Parameters:
  • callback_query_id (str) – Unique identifier for the query to be answered.
  • text (Optional[str]) – Text of the notification. If not specified, nothing will be shown to the user.
  • show_alert (Optional[bool]) – 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 (Optional[str]) – URL that will be opened by the user’s client.
  • cache_time (Optional[int]) – The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, True is returned.

Return type:

bool

Raises:

telegram.TelegramError

answerInlineQuery(*args, **kwargs)

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

Parameters:
  • inline_query_id (str) – Unique identifier for the answered query.
  • results (list[telegram.InlineQueryResult]) – A list of results for the inline query.
  • cache_time (Optional[int]) – The maximum amount of time the result of the inline query may be cached on the server.
  • is_personal (Optional[bool]) – Pass True, if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query.
  • next_offset (Optional[str]) – 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 (Optional[str]) – If passed, clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter switch_pm_parameter.
  • switch_pm_parameter (Optional[str]) – Parameter for the start message sent to the bot when user presses the switch button.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, True is returned.

Return type:

bool

Raises:

telegram.TelegramError

answer_callback_query(*args, **kwargs)

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.

Parameters:
  • callback_query_id (str) – Unique identifier for the query to be answered.
  • text (Optional[str]) – Text of the notification. If not specified, nothing will be shown to the user.
  • show_alert (Optional[bool]) – 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 (Optional[str]) – URL that will be opened by the user’s client.
  • cache_time (Optional[int]) – The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, True is returned.

Return type:

bool

Raises:

telegram.TelegramError

answer_inline_query(*args, **kwargs)

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

Parameters:
  • inline_query_id (str) – Unique identifier for the answered query.
  • results (list[telegram.InlineQueryResult]) – A list of results for the inline query.
  • cache_time (Optional[int]) – The maximum amount of time the result of the inline query may be cached on the server.
  • is_personal (Optional[bool]) – Pass True, if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query.
  • next_offset (Optional[str]) – 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 (Optional[str]) – If passed, clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter switch_pm_parameter.
  • switch_pm_parameter (Optional[str]) – Parameter for the start message sent to the bot when user presses the switch button.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, True is returned.

Return type:

bool

Raises:

telegram.TelegramError

deleteMessage(*args, **kwargs)

Use this method to delete a message. A message can only be deleted if it was sent less than 48 hours ago. Any such recently sent outgoing message may be deleted. Additionally, if the bot is an administrator in a group chat, it can delete any message. If the bot is an administrator in a supergroup, it can delete messages from any other user and service messages about people joining or leaving the group (other types of service messages may only be removed by the group creator). In channels, bots can only remove their own messages.

Parameters:
  • chat_id (int|str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • message_id (int) – Unique message identifier.
Returns:

On success, True is returned.

Return type:

bool

Raises:

telegram.TelegramError

deleteWebhook(*args, **kwargs)

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

Parameters:
  • timeout (Optional[float]) – If this value is specified, use it as the definitive timeout (in seconds) for urlopen() operations.
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, True is returned.

Return type:

bool

Raises:

telegram.TelegramError

delete_message(*args, **kwargs)

Use this method to delete a message. A message can only be deleted if it was sent less than 48 hours ago. Any such recently sent outgoing message may be deleted. Additionally, if the bot is an administrator in a group chat, it can delete any message. If the bot is an administrator in a supergroup, it can delete messages from any other user and service messages about people joining or leaving the group (other types of service messages may only be removed by the group creator). In channels, bots can only remove their own messages.

Parameters:
  • chat_id (int|str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • message_id (int) – Unique message identifier.
Returns:

On success, True is returned.

Return type:

bool

Raises:

telegram.TelegramError

delete_webhook(*args, **kwargs)

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

Parameters:
  • timeout (Optional[float]) – If this value is specified, use it as the definitive timeout (in seconds) for urlopen() operations.
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, True is returned.

Return type:

bool

Raises:

telegram.TelegramError

editMessageCaption(*args, **kwargs)
Use this method to edit captions of messages sent by the bot or via the bot (for inline
bots).
Parameters:
  • chat_id (Optional[int|str]) – Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • message_id (Optional[int]) – Required if inline_message_id is not specified. Unique identifier of the sent message.
  • inline_message_id (Optional[str]) – Required if chat_id and message_id are not specified. Identifier of the inline message.
  • caption (Optional[str]) – New caption of the message.
  • reply_markup (Optional[telegram.InlineKeyboardMarkup]) – A JSON-serialized object for an inline keyboard.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, if edited message is sent by the bot, the edited

message is returned, otherwise True is returned.

Return type:

telegram.Message

Raises:

telegram.TelegramError

editMessageReplyMarkup(*args, **kwargs)

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

Parameters:
  • chat_id (Optional[int|str]) – Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • message_id (Optional[int]) – Required if inline_message_id is not specified. Unique identifier of the sent message.
  • inline_message_id (Optional[str]) – Required if chat_id and message_id are not specified. Identifier of the inline message.
  • reply_markup (Optional[telegram.InlineKeyboardMarkup]) – A JSON-serialized object for an inline keyboard.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

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

Return type:

telegram.Message

Raises:

telegram.TelegramError

editMessageText(*args, **kwargs)

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

Parameters:
  • text (str) – New text of the message.
  • chat_id (Optional[int|str]) – Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • message_id (Optional[int]) – Required if inline_message_id is not specified. Unique identifier of the sent message.
  • inline_message_id (Optional[str]) – Required if chat_id and message_id are not specified. Identifier of the inline message.
  • parse_mode (:class:`telegram.ParseMode`|str) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.
  • disable_web_page_preview (bool) – Disables link previews for links in this message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, if edited message is sent by the bot, the edited

message is returned, otherwise True is returned.

Return type:

telegram.Message

Raises:

telegram.TelegramError

edit_message_caption(*args, **kwargs)
Use this method to edit captions of messages sent by the bot or via the bot (for inline
bots).
Parameters:
  • chat_id (Optional[int|str]) – Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • message_id (Optional[int]) – Required if inline_message_id is not specified. Unique identifier of the sent message.
  • inline_message_id (Optional[str]) – Required if chat_id and message_id are not specified. Identifier of the inline message.
  • caption (Optional[str]) – New caption of the message.
  • reply_markup (Optional[telegram.InlineKeyboardMarkup]) – A JSON-serialized object for an inline keyboard.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, if edited message is sent by the bot, the edited

message is returned, otherwise True is returned.

Return type:

telegram.Message

Raises:

telegram.TelegramError

edit_message_reply_markup(*args, **kwargs)

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

Parameters:
  • chat_id (Optional[int|str]) – Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • message_id (Optional[int]) – Required if inline_message_id is not specified. Unique identifier of the sent message.
  • inline_message_id (Optional[str]) – Required if chat_id and message_id are not specified. Identifier of the inline message.
  • reply_markup (Optional[telegram.InlineKeyboardMarkup]) – A JSON-serialized object for an inline keyboard.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

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

Return type:

telegram.Message

Raises:

telegram.TelegramError

edit_message_text(*args, **kwargs)

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

Parameters:
  • text (str) – New text of the message.
  • chat_id (Optional[int|str]) – Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • message_id (Optional[int]) – Required if inline_message_id is not specified. Unique identifier of the sent message.
  • inline_message_id (Optional[str]) – Required if chat_id and message_id are not specified. Identifier of the inline message.
  • parse_mode (:class:`telegram.ParseMode`|str) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.
  • disable_web_page_preview (bool) – Disables link previews for links in this message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, if edited message is sent by the bot, the edited

message is returned, otherwise True is returned.

Return type:

telegram.Message

Raises:

telegram.TelegramError

forwardMessage(*args, **kwargs)

Use this method to forward messages of any kind.

Parameters:
  • chat_id (int|str) – Unique identifier for the message recipient - Chat id.
  • from_chat_id (int|str) – Unique identifier for the chat where the original message was sent - Chat id.
  • message_id (int) – Unique message identifier.
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, instance representing the message forwarded.

Return type:

telegram.Message

Raises:

telegram.TelegramError

forward_message(*args, **kwargs)

Use this method to forward messages of any kind.

Parameters:
  • chat_id (int|str) – Unique identifier for the message recipient - Chat id.
  • from_chat_id (int|str) – Unique identifier for the chat where the original message was sent - Chat id.
  • message_id (int) – Unique message identifier.
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, instance representing the message forwarded.

Return type:

telegram.Message

Raises:

telegram.TelegramError

getChat(*args, **kwargs)

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.).

Parameters:
  • chat_id (int|str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, telegram.Chat is returned.

Return type:

telegram.Chat

Raises:

telegram.TelegramError

getChatAdministrators(*args, **kwargs)

Use this method to get a list of administrators in a chat. 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.

Parameters:
  • chat_id (int|str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

A list of chat member objects.

Return type:

list[telegram.ChatMember]

Raises:

telegram.TelegramError

getChatMember(*args, **kwargs)

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

Parameters:
  • chat_id (int|str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • user_id (int) – Unique identifier of the target user.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, chat member object is returned.

Return type:

telegram.ChatMember

Raises:

telegram.TelegramError

getChatMembersCount(*args, **kwargs)

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

Parameters:
  • chat_id (int|str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, an int is returned.

Return type:

int

Raises:

telegram.TelegramError

getFile(*args, **kwargs)

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.

Parameters:
  • file_id (str) – File identifier to get info about.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, a telegram.File object is returned.

Return type:

telegram.File

Raises:

telegram.TelegramError

getGameHighScores(user_id, chat_id=None, message_id=None, inline_message_id=None, timeout=None, **kwargs)

Use this method to get data for high score tables.

Parameters:
  • user_id (int) – User identifier.
  • chat_id (Optional[int|str]) – Required if inline_message_id is not specified. Unique identifier for the target chat (or username of the target channel in the format @channelusername)
  • message_id (Optional[int]) – Required if inline_message_id is not specified. Identifier of the sent message.
  • inline_message_id (Optional[str]) – Required if chat_id and message_id are not specified. Identifier of the inline message.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
Returns:

Scores of the specified user and several of his

neighbors in a game.

Return type:

list[telegram.GameHighScore]

getMe(*args, **kwargs)

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

Parameters:timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
Returns:
A telegram.User instance representing that bot if the
credentials are valid, None otherwise.
Return type:telegram.User
Raises:telegram.TelegramError
getUpdates(*args, **kwargs)

Use this method to receive incoming updates using long polling.

Parameters:
  • offset (Optional[int]) – Identifier of the first update to be returned. Must be greater by one than the highest among the identifiers of previously received updates. By default, updates starting with the earliest unconfirmed update are returned. An update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id.
  • limit (Optional[int]) – Limits the number of updates to be retrieved. Values between 1-100 are accepted. Defaults to 100.
  • allowed_updates (Optional[list[str]]) – List the types of updates you want your bot to receive. For example, specify ["message", "edited_channel_post", "callback_query"] to only receive updates of these types. See telegram.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.
  • timeout (Optional[int]) – Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Be careful not to set this timeout too high, as the connection might be dropped and there’s no way of knowing it immediately (so most likely the failure will be detected after the timeout had passed).
  • network_delay – Deprecated. Will be honoured as read_latency for a while but will be removed in the future.
  • read_latency (Optional[float|int]) – Grace time in seconds for receiving the reply from server. Will be added to the timeout value and used as the read timeout from server (Default: 2).
  • **kwargs (dict) – Arbitrary keyword arguments.

Notes

The main problem with long polling is that a connection will be dropped and we won’t be getting the notification in time for it. For that, we need to use long polling, but not too long as well read latency which is short, but not too short. Long polling improves performance, but if it’s too long and the connection is dropped on many cases we won’t know the connection dropped before the long polling timeout and the read latency time had passed. If you experience connection timeouts, you should tune these settings.

Returns:list[telegram.Update]
Raises:telegram.TelegramError
getUserProfilePhotos(*args, **kwargs)

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

Parameters:
  • user_id (int) – Unique identifier of the target user.
  • offset (Optional[int]) – Sequential number of the first photo to be returned. By default, all photos are returned.
  • limit (Optional[int]) – Limits the number of photos to be retrieved. Values between 1-100 are accepted. Defaults to 100.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

A list of user profile photos objects is

returned.

Return type:

list[telegram.UserProfilePhotos]

Raises:

telegram.TelegramError

getWebhookInfo(timeout=None, **kwargs)

Use this method to get current webhook status.

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

Parameters:timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
Returns:class: telegram.WebhookInfo
get_chat(*args, **kwargs)

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.).

Parameters:
  • chat_id (int|str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, telegram.Chat is returned.

Return type:

telegram.Chat

Raises:

telegram.TelegramError

get_chat_administrators(*args, **kwargs)

Use this method to get a list of administrators in a chat. 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.

Parameters:
  • chat_id (int|str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

A list of chat member objects.

Return type:

list[telegram.ChatMember]

Raises:

telegram.TelegramError

get_chat_member(*args, **kwargs)

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

Parameters:
  • chat_id (int|str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • user_id (int) – Unique identifier of the target user.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, chat member object is returned.

Return type:

telegram.ChatMember

Raises:

telegram.TelegramError

get_chat_members_count(*args, **kwargs)

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

Parameters:
  • chat_id (int|str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, an int is returned.

Return type:

int

Raises:

telegram.TelegramError

get_file(*args, **kwargs)

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.

Parameters:
  • file_id (str) – File identifier to get info about.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, a telegram.File object is returned.

Return type:

telegram.File

Raises:

telegram.TelegramError

get_game_high_scores(user_id, chat_id=None, message_id=None, inline_message_id=None, timeout=None, **kwargs)

Use this method to get data for high score tables.

Parameters:
  • user_id (int) – User identifier.
  • chat_id (Optional[int|str]) – Required if inline_message_id is not specified. Unique identifier for the target chat (or username of the target channel in the format @channelusername)
  • message_id (Optional[int]) – Required if inline_message_id is not specified. Identifier of the sent message.
  • inline_message_id (Optional[str]) – Required if chat_id and message_id are not specified. Identifier of the inline message.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
Returns:

Scores of the specified user and several of his

neighbors in a game.

Return type:

list[telegram.GameHighScore]

get_me(*args, **kwargs)

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

Parameters:timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
Returns:
A telegram.User instance representing that bot if the
credentials are valid, None otherwise.
Return type:telegram.User
Raises:telegram.TelegramError
get_updates(*args, **kwargs)

Use this method to receive incoming updates using long polling.

Parameters:
  • offset (Optional[int]) – Identifier of the first update to be returned. Must be greater by one than the highest among the identifiers of previously received updates. By default, updates starting with the earliest unconfirmed update are returned. An update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id.
  • limit (Optional[int]) – Limits the number of updates to be retrieved. Values between 1-100 are accepted. Defaults to 100.
  • allowed_updates (Optional[list[str]]) – List the types of updates you want your bot to receive. For example, specify ["message", "edited_channel_post", "callback_query"] to only receive updates of these types. See telegram.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.
  • timeout (Optional[int]) – Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Be careful not to set this timeout too high, as the connection might be dropped and there’s no way of knowing it immediately (so most likely the failure will be detected after the timeout had passed).
  • network_delay – Deprecated. Will be honoured as read_latency for a while but will be removed in the future.
  • read_latency (Optional[float|int]) – Grace time in seconds for receiving the reply from server. Will be added to the timeout value and used as the read timeout from server (Default: 2).
  • **kwargs (dict) – Arbitrary keyword arguments.

Notes

The main problem with long polling is that a connection will be dropped and we won’t be getting the notification in time for it. For that, we need to use long polling, but not too long as well read latency which is short, but not too short. Long polling improves performance, but if it’s too long and the connection is dropped on many cases we won’t know the connection dropped before the long polling timeout and the read latency time had passed. If you experience connection timeouts, you should tune these settings.

Returns:list[telegram.Update]
Raises:telegram.TelegramError
get_user_profile_photos(*args, **kwargs)

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

Parameters:
  • user_id (int) – Unique identifier of the target user.
  • offset (Optional[int]) – Sequential number of the first photo to be returned. By default, all photos are returned.
  • limit (Optional[int]) – Limits the number of photos to be retrieved. Values between 1-100 are accepted. Defaults to 100.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

A list of user profile photos objects is

returned.

Return type:

list[telegram.UserProfilePhotos]

Raises:

telegram.TelegramError

get_webhook_info(timeout=None, **kwargs)

Use this method to get current webhook status.

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

Parameters:timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
Returns:class: telegram.WebhookInfo
kickChatMember(*args, **kwargs)

Use this method to kick a user from a group or a supergroup.

In the case of supergroups, the user will not be able to return to the group on their own using invite links, etc., unless unbanned first. The bot must be an administrator in the group for this to work.

Parameters:
  • chat_id (int|str) – Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername).
  • user_id (int|str) – Unique identifier of the target user.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, True is returned.

Return type:

bool

Raises:

telegram.TelegramError

kick_chat_member(*args, **kwargs)

Use this method to kick a user from a group or a supergroup.

In the case of supergroups, the user will not be able to return to the group on their own using invite links, etc., unless unbanned first. The bot must be an administrator in the group for this to work.

Parameters:
  • chat_id (int|str) – Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername).
  • user_id (int|str) – Unique identifier of the target user.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, True is returned.

Return type:

bool

Raises:

telegram.TelegramError

leaveChat(*args, **kwargs)

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

Parameters:
  • chat_id (int|str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, True is returned.

Return type:

bool

Raises:

telegram.TelegramError

leave_chat(*args, **kwargs)

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

Parameters:
  • chat_id (int|str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, True is returned.

Return type:

bool

Raises:

telegram.TelegramError

sendAudio(*args, **kwargs)

Use this method to send audio files, if you want Telegram clients to display them in the music player. Your audio must be in an .mp3 format. On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.

For backward compatibility, when both fields title and description are empty and mime-type of the sent file is not “audio/mpeg”, file is sent as playable voice message. In this case, your audio must be in an .ogg file encoded with OPUS. This will be removed in the future. You need to use sendVoice method instead.

Parameters:
  • chat_id (int|str) – Unique identifier for the message recipient - Chat id.
  • audio – Audio file to send. You can either pass a file_id as String to resend an audio that is already on the Telegram servers, or upload a new audio file using multipart/form-data.
  • duration (Optional[int]) – Duration of sent audio in seconds.
  • performer (Optional[str]) – Performer of sent audio.
  • title (Optional[str]) – Title of sent audio.
  • caption (Optional[str]) – Audio caption
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • reply_to_message_id (Optional[int]) – If the message is a reply, ID of the original message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – Send file timeout (default: 20 seconds).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, instance representing the message posted.

Return type:

telegram.Message

Raises:

telegram.TelegramError

sendChatAction(*args, **kwargs)

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).

Parameters:
  • chat_id (int|str) – Unique identifier for the message recipient - Chat id.
  • action (:class:`telegram.ChatAction`|str) –

    Type of action to broadcast. Choose one, depending on what the user is about to receive:

    • ChatAction.TYPING for text messages,
    • ChatAction.UPLOAD_PHOTO for photos,
    • ChatAction.UPLOAD_VIDEO for videos,
    • ChatAction.UPLOAD_AUDIO for audio files,
    • ChatAction.UPLOAD_DOCUMENT for general files,
    • ChatAction.FIND_LOCATION for location data.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
sendContact(*args, **kwargs)

Use this method to send phone contacts.

Parameters:
  • chat_id (int|str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • phone_number (str) – Contact’s phone number.
  • first_name (str) – Contact’s first name.
  • last_name (Optional[str]) – Contact’s last name.
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • reply_to_message_id (Optional[int]) – If the message is a reply, ID of the original message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, instance representing the message posted.

Return type:

telegram.Message

Raises:

telegram.TelegramError

sendDocument(*args, **kwargs)

Use this method to send general files.

Parameters:
  • chat_id (int|str) – Unique identifier for the message recipient - Chat id.
  • document – File to send. You can either pass a file_id as String to resend a file that is already on the Telegram servers, or upload a new file using multipart/form-data.
  • filename (Optional[str]) – File name that shows in telegram message (it is useful when you send file generated by temp module, for example).
  • caption (Optional[str]) – Document caption (may also be used when resending documents by file_id), 0-200 characters.
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • reply_to_message_id (Optional[int]) – If the message is a reply, ID of the original message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – Send file timeout (default: 20 seconds).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, instance representing the message posted.

Return type:

telegram.Message

Raises:

telegram.TelegramError

sendGame(*args, **kwargs)

Use this method to send a game.

Parameters:
  • chat_id (int|str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • game_short_name (str) – Short name of the game, serves as the unique identifier for the game.
Keyword Arguments:
 
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • reply_to_message_id (Optional[int]) – If the message is a reply, ID of the original message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
Returns:

On success, the sent message is returned.

Return type:

telegram.Message

Raises:

telegram.TelegramError

sendLocation(*args, **kwargs)

Use this method to send point on the map.

Parameters:
  • chat_id (int|str) – Unique identifier for the message recipient - Chat id.
  • latitude (float) – Latitude of location.
  • longitude (float) – Longitude of location.
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • reply_to_message_id (Optional[int]) – If the message is a reply, ID of the original message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, instance representing the message posted.

Return type:

telegram.Message

Raises:

telegram.TelegramError

sendMessage(*args, **kwargs)

Use this method to send text messages.

Parameters:
  • chat_id (int|str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • text (str) – Text of the message to be sent. The current maximum length is 4096 UTF-8 characters.
  • parse_mode (Optional[str]) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.
  • disable_web_page_preview (Optional[bool]) – Disables link previews for links in this message.
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • reply_to_message_id (Optional[int]) – If the message is a reply, ID of the original message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, the sent message is returned.

Return type:

telegram.Message

Raises:

telegram.TelegramError

sendPhoto(*args, **kwargs)

Use this method to send photos.

Parameters:
  • chat_id (int|str) – Unique identifier for the message recipient - Chat id.
  • photo – Photo to send. You can either pass a file_id as String to resend a photo that is already on the Telegram servers, or upload a new photo using multipart/form-data.
  • caption (Optional[str]) – Photo caption (may also be used when resending photos by file_id).
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • reply_to_message_id (Optional[int]) – If the message is a reply, ID of the original message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – Send file timeout (default: 20 seconds).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, instance representing the message posted.

Return type:

telegram.Message

Raises:

telegram.TelegramError

sendSticker(*args, **kwargs)

Use this method to send .webp stickers.

Parameters:
  • chat_id (int|str) – Unique identifier for the message recipient - Chat id.
  • sticker – Sticker to send. You can either pass a file_id as String to resend a sticker that is already on the Telegram servers, or upload a new sticker using multipart/form-data.
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • reply_to_message_id (Optional[int]) – If the message is a reply, ID of the original message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, instance representing the message posted.

Return type:

telegram.Message

Raises:

telegram.TelegramError

sendVenue(*args, **kwargs)

Use this method to send information about a venue.

Parameters:
  • chat_id (int|str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • latitude (float) – Latitude of the venue.
  • longitude (float) – Longitude of the venue.
  • title (str) – Name of the venue.
  • address (str) – Address of the venue.
  • foursquare_id (Optional[str]) – Foursquare identifier of the venue.
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • reply_to_message_id (Optional[int]) – If the message is a reply, ID of the original message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, instance representing the message posted.

Return type:

telegram.Message

Raises:

telegram.TelegramError

sendVideo(*args, **kwargs)

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

Parameters:
  • chat_id (int|str) – Unique identifier for the message recipient - Chat id.
  • video – Video to send. You can either pass a file_id as String to resend a video that is already on the Telegram servers, or upload a new video file using multipart/form-data.
  • duration (Optional[int]) – Duration of sent video in seconds.
  • caption (Optional[str]) – Video caption (may also be used when resending videos by file_id).
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • reply_to_message_id (Optional[int]) – If the message is a reply, ID of the original message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – Send file timeout (default: 20 seconds).
Returns:

On success, instance representing the message posted.

Return type:

telegram.Message

Raises:

telegram.TelegramError

sendVoice(*args, **kwargs)

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). On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.

Parameters:
  • chat_id (int|str) – Unique identifier for the message recipient - Chat id.
  • voice – Audio file to send. You can either pass a file_id as String to resend an audio that is already on the Telegram servers, or upload a new audio file using multipart/form-data.
  • duration (Optional[int]) – Duration of sent audio in seconds.
  • caption (Optional[str]) – Voice caption
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • reply_to_message_id (Optional[int]) – If the message is a reply, ID of the original message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – Send file timeout (default: 20 seconds).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, instance representing the message posted.

Return type:

telegram.Message

Raises:

telegram.TelegramError

send_audio(*args, **kwargs)

Use this method to send audio files, if you want Telegram clients to display them in the music player. Your audio must be in an .mp3 format. On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.

For backward compatibility, when both fields title and description are empty and mime-type of the sent file is not “audio/mpeg”, file is sent as playable voice message. In this case, your audio must be in an .ogg file encoded with OPUS. This will be removed in the future. You need to use sendVoice method instead.

Parameters:
  • chat_id (int|str) – Unique identifier for the message recipient - Chat id.
  • audio – Audio file to send. You can either pass a file_id as String to resend an audio that is already on the Telegram servers, or upload a new audio file using multipart/form-data.
  • duration (Optional[int]) – Duration of sent audio in seconds.
  • performer (Optional[str]) – Performer of sent audio.
  • title (Optional[str]) – Title of sent audio.
  • caption (Optional[str]) – Audio caption
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • reply_to_message_id (Optional[int]) – If the message is a reply, ID of the original message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – Send file timeout (default: 20 seconds).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, instance representing the message posted.

Return type:

telegram.Message

Raises:

telegram.TelegramError

send_chat_action(*args, **kwargs)

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).

Parameters:
  • chat_id (int|str) – Unique identifier for the message recipient - Chat id.
  • action (:class:`telegram.ChatAction`|str) –

    Type of action to broadcast. Choose one, depending on what the user is about to receive:

    • ChatAction.TYPING for text messages,
    • ChatAction.UPLOAD_PHOTO for photos,
    • ChatAction.UPLOAD_VIDEO for videos,
    • ChatAction.UPLOAD_AUDIO for audio files,
    • ChatAction.UPLOAD_DOCUMENT for general files,
    • ChatAction.FIND_LOCATION for location data.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
send_contact(*args, **kwargs)

Use this method to send phone contacts.

Parameters:
  • chat_id (int|str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • phone_number (str) – Contact’s phone number.
  • first_name (str) – Contact’s first name.
  • last_name (Optional[str]) – Contact’s last name.
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • reply_to_message_id (Optional[int]) – If the message is a reply, ID of the original message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, instance representing the message posted.

Return type:

telegram.Message

Raises:

telegram.TelegramError

send_document(*args, **kwargs)

Use this method to send general files.

Parameters:
  • chat_id (int|str) – Unique identifier for the message recipient - Chat id.
  • document – File to send. You can either pass a file_id as String to resend a file that is already on the Telegram servers, or upload a new file using multipart/form-data.
  • filename (Optional[str]) – File name that shows in telegram message (it is useful when you send file generated by temp module, for example).
  • caption (Optional[str]) – Document caption (may also be used when resending documents by file_id), 0-200 characters.
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • reply_to_message_id (Optional[int]) – If the message is a reply, ID of the original message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – Send file timeout (default: 20 seconds).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, instance representing the message posted.

Return type:

telegram.Message

Raises:

telegram.TelegramError

send_game(*args, **kwargs)

Use this method to send a game.

Parameters:
  • chat_id (int|str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • game_short_name (str) – Short name of the game, serves as the unique identifier for the game.
Keyword Arguments:
 
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • reply_to_message_id (Optional[int]) – If the message is a reply, ID of the original message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
Returns:

On success, the sent message is returned.

Return type:

telegram.Message

Raises:

telegram.TelegramError

send_location(*args, **kwargs)

Use this method to send point on the map.

Parameters:
  • chat_id (int|str) – Unique identifier for the message recipient - Chat id.
  • latitude (float) – Latitude of location.
  • longitude (float) – Longitude of location.
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • reply_to_message_id (Optional[int]) – If the message is a reply, ID of the original message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, instance representing the message posted.

Return type:

telegram.Message

Raises:

telegram.TelegramError

send_message(*args, **kwargs)

Use this method to send text messages.

Parameters:
  • chat_id (int|str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • text (str) – Text of the message to be sent. The current maximum length is 4096 UTF-8 characters.
  • parse_mode (Optional[str]) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.
  • disable_web_page_preview (Optional[bool]) – Disables link previews for links in this message.
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • reply_to_message_id (Optional[int]) – If the message is a reply, ID of the original message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, the sent message is returned.

Return type:

telegram.Message

Raises:

telegram.TelegramError

send_photo(*args, **kwargs)

Use this method to send photos.

Parameters:
  • chat_id (int|str) – Unique identifier for the message recipient - Chat id.
  • photo – Photo to send. You can either pass a file_id as String to resend a photo that is already on the Telegram servers, or upload a new photo using multipart/form-data.
  • caption (Optional[str]) – Photo caption (may also be used when resending photos by file_id).
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • reply_to_message_id (Optional[int]) – If the message is a reply, ID of the original message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – Send file timeout (default: 20 seconds).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, instance representing the message posted.

Return type:

telegram.Message

Raises:

telegram.TelegramError

send_sticker(*args, **kwargs)

Use this method to send .webp stickers.

Parameters:
  • chat_id (int|str) – Unique identifier for the message recipient - Chat id.
  • sticker – Sticker to send. You can either pass a file_id as String to resend a sticker that is already on the Telegram servers, or upload a new sticker using multipart/form-data.
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • reply_to_message_id (Optional[int]) – If the message is a reply, ID of the original message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, instance representing the message posted.

Return type:

telegram.Message

Raises:

telegram.TelegramError

send_venue(*args, **kwargs)

Use this method to send information about a venue.

Parameters:
  • chat_id (int|str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • latitude (float) – Latitude of the venue.
  • longitude (float) – Longitude of the venue.
  • title (str) – Name of the venue.
  • address (str) – Address of the venue.
  • foursquare_id (Optional[str]) – Foursquare identifier of the venue.
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • reply_to_message_id (Optional[int]) – If the message is a reply, ID of the original message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, instance representing the message posted.

Return type:

telegram.Message

Raises:

telegram.TelegramError

send_video(*args, **kwargs)

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

Parameters:
  • chat_id (int|str) – Unique identifier for the message recipient - Chat id.
  • video – Video to send. You can either pass a file_id as String to resend a video that is already on the Telegram servers, or upload a new video file using multipart/form-data.
  • duration (Optional[int]) – Duration of sent video in seconds.
  • caption (Optional[str]) – Video caption (may also be used when resending videos by file_id).
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • reply_to_message_id (Optional[int]) – If the message is a reply, ID of the original message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – Send file timeout (default: 20 seconds).
Returns:

On success, instance representing the message posted.

Return type:

telegram.Message

Raises:

telegram.TelegramError

send_voice(*args, **kwargs)

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). On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.

Parameters:
  • chat_id (int|str) – Unique identifier for the message recipient - Chat id.
  • voice – Audio file to send. You can either pass a file_id as String to resend an audio that is already on the Telegram servers, or upload a new audio file using multipart/form-data.
  • duration (Optional[int]) – Duration of sent audio in seconds.
  • caption (Optional[str]) – Voice caption
  • disable_notification (Optional[bool]) – Sends the message silently. iOS users will not receive a notification, Android users will receive a notification with no sound.
  • reply_to_message_id (Optional[int]) – If the message is a reply, ID of the original message.
  • reply_markup (Optional[telegram.ReplyMarkup]) – 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.
  • timeout (Optional[int|float]) – Send file timeout (default: 20 seconds).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, instance representing the message posted.

Return type:

telegram.Message

Raises:

telegram.TelegramError

setGameScore(user_id, score, chat_id=None, message_id=None, inline_message_id=None, edit_message=None, force=None, disable_edit_message=None, timeout=None, **kwargs)

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

Parameters:
  • user_id (int) – User identifier.
  • score (int) – New score, must be non-negative.
  • chat_id (Optional[int|str]) – Required if inline_message_id is not specified. Unique identifier for the target chat (or username of the target channel in the format @channelusername)
  • message_id (Optional[int]) – Required if inline_message_id is not specified. Identifier of the sent message.
  • inline_message_id (Optional[str]) – Required if chat_id and message_id are not specified. Identifier of the inline message.
  • force (Optional[bool]) – Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters.
  • disable_edit_message (Optional[bool]) – Pass True, if the game message should not be automatically edited to include the current scoreboard.
  • edit_message (Optional[bool]) – Deprecated. Has the opposite logic for disable_edit_message.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
Returns:

The edited message, or if the

message wasn’t sent by the bot, True.

Return type:

telegram.Message or True

setWebhook(*args, **kwargs)

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.

Parameters:
  • url (str) – HTTPS url to send updates to. Use an empty string to remove webhook integration.
  • certificate (file) – Upload your public key certificate so that the root certificate in use can be checked.
  • max_connections (Optional[int]) – 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 (Optional[list[str]]) – List the types of updates you want your bot to receive. For example, specify ["message", "edited_channel_post", "callback_query"] to only receive updates of these types. See telegram.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.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, True is returned.

Return type:

bool

Raises:

telegram.TelegramError

set_game_score(user_id, score, chat_id=None, message_id=None, inline_message_id=None, edit_message=None, force=None, disable_edit_message=None, timeout=None, **kwargs)

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

Parameters:
  • user_id (int) – User identifier.
  • score (int) – New score, must be non-negative.
  • chat_id (Optional[int|str]) – Required if inline_message_id is not specified. Unique identifier for the target chat (or username of the target channel in the format @channelusername)
  • message_id (Optional[int]) – Required if inline_message_id is not specified. Identifier of the sent message.
  • inline_message_id (Optional[str]) – Required if chat_id and message_id are not specified. Identifier of the inline message.
  • force (Optional[bool]) – Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters.
  • disable_edit_message (Optional[bool]) – Pass True, if the game message should not be automatically edited to include the current scoreboard.
  • edit_message (Optional[bool]) – Deprecated. Has the opposite logic for disable_edit_message.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
Returns:

The edited message, or if the

message wasn’t sent by the bot, True.

Return type:

telegram.Message or True

set_webhook(*args, **kwargs)

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.

Parameters:
  • url (str) – HTTPS url to send updates to. Use an empty string to remove webhook integration.
  • certificate (file) – Upload your public key certificate so that the root certificate in use can be checked.
  • max_connections (Optional[int]) – 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 (Optional[list[str]]) – List the types of updates you want your bot to receive. For example, specify ["message", "edited_channel_post", "callback_query"] to only receive updates of these types. See telegram.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.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, True is returned.

Return type:

bool

Raises:

telegram.TelegramError

unbanChatMember(*args, **kwargs)

Use this method to unban a previously kicked user in a supergroup. The user will not return to the group automatically, but will be able to join via link, etc. The bot must be an administrator in the group for this to work.

Parameters:
  • chat_id (int|str) – Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername).
  • user_id (int|str) – Unique identifier of the target user.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, True is returned.

Return type:

bool

Raises:

telegram.TelegramError

unban_chat_member(*args, **kwargs)

Use this method to unban a previously kicked user in a supergroup. The user will not return to the group automatically, but will be able to join via link, etc. The bot must be an administrator in the group for this to work.

Parameters:
  • chat_id (int|str) – Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername).
  • user_id (int|str) – Unique identifier of the target user.
  • timeout (Optional[int|float]) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, True is returned.

Return type:

bool

Raises:

telegram.TelegramError