telegram package

Module contents

A library that provides a Python interface to the Telegram Bot API

class telegram.Audio(file_id, duration, performer=None, title=None, mime_type=None, file_size=None, thumb=None, bot=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents an audio file to be treated as music by the Telegram clients.

file_id

Unique identifier for this file.

Type:str
duration

Duration of the audio in seconds.

Type:int
performer

Optional. Performer of the audio as defined by sender or by audio tags.

Type:str
title

Optional. Title of the audio as defined by sender or by audio tags.

Type:str
mime_type

Optional. MIME type of the file as defined by sender.

Type:str
file_size

Optional. File size.

Type:int
thumb

Optional. Thumbnail of the album cover to which the music file belongs

Type:telegram.PhotoSize
bot

Optional. The Bot to use for instance methods.

Type:telegram.Bot
Parameters:
  • file_id (str) – Unique identifier for this file.
  • duration (int) – Duration of the audio in seconds as defined by sender.
  • performer (str, optional) – Performer of the audio as defined by sender or by audio tags.
  • title (str, optional) – Title of the audio as defined by sender or by audio tags.
  • mime_type (str, optional) – MIME type of the file as defined by sender.
  • file_size (int, optional) – File size.
  • thumb (telegram.PhotoSize, optional) – Thumbnail of the album cover to which the music file belongs
  • bot (telegram.Bot, optional) – The Bot to use for instance methods.
  • **kwargs (dict) – Arbitrary keyword arguments.
classmethod de_json(data, bot)
get_file(timeout=None, **kwargs)

Convenience wrapper over telegram.Bot.get_file

Parameters:
  • timeout (int | float, optional) – 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:

telegram.File

Raises:

telegram.TelegramError

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

Bases: telegram.base.TelegramObject

This object represents a Telegram Bot.

Parameters:
  • token (str) – Bot’s unique authentication.
  • base_url (str, optional) – Telegram Bot API service URL.
  • base_file_url (str, optional) – Telegram Bot API file URL.
  • request (telegram.utils.request.Request, optional) – Pre initialized telegram.utils.request.Request.
  • private_key (bytes, optional) – Private key for decryption of telegram passport data.
  • private_key_password (bytes, optional) – Password for above private key.
addStickerToSet(user_id, name, png_sticker, emojis, mask_position=None, timeout=20, **kwargs)

Alias for add_sticker_to_set

add_sticker_to_set(user_id, name, png_sticker, emojis, mask_position=None, timeout=20, **kwargs)

Use this method to add a new sticker to a set created by the bot.

Note

The png_sticker argument can be either a file_id, an URL or a file from disk open(filename, 'rb')

Parameters:
  • user_id (int) – User identifier of created sticker set owner.
  • name (str) – Sticker set name.
  • png_sticker (str | filelike object) – 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.
  • emojis (str) – One or more emoji corresponding to the sticker.
  • mask_position (telegram.MaskPosition, optional) – Position where the mask should beplaced on faces.
  • timeout (int | float, optional) – 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

answerCallbackQuery(callback_query_id, text=None, show_alert=False, url=None, cache_time=None, timeout=None, **kwargs)

Alias for answer_callback_query

answerInlineQuery(inline_query_id, results, cache_time=300, is_personal=None, next_offset=None, switch_pm_text=None, switch_pm_parameter=None, timeout=None, **kwargs)

Alias for answer_inline_query

answerPreCheckoutQuery(pre_checkout_query_id, ok, error_message=None, timeout=None, **kwargs)

Alias for answer_pre_checkout_query

answerShippingQuery(shipping_query_id, ok, shipping_options=None, error_message=None, timeout=None, **kwargs)

Alias for answer_shipping_query

answer_callback_query(callback_query_id, text=None, show_alert=False, url=None, cache_time=None, timeout=None, **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. 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.

Parameters:
  • callback_query_id (str) – Unique identifier for the query to be answered.
  • text (str, optional) – Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters.
  • show_alert (bool, optional) – 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 (str, optional) – URL that will be opened by the user’s client. If you have created a Game and accepted the conditions via @Botfather, specify the URL that opens your game - note that this will only work if the query comes from a callback game button. Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.
  • cache_time (int, optional) – The maximum amount of time in seconds that the result of the callback query may be cached client-side. Defaults to 0.
  • timeout (int | float, optional) – 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:

bool On success, True is returned.

Raises:

telegram.TelegramError

answer_inline_query(inline_query_id, results, cache_time=300, is_personal=None, next_offset=None, switch_pm_text=None, switch_pm_parameter=None, timeout=None, **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 (int, optional) – 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 (bool, optional) – 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 (str, optional) – 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 (str, optional) – 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 (str, optional) – 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.
  • timeout (int | float, optional) – If this value is specified, use it as he read timeout from the server (instead of the one specified during creation of the connection pool).
  • **kwargs (dict) – Arbitrary keyword arguments.

Example

An inline bot that sends YouTube videos can ask the user to connect the bot to their YouTube account to adapt search results accordingly. To do this, it displays a ‘Connect your YouTube account’ button above the results, or even before showing any. The user presses the button, switches to a private chat with the bot and, in doing so, passes a start parameter that instructs the bot to return an oauth link. Once done, the bot can offer a switch_inline button so that the user can easily return to the chat where they wanted to use the bot’s inline capabilities.

Returns:bool On success, True is returned.
Raises:telegram.TelegramError
answer_pre_checkout_query(pre_checkout_query_id, ok, error_message=None, timeout=None, **kwargs)

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.

Note

The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.

Parameters:
  • pre_checkout_query_id (str) – Unique identifier for the query to be answered.
  • ok (bool) – 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 (str, optional) – 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.
  • timeout (int | float, optional) – 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_shipping_query(shipping_query_id, ok, shipping_options=None, error_message=None, timeout=None, **kwargs)

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. Use this method to reply to shipping queries.

Parameters:
  • shipping_query_id (str) – Unique identifier for the query to be answered.
  • ok (bool) – 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 (List[telegram.ShippingOption]) – Required if ok is True. A JSON-serialized array of available shipping options.
  • error_message (str, optional) – 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.
  • timeout (int | float, optional) – 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:

bool; On success, True is returned.

Raises:

telegram.TelegramError

createNewStickerSet(user_id, name, title, png_sticker, emojis, contains_masks=None, mask_position=None, timeout=20, **kwargs)

Alias for create_new_sticker_set

create_new_sticker_set(user_id, name, title, png_sticker, emojis, contains_masks=None, mask_position=None, timeout=20, **kwargs)

Use this method to create new sticker set owned by a user.

The bot will be able to edit the created sticker set.

Note

The png_sticker argument can be either a file_id, an URL or a file from disk open(filename, 'rb')

Parameters:
  • user_id (int) – User identifier of created sticker set owner.
  • name (str) – 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 (str) – Sticker set title, 1-64 characters.
  • png_sticker (str | filelike object) – 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.
  • emojis (str) – One or more emoji corresponding to the sticker.
  • contains_masks (bool, optional) – Pass True, if a set of mask stickers should be created.
  • mask_position (telegram.MaskPosition, optional) – Position where the mask should be placed on faces.
  • timeout (int | float, optional) – 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

deleteChatPhoto(chat_id, timeout=None, **kwargs)

Alias for delete_chat_photo

deleteChatStickerSet(chat_id, timeout=None, **kwargs)

Alias for delete_chat_sticker_set

deleteMessage(chat_id, message_id, timeout=None, **kwargs)

Alias for delete_message

deleteStickerFromSet(sticker, timeout=None, **kwargs)

Alias for delete_sticker_from_set

deleteWebhook(timeout=None, **kwargs)

Alias for delete_webhook

delete_chat_photo(chat_id, timeout=None, **kwargs)

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.

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • timeout (int | float, optional) – 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

Note

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

Returns:Returns True on success.
Return type:bool
Raises:telegram.TelegramError
delete_chat_sticker_set(chat_id, timeout=None, **kwargs)

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 telegram.Chat.can_set_sticker_set optionally returned in get_chat requests to check if the bot can use this method.

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername).
  • timeout (int | float, optional) – 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:

True on success.

Return type:

bool

delete_message(chat_id, message_id, timeout=None, **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) – Identifier of the message to delete.
  • timeout (int | float, optional) – If this value is specified, use it as
  • read timeout (the) – 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

delete_sticker_from_set(sticker, timeout=None, **kwargs)

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

Parameters:
  • sticker (str) – File identifier of the sticker.
  • timeout (int | float, optional) – 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

delete_webhook(timeout=None, **kwargs)

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

Parameters:
  • timeout (int | float, optional) – 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:

bool On success, True is returned.

Raises:

telegram.TelegramError

editMessageCaption(chat_id=None, message_id=None, inline_message_id=None, caption=None, reply_markup=None, timeout=None, parse_mode=None, **kwargs)

Alias for edit_message_caption

editMessageLiveLocation(chat_id=None, message_id=None, inline_message_id=None, latitude=None, longitude=None, location=None, reply_markup=None, timeout=None, **kwargs)

Alias for edit_message_live_location

editMessageMedia(chat_id=None, message_id=None, inline_message_id=None, media=None, reply_markup=None, timeout=None, **kwargs)

Alias for edit_message_media

editMessageReplyMarkup(chat_id=None, message_id=None, inline_message_id=None, reply_markup=None, timeout=None, **kwargs)

Alias for edit_message_reply_markup

editMessageText(text, chat_id=None, message_id=None, inline_message_id=None, parse_mode=None, disable_web_page_preview=None, reply_markup=None, timeout=None, **kwargs)

Alias for edit_message_text

edit_message_caption(chat_id=None, message_id=None, inline_message_id=None, caption=None, reply_markup=None, timeout=None, parse_mode=None, **kwargs)

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

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • message_id (int, optional) – Required if inline_message_id is not specified. Identifier of the sent message.
  • inline_message_id (str, optional) – Required if chat_id and message_id are not specified. Identifier of the inline message.
  • caption (str, optional) – New caption of the message.
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • reply_markup (telegram.ReplyMarkup, optional) – 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 (int | float, optional) – 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_live_location(chat_id=None, message_id=None, inline_message_id=None, latitude=None, longitude=None, location=None, reply_markup=None, timeout=None, **kwargs)

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

Note

You can either supply a latitude and longitude or a location.

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • message_id (int, optional) – Required if inline_message_id is not specified. Identifier of the sent message.
  • inline_message_id (str, optional) – Required if chat_id and message_id are not specified. Identifier of the inline message.
  • latitude (float, optional) – Latitude of location.
  • longitude (float, optional) – Longitude of location.
  • location (telegram.Location, optional) – The location to send.
  • reply_markup (telegram.ReplyMarkup, optional) – 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 (int | float, optional) – 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 edited message.

Return type:

telegram.Message

edit_message_media(chat_id=None, message_id=None, inline_message_id=None, media=None, reply_markup=None, timeout=None, **kwargs)

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.

Parameters:
  • chat_id (int | str, optional) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • message_id (int, optional) – Required if inline_message_id is not specified. Identifier of the sent message.
  • inline_message_id (str, optional) – Required if chat_id and message_id are not specified. Identifier of the inline message.
  • media (telegram.InputMedia) – An object for a new media content of the message.
  • reply_markup (telegram.ReplyMarkup, optional) – 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 (int | float, optional) – 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.
edit_message_reply_markup(chat_id=None, message_id=None, inline_message_id=None, reply_markup=None, timeout=None, **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 (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • message_id (int, optional) – Required if inline_message_id is not specified. Identifier of the sent message.
  • inline_message_id (str, optional) – Required if chat_id and message_id are not specified. Identifier of the inline message.
  • reply_markup (telegram.ReplyMarkup, optional) – 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 (int | float, optional) – 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 editedMessage is returned, otherwise True is returned.

Return type:

telegram.Message

Raises:

telegram.TelegramError

edit_message_text(text, chat_id=None, message_id=None, inline_message_id=None, parse_mode=None, disable_web_page_preview=None, reply_markup=None, timeout=None, **kwargs)

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

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • message_id (int, optional) – Required if inline_message_id is not specified. Identifier of the sent message.
  • inline_message_id (str, optional) – Required if chat_id and message_id are not specified. Identifier of the inline message.
  • text (str) – New text of the message.
  • parse_mode (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. See the constants in telegram.ParseMode for the available modes.
  • disable_web_page_preview (bool, optional) – Disables link previews for links in this message.
  • reply_markup (telegram.ReplyMarkup, optional) – 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 (int | float, optional) – 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

exportChatInviteLink(chat_id, timeout=None, **kwargs)

Alias for export_chat_invite_link

export_chat_invite_link(chat_id, timeout=None, **kwargs)

Use this method to export an invite link to 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.

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • timeout (int | float, optional) – 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:

Exported invite link on success.

Return type:

str

Raises:

telegram.TelegramError

first_name

Bot’s first name.

Type:str
forwardMessage(chat_id, from_chat_id, message_id, disable_notification=False, timeout=None, **kwargs)

Alias for forward_message

forward_message(chat_id, from_chat_id, message_id, disable_notification=False, timeout=None, **kwargs)

Use this method to forward messages of any kind.

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • from_chat_id (int | str) – Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername).
  • disable_notification (bool, optional) – Sends the message silently. Users will receive a notification with no sound.
  • message_id (int) – Message identifier in the chat specified in from_chat_id.
  • timeout (int | float, optional) – If this value is specified, use it as
  • read timeout (the) – 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

getChat(chat_id, timeout=None, **kwargs)

Alias for get_chat

getChatAdministrators(chat_id, timeout=None, **kwargs)

Alias for get_chat_administrators

getChatMember(chat_id, user_id, timeout=None, **kwargs)

Alias for get_chat_member

getChatMembersCount(chat_id, timeout=None, **kwargs)

Alias for get_chat_members_count

getFile(file_id, timeout=None, **kwargs)

Alias for get_file

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

Alias for get_game_high_scores

getMe(timeout=None, **kwargs)

Alias for get_me

getStickerSet(name, timeout=None, **kwargs)

Alias for get_sticker_set

getUpdates(offset=None, limit=100, timeout=0, read_latency=2.0, allowed_updates=None, **kwargs)

Alias for get_updates

getUserProfilePhotos(user_id, offset=None, limit=100, timeout=None, **kwargs)

Alias for get_user_profile_photos

getWebhookInfo(timeout=None, **kwargs)

Alias for get_webhook_info

get_chat(chat_id, timeout=None, **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 (int | float, optional) – 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:

telegram.Chat

Raises:

telegram.TelegramError

get_chat_administrators(chat_id, timeout=None, **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 (int | float, optional) – 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:

List[telegram.ChatMember]

Raises:

telegram.TelegramError

get_chat_member(chat_id, user_id, timeout=None, **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 (int | float, optional) – 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:

telegram.ChatMember

Raises:

telegram.TelegramError

get_chat_members_count(chat_id, timeout=None, **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 (int | float, optional) – 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:

Number of members in the chat.

Return type:

int

Raises:

telegram.TelegramError

get_file(file_id, timeout=None, **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. The file can then be downloaded with telegram.File.download. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling get_file again.

Parameters:
Returns:

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. Will return the score of the specified user and several of his neighbors in a game

Parameters:
  • user_id (int) – User identifier.
  • chat_id (int | str, optional) – Required if inline_message_id is not specified. Unique identifier for the target chat.
  • message_id (int, optional) – Required if inline_message_id is not specified. Identifier of the sent message.
  • inline_message_id (str, optional) – Required if chat_id and message_id are not specified. Identifier of the inline message.
  • timeout (int | float, optional) – 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:

List[telegram.GameHighScore]

Raises:

telegram.TelegramError

get_me(timeout=None, **kwargs)

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

Parameters:timeout (int | float, optional) – 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_sticker_set(name, timeout=None, **kwargs)

Use this method to get a sticker set.

Parameters:
  • name (str) – Short name of the sticker set that is used in t.me/addstickers/ URLs (e.g., animals)
  • timeout (int | float, optional) – 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:

telegram.StickerSet

Raises:

telegram.TelegramError

get_updates(offset=None, limit=100, timeout=0, read_latency=2.0, allowed_updates=None, **kwargs)

Use this method to receive incoming updates using long polling.

Parameters:
  • offset (int, optional) – Identifier of the first update to be returned. Must be greater by one than the highest among the identifiers of previously received updates. By default, updates starting with the earliest unconfirmed update are returned. An update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id. The negative offset can be specified to retrieve updates starting from -offset update from the end of the updates queue. All previous updates will forgotten.
  • limit (int, optional) – Limits the number of updates to be retrieved. Values between 1-100 are accepted. Defaults to 100.
  • timeout (int, optional) – Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be positive, short polling should be used for testing purposes only.
  • allowed_updates (List[str]), optional) – 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 get_updates, so unwanted updates may be received for a short period of time.
  • **kwargs (dict) – Arbitrary keyword arguments.

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.
  3. To take full advantage of this library take a look at telegram.ext.Updater
Returns:List[telegram.Update]
Raises:telegram.TelegramError
get_user_profile_photos(user_id, offset=None, limit=100, timeout=None, **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 (int, optional) – Sequential number of the first photo to be returned. By default, all photos are returned.
  • limit (int, optional) – Limits the number of photos to be retrieved. Values between 1-100 are accepted. Defaults to 100.
  • timeout (int | float, optional) – 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:

telegram.UserProfilePhotos

Raises:

telegram.TelegramError

get_webhook_info(timeout=None, **kwargs)

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.

Parameters:
  • timeout (int | float, optional) – 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:

telegram.WebhookInfo

id

Unique identifier for this bot.

Type:int
kickChatMember(chat_id, user_id, timeout=None, until_date=None, **kwargs)

Alias for kick_chat_member

kick_chat_member(chat_id, user_id, timeout=None, until_date=None, **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 chat or username of the target channel (in the format @channelusername).
  • user_id (int) – Unique identifier of the target user.
  • timeout (int | float, optional) – 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).
  • until_date (int | datetime.datetime, optional) – 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.
  • **kwargs (dict) – Arbitrary keyword arguments.

Note

In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’ setting is off in the target group. Otherwise members may only be removed by the group’s creator or by the member that added them.

Returns:bool On success, True is returned.
Raises:telegram.TelegramError
last_name

Optional. Bot’s last name.

Type:str
leaveChat(chat_id, timeout=None, **kwargs)

Alias for leave_chat

leave_chat(chat_id, timeout=None, **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 (int | float, optional) – 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:

bool On success, True is returned.

Raises:

telegram.TelegramError

name

Bot’s @username.

Type:str
pinChatMessage(chat_id, message_id, disable_notification=None, timeout=None, **kwargs)

Alias for pin_chat_message

pin_chat_message(chat_id, message_id, disable_notification=None, timeout=None, **kwargs)

Use this method to pin a message in a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • message_id (int) – Identifier of a message to pin.
  • disable_notification (bool, optional) – Pass True, if it is not necessary to send a notification to all group members about the new pinned message.
  • timeout (int | float, optional) – 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:

Returns True on success.

Return type:

bool

Raises:

telegram.TelegramError

promoteChatMember(chat_id, user_id, can_change_info=None, can_post_messages=None, can_edit_messages=None, can_delete_messages=None, can_invite_users=None, can_restrict_members=None, can_pin_messages=None, can_promote_members=None, timeout=None, **kwargs)

Alias for promote_chat_member

promote_chat_member(chat_id, user_id, can_change_info=None, can_post_messages=None, can_edit_messages=None, can_delete_messages=None, can_invite_users=None, can_restrict_members=None, can_pin_messages=None, can_promote_members=None, timeout=None, **kwargs)

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

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername).
  • user_id (int) – Unique identifier of the target user.
  • can_change_info (bool, optional) – Pass True, if the administrator can change chat title, photo and other settings.
  • can_post_messages (bool, optional) – Pass True, if the administrator can create channel posts, channels only.
  • can_edit_messages (bool, optional) – Pass True, if the administrator can edit messages of other users, channels only.
  • can_delete_messages (bool, optional) – Pass True, if the administrator can delete messages of other users.
  • can_invite_users (bool, optional) – Pass True, if the administrator can invite new users to the chat.
  • can_restrict_members (bool, optional) – Pass True, if the administrator can restrict, ban or unban chat members.
  • can_pin_messages (bool, optional) – Pass True, if the administrator can pin messages, supergroups only.
  • can_promote_members (bool, optional) – 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).
  • timeout (int | float, optional) – 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:

Returns True on success.

Return type:

bool

Raises:

telegram.TelegramError

request
restrictChatMember(chat_id, user_id, until_date=None, can_send_messages=None, can_send_media_messages=None, can_send_other_messages=None, can_add_web_page_previews=None, timeout=None, **kwargs)

Alias for restrict_chat_member

restrict_chat_member(chat_id, user_id, until_date=None, can_send_messages=None, can_send_media_messages=None, can_send_other_messages=None, can_add_web_page_previews=None, timeout=None, **kwargs)

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.

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername).
  • user_id (int) – Unique identifier of the target user.
  • until_date (int | datetime.datetime, optional) – Date when restrictions will be lifted for the user, unix time. If user is restricted for more than 366 days or less than 30 seconds from the current time, they are considered to be restricted forever.
  • can_send_messages (bool, optional) – Pass True, if the user can send text messages, contacts, locations and venues.
  • can_send_media_messages (bool, optional) – Pass True, if the user can send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages.
  • can_send_other_messages (bool, optional) – Pass True, if the user can send animations, games, stickers and use inline bots, implies can_send_media_messages.
  • can_add_web_page_previews (bool, optional) – Pass True, if the user may add web page previews to their messages, implies can_send_media_messages.
  • timeout (int | float, optional) – 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:

Returns True on success.

Return type:

bool

Raises:

telegram.TelegramError

sendAnimation(chat_id, animation, duration=None, width=None, height=None, thumb=None, caption=None, parse_mode=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=20, **kwargs)

Alias for send_animation

sendAudio(chat_id, audio, duration=None, performer=None, title=None, caption=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=20, parse_mode=None, thumb=None, **kwargs)

Alias for send_audio

sendChatAction(chat_id, action, timeout=None, **kwargs)

Alias for send_chat_action

sendContact(chat_id, phone_number=None, first_name=None, last_name=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=None, contact=None, vcard=None, **kwargs)

Alias for send_contact

sendDocument(chat_id, document, filename=None, caption=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=20, parse_mode=None, thumb=None, **kwargs)

Alias for send_document

sendGame(chat_id, game_short_name, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=None, **kwargs)

Alias for send_game

sendInvoice(chat_id, title, description, payload, provider_token, start_parameter, currency, prices, photo_url=None, photo_size=None, photo_width=None, photo_height=None, need_name=None, need_phone_number=None, need_email=None, need_shipping_address=None, is_flexible=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, provider_data=None, send_phone_number_to_provider=None, send_email_to_provider=None, timeout=None, **kwargs)

Alias for send_invoice

sendLocation(chat_id, latitude=None, longitude=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=None, location=None, live_period=None, **kwargs)

Alias for send_location

sendMediaGroup(chat_id, media, disable_notification=None, reply_to_message_id=None, timeout=20, **kwargs)

Alias for send_media_group

sendMessage(chat_id, text, parse_mode=None, disable_web_page_preview=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=None, **kwargs)

Alias for send_message

sendPhoto(chat_id, photo, caption=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=20, parse_mode=None, **kwargs)

Alias for send_photo

sendSticker(chat_id, sticker, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=20, **kwargs)

Alias for send_sticker

sendVenue(chat_id, latitude=None, longitude=None, title=None, address=None, foursquare_id=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=None, venue=None, foursquare_type=None, **kwargs)

Alias for send_venue

sendVideo(chat_id, video, duration=None, caption=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=20, width=None, height=None, parse_mode=None, supports_streaming=None, thumb=None, **kwargs)

Alias for send_video

sendVideoNote(chat_id, video_note, duration=None, length=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=20, thumb=None, **kwargs)

Alias for send_video_note

sendVoice(chat_id, voice, duration=None, caption=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=20, parse_mode=None, **kwargs)

Alias for send_voice

send_animation(chat_id, animation, duration=None, width=None, height=None, thumb=None, caption=None, parse_mode=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=20, **kwargs)

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

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • animation (str | filelike object | telegram.Animation) – Animation to send. Pass a file_id as String to send an animation that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an animation from the Internet, or upload a new animation using multipart/form-data. Lastly you can pass an existing telegram.Animation object to send.
  • duration (int, optional) – Duration of sent animation in seconds.
  • width (int, optional) – Animation width.
  • height (int, optional) – Animation height.
  • thumb (filelike object, optional) – 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 90. Ignored if the file is not is passed as a string or file_id.
  • caption (str, optional) – Animation caption (may also be used when resending animations by file_id), 0-1024 characters.
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • disable_notification (bool, optional) – Sends the message silently. Users will receive a notification with no sound.
  • reply_to_message_id (int, optional) – If the message is a reply, ID of the original message.
  • reply_markup (telegram.ReplyMarkup, optional) – 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 (int | float, optional) – Send file timeout (default: 20 seconds).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, the sent Message is returned.

Return type:

telegram.Message

Raises:

telegram.TelegramError

send_audio(chat_id, audio, duration=None, performer=None, title=None, caption=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=20, parse_mode=None, thumb=None, **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 the .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 sending voice messages, use the sendVoice method instead.

Note

The audio argument can be either a file_id, an URL or a file from disk open(filename, 'rb')

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • audio (str | filelike object | telegram.Audio) – Audio file to send. Pass a file_id as String to send an audio file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an audio file from the Internet, or upload a new one using multipart/form-data. Lastly you can pass an existing telegram.Audio object to send.
  • caption (str, optional) – Audio caption, 0-1024 characters.
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • duration (int, optional) – Duration of sent audio in seconds.
  • performer (str, optional) – Performer.
  • title (str, optional) – Track name.
  • disable_notification (bool, optional) – Sends the message silently. Users will receive a notification with no sound.
  • reply_to_message_id (int, optional) – If the message is a reply, ID of the original message.
  • reply_markup (telegram.ReplyMarkup, optional) – 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.
  • thumb (filelike object, optional) – 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 90. Ignored if the file is not is passed as a string or file_id.
  • timeout (int | float, optional) – Send file timeout (default: 20 seconds).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, the sent Message is returned.

Return type:

telegram.Message

Raises:

telegram.TelegramError

send_chat_action(chat_id, action, timeout=None, **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 target chat or username of the target channel (in the format @channelusername).
  • action (telegram.ChatAction | str) – Type of action to broadcast. Choose one, depending on what the user is about to receive. For convenience look at the constants in telegram.ChatAction
  • timeout (int | float, optional) – 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:

True on success.

Return type:

bool

Raises:

telegram.TelegramError

send_contact(chat_id, phone_number=None, first_name=None, last_name=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=None, contact=None, vcard=None, **kwargs)

Use this method to send phone contacts.

Note

You can either supply contact or phone_number and first_name with optionally last_name and optionally vcard.

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • phone_number (str, optional) – Contact’s phone number.
  • first_name (str, optional) – Contact’s first name.
  • last_name (str, optional) – Contact’s last name.
  • vcard (str, optional) – Additional data about the contact in the form of a vCard, 0-2048 bytes.
  • contact (telegram.Contact, optional) – The contact to send.
  • disable_notification (bool, optional) – Sends the message silently. Users will receive a notification with no sound.
  • reply_to_message_id (int, optional) – If the message is a reply, ID of the original message.
  • reply_markup (telegram.ReplyMarkup, optional) – 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 (int | float, optional) – 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_document(chat_id, document, filename=None, caption=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=20, parse_mode=None, thumb=None, **kwargs)

Use this method to send general files.

Note

The document argument can be either a file_id, an URL or a file from disk open(filename, 'rb')

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • document (str | filelike object | telegram.Document) – File to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. Lastly you can pass an existing telegram.Document object to send.
  • filename (str, optional) – File name that shows in telegram message (it is useful when you send file generated by temp module, for example). Undocumented.
  • caption (str, optional) – Document caption (may also be used when resending documents by file_id), 0-1024 characters.
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • disable_notification (bool, optional) – Sends the message silently. Users will receive a notification with no sound.
  • reply_to_message_id (int, optional) – If the message is a reply, ID of the original message.
  • reply_markup (telegram.ReplyMarkup, optional) – 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.
  • thumb (filelike object, optional) – 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 90. Ignored if the file is not is passed as a string or file_id.
  • timeout (int | float, optional) – Send file timeout (default: 20 seconds).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, the sent Message is returned.

Return type:

telegram.Message

Raises:

telegram.TelegramError

send_game(chat_id, game_short_name, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=None, **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. Set up your games via Botfather.
  • disable_notification (bool, optional) – Sends the message silently. Users will receive a notification with no sound.
  • reply_to_message_id (int, optional) – If the message is a reply, ID of the original message.
  • reply_markup (telegram.ReplyMarkup, optional) – 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 (int | float, optional) – 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_invoice(chat_id, title, description, payload, provider_token, start_parameter, currency, prices, photo_url=None, photo_size=None, photo_width=None, photo_height=None, need_name=None, need_phone_number=None, need_email=None, need_shipping_address=None, is_flexible=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, provider_data=None, send_phone_number_to_provider=None, send_email_to_provider=None, timeout=None, **kwargs)

Use this method to send invoices.

Parameters:
  • chat_id (int | str) – Unique identifier for the target private chat.
  • title (str) – Product name.
  • description (str) – Product description.
  • payload (str) – Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
  • provider_token (str) – Payments provider token, obtained via Botfather.
  • start_parameter (str) – Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter.
  • currency (str) – Three-letter ISO 4217 currency code.
  • prices (List[telegram.LabeledPrice) – Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.).
  • provider_data (str | object, optional) – JSON-encoded 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. When an object is passed, it will be encoded as JSON.
  • photo_url (str, optional) – URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. People like it better when they see what they are paying for.
  • photo_size (str, optional) – Photo size.
  • photo_width (int, optional) – Photo width.
  • photo_height (int, optional) – Photo height.
  • need_name (bool, optional) – Pass True, if you require the user’s full name to complete the order.
  • need_phone_number (bool, optional) – Pass True, if you require the user’s phone number to complete the order.
  • need_email (bool, optional) – Pass True, if you require the user’s email to complete the order.
  • need_shipping_address (bool, optional) – Pass True, if you require the user’s shipping address to complete the order.
  • send_phone_number_to_provider (bool, optional) – Pass True, if user’s phone number should be sent to provider.
  • send_email_to_provider (bool, optional) – Pass True, if user’s email address should be sent to provider.
  • is_flexible (bool, optional) – Pass True, if the final price depends on the shipping method.
  • disable_notification (bool, optional) – Sends the message silently. Users will receive a notification with no sound.
  • reply_to_message_id (int, optional) – If the message is a reply, ID of the original message.
  • reply_markup (telegram.ReplyMarkup, optional) – Additional interface options. An inlinekeyboard. If empty, one ‘Pay total price’ button will be shown. If not empty, the first button must be a Pay button.
  • timeout (int | float, optional) – 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_location(chat_id, latitude=None, longitude=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=None, location=None, live_period=None, **kwargs)

Use this method to send point on the map.

Note

You can either supply a latitude and longitude or a location.

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • latitude (float, optional) – Latitude of location.
  • longitude (float, optional) – Longitude of location.
  • location (telegram.Location, optional) – The location to send.
  • live_period (int, optional) – Period in seconds for which the location will be updated, should be between 60 and 86400.
  • disable_notification (bool, optional) – Sends the message silently. Users will receive a notification with no sound.
  • reply_to_message_id (int, optional) – If the message is a reply, ID of the original message.
  • reply_markup (telegram.ReplyMarkup, optional) – 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 (int | float, optional) – 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_media_group(chat_id, media, disable_notification=None, reply_to_message_id=None, timeout=20, **kwargs)

Use this method to send a group of photos or videos as an album.

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • media (List[telegram.InputMedia]) – An array describing photos and videos to be sent, must include 2–10 items.
  • disable_notification (bool, optional) – Sends the message silently. Users will receive a notification with no sound.
  • reply_to_message_id (int, optional) – If the message is a reply, ID of the original message.
  • timeout (int | float, optional) – Send file timeout (default: 20 seconds).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

An array of the sent Messages.

Return type:

List[telegram.Message]

Raises:

telegram.TelegramError

send_message(chat_id, text, parse_mode=None, disable_web_page_preview=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=None, **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. Max 4096 characters. Also found as telegram.constants.MAX_MESSAGE_LENGTH.
  • parse_mode (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. See the constants in telegram.ParseMode for the available modes.
  • disable_web_page_preview (bool, optional) – Disables link previews for links in this message.
  • disable_notification (bool, optional) – Sends the message silently. Users will receive a notification with no sound.
  • reply_to_message_id (int, optional) – If the message is a reply, ID of the original message.
  • reply_markup (telegram.ReplyMarkup, optional) – 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 (int | float, optional) – 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(chat_id, photo, caption=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=20, parse_mode=None, **kwargs)

Use this method to send photos.

Note

The photo argument can be either a file_id, an URL or a file from disk open(filename, 'rb')

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • photo (str | filelike object | telegram.PhotoSize) – Photo to send. Pass a file_id as String to send a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload a new photo using multipart/form-data. Lastly you can pass an existing telegram.PhotoSize object to send.
  • caption (str, optional) – Photo caption (may also be used when resending photos by file_id), 0-1024 characters.
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • disable_notification (bool, optional) – Sends the message silently. Users will receive a notification with no sound.
  • reply_to_message_id (int, optional) – If the message is a reply, ID of the original message.
  • reply_markup (telegram.ReplyMarkup, optional) – 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 (int | float, optional) – Send file timeout (default: 20 seconds).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, the sent Message is returned.

Return type:

telegram.Message

Raises:

telegram.TelegramError

send_sticker(chat_id, sticker, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=20, **kwargs)

Use this method to send .webp stickers.

Note

The sticker argument can be either a file_id, an URL or a file from disk open(filename, 'rb')

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • sticker (str | filelike object telegram.Sticker) – Sticker to send. Pass a file_id as String to send a file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a .webp file from the Internet, or upload a new one using multipart/form-data. Lastly you can pass an existing telegram.Sticker object to send.
  • disable_notification (bool, optional) – Sends the message silently. Users will receive a notification with no sound.
  • reply_to_message_id (int, optional) – If the message is a reply, ID of the original message.
  • reply_markup (telegram.ReplyMarkup, optional) – 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 (int | float, optional) – Send file timeout (default: 20 seconds).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, the sent Message is returned.

Return type:

telegram.Message

Raises:

telegram.TelegramError

send_venue(chat_id, latitude=None, longitude=None, title=None, address=None, foursquare_id=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=None, venue=None, foursquare_type=None, **kwargs)

Use this method to send information about a venue.

Note

you can either supply venue, or latitude, longitude, title and address and optionally foursquare_id and optionally foursquare_type.

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • latitude (float, optional) – Latitude of venue.
  • longitude (float, optional) – Longitude of venue.
  • title (str, optional) – Name of the venue.
  • address (str, optional) – Address of the venue.
  • foursquare_id (str, optional) – Foursquare identifier of the venue.
  • foursquare_type (str, optional) – Foursquare type of the venue, if known. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.)
  • venue (telegram.Venue, optional) – The venue to send.
  • disable_notification (bool, optional) – Sends the message silently. Users will receive a notification with no sound.
  • reply_to_message_id (int, optional) – If the message is a reply, ID of the original message.
  • reply_markup (telegram.ReplyMarkup, optional) – 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 (int | float, optional) – 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_video(chat_id, video, duration=None, caption=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=20, width=None, height=None, parse_mode=None, supports_streaming=None, thumb=None, **kwargs)

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

Note

The video argument can be either a file_id, an URL or a file from disk open(filename, 'rb')

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • video (str | filelike object | telegram.Video) – Video file to send. Pass a file_id as String to send an video file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an video file from the Internet, or upload a new one using multipart/form-data. Lastly you can pass an existing telegram.Video object to send.
  • duration (int, optional) – Duration of sent video in seconds.
  • width (int, optional) – Video width.
  • height (int, optional) – Video height.
  • caption (str, optional) – Video caption (may also be used when resending videos by file_id), 0-1024 characters.
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • supports_streaming (bool, optional) – Pass True, if the uploaded video is suitable for streaming.
  • disable_notification (bool, optional) – Sends the message silently. Users will receive a notification with no sound.
  • reply_to_message_id (int, optional) – If the message is a reply, ID of the original message.
  • reply_markup (telegram.ReplyMarkup, optional) – 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.
  • thumb (filelike object, optional) – 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 90. Ignored if the file is not is passed as a string or file_id.
  • timeout (int | float, optional) – Send file timeout (default: 20 seconds).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, the sent Message is returned.

Return type:

telegram.Message

Raises:

telegram.TelegramError

send_video_note(chat_id, video_note, duration=None, length=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=20, thumb=None, **kwargs)

Use this method to send video messages.

Note

The video_note argument can be either a file_id or a file from disk open(filename, 'rb')

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • video_note (str | filelike object | telegram.VideoNote) – Video note to send. Pass a file_id as String to send a video note that exists on the Telegram servers (recommended) or upload a new video using multipart/form-data. Or you can pass an existing telegram.VideoNote object to send. Sending video notes by a URL is currently unsupported.
  • duration (int, optional) – Duration of sent video in seconds.
  • length (int, optional) – Video width and height
  • disable_notification (bool, optional) – Sends the message silently. Users will receive a notification with no sound.
  • reply_to_message_id (int, optional) – If the message is a reply, ID of the original message.
  • reply_markup (telegram.ReplyMarkup, optional) – 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.
  • thumb (filelike object, optional) – 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 90. Ignored if the file is not is passed as a string or file_id.
  • timeout (int | float, optional) – Send file timeout (default: 20 seconds).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, the sent Message is returned.

Return type:

telegram.Message

Raises:

telegram.TelegramError

send_voice(chat_id, voice, duration=None, caption=None, disable_notification=False, reply_to_message_id=None, reply_markup=None, timeout=20, parse_mode=None, **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).

Note

The voice argument can be either a file_id, an URL or a file from disk open(filename, 'rb')

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • voice (str | filelike object | telegram.Voice) – Voice file to send. Pass a file_id as String to send an voice file that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an voice file from the Internet, or upload a new one using multipart/form-data. Lastly you can pass an existing telegram.Voice object to send.
  • caption (str, optional) – Voice message caption, 0-1024 characters.
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • duration (int, optional) – Duration of the voice message in seconds.
  • disable_notification (bool, optional) – Sends the message silently. Users will receive a notification with no sound.
  • reply_to_message_id (int, optional) – If the message is a reply, ID of the original message.
  • reply_markup (telegram.ReplyMarkup, optional) – 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 (int | float, optional) – Send file timeout (default: 20 seconds).
  • **kwargs (dict) – Arbitrary keyword arguments.
Returns:

On success, the sent Message is returned.

Return type:

telegram.Message

Raises:

telegram.TelegramError

setChatDescription(chat_id, description, timeout=None, **kwargs)

Alias for set_chat_description

setChatPhoto(chat_id, photo, timeout=20, **kwargs)

Alias for set_chat_photo

setChatStickerSet(chat_id, sticker_set_name, timeout=None, **kwargs)

Alias for set_chat_sticker_set

setChatTitle(chat_id, title, timeout=None, **kwargs)

Alias for set_chat_title

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

Alias for set_game_score

setPassportDataErrors(user_id, errors, timeout=None, **kwargs)

Alias for set_passport_data_errors

setStickerPositionInSet(sticker, position, timeout=None, **kwargs)

Alias for set_sticker_position_in_set

setWebhook(url=None, certificate=None, timeout=None, max_connections=40, allowed_updates=None, **kwargs)

Alias for set_webhook

set_chat_description(chat_id, description, timeout=None, **kwargs)

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.

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • description (str) – New chat description, 1-255 characters.
  • timeout (int | float, optional) – 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:

Returns True on success.

Return type:

bool

Raises:

telegram.TelegramError

set_chat_photo(chat_id, photo, timeout=20, **kwargs)

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.

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • photo (filelike object) – New chat photo.
  • timeout (int | float, optional) – 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

Note

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

Returns:Returns True on success.
Return type:bool
Raises:telegram.TelegramError
set_chat_sticker_set(chat_id, sticker_set_name, timeout=None, **kwargs)

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 telegram.Chat.can_set_sticker_set optionally returned in get_chat requests to check if the bot can use this method.

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername).
  • sticker_set_name (str) – Name of the sticker set to be set as the group sticker set.
  • timeout (int | float, optional) – 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:

True on success.

Return type:

bool

set_chat_title(chat_id, title, timeout=None, **kwargs)

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.

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • title (str) – New chat title, 1-255 characters.
  • timeout (int | float, optional) – 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

Note

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

Returns:Returns True on success.
Return type:bool
Raises:telegram.TelegramError
set_game_score(user_id, score, chat_id=None, message_id=None, inline_message_id=None, force=None, disable_edit_message=None, timeout=None, **kwargs)

Use this method to set the score of the specified user in a game. 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.

Parameters:
  • user_id (int) – User identifier.
  • score (int) – New score, must be non-negative.
  • force (bool, optional) – Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters
  • disable_edit_message (bool, optional) – Pass True, if the game message should not be automatically edited to include the current scoreboard.
  • chat_id (int|str, optional) – Required if inline_message_id is not specified. Unique identifier for the target chat.
  • message_id (int, optional) – Required if inline_message_id is not specified. Identifier of the sent message.
  • inline_message_id (str, optional) – Required if chat_id and message_id are not specified. Identifier of the inline message.
  • timeout (int | float, optional) – 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:

The edited message, or if the message wasn’t sent by the bot , True.

Return type:

telegram.Message

Raises:
  • telegram.TelegramError – If the new score is not greater than the user’s
  • current score in the chat and force is False.
set_passport_data_errors(user_id, errors, timeout=None, **kwargs)

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.

Parameters:
  • user_id (int) – User identifier
  • errors (List[PassportElementError]) – A JSON-serialized array describing the errors.
  • timeout (int | float, optional) – 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_sticker_position_in_set(sticker, position, timeout=None, **kwargs)

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

Parameters:
  • sticker (str) – File identifier of the sticker.
  • position (int) – New sticker position in the set, zero-based.
  • timeout (int | float, optional) – 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_webhook(url=None, certificate=None, timeout=None, max_connections=40, allowed_updates=None, **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.

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.

Note

The certificate argument should be a file from disk open(filename, 'rb').

Parameters:
  • url (str) – HTTPS url to send updates to. Use an empty string to remove webhook integration.
  • certificate (filelike) – Upload your public key certificate so that the root certificate in use can be checked. See our self-signed guide for details. (https://goo.gl/rw7w6Y)
  • max_connections (int, optional) – 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 (List[str], optional) – 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 set_webhook, so unwanted updates may be received for a short period of time.
  • timeout (int | float, optional) – 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.

Note

  1. You will not be able to receive updates using get_updates for as long as an outgoing webhook is set up.
  2. To use a self-signed certificate, you need to upload your public key certificate using certificate parameter. Please upload as InputFile, sending a String will not work.
  3. Ports currently supported for Webhooks: 443, 80, 88, 8443.
Returns:bool On success, True is returned.
Raises:telegram.TelegramError
stopMessageLiveLocation(chat_id=None, message_id=None, inline_message_id=None, reply_markup=None, timeout=None, **kwargs)

Alias for stop_message_live_location

stop_message_live_location(chat_id=None, message_id=None, inline_message_id=None, reply_markup=None, timeout=None, **kwargs)

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.

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • message_id (int, optional) – Required if inline_message_id is not specified. Identifier of the sent message.
  • inline_message_id (str, optional) – Required if chat_id and message_id are not specified. Identifier of the inline message.
  • reply_markup (telegram.ReplyMarkup, optional) – 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 (int | float, optional) – 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 edited message.

Return type:

telegram.Message

to_dict()
unbanChatMember(chat_id, user_id, timeout=None, **kwargs)

Alias for unban_chat_member

unban_chat_member(chat_id, user_id, timeout=None, **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 chat or username of the target channel (in the format @channelusername).
  • user_id (int) – Unique identifier of the target user.
  • timeout (int | float, optional) – 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:

bool On success, True is returned.

Raises:

telegram.TelegramError

unpinChatMessage(chat_id, timeout=None, **kwargs)

Alias for unpin_chat_message

unpin_chat_message(chat_id, timeout=None, **kwargs)

Use this method to unpin a message in a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername).
  • timeout (int | float, optional) – 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:

Returns True on success.

Return type:

bool

Raises:

telegram.TelegramError

uploadStickerFile(user_id, png_sticker, timeout=20, **kwargs)

Alias for upload_sticker_file

upload_sticker_file(user_id, png_sticker, timeout=20, **kwargs)

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

Note

The png_sticker argument can be either a file_id, an URL or a file from disk open(filename, 'rb')

Parameters:
  • user_id (int) – User identifier of sticker file owner.
  • png_sticker (str | filelike object) – 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.
  • timeout (int | float, optional) – 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:

The uploaded File

Return type:

telegram.File

Raises:

telegram.TelegramError

username

Bot’s username.

Type:str
class telegram.Chat(id, type, title=None, username=None, first_name=None, last_name=None, all_members_are_administrators=None, bot=None, photo=None, description=None, invite_link=None, pinned_message=None, sticker_set_name=None, can_set_sticker_set=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents a chat.

id

Unique identifier for this chat.

Type:int
type

Type of chat.

Type:str
title

Optional. Title, for supergroups, channels and group chats.

Type:str
username

Optional. Username.

Type:str
first_name

Optional. First name of the other party in a private chat.

Type:str
last_name

Optional. Last name of the other party in a private chat.

Type:str
all_members_are_administrators

Optional.

Type:bool
photo

Optional. Chat photo.

Type:telegram.ChatPhoto
description

Optional. Description, for supergroups and channel chats.

Type:str

Optional. Chat invite link, for supergroups and channel chats.

Type:str
pinned_message

Optional. Pinned message, for supergroups. Returned only in get_chat.

Type:telegram.Message
sticker_set_name

Optional. For supergroups, name of Group sticker set.

Type:str
can_set_sticker_set

Optional. True, if the bot can change group the sticker set.

Type:bool
Parameters:
  • id (int) – Unique identifier for this chat. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
  • type (str) – Type of chat, can be either ‘private’, ‘group’, ‘supergroup’ or ‘channel’.
  • title (str, optional) – Title, for supergroups, channels and group chats.
  • username (str, optional) – Username, for private chats, supergroups and channels if available.
  • first_name (str, optional) – First name of the other party in a private chat.
  • last_name (str, optional) – Last name of the other party in a private chat.
  • all_members_are_administrators (bool, optional) – True if a group has All Members Are Admins enabled.
  • photo (telegram.ChatPhoto, optional) – Chat photo. Returned only in getChat.
  • description (str, optional) – Description, for supergroups and channel chats. Returned only in get_chat.
  • invite_link (str, optional) – Chat invite link, for supergroups and channel chats. Returned only in get_chat.
  • pinned_message (telegram.Message, optional) – Pinned message, for supergroups. Returned only in get_chat.
  • bot (telegram.Bot, optional) – The Bot to use for instance methods.
  • sticker_set_name (str, optional) – For supergroups, name of Group sticker set. Returned only in get_chat.
  • can_set_sticker_set (bool, optional) – True, if the bot can change group the sticker set. Returned only in get_chat.
  • **kwargs (dict) – Arbitrary keyword arguments.
CHANNEL = 'channel'

‘channel’

Type:str
GROUP = 'group'

‘group’

Type:str
PRIVATE = 'private'

‘private’

Type:str
SUPERGROUP = 'supergroup'

‘supergroup’

Type:str
classmethod de_json(data, bot)
get_administrators(*args, **kwargs)

Shortcut for:

bot.get_chat_administrators(update.message.chat.id, *args, **kwargs)
Returns:A list of administrators in a chat. An Array of telegram.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:List[telegram.ChatMember]
get_member(*args, **kwargs)

Shortcut for:

bot.get_chat_member(update.message.chat.id, *args, **kwargs)
Returns:telegram.ChatMember
get_members_count(*args, **kwargs)

Shortcut for:

bot.get_chat_members_count(update.message.chat.id, *args, **kwargs)
Returns:int
kick_member(*args, **kwargs)

Shortcut for:

bot.kick_chat_member(update.message.chat.id, *args, **kwargs)
Returns:If the action was sent succesfully.
Return type:bool

Note

This method will only work if the All Members Are Admins setting is off in the target group. Otherwise members may only be removed by the group’s creator or by the member that added them.

leave(*args, **kwargs)

Shortcut for:

bot.leave_chat(update.message.chat.id, *args, **kwargs)
Returns:bool If the action was sent successfully.
link

Convenience property. If the chat has a username, returns a t.me link of the chat.

Type:str
send_action(*args, **kwargs)

Shortcut for:

bot.send_chat_action(update.message.chat.id, *args, **kwargs)
Returns:If the action was sent successfully.
Return type:bool
send_animation(*args, **kwargs)

Shortcut for:

bot.send_animation(Chat.id, *args, **kwargs)

Where Chat is the current instance.

Returns:On success, instance representing the message posted.
Return type:telegram.Message
send_audio(*args, **kwargs)

Shortcut for:

bot.send_audio(Chat.id, *args, **kwargs)

Where Chat is the current instance.

Returns:On success, instance representing the message posted.
Return type:telegram.Message
send_document(*args, **kwargs)

Shortcut for:

bot.send_document(Chat.id, *args, **kwargs)

Where Chat is the current instance.

Returns:On success, instance representing the message posted.
Return type:telegram.Message
send_message(*args, **kwargs)

Shortcut for:

bot.send_message(Chat.id, *args, **kwargs)

Where Chat is the current instance.

Returns:On success, instance representing the message posted.
Return type:telegram.Message
send_photo(*args, **kwargs)

Shortcut for:

bot.send_photo(Chat.id, *args, **kwargs)

Where Chat is the current instance.

Returns:On success, instance representing the message posted.
Return type:telegram.Message
send_sticker(*args, **kwargs)

Shortcut for:

bot.send_sticker(Chat.id, *args, **kwargs)

Where Chat is the current instance.

Returns:On success, instance representing the message posted.
Return type:telegram.Message
send_video(*args, **kwargs)

Shortcut for:

bot.send_video(Chat.id, *args, **kwargs)

Where Chat is the current instance.

Returns:On success, instance representing the message posted.
Return type:telegram.Message
send_video_note(*args, **kwargs)

Shortcut for:

bot.send_video_note(Chat.id, *args, **kwargs)

Where Chat is the current instance.

Returns:On success, instance representing the message posted.
Return type:telegram.Message
send_voice(*args, **kwargs)

Shortcut for:

bot.send_voice(Chat.id, *args, **kwargs)

Where Chat is the current instance.

Returns:On success, instance representing the message posted.
Return type:telegram.Message
unban_member(*args, **kwargs)

Shortcut for:

bot.unban_chat_member(update.message.chat.id, *args, **kwargs)
Returns:If the action was sent successfully.
Return type:bool
class telegram.ChatMember(user, status, until_date=None, can_be_edited=None, can_change_info=None, can_post_messages=None, can_edit_messages=None, can_delete_messages=None, can_invite_users=None, can_restrict_members=None, can_pin_messages=None, can_promote_members=None, can_send_messages=None, can_send_media_messages=None, can_send_other_messages=None, can_add_web_page_previews=None, **kwargs)

Bases: telegram.base.TelegramObject

This object contains information about one member of the chat.

user

Information about the user.

Type:telegram.User
status

The member’s status in the chat.

Type:str
until_date

Optional. Date when restrictions will be lifted for this user.

Type:datetime.datetime
can_be_edited

Optional. If the bot is allowed to edit administrator privileges of that user.

Type:bool
can_change_info

Optional. If the administrator can change the chat title, photo and other settings.

Type:bool
can_post_messages

Optional. If the administrator can post in the channel.

Type:bool
can_edit_messages

Optional. If the administrator can edit messages of other users.

Type:bool
can_delete_messages

Optional. If the administrator can delete messages of other users.

Type:bool
can_invite_users

Optional. If the administrator can invite new users to the chat.

Type:bool
can_restrict_members

Optional. If the administrator can restrict, ban or unban chat members.

Type:bool
can_pin_messages

Optional. If the administrator can pin messages.

Type:bool
can_promote_members

Optional. If the administrator can add new administrators.

Type:bool
can_send_messages

Optional. If the user can send text messages, contacts, locations and venues.

Type:bool
can_send_media_messages

Optional. If the user can send media messages, implies can_send_messages.

Type:bool
can_send_other_messages

Optional. If the user can send animations, games, stickers and use inline bots, implies can_send_media_messages.

Type:bool
can_add_web_page_previews

Optional. If user may add web page previews to his messages, implies can_send_media_messages

Type:bool
Parameters:
  • user (telegram.User) – Information about the user.
  • status (str) – The member’s status in the chat. Can be ‘creator’, ‘administrator’, ‘member’, ‘restricted’, ‘left’ or ‘kicked’.
  • until_date (datetime.datetime, optional) – Restricted and kicked only. Date when restrictions will be lifted for this user.
  • can_be_edited (bool, optional) – Administrators only. True, if the bot is allowed to edit administrator privileges of that user.
  • can_change_info (bool, optional) – Administrators only. True, if the administrator can change the chat title, photo and other settings.
  • can_post_messages (bool, optional) – Administrators only. True, if the administrator can post in the channel, channels only.
  • can_edit_messages (bool, optional) – Administrators only. True, if the administrator can edit messages of other users, channels only.
  • can_delete_messages (bool, optional) – Administrators only. True, if the administrator can delete messages of other user.
  • can_invite_users (bool, optional) – Administrators only. True, if the administrator can invite new users to the chat.
  • can_restrict_members (bool, optional) – Administrators only. True, if the administrator can restrict, ban or unban chat members.
  • can_pin_messages (bool, optional) – Administrators only. True, if the administrator can pin messages, supergroups only.
  • can_promote_members (bool, optional) – Administrators only. 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 the user).
  • can_send_messages (bool, optional) – Restricted only. True, if the user can send text messages, contacts, locations and venues.
  • can_send_media_messages (bool, optional) – Restricted only. True, if the user can send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages.
  • can_send_other_messages (bool, optional) – Restricted only. True, if the user can send animations, games, stickers and use inline bots, implies can_send_media_messages.
  • can_add_web_page_previews (bool, optional) – Restricted only. True, if user may add web page previews to his messages, implies can_send_media_messages.
ADMINISTRATOR = 'administrator'

‘administrator’

Type:str
CREATOR = 'creator'

‘creator’

Type:str
KICKED = 'kicked'

‘kicked’

Type:str
LEFT = 'left'

‘left’

Type:str
MEMBER = 'member'

‘member’

Type:str
RESTRICTED = 'restricted'

‘restricted’

Type:str
classmethod de_json(data, bot)
to_dict()
class telegram.ChatAction

Bases: object

Helper class to provide constants for different chatactions.

FIND_LOCATION = 'find_location'

‘find_location’

Type:str
RECORD_AUDIO = 'record_audio'

‘record_audio’

Type:str
RECORD_VIDEO = 'record_video'

‘record_video’

Type:str
RECORD_VIDEO_NOTE = 'record_video_note'

‘record_video_note’

Type:str
TYPING = 'typing'

‘typing’

Type:str
UPLOAD_AUDIO = 'upload_audio'

‘upload_audio’

Type:str
UPLOAD_DOCUMENT = 'upload_document'

‘upload_document’

Type:str
UPLOAD_PHOTO = 'upload_photo'

‘upload_photo’

Type:str
UPLOAD_VIDEO = 'upload_video'

‘upload_video’

Type:str
UPLOAD_VIDEO_NOTE = 'upload_video_note'

‘upload_video_note’

Type:str
class telegram.ChosenInlineResult(result_id, from_user, query, location=None, inline_message_id=None, **kwargs)

Bases: telegram.base.TelegramObject

Represents a result of an inline query that was chosen by the user and sent to their chat partner.

Note

In Python from is a reserved word, use from_user instead.

result_id

The unique identifier for the result that was chosen.

Type:str
from_user

The user that chose the result.

Type:telegram.User
location

Optional. Sender location.

Type:telegram.Location
inline_message_id

Optional. Identifier of the sent inline message.

Type:str
query

The query that was used to obtain the result.

Type:str
Parameters:
  • result_id (str) – The unique identifier for the result that was chosen.
  • from_user (telegram.User) – The user that chose the result.
  • location (telegram.Location, optional) – Sender location, only for bots that require user location.
  • inline_message_id (str, optional) – Identifier of the sent inline message. Available only if there is an inline keyboard attached to the message. Will be also received in callback queries and can be used to edit the message.
  • query (str) – The query that was used to obtain the result.
  • **kwargs (dict) – Arbitrary keyword arguments.
classmethod de_json(data, bot)
class telegram.CallbackQuery(id, from_user, chat_instance, message=None, data=None, inline_message_id=None, game_short_name=None, bot=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents an incoming callback query from a callback button in an inline keyboard.

If the button that originated the query was attached to a message sent by the bot, the field message will be present. If the button was attached to a message sent via the bot (in inline mode), the field inline_message_id will be present.

Note

  • In Python from is a reserved word, use from_user instead.
  • Exactly one of the fields data or game_short_name will be present.
id

Unique identifier for this query.

Type:str
from_user

Sender.

Type:telegram.User
message

Optional. Message with the callback button that originated the query.

Type:telegram.Message
inline_message_id

Optional. Identifier of the message sent via the bot in inline mode, that originated the query.

Type:str
chat_instance

Optional. Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent.

Type:str
data

Optional. Data associated with the callback button.

Type:str
game_short_name

Optional. Short name of a Game to be returned.

Type:str
Parameters:
  • id (str) – Unique identifier for this query.
  • from_user (telegram.User) – Sender.
  • message (telegram.Message, optional) – Message with the callback button that originated the query. Note that message content and message date will not be available if the message is too old.
  • inline_message_id (str, optional) – Identifier of the message sent via the bot in inline mode, that originated the query.
  • chat_instance (str, optional) – Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. Useful for high scores in games.
  • data (str, optional) – Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field.
  • game_short_name (str, optional) – Short name of a Game to be returned, serves as the unique identifier for the game

Note

After the user presses an inline button, Telegram clients will display a progress bar until you call answer. It is, therefore, necessary to react by calling telegram.Bot.answer_callback_query even if no notification to the user is needed (e.g., without specifying any of the optional parameters).

answer(*args, **kwargs)

Shortcut for:

bot.answer_callback_query(update.callback_query.id, *args, **kwargs)
Returns:On success, True is returned.
Return type:bool
classmethod de_json(data, bot)
edit_message_caption(caption, *args, **kwargs)

Shortcut for either:

bot.edit_message_caption(caption=caption,
                       chat_id=update.callback_query.message.chat_id,
                       message_id=update.callback_query.message.message_id,
                       *args, **kwargs)

or:

bot.edit_message_caption(caption=caption
                        inline_message_id=update.callback_query.inline_message_id,
                       *args, **kwargs)
Returns:On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
Return type:telegram.Message
edit_message_reply_markup(reply_markup, *args, **kwargs)

Shortcut for either:

bot.edit_message_replyMarkup(chat_id=update.callback_query.message.chat_id,
                           message_id=update.callback_query.message.message_id,
                           reply_markup=reply_markup,
                           *args, **kwargs)

or:

bot.edit_message_reply_markup(inline_message_id=update.callback_query.inline_message_id,
                            reply_markup=reply_markup,
                           *args, **kwargs)
Returns:On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
Return type:telegram.Message
edit_message_text(text, *args, **kwargs)

Shortcut for either:

bot.edit_message_text(text, chat_id=update.callback_query.message.chat_id,
                    message_id=update.callback_query.message.message_id,
                    *args, **kwargs)

or:

bot.edit_message_text(text, inline_message_id=update.callback_query.inline_message_id,
                    *args, **kwargs)
Returns:On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
Return type:telegram.Message
class telegram.Contact(phone_number, first_name, last_name=None, user_id=None, vcard=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents a phone contact.

phone_number

Contact’s phone number.

Type:str
first_name

Contact’s first name.

Type:str
last_name

Optional. Contact’s last name.

Type:str
user_id

Optional. Contact’s user identifier in Telegram.

Type:int
vcard

Optional. Additional data about the contact in the form of a vCard.

Type:str
Parameters:
  • phone_number (str) – Contact’s phone number.
  • first_name (str) – Contact’s first name.
  • last_name (str, optional) – Contact’s last name.
  • user_id (int, optional) – Contact’s user identifier in Telegram.
  • vcard (str, optional) – Additional data about the contact in the form of a vCard.
  • **kwargs (dict) – Arbitrary keyword arguments.
classmethod de_json(data, bot)
class telegram.Document(file_id, thumb=None, file_name=None, mime_type=None, file_size=None, bot=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents a general file (as opposed to photos, voice messages and audio files).

file_id

Unique file identifier.

Type:str
thumb

Optional. Document thumbnail.

Type:telegram.PhotoSize
file_name

Original filename.

Type:str
mime_type

Optional. MIME type of the file.

Type:str
file_size

Optional. File size.

Type:int
bot

Optional. The Bot to use for instance methods.

Type:telegram.Bot
Parameters:
  • file_id (str) – Unique file identifier
  • thumb (telegram.PhotoSize, optional) – Document thumbnail as defined by sender.
  • file_name (str, optional) – Original filename as defined by sender.
  • mime_type (str, optional) – MIME type of the file as defined by sender.
  • file_size (int, optional) – File size.
  • bot (telegram.Bot, optional) – The Bot to use for instance methods.
  • **kwargs (dict) – Arbitrary keyword arguments.
classmethod de_json(data, bot)
get_file(timeout=None, **kwargs)

Convenience wrapper over telegram.Bot.get_file

Parameters:
  • timeout (int | float, optional) – 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:

telegram.File

Raises:

telegram.TelegramError

class telegram.File(file_id, bot=None, file_size=None, file_path=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents a file ready to be downloaded. The file can be downloaded with download. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling getFile.

Note

Maximum file size to download is 20 MB

file_id

Unique identifier for this file.

Type:str
file_size

Optional. File size.

Type:str
file_path

Optional. File path. Use download to get the file.

Type:str
Parameters:
  • file_id (str) – Unique identifier for this file.
  • file_size (int, optional) – Optional. File size, if known.
  • file_path (str, optional) – File path. Use download to get the file.
  • bot (telegram.Bot, optional) – Bot to use with shortcut method.
  • **kwargs (dict) – Arbitrary keyword arguments.

Note

If you obtain an instance of this class from telegram.PassportFile.get_file, then it will automatically be decrypted as it downloads when you call download().

classmethod de_json(data, bot)
download(custom_path=None, out=None, timeout=None)

Download this file. By default, the file is saved in the current working directory with its original filename as reported by Telegram. If a custom_path is supplied, it will be saved to that path instead. If out is defined, the file contents will be saved to that object using the out.write method.

Note

custom_path and out are mutually exclusive.

Parameters:
  • custom_path (str, optional) – Custom path.
  • out (io.BufferedWriter, optional) – A file-like object. Must be opened for writing in binary mode, if applicable.
  • timeout (int | float, optional) – 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 same object as out if specified. Otherwise, returns the filename downloaded to.

Return type:

str | io.BufferedWriter

Raises:

ValueError – If both custom_path and out are passed.

download_as_bytearray(buf=None)

Download this file and return it as a bytearray.

Parameters:buf (bytearray, optional) – Extend the given bytearray with the downloaded data.
Returns:The same object as buf if it was specified. Otherwise a newly allocated bytearray.
Return type:bytearray
set_credentials(credentials)
class telegram.ForceReply(force_reply=True, selective=False, **kwargs)

Bases: telegram.replymarkup.ReplyMarkup

Upon receiving a message with this object, Telegram clients will display a reply interface to the user (act as if the user has selected the bot’s message and tapped ‘Reply’). This can be extremely useful if you want to create user-friendly step-by-step interfaces without having to sacrifice privacy mode.

force_reply

Shows reply interface to the user.

Type:True
selective

Optional. Force reply from specific users only.

Type:bool
Parameters:
  • selective (bool, optional) –

    Use this parameter if you want to force reply from specific users only. Targets:

    1. users that are @mentioned in the text of the Message object
    2. if the bot’s message is a reply (has reply_to_message_id), sender of the original message.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InlineKeyboardButton(text, url=None, callback_data=None, switch_inline_query=None, switch_inline_query_current_chat=None, callback_game=None, pay=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents one button of an inline keyboard.

Note

You must use exactly one of the optional fields. Mind that callback_game is not working as expected. Putting a game short name in it might, but is not guaranteed to work.

text

Label text on the button.

Type:str
url

Optional. HTTP url to be opened when button is pressed.

Type:str
callback_data

Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes.

Type:str
switch_inline_query

Optional. Will prompt the user to select one of their chats, open that chat and insert the bot’s username and the specified inline query in the input field.

Type:str
switch_inline_query_current_chat

Optional. Will insert the bot’s username and the specified inline query in the current chat’s input field.

Type:str
callback_game

Optional. Description of the game that will be launched when the user presses the button.

Type:telegram.CallbackGame
pay

Optional. Specify True, to send a Pay button.

Type:bool
Parameters:
  • text (str) – Label text on the button.
  • url (str) – HTTP url to be opened when button is pressed.
  • callback_data (str, optional) – Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes.
  • switch_inline_query (str, optional) – If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot’s username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted. This offers an easy way for users to start using your bot in inline mode when they are currently in a private chat with it. Especially useful when combined with switch_pm* actions - in this case the user will be automatically returned to the chat they switched from, skipping the chat selection screen.
  • switch_inline_query_current_chat (str, optional) – If set, pressing the button will insert the bot’s username and the specified inline query in the current chat’s input field. Can be empty, in which case only the bot’s username will be inserted. This offers a quick way for the user to open your bot in inline mode in the same chat - good for selecting something from multiple options.
  • callback_game (telegram.CallbackGame, optional) – Description of the game that will be launched when the user presses the button. This type of button must always be the first button in the first row.
  • pay (bool, optional) – Specify True, to send a Pay button. This type of button must always be the first button in the first row.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InlineKeyboardMarkup(inline_keyboard, **kwargs)

Bases: telegram.replymarkup.ReplyMarkup

This object represents an inline keyboard that appears right next to the message it belongs to.

inline_keyboard

Array of button rows, each represented by an Array of InlineKeyboardButton objects.

Type:List[List[telegram.InlineKeyboardButton]]
Parameters:
  • inline_keyboard (List[List[telegram.InlineKeyboardButton]]) – Array of button rows, each represented by an Array of InlineKeyboardButton objects.
  • **kwargs (dict) – Arbitrary keyword arguments.
classmethod from_button(button, **kwargs)

Shortcut for:

InlineKeyboardMarkup([[button]], **kwargs)

Return an InlineKeyboardMarkup from a single InlineKeyboardButton

Parameters:
classmethod from_column(button_column, **kwargs)

Shortcut for:

InlineKeyboardMarkup([[button] for button in button_column], **kwargs)

Return an InlineKeyboardMarkup from a single column of InlineKeyboardButtons

Parameters:
classmethod from_row(button_row, **kwargs)

Shortcut for:

InlineKeyboardMarkup([button_row], **kwargs)

Return an InlineKeyboardMarkup from a single row of InlineKeyboardButtons

Parameters:
to_dict()
class telegram.InlineQuery(id, from_user, query, offset, location=None, bot=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents an incoming inline query. When the user sends an empty query, your bot could return some default or trending results.

Note

  • In Python from is a reserved word, use from_user instead.
id

Unique identifier for this query.

Type:str
from_user

Sender.

Type:telegram.User
location

Optional. Sender location, only for bots that request user location.

Type:telegram.Location
query

Text of the query (up to 512 characters).

Type:str
offset

Offset of the results to be returned, can be controlled by the bot.

Type:str
Parameters:
  • id (str) – Unique identifier for this query.
  • from_user (telegram.User) – Sender.
  • location (telegram.Location, optional) – Sender location, only for bots that request user location.
  • query (str) – Text of the query (up to 512 characters).
  • offset (str) – Offset of the results to be returned, can be controlled by the bot.
  • bot (telegram.Bot, optional) – The Bot to use for instance methods.
  • **kwargs (dict) – Arbitrary keyword arguments.
answer(*args, **kwargs)

Shortcut for:

bot.answer_inline_query(update.inline_query.id, *args, **kwargs)
Parameters:
  • results (List[telegram.InlineQueryResult]) – A list of results for the inline query.
  • cache_time (int, optional) – 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 (bool, optional) – 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 (str, optional) – 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 (str, optional) – 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 (str, optional) – 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.
classmethod de_json(data, bot)
class telegram.InlineQueryResult(type, id, **kwargs)

Bases: telegram.base.TelegramObject

Baseclass for the InlineQueryResult* classes.

type

Type of the result.

Type:str
id

Unique identifier for this result, 1-64 Bytes.

Type:str
Parameters:
  • type (str) – Type of the result.
  • id (str) – Unique identifier for this result, 1-64 Bytes.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InlineQueryResult(type, id, **kwargs)

Bases: telegram.base.TelegramObject

Baseclass for the InlineQueryResult* classes.

type

Type of the result.

Type:str
id

Unique identifier for this result, 1-64 Bytes.

Type:str
Parameters:
  • type (str) – Type of the result.
  • id (str) – Unique identifier for this result, 1-64 Bytes.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InlineQueryResultArticle(id, title, input_message_content, reply_markup=None, url=None, hide_url=None, description=None, thumb_url=None, thumb_width=None, thumb_height=None, **kwargs)

Bases: telegram.inline.inlinequeryresult.InlineQueryResult

This object represents a Telegram InlineQueryResultArticle.

type

‘article’.

Type:str
id

Unique identifier for this result, 1-64 Bytes.

Type:str
title

Title of the result.

Type:str
input_message_content

Content of the message to be sent.

Type:telegram.InputMessageContent
reply_markup

Optional. Inline keyboard attached to the message.

Type:telegram.ReplyMarkup
url

Optional. URL of the result.

Type:str
hide_url

Optional. Pass True, if you don’t want the URL to be shown in the message.

Type:bool
description

Optional. Short description of the result.

Type:str
thumb_url

Optional. Url of the thumbnail for the result.

Type:str
thumb_width

Optional. Thumbnail width.

Type:int
thumb_height

Optional. Thumbnail height.

Type:int
Parameters:
  • id (str) – Unique identifier for this result, 1-64 Bytes.
  • title (str) – Title of the result.
  • input_message_content (telegram.InputMessageContent) – Content of the message to be sent.
  • reply_markup (telegram.ReplyMarkup, optional) – Inline keyboard attached to the message
  • url (str, optional) – URL of the result.
  • hide_url (bool, optional) – Pass True, if you don’t want the URL to be shown in the message.
  • description (str, optional) – Short description of the result.
  • thumb_url (str, optional) – Url of the thumbnail for the result.
  • thumb_width (int, optional) – Thumbnail width.
  • thumb_height (int, optional) – Thumbnail height.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InlineQueryResultAudio(id, audio_url, title, performer=None, audio_duration=None, caption=None, reply_markup=None, input_message_content=None, parse_mode=None, **kwargs)

Bases: telegram.inline.inlinequeryresult.InlineQueryResult

Represents a link to an mp3 audio file. By default, this audio file will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the audio.

type

‘audio’.

Type:str
id

Unique identifier for this result, 1-64 bytes.

Type:str
audio_url

A valid URL for the audio file.

Type:str
title

Title.

Type:str
performer

Optional. Caption, 0-200 characters.

Type:str
audio_duration

Optional. Performer.

Type:str
caption

Optional. Audio duration in seconds.

Type:str
parse_mode

Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.

Type:str
reply_markup

Optional. Inline keyboard attached to the message.

Type:telegram.InlineKeyboardMarkup
input_message_content

Optional. Content of the message to be sent instead of the audio.

Type:telegram.InputMessageContent
Parameters:
  • id (str) – Unique identifier for this result, 1-64 bytes.
  • audio_url (str) – A valid URL for the audio file.
  • title (str) – Title.
  • performer (str, optional) – Caption, 0-200 characters.
  • audio_duration (str, optional) – Performer.
  • caption (str, optional) – Audio duration in seconds.
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • reply_markup (telegram.InlineKeyboardMarkup, optional) – Inline keyboard attached to the message.
  • input_message_content (telegram.InputMessageContent, optional) – Content of the message to be sent instead of the audio.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InlineQueryResultCachedAudio(id, audio_file_id, caption=None, reply_markup=None, input_message_content=None, parse_mode=None, **kwargs)

Bases: telegram.inline.inlinequeryresult.InlineQueryResult

Represents a link to an mp3 audio file stored on the Telegram servers. By default, this audio file will be sent by the user. Alternatively, you can use input_message_content to send amessage with the specified content instead of the audio.

type

‘audio’.

Type:str
id

Unique identifier for this result, 1-64 bytes.

Type:str
audio_file_id

A valid file identifier for the audio file.

Type:str
caption

Optional. Caption, 0-1024 characters

Type:str
parse_mode

Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.

Type:str
reply_markup

Optional. Inline keyboard attached to the message.

Type:telegram.InlineKeyboardMarkup
input_message_content

Optional. Content of the message to be sent instead of the audio.

Type:telegram.InputMessageContent
Parameters:
  • id (str) – Unique identifier for this result, 1-64 bytes.
  • audio_file_id (str) – A valid file identifier for the audio file.
  • caption (str, optional) – Caption, 0-1024 characters
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • reply_markup (telegram.InlineKeyboardMarkup, optional) – Inline keyboard attached to the message.
  • input_message_content (telegram.InputMessageContent, optional) – Content of the message to be sent instead of the audio.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InlineQueryResultCachedDocument(id, title, document_file_id, description=None, caption=None, reply_markup=None, input_message_content=None, parse_mode=None, **kwargs)

Bases: telegram.inline.inlinequeryresult.InlineQueryResult

Represents a link to a file stored on the Telegram servers. By default, this file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the file.

type

‘document’.

Type:str
id

Unique identifier for this result, 1-64 bytes.

Type:str
title

Title for the result.

Type:str
document_file_id

A valid file identifier for the file.

Type:str
description

Optional. Short description of the result.

Type:str
caption

Optional. Caption, 0-1024 characters

Type:str
parse_mode

Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.. See the constants in telegram.ParseMode for the available modes.

Type:str
reply_markup

Optional. Inline keyboard attached to the message.

Type:telegram.InlineKeyboardMarkup
input_message_content

Optional. Content of the message to be sent instead of the file.

Type:telegram.InputMessageContent
Parameters:
  • id (str) – Unique identifier for this result, 1-64 bytes.
  • title (str) – Title for the result.
  • document_file_id (str) – A valid file identifier for the file.
  • description (str, optional) – Short description of the result.
  • caption (str, optional) – Caption, 0-1024 characters
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.. See the constants in telegram.ParseMode for the available modes.
  • reply_markup (telegram.InlineKeyboardMarkup, optional) – Inline keyboard attached to the message.
  • input_message_content (telegram.InputMessageContent, optional) – Content of the message to be sent instead of the file.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InlineQueryResultCachedGif(id, gif_file_id, title=None, caption=None, reply_markup=None, input_message_content=None, parse_mode=None, **kwargs)

Bases: telegram.inline.inlinequeryresult.InlineQueryResult

Represents a link to an animated GIF file stored on the Telegram servers. By default, this animated GIF file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with specified content instead of the animation.

type

‘gif’.

Type:str
id

Unique identifier for this result, 1-64 bytes.

Type:str
gif_file_id

A valid file identifier for the GIF file.

Type:str
title

Optional. Title for the result.

Type:str
caption

Optional. Caption, 0-1024 characters

Type:str
parse_mode

Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.

Type:str
reply_markup

Optional. Inline keyboard attached to the message.

Type:telegram.InlineKeyboardMarkup
input_message_content

Optional. Content of the message to be sent instead of the gif.

Type:telegram.InputMessageContent
Parameters:
  • id (str) – Unique identifier for this result, 1-64 bytes.
  • gif_file_id (str) – A valid file identifier for the GIF file.
  • title (str, optional) – Title for the result.caption (str, optional):
  • caption (str, optional) – Caption, 0-1024 characters
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • reply_markup (telegram.InlineKeyboardMarkup, optional) – Inline keyboard attached to the message.
  • input_message_content (telegram.InputMessageContent, optional) – Content of the message to be sent instead of the gif.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InlineQueryResultCachedMpeg4Gif(id, mpeg4_file_id, title=None, caption=None, reply_markup=None, input_message_content=None, parse_mode=None, **kwargs)

Bases: telegram.inline.inlinequeryresult.InlineQueryResult

Represents a link to a video animation (H.264/MPEG-4 AVC video without sound) stored on the Telegram servers. By default, this animated MPEG-4 file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation.

type

‘mpeg4_gif’.

Type:str
id

Unique identifier for this result, 1-64 bytes.

Type:str
mpeg4_file_id

A valid file identifier for the MP4 file.

Type:str
title

Optional. Title for the result.

Type:str
caption

Optional. Caption, 0-1024 characters

Type:str
parse_mode

Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.

Type:str
reply_markup

Optional. Inline keyboard attached to the message.

Type:telegram.InlineKeyboardMarkup
input_message_content

Optional. Content of the message to be sent instead of the MPEG-4 file.

Type:telegram.InputMessageContent
Parameters:
  • id (str) – Unique identifier for this result, 1-64 bytes.
  • mpeg4_file_id (str) – A valid file identifier for the MP4 file.
  • title (str, optional) – Title for the result.
  • caption (str, optional) – Caption, 0-1024 characters
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • reply_markup (telegram.InlineKeyboardMarkup, optional) – Inline keyboard attached to the message.
  • input_message_content (telegram.InputMessageContent, optional) – Content of the message to be sent instead of the MPEG-4 file.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InlineQueryResultCachedPhoto(id, photo_file_id, title=None, description=None, caption=None, reply_markup=None, input_message_content=None, parse_mode=None, **kwargs)

Bases: telegram.inline.inlinequeryresult.InlineQueryResult

Represents a link to a photo stored on the Telegram servers. By default, this photo will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the photo.

type

‘photo’.

Type:str
id

Unique identifier for this result, 1-64 bytes.

Type:str
photo_file_id

A valid file identifier of the photo.

Type:str
title

Optional. Title for the result.

Type:str
description

Optional. Short description of the result.

Type:str
caption

Optional. Caption, 0-1024 characters

Type:str
parse_mode

Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.

Type:str
reply_markup

Optional. Inline keyboard attached to the message.

Type:telegram.InlineKeyboardMarkup
input_message_content

Optional. Content of the message to be sent instead of the photo.

Type:telegram.InputMessageContent
Parameters:
  • id (str) – Unique identifier for this result, 1-64 bytes.
  • photo_file_id (str) – A valid file identifier of the photo.
  • title (str, optional) – Title for the result.
  • description (str, optional) – Short description of the result.
  • caption (str, optional) – Caption, 0-1024 characters
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • reply_markup (telegram.InlineKeyboardMarkup, optional) – Inline keyboard attached to the message.
  • input_message_content (telegram.InputMessageContent, optional) – Content of the message to be sent instead of the photo.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InlineQueryResultCachedSticker(id, sticker_file_id, reply_markup=None, input_message_content=None, **kwargs)

Bases: telegram.inline.inlinequeryresult.InlineQueryResult

Represents a link to a sticker stored on the Telegram servers. By default, this sticker will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the sticker.

type

‘sticker`.

Type:str
id

Unique identifier for this result, 1-64 bytes.

Type:str
sticker_file_id

A valid file identifier of the sticker.

Type:str
reply_markup

Optional. Inline keyboard attached to the message.

Type:telegram.InlineKeyboardMarkup
input_message_content

Optional. Content of the message to be sent instead of the sticker.

Type:telegram.InputMessageContent
Parameters:
  • id (str) –
  • sticker_file_id (str) –
  • reply_markup (telegram.InlineKeyboardMarkup, optional) – Inline keyboard attached to the message.
  • input_message_content (telegram.InputMessageContent, optional) – Content of the message to be sent instead of the sticker.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InlineQueryResultCachedVideo(id, video_file_id, title, description=None, caption=None, reply_markup=None, input_message_content=None, parse_mode=None, **kwargs)

Bases: telegram.inline.inlinequeryresult.InlineQueryResult

Represents a link to a video file stored on the Telegram servers. By default, this video file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the video.

type

‘video’.

Type:str
id

Unique identifier for this result, 1-64 bytes.

Type:str
video_file_id

A valid file identifier for the video file.

Type:str
title

Title for the result.

Type:str
description

Optional. Short description of the result.

Type:str
caption

Optional. Caption, 0-1024 characters.

Type:str
parse_mode

Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.

Type:str
reply_markup

Optional. Inline keyboard attached to the message.

Type:telegram.InlineKeyboardMarkup
input_message_content

Optional. Content of the message to be sent instead of the video.

Type:telegram.InputMessageContent
Parameters:
  • id (str) – Unique identifier for this result, 1-64 bytes.
  • video_file_id (str) – A valid file identifier for the video file.
  • title (str) – Title for the result.
  • description (str, optional) – Short description of the result.
  • caption (str, optional) – Caption, 0-1024 characters.
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • reply_markup (telegram.InlineKeyboardMarkup, optional) – Inline keyboard attached to the message.
  • input_message_content (telegram.InputMessageContent, optional) – Content of the message to be sent instead of the video.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InlineQueryResultCachedVoice(id, voice_file_id, title, caption=None, reply_markup=None, input_message_content=None, parse_mode=None, **kwargs)

Bases: telegram.inline.inlinequeryresult.InlineQueryResult

Represents a link to a voice message stored on the Telegram servers. By default, this voice message will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the voice message.

type

‘voice’.

Type:str
id

Unique identifier for this result, 1-64 bytes.

Type:str
voice_file_id

A valid file identifier for the voice message.

Type:str
title

Voice message title.

Type:str
caption

Optional. Caption, 0-1024 characters.

Type:str
parse_mode

Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.

Type:str
reply_markup

Optional. Inline keyboard attached to the message.

Type:telegram.InlineKeyboardMarkup
input_message_content

Optional. Content of the message to be sent instead of the voice.

Type:telegram.InputMessageContent
Parameters:
  • id (str) – Unique identifier for this result, 1-64 bytes.
  • voice_file_id (str) – A valid file identifier for the voice message.
  • title (str) – Voice message title.
  • caption (str, optional) – Caption, 0-1024 characters.
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • reply_markup (telegram.InlineKeyboardMarkup, optional) – Inline keyboard attached to the message.
  • input_message_content (telegram.InputMessageContent, optional) – Content of the message to be sent instead of the voice.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InlineQueryResultContact(id, phone_number, first_name, last_name=None, reply_markup=None, input_message_content=None, thumb_url=None, thumb_width=None, thumb_height=None, vcard=None, **kwargs)

Bases: telegram.inline.inlinequeryresult.InlineQueryResult

Represents a contact with a phone number. By default, this contact will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the contact.

type

‘contact’.

Type:str
id

Unique identifier for this result, 1-64 bytes.

Type:str
phone_number

Contact’s phone number.

Type:str
first_name

Contact’s first name.

Type:str
last_name

Optional. Contact’s last name.

Type:str
vcard

Optional. Additional data about the contact in the form of a vCard, 0-2048 bytes.

Type:str
reply_markup

Optional. Inline keyboard attached to the message.

Type:telegram.InlineKeyboardMarkup
input_message_content

Optional. Content of the message to be sent instead of the contact.

Type:telegram.InputMessageContent
thumb_url

Optional. Url of the thumbnail for the result.

Type:str
thumb_width

Optional. Thumbnail width.

Type:int
thumb_height

Optional. Thumbnail height.

Type:int
Parameters:
  • id (str) – Unique identifier for this result, 1-64 bytes.
  • phone_number (str) – Contact’s phone number.
  • first_name (str) – Contact’s first name.
  • last_name (str, optional) – Contact’s last name.
  • vcard (str, optional) – Additional data about the contact in the form of a vCard, 0-2048 bytes.
  • reply_markup (telegram.InlineKeyboardMarkup, optional) – Inline keyboard attached to the message.
  • input_message_content (telegram.InputMessageContent, optional) – Content of the message to be sent instead of the contact.
  • thumb_url (str, optional) – Url of the thumbnail for the result.
  • thumb_width (int, optional) – Thumbnail width.
  • thumb_height (int, optional) – Thumbnail height.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InlineQueryResultDocument(id, document_url, title, mime_type, caption=None, description=None, reply_markup=None, input_message_content=None, thumb_url=None, thumb_width=None, thumb_height=None, parse_mode=None, **kwargs)

Bases: telegram.inline.inlinequeryresult.InlineQueryResult

Represents a link to a file. By default, this file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the file. Currently, only .PDF and .ZIP files can be sent using this method.

type

‘document’.

Type:str
id

Unique identifier for this result, 1-64 bytes.

Type:str
title

Title for the result.

Type:str
caption

Optional. Caption, 0-1024 characters

Type:str
parse_mode

Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.

Type:str
document_url

A valid URL for the file.

Type:str
mime_type

Mime type of the content of the file, either “application/pdf” or “application/zip”.

Type:str
description

Optional. Short description of the result.

Type:str
reply_markup

Optional. Inline keyboard attached to the message.

Type:telegram.InlineKeyboardMarkup
input_message_content

Optional. Content of the message to be sent instead of the file.

Type:telegram.InputMessageContent
thumb_url

Optional. URL of the thumbnail (jpeg only) for the file.

Type:str
thumb_width

Optional. Thumbnail width.

Type:int
thumb_height

Optional. Thumbnail height.

Type:int
Parameters:
  • id (str) – Unique identifier for this result, 1-64 bytes.
  • title (str) – Title for the result.
  • caption (str, optional) – Caption, 0-1024 characters
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • document_url (str) – A valid URL for the file.
  • mime_type (str) – Mime type of the content of the file, either “application/pdf” or “application/zip”.
  • description (str, optional) – Short description of the result.
  • reply_markup (telegram.InlineKeyboardMarkup) – Optional. Inline keyboard attached to the message.
  • input_message_content (telegram.InputMessageContent) – Optional. Content of the message to be sent instead of the file.
  • thumb_url (str, optional) – URL of the thumbnail (jpeg only) for the file.
  • thumb_width (int, optional) – Thumbnail width.
  • thumb_height (int, optional) – Thumbnail height.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InlineQueryResultGif(id, gif_url, thumb_url, gif_width=None, gif_height=None, title=None, caption=None, reply_markup=None, input_message_content=None, gif_duration=None, parse_mode=None, **kwargs)

Bases: telegram.inline.inlinequeryresult.InlineQueryResult

Represents a link to an animated GIF file. By default, this animated GIF file will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation.

type

‘gif’.

Type:str
id

Unique identifier for this result, 1-64 bytes.

Type:str
gif_url

A valid URL for the GIF file. File size must not exceed 1MB.

Type:str
gif_width

Optional. Width of the GIF.

Type:int
gif_height

Optional. Height of the GIF.

Type:int
gif_duration

Optional. Duration of the GIF.

Type:int
thumb_url

URL of the static thumbnail for the result (jpeg or gif).

Type:str
title

Optional. Title for the result.

Type:str
caption

Optional. Caption, 0-1024 characters

Type:str
parse_mode

Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.

Type:str
reply_markup

Optional. Inline keyboard attached to the message.

Type:telegram.InlineKeyboardMarkup
input_message_content

Optional. Content of the message to be sent instead of the gif.

Type:telegram.InputMessageContent
Parameters:
  • id (str) – Unique identifier for this result, 1-64 bytes.
  • gif_url (str) – A valid URL for the GIF file. File size must not exceed 1MB.
  • gif_width (int, optional) – Width of the GIF.
  • gif_height (int, optional) – Height of the GIF.
  • gif_duration (int, optional) – Duration of the GIF
  • thumb_url (str) – URL of the static thumbnail for the result (jpeg or gif).
  • title (str, optional) – Title for the result.caption (str, optional):
  • caption (str, optional) – Caption, 0-1024 characters
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • reply_markup (telegram.InlineKeyboardMarkup, optional) – Inline keyboard attached to the message.
  • input_message_content (telegram.InputMessageContent, optional) – Content of the message to be sent instead of the gif.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InlineQueryResultLocation(id, latitude, longitude, title, live_period=None, reply_markup=None, input_message_content=None, thumb_url=None, thumb_width=None, thumb_height=None, **kwargs)

Bases: telegram.inline.inlinequeryresult.InlineQueryResult

Represents a location on a map. By default, the location will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the location.

type

‘location’.

Type:str
id

Unique identifier for this result, 1-64 bytes.

Type:str
latitude

Location latitude in degrees.

Type:float
longitude

Location longitude in degrees.

Type:float
title

Location title.

Type:str
live_period

Optional. Period in seconds for which the location can be updated, should be between 60 and 86400.

Type:int
reply_markup

Optional. Inline keyboard attached to the message.

Type:telegram.InlineKeyboardMarkup
input_message_content

Optional. Content of the message to be sent instead of the location.

Type:telegram.InputMessageContent
thumb_url

Optional. Url of the thumbnail for the result.

Type:str
thumb_width

Optional. Thumbnail width.

Type:int
thumb_height

Optional. Thumbnail height.

Type:int
Parameters:
  • id (str) – Unique identifier for this result, 1-64 bytes.
  • latitude (float) – Location latitude in degrees.
  • longitude (float) – Location longitude in degrees.
  • title (str) – Location title.
  • live_period (int, optional) – Period in seconds for which the location can be updated, should be between 60 and 86400.
  • reply_markup (telegram.InlineKeyboardMarkup, optional) – Inline keyboard attached to the message.
  • input_message_content (telegram.InputMessageContent, optional) – Content of the message to be sent instead of the location.
  • thumb_url (str, optional) – Url of the thumbnail for the result.
  • thumb_width (int, optional) – Thumbnail width.
  • thumb_height (int, optional) – Thumbnail height.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InlineQueryResultMpeg4Gif(id, mpeg4_url, thumb_url, mpeg4_width=None, mpeg4_height=None, title=None, caption=None, reply_markup=None, input_message_content=None, mpeg4_duration=None, parse_mode=None, **kwargs)

Bases: telegram.inline.inlinequeryresult.InlineQueryResult

Represents a link to a video animation (H.264/MPEG-4 AVC video without sound). By default, this animated MPEG-4 file will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation.

type

‘mpeg4_gif’.

Type:str
id

Unique identifier for this result, 1-64 bytes.

Type:str
mpeg4_url

A valid URL for the MP4 file. File size must not exceed 1MB.

Type:str
mpeg4_width

Optional. Video width.

Type:int
mpeg4_height

Optional. Video height.

Type:int
mpeg4_duration

Optional. Video duration.

Type:int
thumb_url

URL of the static thumbnail (jpeg or gif) for the result.

Type:str
title

Optional. Title for the result.

Type:str
caption

Optional. Caption, 0-1024 characters

Type:str
parse_mode

Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.

Type:str
reply_markup

Optional. Inline keyboard attached to the message.

Type:telegram.InlineKeyboardMarkup
input_message_content

Optional. Content of the message to be sent instead of the MPEG-4 file.

Type:telegram.InputMessageContent
Parameters:
  • id (str) – Unique identifier for this result, 1-64 bytes.
  • mpeg4_url (str) – A valid URL for the MP4 file. File size must not exceed 1MB.
  • mpeg4_width (int, optional) – Video width.
  • mpeg4_height (int, optional) – Video height.
  • mpeg4_duration (int, optional) – Video duration.
  • thumb_url (str) – URL of the static thumbnail (jpeg or gif) for the result.
  • title (str, optional) – Title for the result.
  • caption (str, optional) – Caption, 0-1024 characters
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • reply_markup (telegram.InlineKeyboardMarkup, optional) – Inline keyboard attached to the message.
  • input_message_content (telegram.InputMessageContent, optional) – Content of the message to be sent instead of the MPEG-4 file.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InlineQueryResultPhoto(id, photo_url, thumb_url, photo_width=None, photo_height=None, title=None, description=None, caption=None, reply_markup=None, input_message_content=None, parse_mode=None, **kwargs)

Bases: telegram.inline.inlinequeryresult.InlineQueryResult

Represents a link to a photo. By default, this photo will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the photo.

type

‘photo’.

Type:str
id

Unique identifier for this result, 1-64 bytes.

Type:str
photo_url

A valid URL of the photo. Photo must be in jpeg format. Photo size must not exceed 5MB.

Type:str
thumb_url

URL of the thumbnail for the photo.

Type:str
photo_width

Optional. Width of the photo.

Type:int
photo_height

Optional. Height of the photo.

Type:int
title

Optional. Title for the result.

Type:str
description

Optional. Short description of the result.

Type:str
caption

Optional. Caption, 0-1024 characters

Type:str
parse_mode

Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.

Type:str
reply_markup

Optional. Inline keyboard attached to the message.

Type:telegram.InlineKeyboardMarkup
input_message_content

Optional. Content of the message to be sent instead of the photo.

Type:telegram.InputMessageContent
Parameters:
  • id (str) – Unique identifier for this result, 1-64 bytes.
  • photo_url (str) – A valid URL of the photo. Photo must be in jpeg format. Photo size must not exceed 5MB.
  • thumb_url (str) – URL of the thumbnail for the photo.
  • photo_width (int, optional) – Width of the photo.
  • photo_height (int, optional) – Height of the photo.
  • title (str, optional) – Title for the result.
  • description (str, optional) – Short description of the result.
  • caption (str, optional) – Caption, 0-1024 characters
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • reply_markup (telegram.InlineKeyboardMarkup, optional) – Inline keyboard attached to the message.
  • input_message_content (telegram.InputMessageContent, optional) – Content of the message to be sent instead of the photo.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InlineQueryResultVenue(id, latitude, longitude, title, address, foursquare_id=None, foursquare_type=None, reply_markup=None, input_message_content=None, thumb_url=None, thumb_width=None, thumb_height=None, **kwargs)

Bases: telegram.inline.inlinequeryresult.InlineQueryResult

Represents a venue. By default, the venue will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the venue.

type

‘venue’.

Type:str
id

Unique identifier for this result, 1-64 Bytes.

Type:str
latitude

Latitude of the venue location in degrees.

Type:float
longitude

Longitude of the venue location in degrees.

Type:float
title

Title of the venue.

Type:str
address

Address of the venue.

Type:str
foursquare_id

Optional. Foursquare identifier of the venue if known.

Type:str
foursquare_type

Optional. Foursquare type of the venue, if known. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.)

Type:str
reply_markup

Optional. Inline keyboard attached to the message.

Type:telegram.InlineKeyboardMarkup
input_message_content

Optional. Content of the message to be sent instead of the venue.

Type:telegram.InputMessageContent
thumb_url

Optional. Url of the thumbnail for the result.

Type:str
thumb_width

Optional. Thumbnail width.

Type:int
thumb_height

Optional. Thumbnail height.

Type:int
Parameters:
  • id (str) – Unique identifier for this result, 1-64 Bytes.
  • latitude (float) – Latitude of the venue location in degrees.
  • longitude (float) – Longitude of the venue location in degrees.
  • title (str) – Title of the venue.
  • address (str) – Address of the venue.
  • foursquare_id (str, optional) – Foursquare identifier of the venue if known.
  • foursquare_type (str, optional) – Foursquare type of the venue, if known. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.)
  • reply_markup (telegram.InlineKeyboardMarkup, optional) – Inline keyboard attached to the message.
  • input_message_content (telegram.InputMessageContent, optional) – Content of the message to be sent instead of the location.
  • thumb_url (str, optional) – Url of the thumbnail for the result.
  • thumb_width (int, optional) – Thumbnail width.
  • thumb_height (int, optional) – Thumbnail height.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InlineQueryResultVideo(id, video_url, mime_type, thumb_url, title, caption=None, video_width=None, video_height=None, video_duration=None, description=None, reply_markup=None, input_message_content=None, parse_mode=None, **kwargs)

Bases: telegram.inline.inlinequeryresult.InlineQueryResult

Represents a link to a page containing an embedded video player or a video file. By default, this video file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the video.

type

‘video’.

Type:str
id

Unique identifier for this result, 1-64 bytes.

Type:str
video_url

A valid URL for the embedded video player or video file.

Type:str
mime_type

Mime type of the content of video url, “text/html” or “video/mp4”.

Type:str
thumb_url

URL of the thumbnail (jpeg only) for the video.

Type:str
title

Title for the result.

Type:str
caption

Optional. Caption, 0-1024 characters

Type:str
parse_mode

Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.

Type:str
video_width

Optional. Video width.

Type:int
video_height

Optional. Video height.

Type:int
video_duration

Optional. Video duration in seconds.

Type:int
description

Optional. Short description of the result.

Type:str
reply_markup

Optional. Inline keyboard attached to the message.

Type:telegram.InlineKeyboardMarkup
input_message_content

Optional. Content of the message to be sent instead of the video.

Type:telegram.InputMessageContent
Parameters:
  • id (str) – Unique identifier for this result, 1-64 bytes.
  • video_url (str) – A valid URL for the embedded video player or video file.
  • mime_type (str) – Mime type of the content of video url, “text/html” or “video/mp4”.
  • thumb_url (str) – URL of the thumbnail (jpeg only) for the video.
  • title (str) – Title for the result.
  • caption (str, optional) – Caption, 0-1024 characters.
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • video_width (int, optional) – Video width.
  • video_height (int, optional) – Video height.
  • video_duration (int, optional) – Video duration in seconds.
  • description (str, optional) – Short description of the result.
  • reply_markup (telegram.InlineKeyboardMarkup, optional) – Inline keyboard attached to the message.
  • input_message_content (telegram.InputMessageContent, optional) – Content of the message to be sent instead of the video.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InlineQueryResultVoice(id, voice_url, title, voice_duration=None, caption=None, reply_markup=None, input_message_content=None, parse_mode=None, **kwargs)

Bases: telegram.inline.inlinequeryresult.InlineQueryResult

Represents a link to a voice recording in an .ogg container encoded with OPUS. By default, this voice recording will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the the voice message.

type

‘voice’.

Type:str
id

Unique identifier for this result, 1-64 bytes.

Type:str
voice_url

A valid URL for the voice recording.

Type:str
title

Voice message title.

Type:str
caption

Optional. Caption, 0-1024 characters.

Type:str
parse_mode

Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.. See the constants in telegram.ParseMode for the available modes.

Type:str
voice_duration

Optional. Recording duration in seconds.

Type:int
reply_markup

Optional. Inline keyboard attached to the message.

Type:telegram.InlineKeyboardMarkup
input_message_content

Optional. Content of the message to be sent instead of the voice.

Type:telegram.InputMessageContent
Parameters:
  • id (str) – Unique identifier for this result, 1-64 bytes.
  • voice_url (str) – A valid URL for the voice recording.
  • title (str) – Voice message title.
  • caption (str, optional) – Caption, 0-1024 characters.
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.. See the constants in telegram.ParseMode for the available modes.
  • voice_duration (int, optional) – Recording duration in seconds.
  • reply_markup (telegram.InlineKeyboardMarkup, optional) – Inline keyboard attached to the message.
  • input_message_content (telegram.InputMessageContent, optional) – Content of the message to be sent instead of the voice.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InlineQueryResultGame(id, game_short_name, reply_markup=None, **kwargs)

Bases: telegram.inline.inlinequeryresult.InlineQueryResult

Represents a Game.

type

‘game’.

Type:str
id

Unique identifier for this result, 1-64 bytes.

Type:str
game_short_name

Short name of the game.

Type:str
reply_markup

Optional. Inline keyboard attached to the message.

Type:telegram.InlineKeyboardMarkup
Parameters:
  • id (str) – Unique identifier for this result, 1-64 bytes.
  • game_short_name (str) – Short name of the game.
  • reply_markup (telegram.InlineKeyboardMarkup, optional) – Inline keyboard attached to the message.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InputContactMessageContent(phone_number, first_name, last_name=None, vcard=None, **kwargs)

Bases: telegram.inline.inputmessagecontent.InputMessageContent

Represents the content of a contact message to be sent as the result of an inline query.

phone_number

Contact’s phone number.

Type:str
first_name

Contact’s first name.

Type:str
last_name

Optional. Contact’s last name.

Type:str
vcard

Optional. Additional data about the contact in the form of a vCard, 0-2048 bytes.

Type:str
Parameters:
  • phone_number (str) – Contact’s phone number.
  • first_name (str) – Contact’s first name.
  • last_name (str, optional) – Contact’s last name.
  • vcard (str, optional) – Additional data about the contact in the form of a vCard, 0-2048 bytes.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InputFile(obj, filename=None, attach=None)

Bases: object

This object represents a Telegram InputFile.

input_file_content

The binaray content of the file to send.

Type:bytes
filename

Optional, Filename for the file to be sent.

Type:str
attach

Optional, attach id for sending multiple files.

Type:str
Parameters:
  • obj (File handler) – An open file descriptor.
  • filename (str, optional) – Filename for this InputFile.
  • attach (bool, optional) – Whether this should be send as one file or is part of a collection of files.
Raises:

TelegramError

field_tuple
static is_file(obj)
static is_image(stream)

Check if the content file is an image by analyzing its headers.

Parameters:stream (str) – A str representing the content of a file.
Returns:The str mime-type of an image.
Return type:str
to_dict()
class telegram.InputLocationMessageContent(latitude, longitude, live_period=None, **kwargs)

Bases: telegram.inline.inputmessagecontent.InputMessageContent

Represents the content of a location message to be sent as the result of an inline query.

latitude

Latitude of the location in degrees.

Type:float
longitude

Longitude of the location in degrees.

Type:float
Parameters:
  • latitude (float) – Latitude of the location in degrees.
  • longitude (float) – Longitude of the location in degrees.
  • live_period (int, optional) – Period in seconds for which the location can be updated, should be between 60 and 86400.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InputMessageContent

Bases: telegram.base.TelegramObject

Base class for Telegram InputMessageContent Objects.

See: telegram.InputContactMessageContent, telegram.InputLocationMessageContent, telegram.InputTextMessageContent and telegram.InputVenueMessageContent for more details.

class telegram.InputTextMessageContent(message_text, parse_mode=None, disable_web_page_preview=None, **kwargs)

Bases: telegram.inline.inputmessagecontent.InputMessageContent

Represents the content of a text message to be sent as the result of an inline query.

message_text

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

Type:str
parse_mode

Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot’s message.

Type:str
disable_web_page_preview

Optional. Disables link previews for links in the sent message.

Type:bool
Parameters:
  • message_text (str) – Text of the message to be sent, 1-4096 characters. Also found as telegram.constants.MAX_MESSAGE_LENGTH.
  • parse_mode (str, optional) – 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, optional) – Disables link previews for links in the sent message.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.InputVenueMessageContent(latitude, longitude, title, address, foursquare_id=None, foursquare_type=None, **kwargs)

Bases: telegram.inline.inputmessagecontent.InputMessageContent

Represents the content of a venue message to be sent as the result of an inline query.

latitude

Latitude of the location in degrees.

Type:float
longitude

Longitude of the location in degrees.

Type:float
title

Name of the venue.

Type:str
address

Address of the venue.

Type:str
foursquare_id

Optional. Foursquare identifier of the venue, if known.

Type:str
foursquare_type

Optional. Foursquare type of the venue, if known. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.)

Type:str
Parameters:
  • latitude (float) – Latitude of the location in degrees.
  • longitude (float) – Longitude of the location in degrees.
  • title (str) – Name of the venue.
  • address (str) – Address of the venue.
  • foursquare_id (str, optional) – Foursquare identifier of the venue, if known.
  • foursquare_type (str, optional) – Foursquare type of the venue, if known. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.)
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.KeyboardButton(text, request_contact=None, request_location=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents one button of the reply keyboard. For simple text buttons String can be used instead of this object to specify text of the button.

Note

Optional fields are mutually exclusive.

text

Text of the button.

Type:str
request_contact

Optional. If the user’s phone number will be sent.

Type:bool
request_location

Optional. If the user’s current location will be sent.

Type:bool
Parameters:
  • text (str) – Text of the button. If none of the optional fields are used, it will be sent to the bot as a message when the button is pressed.
  • request_contact (bool, optional) – If True, the user’s phone number will be sent as a contact when the button is pressed. Available in private chats only.
  • request_location (bool, optional) – If True, the user’s current location will be sent when the button is pressed. Available in private chats only.

Note

request_contact and request_location options will only work in Telegram versions released after 9 April, 2016. Older clients will ignore them.

class telegram.Location(longitude, latitude, **kwargs)

Bases: telegram.base.TelegramObject

This object represents a point on the map.

longitude

Longitude as defined by sender.

Type:float
latitude

Latitude as defined by sender.

Type:float
Parameters:
  • longitude (float) – Longitude as defined by sender.
  • latitude (float) – Latitude as defined by sender.
  • **kwargs (dict) – Arbitrary keyword arguments.
classmethod de_json(data, bot)
class telegram.EncryptedCredentials(data, hash, secret, bot=None, **kwargs)

Bases: telegram.base.TelegramObject

Contains data required for decrypting and authenticating EncryptedPassportElement. See the Telegram Passport Documentation for a complete description of the data decryption and authentication processes.

data

Decrypted data with unique user’s nonce, data hashes and secrets used for EncryptedPassportElement decryption and authentication or base64 encrypted data.

Type:telegram.Credentials or str
hash

Base64-encoded data hash for data authentication.

Type:str
secret

Decrypted or encrypted secret used for decryption.

Type:str
Parameters:
  • data (telegram.Credentials or str) – Decrypted data with unique user’s nonce, data hashes and secrets used for EncryptedPassportElement decryption and authentication or base64 encrypted data.
  • hash (str) – Base64-encoded data hash for data authentication.
  • secret (str) – Decrypted or encrypted secret used for decryption.
  • **kwargs (dict) – Arbitrary keyword arguments.

Note

This object is decrypted only when originating from telegram.PassportData.decrypted_credentials.

classmethod de_json(data, bot)
decrypted_data
Lazily decrypt and return credentials data. This object
also contains the user specified nonce as decrypted_data.nonce.
Raises:telegram.TelegramDecryptionError – Decryption failed. Usually due to bad private/public key but can also suggest malformed/tampered data.
Type:telegram.Credentials
decrypted_secret

Lazily decrypt and return secret.

Raises:telegram.TelegramDecryptionError – Decryption failed. Usually due to bad private/public key but can also suggest malformed/tampered data.
Type:str
class telegram.PassportFile(file_id, file_date, file_size=None, bot=None, credentials=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents a file uploaded to Telegram Passport. Currently all Telegram Passport files are in JPEG format when decrypted and don’t exceed 10MB.

file_id

Unique identifier for this file.

Type:str
file_size

File size.

Type:int
file_date

Unix time when the file was uploaded.

Type:int
bot

Optional. The Bot to use for instance methods.

Type:telegram.Bot
Parameters:
  • file_id (str) – Unique identifier for this file.
  • file_size (int) – File size.
  • file_date (int) – Unix time when the file was uploaded.
  • bot (telegram.Bot, optional) – The Bot to use for instance methods.
  • **kwargs (dict) – Arbitrary keyword arguments.
classmethod de_json(data, bot)
classmethod de_json_decrypted(data, bot, credentials)
classmethod de_list(data, bot)
classmethod de_list_decrypted(data, bot, credentials)
get_file(timeout=None, **kwargs)

Wrapper over telegram.Bot.get_file. Will automatically assign the correct credentials to the returned telegram.File if originating from telegram.PassportData.decrypted_data.

Parameters:
  • timeout (int | float, optional) – 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:

telegram.File

Raises:

telegram.TelegramError

class telegram.EncryptedPassportElement(type, data=None, phone_number=None, email=None, files=None, front_side=None, reverse_side=None, selfie=None, translation=None, hash=None, bot=None, credentials=None, **kwargs)

Bases: telegram.base.TelegramObject

Contains information about documents or other Telegram Passport elements shared with the bot by the user. The data has been automatically decrypted by python-telegram-bot.

type

Element type. One of “personal_details”, “passport”, “driver_license”, “identity_card”, “internal_passport”, “address”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration”, “phone_number”, “email”.

Type:str
data

Optional. Decrypted or encrypted data, available for “personal_details”, “passport”, “driver_license”, “identity_card”, “identity_passport” and “address” types.

Type:telegram.PersonalDetails or telegram.IdDocument or telegram.ResidentialAddress or str
phone_number

Optional. User’s verified phone number, available only for “phone_number” type.

Type:str
email

Optional. User’s verified email address, available only for “email” type.

Type:str
files

Optional. Array of encrypted/decrypted files with documents provided by the user, available for “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration” and “temporary_registration” types.

Type:List[telegram.PassportFile]
front_side

Optional. Encrypted/decrypted file with the front side of the document, provided by the user. Available for “passport”, “driver_license”, “identity_card” and “internal_passport”.

Type:telegram.PassportFile
reverse_side

Optional. Encrypted/decrypted file with the reverse side of the document, provided by the user. Available for “driver_license” and “identity_card”.

Type:telegram.PassportFile
selfie

Optional. Encrypted/decrypted file with the selfie of the user holding a document, provided by the user; available for “passport”, “driver_license”, “identity_card” and “internal_passport”.

Type:telegram.PassportFile
translation

Optional. Array of encrypted/decrypted files with translated versions of documents provided by the user. Available if requested for “passport”, “driver_license”, “identity_card”, “internal_passport”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration” and “temporary_registration” types.

Type:List[telegram.PassportFile]
hash

Base64-encoded element hash for using in telegram.PassportElementErrorUnspecified.

Type:str
bot

Optional. The Bot to use for instance methods.

Type:telegram.Bot
Parameters:
  • type (str) – Element type. One of “personal_details”, “passport”, “driver_license”, “identity_card”, “internal_passport”, “address”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration”, “phone_number”, “email”.
  • data (telegram.PersonalDetails or telegram.IdDocument or telegram.ResidentialAddress or str, optional) – Decrypted or encrypted data, available for “personal_details”, “passport”, “driver_license”, “identity_card”, “identity_passport” and “address” types.
  • phone_number (str, optional) – User’s verified phone number, available only for “phone_number” type.
  • email (str, optional) – User’s verified email address, available only for “email” type.
  • files (List[telegram.PassportFile], optional) – Array of encrypted/decrypted files with documents provided by the user, available for “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration” and “temporary_registration” types.
  • front_side (telegram.PassportFile, optional) – Encrypted/decrypted file with the front side of the document, provided by the user. Available for “passport”, “driver_license”, “identity_card” and “internal_passport”.
  • reverse_side (telegram.PassportFile, optional) – Encrypted/decrypted file with the reverse side of the document, provided by the user. Available for “driver_license” and “identity_card”.
  • selfie (telegram.PassportFile, optional) – Encrypted/decrypted file with the selfie of the user holding a document, provided by the user; available for “passport”, “driver_license”, “identity_card” and “internal_passport”.
  • translation (List[telegram.PassportFile], optional) – Array of encrypted/decrypted files with translated versions of documents provided by the user. Available if requested for “passport”, “driver_license”, “identity_card”, “internal_passport”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration” and “temporary_registration” types.
  • hash (str) – Base64-encoded element hash for using in telegram.PassportElementErrorUnspecified.
  • bot (telegram.Bot, optional) – The Bot to use for instance methods.
  • **kwargs (dict) – Arbitrary keyword arguments.

Note

This object is decrypted only when originating from telegram.PassportData.decrypted_data.

classmethod de_json(data, bot)
classmethod de_json_decrypted(data, bot, credentials)
classmethod de_list(data, bot)
to_dict()
class telegram.PassportData(data, credentials, bot=None, **kwargs)

Bases: telegram.base.TelegramObject

Contains information about Telegram Passport data shared with the bot by the user.

data

Array with encrypted information about documents and other Telegram Passport elements that was shared with the bot.

Type:List[telegram.EncryptedPassportElement]
credentials

Encrypted credentials.

Type:telegram.EncryptedCredentials
bot

The Bot to use for instance methods.

Type:telegram.Bot, optional
Parameters:
  • data (List[telegram.EncryptedPassportElement]) – Array with encrypted information about documents and other Telegram Passport elements that was shared with the bot.
  • credentials (str) – Encrypted credentials.
  • bot (telegram.Bot, optional) – The Bot to use for instance methods.
  • **kwargs (dict) – Arbitrary keyword arguments.

Note

To be able to decrypt this object, you must pass your private_key to either telegram.Updater or telegram.Bot. Decrypted data is then found in decrypted_data and the payload can be found in decrypted_credentials’s attribute telegram.Credentials.payload.

classmethod de_json(data, bot)
decrypted_credentials
Lazily decrypt and return credentials that were used
to decrypt the data. This object also contains the user specified payload as decrypted_data.payload.
Raises:telegram.TelegramDecryptionError – Decryption failed. Usually due to bad private/public key but can also suggest malformed/tampered data.
Type:telegram.Credentials
decrypted_data
Lazily decrypt and return information
about documents and other Telegram Passport elements which were shared with the bot.
Raises:telegram.TelegramDecryptionError – Decryption failed. Usually due to bad private/public key but can also suggest malformed/tampered data.
Type:List[telegram.EncryptedPassportElement]
to_dict()
class telegram.Message(message_id, from_user, date, chat, forward_from=None, forward_from_chat=None, forward_from_message_id=None, forward_date=None, reply_to_message=None, edit_date=None, text=None, entities=None, caption_entities=None, audio=None, document=None, game=None, photo=None, sticker=None, video=None, voice=None, video_note=None, new_chat_members=None, caption=None, contact=None, location=None, venue=None, left_chat_member=None, new_chat_title=None, new_chat_photo=None, delete_chat_photo=False, group_chat_created=False, supergroup_chat_created=False, channel_chat_created=False, migrate_to_chat_id=None, migrate_from_chat_id=None, pinned_message=None, invoice=None, successful_payment=None, forward_signature=None, author_signature=None, media_group_id=None, connected_website=None, animation=None, passport_data=None, bot=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents a message.

Note

  • In Python from is a reserved word, use from_user instead.
message_id

Unique message identifier inside this chat.

Type:int
from_user

Optional. Sender.

Type:telegram.User
date

Date the message was sent.

Type:datetime.datetime
chat

Conversation the message belongs to.

Type:telegram.Chat
forward_from

Optional. Sender of the original message.

Type:telegram.User
forward_from_chat

Optional. Information about the original channel.

Type:telegram.Chat
forward_from_message_id

Optional. Identifier of the original message in the channel.

Type:int
forward_date

Optional. Date the original message was sent.

Type:datetime.datetime
reply_to_message

Optional. The original message.

Type:telegram.Message
edit_date

Optional. Date the message was last edited.

Type:datetime.datetime
media_group_id

Optional. The unique identifier of a media message group this message belongs to.

Type:str
text

Optional. The actual UTF-8 text of the message.

Type:str
entities

Optional. Special entities like usernames, URLs, bot commands, etc. that appear in the text. See Message.parse_entity and parse_entities methods for how to use properly.

Type:List[telegram.MessageEntity]
caption_entities

Optional. Special entities like usernames, URLs, bot commands, etc. that appear in the caption. See Message.parse_caption_entity and parse_caption_entities methods for how to use properly.

Type:List[telegram.MessageEntity]
audio

Optional. Information about the file.

Type:telegram.Audio
document

Optional. Information about the file.

Type:telegram.Document
animation

For backward compatibility, when this field is set, the document field will also be set.

Type:telegram.Animation
game

Optional. Information about the game.

Type:telegram.Game
photo

Optional. Available sizes of the photo.

Type:List[telegram.PhotoSize]
sticker

Optional. Information about the sticker.

Type:telegram.Sticker
video

Optional. Information about the video.

Type:telegram.Video
voice

Optional. Information about the file.

Type:telegram.Voice
video_note

Optional. Information about the video message.

Type:telegram.VideoNote
new_chat_members

Optional. Information about new members to the chat. (the bot itself may be one of these members).

Type:List[telegram.User]
caption

Optional. Caption for the document, photo or video, 0-1024 characters.

Type:str
contact

Optional. Information about the contact.

Type:telegram.Contact
location

Optional. Information about the location.

Type:telegram.Location
venue

Optional. Information about the venue.

Type:telegram.Venue
left_chat_member

Optional. Information about the user that left the group. (this member may be the bot itself).

Type:telegram.User
new_chat_title

Optional. A chat title was changed to this value.

Type:str
new_chat_photo

Optional. A chat photo was changed to this value.

Type:List[telegram.PhotoSize]
delete_chat_photo

Optional. The chat photo was deleted.

Type:bool
group_chat_created

Optional. The group has been created.

Type:bool
supergroup_chat_created

Optional. The supergroup has been created.

Type:bool
channel_chat_created

Optional. The channel has been created.

Type:bool
migrate_to_chat_id

Optional. The group has been migrated to a supergroup with the specified identifier.

Type:int
migrate_from_chat_id

Optional. The supergroup has been migrated from a group with the specified identifier.

Type:int
pinned_message

Optional. Specified message was pinned.

Type:telegram.message
invoice

Optional. Information about the invoice.

Type:telegram.Invoice
successful_payment

Optional. Information about the payment.

Type:telegram.SuccessfulPayment
connected_website

Optional. The domain name of the website on which the user has logged in.

Type:str
forward_signature

Optional. Signature of the post author for messages forwarded from channels.

Type:str
author_signature

Optional. Signature of the post author for messages in channels.

Type:str
passport_data

Optional. Telegram Passport data

Type:telegram.PassportData
bot

Optional. The Bot to use for instance methods.

Type:telegram.Bot
Parameters:
  • message_id (int) – Unique message identifier inside this chat.
  • from_user (telegram.User, optional) – Sender, can be empty for messages sent to channels.
  • date (datetime.datetime) – Date the message was sent in Unix time. Converted to datetime.datetime.
  • chat (telegram.Chat) – Conversation the message belongs to.
  • forward_from (telegram.User, optional) – For forwarded messages, sender of the original message.
  • forward_from_chat (telegram.Chat, optional) – For messages forwarded from a channel, information about the original channel.
  • forward_from_message_id (int, optional) – For forwarded channel posts, identifier of the original message in the channel.
  • forward_date (datetime.datetime, optional) – For forwarded messages, date the original message was sent in Unix time. Converted to datetime.datetime.
  • reply_to_message (telegram.Message, optional) – For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.
  • edit_date (datetime.datetime, optional) – Date the message was last edited in Unix time. Converted to datetime.datetime.
  • media_group_id (str, optional) – The unique identifier of a media message group this message belongs to.
  • text (str, optional) – For text messages, the actual UTF-8 text of the message, 0-4096 characters. Also found as telegram.constants.MAX_MESSAGE_LENGTH.
  • entities (List[telegram.MessageEntity], optional) – For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text. See attr:parse_entity and attr:parse_entities methods for how to use properly.
  • caption_entities (List[telegram.MessageEntity]) – Optional. For Messages with a Caption. Special entities like usernames, URLs, bot commands, etc. that appear in the caption. See Message.parse_caption_entity and parse_caption_entities methods for how to use properly.
  • audio (telegram.Audio, optional) – Message is an audio file, information about the file.
  • document (telegram.Document, optional) – Message is a general file, information about the file.
  • animation (telegram.Animation, optional) – Message is an animation, information about the animation. For backward compatibility, when this field is set, the document field will also be set.
  • game (telegram.Game, optional) – Message is a game, information about the game.
  • photo (List[telegram.PhotoSize], optional) – Message is a photo, available sizes of the photo.
  • sticker (telegram.Sticker, optional) – Message is a sticker, information about the sticker.
  • video (telegram.Video, optional) – Message is a video, information about the video.
  • voice (telegram.Voice, optional) – Message is a voice message, information about the file.
  • video_note (telegram.VideoNote, optional) – Message is a video note, information about the video message.
  • new_chat_members (List[telegram.User], optional) – New members that were added to the group or supergroup and information about them (the bot itself may be one of these members).
  • caption (str, optional) – Caption for the document, photo or video, 0-1024 characters.
  • contact (telegram.Contact, optional) – Message is a shared contact, information about the contact.
  • location (telegram.Location, optional) – Message is a shared location, information about the location.
  • venue (telegram.Venue, optional) – Message is a venue, information about the venue.
  • left_chat_member (telegram.User, optional) – A member was removed from the group, information about them (this member may be the bot itself).
  • new_chat_title (str, optional) – A chat title was changed to this value.
  • new_chat_photo (List[telegram.PhotoSize], optional) – A chat photo was change to this value.
  • delete_chat_photo (bool, optional) – Service message: The chat photo was deleted.
  • group_chat_created (bool, optional) – Service message: The group has been created.
  • supergroup_chat_created (bool, optional) – Service message: The supergroup has been created. This field can’t be received in a message coming through updates, because bot can’t be a member of a supergroup when it is created. It can only be found in reply_to_message if someone replies to a very first message in a directly created supergroup.
  • channel_chat_created (bool, optional) – Service message: The channel has been created. This field can’t be received in a message coming through updates, because bot can’t be a member of a channel when it is created. It can only be found in attr:reply_to_message if someone replies to a very first message in a channel.
  • migrate_to_chat_id (int, optional) – The group has been migrated to a supergroup with the specified identifier. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
  • migrate_from_chat_id (int, optional) – The supergroup has been migrated from a group with the specified identifier. This number may be greater than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it is smaller than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier.
  • pinned_message (telegram.message, optional) – Specified message was pinned. Note that the Message object in this field will not contain further attr:reply_to_message fields even if it is itself a reply.
  • invoice (telegram.Invoice, optional) – Message is an invoice for a payment, information about the invoice.
  • successful_payment (telegram.SuccessfulPayment, optional) – Message is a service message about a successful payment, information about the payment.
  • connected_website (str, optional) – The domain name of the website on which the user has logged in.
  • forward_signature (str, optional) – Signature of the post author for messages forwarded from channels.
  • author_signature (str, optional) – Signature of the post author for messages in channels.
  • passport_data (telegram.PassportData, optional) – Telegram Passport data
ATTACHMENT_TYPES = ['audio', 'game', 'animation', 'document', 'photo', 'sticker', 'video', 'voice', 'video_note', 'contact', 'location', 'venue', 'invoice', 'successful_payment']
MESSAGE_TYPES = ['text', 'new_chat_members', 'left_chat_member', 'new_chat_title', 'new_chat_photo', 'delete_chat_photo', 'group_chat_created', 'supergroup_chat_created', 'channel_chat_created', 'migrate_to_chat_id', 'migrate_from_chat_id', 'pinned_message', 'passport_data', 'audio', 'game', 'animation', 'document', 'photo', 'sticker', 'video', 'voice', 'video_note', 'contact', 'location', 'venue', 'invoice', 'successful_payment']
caption_html

Creates an HTML-formatted string from the markup entities found in the message’s caption.

Use this if you want to retrieve the message caption with the caption entities formatted as HTML in the same way the original message was formatted.

Returns:Message caption with captionentities formatted as HTML.
Return type:str
caption_html_urled

Creates an HTML-formatted string from the markup entities found in the message’s caption.

Use this if you want to retrieve the message caption with the caption entities formatted as HTML. This also formats telegram.MessageEntity.URL as a hyperlink.

Returns:Message caption with caption entities formatted as HTML.
Return type:str
caption_markdown

Creates an Markdown-formatted string from the markup entities found in the message’s caption.

Use this if you want to retrieve the message caption with the caption entities formatted as Markdown in the same way the original message was formatted.

Returns:Message caption with caption entities formatted as Markdown.
Return type:str
caption_markdown_urled

Creates an Markdown-formatted string from the markup entities found in the message’s caption.

Use this if you want to retrieve the message caption with the caption entities formatted as Markdown. This also formats telegram.MessageEntity.URL as a hyperlink.

Returns:Message caption with caption entities formatted as Markdown.
Return type:str
chat_id

Shortcut for telegram.Chat.id for chat.

Type:int
classmethod de_json(data, bot)
delete(*args, **kwargs)

Shortcut for:

bot.delete_message(chat_id=message.chat_id,
                   message_id=message.message_id,
                   *args,
                   **kwargs)
Returns:On success, True is returned.
Return type:bool
edit_caption(*args, **kwargs)

Shortcut for:

bot.edit_message_caption(chat_id=message.chat_id,
                         message_id=message.message_id,
                         *args,
                         **kwargs)

Note

You can only edit messages that the bot sent itself, therefore this method can only be used on the return value of the bot.send_* family of methods.

Returns:On success, instance representing the edited message.
Return type:telegram.Message
edit_media(media, *args, **kwargs)

Shortcut for:

bot.edit_message_media(chat_id=message.chat_id,
                         message_id=message.message_id,
                         *args,
                         **kwargs)

Note

You can only edit messages that the bot sent itself, therefore this method can only be used on the return value of the bot.send_* family of methods.

Returns:On success, instance representing the edited message.
Return type:telegram.Message
edit_reply_markup(*args, **kwargs)

Shortcut for:

bot.edit_message_reply_markup(chat_id=message.chat_id,
                              message_id=message.message_id,
                              *args,
                              **kwargs)

Note

You can only edit messages that the bot sent itself, therefore this method can only be used on the return value of the bot.send_* family of methods.

Returns:On success, instance representing the edited message.
Return type:telegram.Message
edit_text(*args, **kwargs)

Shortcut for:

bot.edit_message_text(chat_id=message.chat_id,
                      message_id=message.message_id,
                      *args,
                      **kwargs)

Note

You can only edit messages that the bot sent itself, therefore this method can only be used on the return value of the bot.send_* family of methods.

Returns:On success, instance representing the edited message.
Return type:telegram.Message
effective_attachment

telegram.Audio or telegram.Contact or telegram.Document or telegram.Animation or telegram.Game or telegram.Invoice or telegram.Location or List[telegram.PhotoSize] or telegram.Sticker or telegram.SuccessfulPayment or telegram.Venue or telegram.Video or telegram.VideoNote or telegram.Voice: The attachment that this message was sent with. May be None if no attachment was sent.

forward(chat_id, disable_notification=False)

Shortcut for:

bot.forward_message(chat_id=chat_id,
                    from_chat_id=update.message.chat_id,
                    disable_notification=disable_notification,
                    message_id=update.message.message_id)
Returns:On success, instance representing the message forwarded.
Return type:telegram.Message
link

Convenience property. If the chat of the message is a supergroup or a channel and has a Chat.username, returns a t.me link of the message.

Type:str
parse_caption_entities(types=None)

Returns a dict that maps telegram.MessageEntity to str. It contains entities from this message’s caption filtered by their telegram.MessageEntity.type attribute as the key, and the text that each entity belongs to as the value of the dict.

Note

This method should always be used instead of the caption_entities attribute, since it calculates the correct substring from the message text based on UTF-16 codepoints. See parse_entity for more info.

Parameters:types (List[str], optional) – List of telegram.MessageEntity types as strings. If the type attribute of an entity is contained in this list, it will be returned. Defaults to a list of all types. All types can be found as constants in telegram.MessageEntity.
Returns:A dictionary of entities mapped to the text that belongs to them, calculated based on UTF-16 codepoints.
Return type:Dict[telegram.MessageEntity, str]
parse_caption_entity(entity)

Returns the text from a given telegram.MessageEntity.

Note

This method is present because Telegram calculates the offset and length in UTF-16 codepoint pairs, which some versions of Python don’t handle automatically. (That is, you can’t just slice Message.caption with the offset and length.)

Parameters:
  • entity (telegram.MessageEntity) – The entity to extract the text from. It must
  • an entity that belongs to this message. (be) –
Returns:

The text of the given entity

Return type:

str

parse_entities(types=None)

Returns a dict that maps telegram.MessageEntity to str. It contains entities from this message filtered by their telegram.MessageEntity.type attribute as the key, and the text that each entity belongs to as the value of the dict.

Note

This method should always be used instead of the entities attribute, since it calculates the correct substring from the message text based on UTF-16 codepoints. See parse_entity for more info.

Parameters:types (List[str], optional) – List of telegram.MessageEntity types as strings. If the type attribute of an entity is contained in this list, it will be returned. Defaults to a list of all types. All types can be found as constants in telegram.MessageEntity.
Returns:A dictionary of entities mapped to the text that belongs to them, calculated based on UTF-16 codepoints.
Return type:Dict[telegram.MessageEntity, str]
parse_entity(entity)

Returns the text from a given telegram.MessageEntity.

Note

This method is present because Telegram calculates the offset and length in UTF-16 codepoint pairs, which some versions of Python don’t handle automatically. (That is, you can’t just slice Message.text with the offset and length.)

Parameters:
  • entity (telegram.MessageEntity) – The entity to extract the text from. It must
  • an entity that belongs to this message. (be) –
Returns:

The text of the given entity

Return type:

str

reply_animation(*args, **kwargs)

Shortcut for:

bot.send_animation(update.message.chat_id, *args, **kwargs)
Keyword Arguments:
 quote (bool, optional) – If set to True, the photo is sent as an actual reply to this message. If reply_to_message_id is passed in kwargs, this parameter will be ignored. Default: True in group chats and False in private chats.
Returns:On success, instance representing the message posted.
Return type:telegram.Message
reply_audio(*args, **kwargs)

Shortcut for:

bot.send_audio(update.message.chat_id, *args, **kwargs)
Keyword Arguments:
 quote (bool, optional) – If set to True, the photo is sent as an actual reply to this message. If reply_to_message_id is passed in kwargs, this parameter will be ignored. Default: True in group chats and False in private chats.
Returns:On success, instance representing the message posted.
Return type:telegram.Message
reply_contact(*args, **kwargs)

Shortcut for:

bot.send_contact(update.message.chat_id, *args, **kwargs)
Keyword Arguments:
 quote (bool, optional) – If set to True, the photo is sent as an actual reply to this message. If reply_to_message_id is passed in kwargs, this parameter will be ignored. Default: True in group chats and False in private chats.
Returns:On success, instance representing the message posted.
Return type:telegram.Message
reply_document(*args, **kwargs)

Shortcut for:

bot.send_document(update.message.chat_id, *args, **kwargs)
Keyword Arguments:
 quote (bool, optional) – If set to True, the photo is sent as an actual reply to this message. If reply_to_message_id is passed in kwargs, this parameter will be ignored. Default: True in group chats and False in private chats.
Returns:On success, instance representing the message posted.
Return type:telegram.Message
reply_html(*args, **kwargs)

Shortcut for:

bot.send_message(update.message.chat_id, parse_mode=ParseMode.HTML, *args, **kwargs)

Sends a message with HTML formatting.

Keyword Arguments:
 quote (bool, optional) – If set to True, the message is sent as an actual reply to this message. If reply_to_message_id is passed in kwargs, this parameter will be ignored. Default: True in group chats and False in private chats.
reply_location(*args, **kwargs)

Shortcut for:

bot.send_location(update.message.chat_id, *args, **kwargs)
Keyword Arguments:
 quote (bool, optional) – If set to True, the photo is sent as an actual reply to this message. If reply_to_message_id is passed in kwargs, this parameter will be ignored. Default: True in group chats and False in private chats.
Returns:On success, instance representing the message posted.
Return type:telegram.Message
reply_markdown(*args, **kwargs)

Shortcut for:

bot.send_message(update.message.chat_id, parse_mode=ParseMode.MARKDOWN, *args,
**kwargs)

Sends a message with markdown formatting.

Keyword Arguments:
 quote (bool, optional) – If set to True, the message is sent as an actual reply to this message. If reply_to_message_id is passed in kwargs, this parameter will be ignored. Default: True in group chats and False in private chats.
reply_media_group(*args, **kwargs)

Shortcut for:

bot.reply_media_group(update.message.chat_id, *args, **kwargs)
Keyword Arguments:
 quote (bool, optional) – If set to True, the media group is sent as an actual reply to this message. If reply_to_message_id is passed in kwargs, this parameter will be ignored. Default: True in group chats and False in private chats.
Returns:An array of the sent Messages.
Return type:List[telegram.Message]
Raises:telegram.TelegramError
reply_photo(*args, **kwargs)

Shortcut for:

bot.send_photo(update.message.chat_id, *args, **kwargs)
Keyword Arguments:
 quote (bool, optional) – If set to True, the photo is sent as an actual reply to this message. If reply_to_message_id is passed in kwargs, this parameter will be ignored. Default: True in group chats and False in private chats.
Returns:On success, instance representing the message posted.
Return type:telegram.Message
reply_sticker(*args, **kwargs)

Shortcut for:

bot.send_sticker(update.message.chat_id, *args, **kwargs)
Keyword Arguments:
 quote (bool, optional) – If set to True, the photo is sent as an actual reply to this message. If reply_to_message_id is passed in kwargs, this parameter will be ignored. Default: True in group chats and False in private chats.
Returns:On success, instance representing the message posted.
Return type:telegram.Message
reply_text(*args, **kwargs)

Shortcut for:

bot.send_message(update.message.chat_id, *args, **kwargs)
Keyword Arguments:
 quote (bool, optional) – If set to True, the message is sent as an actual reply to this message. If reply_to_message_id is passed in kwargs, this parameter will be ignored. Default: True in group chats and False in private chats.
reply_venue(*args, **kwargs)

Shortcut for:

bot.send_venue(update.message.chat_id, *args, **kwargs)
Keyword Arguments:
 quote (bool, optional) – If set to True, the photo is sent as an actual reply to this message. If reply_to_message_id is passed in kwargs, this parameter will be ignored. Default: True in group chats and False in private chats.
Returns:On success, instance representing the message posted.
Return type:telegram.Message
reply_video(*args, **kwargs)

Shortcut for:

bot.send_video(update.message.chat_id, *args, **kwargs)
Keyword Arguments:
 quote (bool, optional) – If set to True, the photo is sent as an actual reply to this message. If reply_to_message_id is passed in kwargs, this parameter will be ignored. Default: True in group chats and False in private chats.
Returns:On success, instance representing the message posted.
Return type:telegram.Message
reply_video_note(*args, **kwargs)

Shortcut for:

bot.send_video_note(update.message.chat_id, *args, **kwargs)
Keyword Arguments:
 quote (bool, optional) – If set to True, the photo is sent as an actual reply to this message. If reply_to_message_id is passed in kwargs, this parameter will be ignored. Default: True in group chats and False in private chats.
Returns:On success, instance representing the message posted.
Return type:telegram.Message
reply_voice(*args, **kwargs)

Shortcut for:

bot.send_voice(update.message.chat_id, *args, **kwargs)
Keyword Arguments:
 quote (bool, optional) – If set to True, the photo is sent as an actual reply to this message. If reply_to_message_id is passed in kwargs, this parameter will be ignored. Default: True in group chats and False in private chats.
Returns:On success, instance representing the message posted.
Return type:telegram.Message
text_html

Creates an HTML-formatted string from the markup entities found in the message.

Use this if you want to retrieve the message text with the entities formatted as HTML in the same way the original message was formatted.

Returns:Message text with entities formatted as HTML.
Return type:str
text_html_urled

Creates an HTML-formatted string from the markup entities found in the message.

Use this if you want to retrieve the message text with the entities formatted as HTML. This also formats telegram.MessageEntity.URL as a hyperlink.

Returns:Message text with entities formatted as HTML.
Return type:str
text_markdown

Creates an Markdown-formatted string from the markup entities found in the message.

Use this if you want to retrieve the message text with the entities formatted as Markdown in the same way the original message was formatted.

Returns:Message text with entities formatted as Markdown.
Return type:str
text_markdown_urled

Creates an Markdown-formatted string from the markup entities found in the message.

Use this if you want to retrieve the message text with the entities formatted as Markdown. This also formats telegram.MessageEntity.URL as a hyperlink.

Returns:Message text with entities formatted as Markdown.
Return type:str
to_dict()
class telegram.MessageEntity(type, offset, length, url=None, user=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents one special entity in a text message. For example, hashtags, usernames, URLs, etc.

type

Type of the entity.

Type:str
offset

Offset in UTF-16 code units to the start of the entity.

Type:int
length

Length of the entity in UTF-16 code units.

Type:int
url

Optional. Url that will be opened after user taps on the text.

Type:str
user

Optional. The mentioned user.

Type:telegram.User
Parameters:
  • type (str) – Type of the entity. Can be mention (@username), hashtag, bot_command, url, email, bold (bold text), italic (italic text), code (monowidth string), pre (monowidth block), text_link (for clickable text URLs), text_mention (for users without usernames).
  • offset (int) – Offset in UTF-16 code units to the start of the entity.
  • length (int) – Length of the entity in UTF-16 code units.
  • url (str, optional) – For “text_link” only, url that will be opened after usertaps on the text.
  • user (telegram.User, optional) – For “text_mention” only, the mentioned user.
ALL_TYPES = ['mention', 'hashtag', 'cashtag', 'phone_number', 'bot_command', 'url', 'email', 'bold', 'italic', 'code', 'pre', 'text_link', 'text_mention']

List of all the types.

Type:List[str]
BOLD = 'bold'

‘bold’

Type:str
BOT_COMMAND = 'bot_command'

‘bot_command’

Type:str
CASHTAG = 'cashtag'

‘cashtag’

Type:str
CODE = 'code'

‘code’

Type:str
EMAIL = 'email'

‘email’

Type:str
HASHTAG = 'hashtag'

‘hashtag’

Type:str
ITALIC = 'italic'

‘italic’

Type:str
MENTION = 'mention'

‘mention’

Type:str
PHONE_NUMBER = 'phone_number'

‘phone_number’

Type:str
PRE = 'pre'

‘pre’

Type:str
TEXT_LINK = 'text_link'

‘text_link’

Type:str
TEXT_MENTION = 'text_mention'

‘text_mention’

Type:str
URL = 'url'

‘url’

Type:str
classmethod de_json(data, bot)
classmethod de_list(data, bot)
class telegram.ParseMode

Bases: object

This object represents a Telegram Message Parse Modes.

HTML = 'HTML'

‘HTML’

Type:str
MARKDOWN = 'Markdown'

‘Markdown’

Type:str
class telegram.PhotoSize(file_id, width, height, file_size=None, bot=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents one size of a photo or a file/sticker thumbnail.

file_id

Unique identifier for this file.

Type:str
width

Photo width.

Type:int
height

Photo height.

Type:int
file_size

Optional. File size.

Type:int
bot

Optional. The Bot to use for instance methods.

Type:telegram.Bot
Parameters:
  • file_id (str) – Unique identifier for this file.
  • width (int) – Photo width.
  • height (int) – Photo height.
  • file_size (int, optional) – File size.
  • bot (telegram.Bot, optional) – The Bot to use for instance methods.
  • **kwargs (dict) – Arbitrary keyword arguments.
classmethod de_json(data, bot)
classmethod de_list(data, bot)
get_file(timeout=None, **kwargs)

Convenience wrapper over telegram.Bot.get_file

Parameters:
  • timeout (int | float, optional) – 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:

telegram.File

Raises:

telegram.TelegramError

class telegram.ReplyKeyboardRemove(selective=False, **kwargs)

Bases: telegram.replymarkup.ReplyMarkup

Upon receiving a message with this object, Telegram clients will remove the current custom keyboard and display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent by a bot. An exception is made for one-time keyboards that are hidden immediately after the user presses a button (see telegram.ReplyKeyboardMarkup).

remove_keyboard

Requests clients to remove the custom keyboard.

Type:True
selective

Optional. Use this parameter if you want to remove the keyboard for specific users only.

Type:bool

Example

A user votes in a poll, bot returns confirmation message in reply to the vote and removes the keyboard for that user, while still showing the keyboard with poll options to users who haven’t voted yet.

Parameters:
  • selective (bool, optional) –

    Use this parameter if you want to remove the keyboard for specific users only. Targets:

    1. users that are @mentioned in the text of the Message object
    2. if the bot’s message is a reply (has reply_to_message_id), sender of the original message.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.ReplyKeyboardMarkup(keyboard, resize_keyboard=False, one_time_keyboard=False, selective=False, **kwargs)

Bases: telegram.replymarkup.ReplyMarkup

This object represents a custom keyboard with reply options.

keyboard

Array of button rows.

Type:List[List[telegram.KeyboardButton | str]]
resize_keyboard

Optional. Requests clients to resize the keyboard.

Type:bool
one_time_keyboard

Optional. Requests clients to hide the keyboard as soon as it’s been used.

Type:bool
selective

Optional. Show the keyboard to specific users only.

Type:bool

Example

A user requests to change the bot’s language, bot replies to the request with a keyboard to select the new language. Other users in the group don’t see the keyboard.

Parameters:
  • keyboard (List[List[str | telegram.KeyboardButton]]) – Array of button rows, each represented by an Array of telegram.KeyboardButton objects.
  • resize_keyboard (bool, optional) – Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false, in which case the custom keyboard is always of the same height as the app’s standard keyboard. Defaults to False
  • one_time_keyboard (bool, optional) – Requests clients to hide the keyboard as soon as it’s been used. The keyboard will still be available, but clients will automatically display the usual letter-keyboard in the chat - the user can press a special button in the input field to see the custom keyboard again. Defaults to False.
  • selective (bool, optional) –

    Use this parameter if you want to show the keyboard to specific users only. Targets:

    1. users that are @mentioned in the text of the Message object
    2. if the bot’s message is a reply (has reply_to_message_id), sender of the original message.

    Defaults to False.

  • **kwargs (dict) – Arbitrary keyword arguments.
classmethod from_button(button, resize_keyboard=False, one_time_keyboard=False, selective=False, **kwargs)

Shortcut for:

ReplyKeyboardMarkup([[button]], **kwargs)

Return an ReplyKeyboardMarkup from a single KeyboardButton

Parameters:
  • button (telegram.KeyboardButton | str) – The button to use in the markup
  • resize_keyboard (bool, optional) – Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false, in which case the custom keyboard is always of the same height as the app’s standard keyboard. Defaults to False
  • one_time_keyboard (bool, optional) – Requests clients to hide the keyboard as soon as it’s been used. The keyboard will still be available, but clients will automatically display the usual letter-keyboard in the chat - the user can press a special button in the input field to see the custom keyboard again. Defaults to False.
  • selective (bool, optional) –

    Use this parameter if you want to show the keyboard to specific users only. Targets:

    1. users that are @mentioned in the text of the Message object
    2. if the bot’s message is a reply (has reply_to_message_id), sender of the
      original message.

    Defaults to False.

  • **kwargs (dict) – Arbitrary keyword arguments.
classmethod from_column(button_column, resize_keyboard=False, one_time_keyboard=False, selective=False, **kwargs)

Shortcut for:

ReplyKeyboardMarkup([[button] for button in button_column], **kwargs)

Return an ReplyKeyboardMarkup from a single column of KeyboardButtons

Parameters:
  • button_column (List[telegram.KeyboardButton | str]) – The button to use in the markup
  • resize_keyboard (bool, optional) – Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false, in which case the custom keyboard is always of the same height as the app’s standard keyboard. Defaults to False
  • one_time_keyboard (bool, optional) – Requests clients to hide the keyboard as soon as it’s been used. The keyboard will still be available, but clients will automatically display the usual letter-keyboard in the chat - the user can press a special button in the input field to see the custom keyboard again. Defaults to False.
  • selective (bool, optional) –

    Use this parameter if you want to show the keyboard to specific users only. Targets:

    1. users that are @mentioned in the text of the Message object
    2. if the bot’s message is a reply (has reply_to_message_id), sender of the
      original message.

    Defaults to False.

  • **kwargs (dict) – Arbitrary keyword arguments.
classmethod from_row(button_row, resize_keyboard=False, one_time_keyboard=False, selective=False, **kwargs)

Shortcut for:

ReplyKeyboardMarkup([button_row], **kwargs)

Return an ReplyKeyboardMarkup from a single row of KeyboardButtons

Parameters:
  • button_row (List[telegram.KeyboardButton | str]) – The button to use in the markup
  • resize_keyboard (bool, optional) – Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false, in which case the custom keyboard is always of the same height as the app’s standard keyboard. Defaults to False
  • one_time_keyboard (bool, optional) – Requests clients to hide the keyboard as soon as it’s been used. The keyboard will still be available, but clients will automatically display the usual letter-keyboard in the chat - the user can press a special button in the input field to see the custom keyboard again. Defaults to False.
  • selective (bool, optional) –

    Use this parameter if you want to show the keyboard to specific users only. Targets:

    1. users that are @mentioned in the text of the Message object
    2. if the bot’s message is a reply (has reply_to_message_id), sender of the
      original message.

    Defaults to False.

  • **kwargs (dict) – Arbitrary keyword arguments.
to_dict()
class telegram.ReplyMarkup

Bases: telegram.base.TelegramObject

Base class for Telegram ReplyMarkup Objects.

See telegram.ReplyKeyboardMarkup and telegram.InlineKeyboardMarkup for detailed use.

class telegram.Sticker(file_id, width, height, thumb=None, emoji=None, file_size=None, set_name=None, mask_position=None, bot=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents a sticker.

file_id

Unique identifier for this file.

Type:str
width

Sticker width.

Type:int
height

Sticker height.

Type:int
thumb

Optional. Sticker thumbnail in the .webp or .jpg format.

Type:telegram.PhotoSize
emoji

Optional. Emoji associated with the sticker.

Type:str
set_name

Optional. Name of the sticker set to which the sticker belongs.

Type:str
mask_position

Optional. For mask stickers, the position where the mask should be placed.

Type:telegram.MaskPosition
file_size

Optional. File size.

Type:int
bot

Optional. The Bot to use for instance methods.

Type:telegram.Bot
Parameters:
  • file_id (str) – Unique identifier for this file.
  • width (int) – Sticker width.
  • height (int) – Sticker height.
  • thumb (telegram.PhotoSize, optional) – Sticker thumbnail in the .webp or .jpg format.
  • emoji (str, optional) – Emoji associated with the sticker
  • set_name (str, optional) – Name of the sticker set to which the sticker belongs.
  • mask_position (telegram.MaskPosition, optional) – For mask stickers, the position where the mask should be placed.
  • file_size (int, optional) – File size.
  • (obj (**kwargs) – dict): Arbitrary keyword arguments.7
  • bot (telegram.Bot, optional) – The Bot to use for instance methods.
classmethod de_json(data, bot)
classmethod de_list(data, bot)
get_file(timeout=None, **kwargs)

Convenience wrapper over telegram.Bot.get_file

Parameters:
  • timeout (int | float, optional) – 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:

telegram.File

Raises:

telegram.TelegramError

exception telegram.TelegramError(message)

Bases: Exception

class telegram.TelegramObject

Bases: object

Base class for most telegram objects.

classmethod de_json(data, bot)
to_dict()
to_json()
Returns:str
class telegram.Update(update_id, message=None, edited_message=None, channel_post=None, edited_channel_post=None, inline_query=None, chosen_inline_result=None, callback_query=None, shipping_query=None, pre_checkout_query=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents an incoming update.

Note

At most one of the optional parameters can be present in any given update.

update_id

The update’s unique identifier.

Type:int
message

Optional. New incoming message.

Type:telegram.Message
edited_message

Optional. New version of a message.

Type:telegram.Message
channel_post

Optional. New incoming channel post.

Type:telegram.Message
edited_channel_post

Optional. New version of a channel post.

Type:telegram.Message
inline_query

Optional. New incoming inline query.

Type:telegram.InlineQuery
chosen_inline_result

Optional. The result of an inline query that was chosen by a user.

Type:telegram.ChosenInlineResult
callback_query

Optional. New incoming callback query.

Type:telegram.CallbackQuery
shipping_query

Optional. New incoming shipping query.

Type:telegram.ShippingQuery
pre_checkout_query

Optional. New incoming pre-checkout query.

Type:telegram.PreCheckoutQuery
Parameters:
  • update_id (int) – The update’s unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order.
  • message (telegram.Message, optional) – New incoming message of any kind - text, photo, sticker, etc.
  • edited_message (telegram.Message, optional) – New version of a message that is known to the bot and was edited.
  • channel_post (telegram.Message, optional) – New incoming channel post of any kind - text, photo, sticker, etc.
  • edited_channel_post (telegram.Message, optional) – New version of a channel post that is known to the bot and was edited.
  • inline_query (telegram.InlineQuery, optional) – New incoming inline query.
  • chosen_inline_result (telegram.ChosenInlineResult, optional) – The result of an inline query that was chosen by a user and sent to their chat partner.
  • callback_query (telegram.CallbackQuery, optional) – New incoming callback query.
  • shipping_query (telegram.ShippingQuery, optional) – New incoming shipping query. Only for invoices with flexible price.
  • pre_checkout_query (telegram.PreCheckoutQuery, optional) – New incoming pre-checkout query. Contains full information about checkout
  • **kwargs (dict) – Arbitrary keyword arguments.
classmethod de_json(data, bot)
effective_chat

The chat that this update was sent in, no matter what kind of update this is. Will be None for inline_query, chosen_inline_result, callback_query from inline messages, shipping_query and pre_checkout_query.

Type:telegram.Chat
effective_message

The message included in this update, no matter what kind of update this is. Will be None for inline_query, chosen_inline_result, callback_query from inline messages, shipping_query and pre_checkout_query.

Type:telegram.Message
effective_user

The user that sent this update, no matter what kind of update this is. Will be None for channel_post.

Type:telegram.User
class telegram.User(id, first_name, is_bot, last_name=None, username=None, language_code=None, bot=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents a Telegram user or bot.

id

Unique identifier for this user or bot.

Type:int
is_bot

True, if this user is a bot

Type:bool
first_name

User’s or bot’s first name.

Type:str
last_name

Optional. User’s or bot’s last name.

Type:str
username

Optional. User’s or bot’s username.

Type:str
language_code

Optional. IETF language tag of the user’s language.

Type:str
bot

Optional. The Bot to use for instance methods.

Type:telegram.Bot
Parameters:
  • id (int) – Unique identifier for this user or bot.
  • is_bot (bool) – True, if this user is a bot
  • first_name (str) – User’s or bot’s first name.
  • last_name (str, optional) – User’s or bot’s last name.
  • username (str, optional) – User’s or bot’s username.
  • language_code (str, optional) – IETF language tag of the user’s language.
  • bot (telegram.Bot, optional) – The Bot to use for instance methods.
classmethod de_json(data, bot)
classmethod de_list(data, bot)
full_name

Convenience property. The user’s first_name, followed by (if available) last_name.

Type:str
get_profile_photos(*args, **kwargs)

Shortcut for:

bot.get_user_profile_photos(update.message.from_user.id, *args, **kwargs)
link

Convenience property. If username is available, returns a t.me link of the user.

Type:str
mention_html(name=None)
Parameters:name (str) – The name used as a link for the user. Defaults to full_name.
Returns:The inline mention for the user as HTML.
Return type:str
mention_markdown(name=None)
Parameters:name (str) – The name used as a link for the user. Defaults to full_name.
Returns:The inline mention for the user as markdown.
Return type:str
name

Convenience property. If available, returns the user’s username prefixed with “@”. If username is not available, returns full_name.

Type:str
send_animation(*args, **kwargs)

Shortcut for:

bot.send_animation(User.id, *args, **kwargs)

Where User is the current instance.

Returns:On success, instance representing the message posted.
Return type:telegram.Message
send_audio(*args, **kwargs)

Shortcut for:

bot.send_audio(User.id, *args, **kwargs)

Where User is the current instance.

Returns:On success, instance representing the message posted.
Return type:telegram.Message
send_document(*args, **kwargs)

Shortcut for:

bot.send_document(User.id, *args, **kwargs)

Where User is the current instance.

Returns:On success, instance representing the message posted.
Return type:telegram.Message
send_message(*args, **kwargs)

Shortcut for:

bot.send_message(User.id, *args, **kwargs)

Where User is the current instance.

Returns:On success, instance representing the message posted.
Return type:telegram.Message
send_photo(*args, **kwargs)

Shortcut for:

bot.send_photo(User.id, *args, **kwargs)

Where User is the current instance.

Returns:On success, instance representing the message posted.
Return type:telegram.Message
send_sticker(*args, **kwargs)

Shortcut for:

bot.send_sticker(User.id, *args, **kwargs)

Where User is the current instance.

Returns:On success, instance representing the message posted.
Return type:telegram.Message
send_video(*args, **kwargs)

Shortcut for:

bot.send_video(User.id, *args, **kwargs)

Where User is the current instance.

Returns:On success, instance representing the message posted.
Return type:telegram.Message
send_video_note(*args, **kwargs)

Shortcut for:

bot.send_video_note(User.id, *args, **kwargs)

Where User is the current instance.

Returns:On success, instance representing the message posted.
Return type:telegram.Message
send_voice(*args, **kwargs)

Shortcut for:

bot.send_voice(User.id, *args, **kwargs)

Where User is the current instance.

Returns:On success, instance representing the message posted.
Return type:telegram.Message
class telegram.UserProfilePhotos(total_count, photos, **kwargs)

Bases: telegram.base.TelegramObject

This object represent a user’s profile pictures.

total_count

Total number of profile pictures.

Type:int
photos

Requested profile pictures.

Type:List[List[telegram.PhotoSize]]
Parameters:
  • total_count (int) – Total number of profile pictures the target user has.
  • photos (List[List[telegram.PhotoSize]]) – Requested profile pictures (in up to 4 sizes each).
classmethod de_json(data, bot)
to_dict()
class telegram.Venue(location, title, address, foursquare_id=None, foursquare_type=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents a venue.

location

Venue location.

Type:telegram.Location
title

Name of the venue.

Type:str
address

Address of the venue.

Type:str
foursquare_id

Optional. Foursquare identifier of the venue.

Type:str
foursquare_type

Optional. Foursquare type of the venue. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.)

Type:str
Parameters:
  • location (telegram.Location) – Venue location.
  • title (str) – Name of the venue.
  • address (str) – Address of the venue.
  • foursquare_id (str, optional) – Foursquare identifier of the venue.
  • foursquare_type (str, optional) – Foursquare type of the venue. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.)
  • **kwargs (dict) – Arbitrary keyword arguments.
classmethod de_json(data, bot)
class telegram.Video(file_id, width, height, duration, thumb=None, mime_type=None, file_size=None, bot=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents a video file.

file_id

Unique identifier for this file.

Type:str
width

Video width as defined by sender.

Type:int
height

Video height as defined by sender.

Type:int
duration

Duration of the video in seconds as defined by sender.

Type:int
thumb

Optional. Video thumbnail.

Type:telegram.PhotoSize
mime_type

Optional. Mime type of a file as defined by sender.

Type:str
file_size

Optional. File size.

Type:int
bot

Optional. The Bot to use for instance methods.

Type:telegram.Bot
Parameters:
  • file_id (str) – Unique identifier for this file.
  • width (int) – Video width as defined by sender.
  • height (int) – Video height as defined by sender.
  • duration (int) – Duration of the video in seconds as defined by sender.
  • thumb (telegram.PhotoSize, optional) – Video thumbnail.
  • mime_type (str, optional) – Mime type of a file as defined by sender.
  • file_size (int, optional) – File size.
  • bot (telegram.Bot, optional) – The Bot to use for instance methods.
  • **kwargs (dict) – Arbitrary keyword arguments.
classmethod de_json(data, bot)
get_file(timeout=None, **kwargs)

Convenience wrapper over telegram.Bot.get_file

Parameters:
  • timeout (int | float, optional) – 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:

telegram.File

Raises:

telegram.TelegramError

class telegram.Voice(file_id, duration, mime_type=None, file_size=None, bot=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents a voice note.

file_id

Unique identifier for this file.

Type:str
duration

Duration of the audio in seconds as defined by sender.

Type:int
mime_type

Optional. MIME type of the file as defined by sender.

Type:str
file_size

Optional. File size.

Type:int
bot

Optional. The Bot to use for instance methods.

Type:telegram.Bot
Parameters:
  • file_id (str) – Unique identifier for this file.
  • duration (int, optional) – Duration of the audio in seconds as defined by sender.
  • mime_type (str, optional) – MIME type of the file as defined by sender.
  • file_size (int, optional) – File size.
  • bot (telegram.Bot, optional) – The Bot to use for instance methods.
  • **kwargs (dict) – Arbitrary keyword arguments.
classmethod de_json(data, bot)
get_file(timeout=None, **kwargs)

Convenience wrapper over telegram.Bot.get_file

Parameters:
  • timeout (int | float, optional) – 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:

telegram.File

Raises:

telegram.TelegramError

class telegram.WebhookInfo(url, has_custom_certificate, pending_update_count, last_error_date=None, last_error_message=None, max_connections=None, allowed_updates=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents a Telegram WebhookInfo.

Contains information about the current status of a webhook.

url

Webhook URL.

Type:str
has_custom_certificate

If a custom certificate was provided for webhook.

Type:bool
pending_update_count

Number of updates awaiting delivery.

Type:int
last_error_date

Optional. Unix time for the most recent error that happened.

Type:int
last_error_message

Optional. Error message in human-readable format.

Type:str
max_connections

Optional. Maximum allowed number of simultaneous HTTPS connections.

Type:int
allowed_updates

Optional. A list of update types the bot is subscribed to.

Type:List[str]
Parameters:
  • url (str) – Webhook URL, may be empty if webhook is not set up.
  • has_custom_certificate (bool) – True, if a custom certificate was provided for webhook certificate checks.
  • pending_update_count (int) – Number of updates awaiting delivery.
  • last_error_date (int, optional) – Unix time for the most recent error that happened when trying todeliver an update via webhook.
  • last_error_message (str, optional) – Error message in human-readable format for the most recent error that happened when trying to deliver an update via webhook.
  • max_connections (int, optional) – Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery.
  • allowed_updates (List[str], optional) – A list of update types the bot is subscribed to. Defaults to all update types.
classmethod de_json(data, bot)
class telegram.Animation(file_id, width, height, duration, thumb=None, file_name=None, mime_type=None, file_size=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents an animation file to be displayed in the message containing a game.

file_id

Unique file identifier.

Type:str
width

Video width as defined by sender.

Type:int
height

Video height as defined by sender.

Type:int
duration

Duration of the video in seconds as defined by sender.

Type:int
thumb

Optional. Animation thumbnail as defined by sender.

Type:telegram.PhotoSize
file_name

Optional. Original animation filename as defined by sender.

Type:str
mime_type

Optional. MIME type of the file as defined by sender.

Type:str
file_size

Optional. File size.

Type:int
Parameters:
  • file_id (str) – Unique file identifier.
  • width (int) – Video width as defined by sender.
  • height (int) – Video height as defined by sender.
  • duration (int) – Duration of the video in seconds as defined by sender.
  • thumb (telegram.PhotoSize, optional) – Animation thumbnail as defined by sender.
  • file_name (str, optional) – Original animation filename as defined by sender.
  • mime_type (str, optional) – MIME type of the file as defined by sender.
  • file_size (int, optional) – File size.
classmethod de_json(data, bot)
class telegram.Game(title, description, photo, text=None, text_entities=None, animation=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents a game. Use BotFather to create and edit games, their short names will act as unique identifiers.

title

Title of the game.

Type:str
description

Description of the game.

Type:str
photo

Photo that will be displayed in the game message in chats.

Type:List[telegram.PhotoSize]
text

Optional. Brief description of the game or high scores included in the game message. Can be automatically edited to include current high scores for the game when the bot calls set_game_score, or manually edited using edit_message_text.

Type:str
text_entities

Optional. Special entities that appear in text, such as usernames, URLs, bot commands, etc.

Type:List[telegram.MessageEntity]
animation

Optional. Animation that will be displayed in the game message in chats. Upload via BotFather.

Type:telegram.Animation
Parameters:
  • title (str) – Title of the game.
  • description (str) – Description of the game.
  • photo (List[telegram.PhotoSize]) – Photo that will be displayed in the game message in chats.
  • text (str, optional) – Brief description of the game or high scores included in the game message. Can be automatically edited to include current high scores for the game when the bot calls set_game_score, or manually edited using edit_message_text. 0-4096 characters. Also found as telegram.constants.MAX_MESSAGE_LENGTH.
  • text_entities (List[telegram.MessageEntity], optional) – Special entities that appear in text, such as usernames, URLs, bot commands, etc.
  • animation (telegram.Animation, optional) – Animation that will be displayed in the game message in chats. Upload via BotFather.
classmethod de_json(data, bot)
parse_text_entities(types=None)

Returns a dict that maps telegram.MessageEntity to str. It contains entities from this message filtered by their type attribute as the key, and the text that each entity belongs to as the value of the dict.

Note

This method should always be used instead of the text_entities attribute, since it calculates the correct substring from the message text based on UTF-16 codepoints. See parse_text_entity for more info.

Parameters:types (List[str], optional) – List of MessageEntity types as strings. If the type attribute of an entity is contained in this list, it will be returned. Defaults to telegram.MessageEntity.ALL_TYPES.
Returns:A dictionary of entities mapped to the text that belongs to them, calculated based on UTF-16 codepoints.
Return type:Dict[telegram.MessageEntity, str]
parse_text_entity(entity)

Returns the text from a given telegram.MessageEntity.

Note

This method is present because Telegram calculates the offset and length in UTF-16 codepoint pairs, which some versions of Python don’t handle automatically. (That is, you can’t just slice Message.text with the offset and length.)

Parameters:entity (telegram.MessageEntity) – The entity to extract the text from. It must be an entity that belongs to this message.
Returns:The text of the given entity.
Return type:str
to_dict()
class telegram.GameHighScore(position, user, score)

Bases: telegram.base.TelegramObject

This object represents one row of the high scores table for a game.

position

Position in high score table for the game.

Type:int
user

User.

Type:telegram.User
score

Score.

Type:int
Parameters:
  • position (int) – Position in high score table for the game.
  • user (telegram.User) – User.
  • score (int) – Score.
classmethod de_json(data, bot)
class telegram.VideoNote(file_id, length, duration, thumb=None, file_size=None, bot=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents a video message (available in Telegram apps as of v.4.0).

file_id

Unique identifier for this file.

Type:str
length

Video width and height as defined by sender.

Type:int
duration

Duration of the video in seconds as defined by sender.

Type:int
thumb

Optional. Video thumbnail.

Type:telegram.PhotoSize
file_size

Optional. File size.

Type:int
bot

Optional. The Bot to use for instance methods.

Type:telegram.Bot
Parameters:
  • file_id (str) – Unique identifier for this file.
  • length (int) – Video width and height as defined by sender.
  • duration (int) – Duration of the video in seconds as defined by sender.
  • thumb (telegram.PhotoSize, optional) – Video thumbnail.
  • file_size (int, optional) – File size.
  • bot (telegram.Bot, optional) – The Bot to use for instance methods.
  • **kwargs (dict) – Arbitrary keyword arguments.
classmethod de_json(data, bot)
get_file(timeout=None, **kwargs)

Convenience wrapper over telegram.Bot.get_file

Parameters:
  • timeout (int | float, optional) – 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:

telegram.File

Raises:

telegram.TelegramError

class telegram.LabeledPrice(label, amount, **kwargs)

Bases: telegram.base.TelegramObject

This object represents a portion of the price for goods or services.

label

Portion label.

Type:str
amount

Price of the product in the smallest units of the currency.

Type:int
Parameters:
  • label (str) – Portion label
  • amount (int) – Price of the product in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass 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).
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.SuccessfulPayment(currency, total_amount, invoice_payload, telegram_payment_charge_id, provider_payment_charge_id, shipping_option_id=None, order_info=None, **kwargs)

Bases: telegram.base.TelegramObject

This object contains basic information about a successful payment.

currency

Three-letter ISO 4217 currency code.

Type:str
total_amount

Total price in the smallest units of the currency.

Type:int
invoice_payload

Bot specified invoice payload.

Type:str
shipping_option_id

Optional. Identifier of the shipping option chosen by the user.

Type:str
order_info

Optional. Order info provided by the user.

Type:telegram.OrderInfo
telegram_payment_charge_id

Telegram payment identifier.

Type:str
provider_payment_charge_id

Provider payment identifier.

Type:str
Parameters:
  • currency (str) – Three-letter ISO 4217 currency code.
  • total_amount (int) – Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass 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).
  • invoice_payload (str) – Bot specified invoice payload.
  • shipping_option_id (str, optional) – Identifier of the shipping option chosen by the user.
  • order_info (telegram.OrderInfo, optional) – Order info provided by the user
  • telegram_payment_charge_id (str) – Telegram payment identifier.
  • provider_payment_charge_id (str) – Provider payment identifier.
  • **kwargs (dict) – Arbitrary keyword arguments.
classmethod de_json(data, bot)
class telegram.ShippingOption(id, title, prices, **kwargs)

Bases: telegram.base.TelegramObject

This object represents one shipping option.

id

Shipping option identifier.

Type:str
title

Option title.

Type:str
prices

List of price portions.

Type:List[telegram.LabeledPrice]
Parameters:
  • id (str) – Shipping option identifier.
  • title (str) – Option title.
  • prices (List[telegram.LabeledPrice]) – List of price portions.
  • **kwargs (dict) – Arbitrary keyword arguments.
to_dict()
class telegram.ShippingAddress(country_code, state, city, street_line1, street_line2, post_code, **kwargs)

Bases: telegram.base.TelegramObject

This object represents a Telegram ShippingAddress.

country_code

ISO 3166-1 alpha-2 country code.

Type:str
state

State, if applicable.

Type:str
city

City.

Type:str
street_line1

First line for the address.

Type:str
street_line2

Second line for the address.

Type:str
post_code

Address post code.

Type:str
Parameters:
  • country_code (str) – ISO 3166-1 alpha-2 country code.
  • state (str) – State, if applicable.
  • city (str) – City.
  • street_line1 (str) – First line for the address.
  • street_line2 (str) – Second line for the address.
  • post_code (str) – Address post code.
  • **kwargs (dict) – Arbitrary keyword arguments.
classmethod de_json(data, bot)
class telegram.PreCheckoutQuery(id, from_user, currency, total_amount, invoice_payload, shipping_option_id=None, order_info=None, bot=None, **kwargs)

Bases: telegram.base.TelegramObject

This object contains information about an incoming pre-checkout query.

Note

  • In Python from is a reserved word, use from_user instead.
id

Unique query identifier.

Type:str
from_user

User who sent the query.

Type:telegram.User
currency

Three-letter ISO 4217 currency code.

Type:str
total_amount

Total price in the smallest units of the currency.

Type:int
invoice_payload

Bot specified invoice payload.

Type:str
shipping_option_id

Optional. Identifier of the shipping option chosen by the user.

Type:str
order_info

Optional. Order info provided by the user.

Type:telegram.OrderInfo
bot

Optional. The Bot to use for instance methods.

Type:telegram.Bot
Parameters:
  • id (str) – Unique query identifier.
  • from_user (telegram.User) – User who sent the query.
  • currency (str) – Three-letter ISO 4217 currency code
  • total_amount (int) – Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass 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).
  • invoice_payload (str) – Bot specified invoice payload.
  • shipping_option_id (str, optional) – Identifier of the shipping option chosen by the user.
  • order_info (telegram.OrderInfo, optional) – Order info provided by the user.
  • bot (telegram.Bot, optional) – The Bot to use for instance methods.
  • **kwargs (dict) – Arbitrary keyword arguments.
answer(*args, **kwargs)

Shortcut for:

bot.answer_pre_checkout_query(update.pre_checkout_query.id, *args, **kwargs)
Parameters:
  • ok (bool) – 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 (str, optional) – 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.
  • **kwargs (dict) – Arbitrary keyword arguments.
classmethod de_json(data, bot)
class telegram.OrderInfo(name=None, phone_number=None, email=None, shipping_address=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents information about an order.

name

Optional. User name.

Type:str
phone_number

Optional. User’s phone number.

Type:str
email

Optional. User email.

Type:str
shipping_address

Optional. User shipping address.

Type:telegram.ShippingAddress
Parameters:
  • name (str, optional) – User name.
  • phone_number (str, optional) – User’s phone number.
  • email (str, optional) – User email.
  • shipping_address (telegram.ShippingAddress, optional) – User shipping address.
  • **kwargs (dict) – Arbitrary keyword arguments.
classmethod de_json(data, bot)
class telegram.Invoice(title, description, start_parameter, currency, total_amount, **kwargs)

Bases: telegram.base.TelegramObject

This object contains basic information about an invoice.

title

Product name.

Type:str
description

Product description.

Type:str
start_parameter

Unique bot deep-linking parameter.

Type:str
currency

Three-letter ISO 4217 currency code.

Type:str
total_amount

Total price in the smallest units of the currency.

Type:int
Parameters:
  • title (str) – Product name.
  • description (str) – Product description.
  • start_parameter (str) – Unique bot deep-linking parameter that can be used to generate this invoice.
  • currency (str) – Three-letter ISO 4217 currency code.
  • total_amount (int) – Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145.
  • **kwargs (dict) – Arbitrary keyword arguments.
classmethod de_json(data, bot)
class telegram.ShippingQuery(id, from_user, invoice_payload, shipping_address, bot=None, **kwargs)

Bases: telegram.base.TelegramObject

This object contains information about an incoming shipping query.

Note

  • In Python from is a reserved word, use from_user instead.
id

Unique query identifier.

Type:str
from_user

User who sent the query.

Type:telegram.User
invoice_payload

Bot specified invoice payload.

Type:str
shipping_address

User specified shipping address.

Type:telegram.ShippingAddress
bot

Optional. The Bot to use for instance methods.

Type:telegram.Bot
Parameters:
  • id (str) – Unique query identifier.
  • from_user (telegram.User) – User who sent the query.
  • invoice_payload (str) – Bot specified invoice payload.
  • shipping_address (telegram.ShippingAddress) – User specified shipping address.
  • bot (telegram.Bot, optional) – The Bot to use for instance methods.
  • **kwargs (dict) – Arbitrary keyword arguments.
answer(*args, **kwargs)

Shortcut for:

bot.answer_shipping_query(update.shipping_query.id, *args, **kwargs)
Parameters:
  • ok (bool) – 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 (List[telegram.ShippingOption], optional) – Required if ok is True. A JSON-serialized array of available shipping options.
  • error_message (str, optional) – 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.
classmethod de_json(data, bot)
class telegram.ChatPhoto(small_file_id, big_file_id, bot=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents a chat photo.

small_file_id

Unique file identifier of small (160x160) chat photo.

Type:str
big_file_id

Unique file identifier of big (640x640) chat photo.

Type:str
Parameters:
  • small_file_id (str) – Unique file identifier of small (160x160) chat photo. This file_id can be used only for photo download.
  • big_file_id (str) – Unique file identifier of big (640x640) chat photo. This file_id can be used only for photo download.
  • bot (telegram.Bot, optional) – The Bot to use for instance methods
  • **kwargs (dict) – Arbitrary keyword arguments.
classmethod de_json(data, bot)
class telegram.StickerSet(name, title, contains_masks, stickers, bot=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents a sticker set.

name

Sticker set name.

Type:str
title

Sticker set title.

Type:str
contains_masks

True, if the sticker set contains masks.

Type:bool
stickers

List of all set stickers.

Type:List[telegram.Sticker]
Parameters:
  • name (str) – Sticker set name.
  • title (str) – Sticker set title.
  • contains_masks (bool) – True, if the sticker set contains masks.
  • stickers (List[telegram.Sticker]) – List of all set stickers.
static de_json(data, bot)
to_dict()
class telegram.MaskPosition(point, x_shift, y_shift, scale, **kwargs)

Bases: telegram.base.TelegramObject

This object describes the position on faces where a mask should be placed by default.

point

The part of the face relative to which the mask should be placed.

Type:str
x_shift

Shift by X-axis measured in widths of the mask scaled to the face size, from left to right.

Type:float
y_shift

Shift by Y-axis measured in heights of the mask scaled to the face size, from top to bottom.

Type:float
scale

Mask scaling coefficient. For example, 2.0 means double size.

Type:float

Notes

type should be one of the following: forehead, eyes, mouth or chin. You can use the classconstants for those.

Parameters:
  • point (str) – The part of the face relative to which the mask should be placed.
  • x_shift (float) – Shift by X-axis measured in widths of the mask scaled to the face size, from left to right. For example, choosing -1.0 will place mask just to the left of the default mask position.
  • y_shift (float) – Shift by Y-axis measured in heights of the mask scaled to the face size, from top to bottom. For example, 1.0 will place the mask just below the default mask position.
  • scale (float) – Mask scaling coefficient. For example, 2.0 means double size.
CHIN = 'chin'

‘chin’

Type:str
EYES = 'eyes'

‘eyes’

Type:str
FOREHEAD = 'forehead'

‘forehead’

Type:str
MOUTH = 'mouth'

‘mouth’

Type:str
classmethod de_json(data, bot)
class telegram.CallbackGame

Bases: telegram.base.TelegramObject

A placeholder, currently holds no information. Use BotFather to set up your game.

class telegram.InputMedia

Bases: telegram.base.TelegramObject

Base class for Telegram InputMedia Objects.

See telegram.InputMediaAnimation, telegram.InputMediaAudio, telegram.InputMediaDocument, telegram.InputMediaPhoto and telegram.InputMediaVideo for detailed use.

class telegram.InputMediaPhoto(media, caption=None, parse_mode=None)

Bases: telegram.files.inputmedia.InputMedia

Represents a photo to be sent.

type

photo.

Type:str
media

File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet. Lastly you can pass an existing telegram.PhotoSize object to send.

Type:str
caption

Optional. Caption of the photo to be sent, 0-1024 characters.

Type:str
parse_mode

Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.

Type:str
Parameters:
  • media (str) – File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet. Lastly you can pass an existing telegram.PhotoSize object to send.
  • caption (str, optional) – Caption of the photo to be sent, 0-1024 characters.
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
class telegram.InputMediaVideo(media, caption=None, width=None, height=None, duration=None, supports_streaming=None, parse_mode=None, thumb=None)

Bases: telegram.files.inputmedia.InputMedia

Represents a video to be sent.

type

video.

Type:str
media

File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet. Lastly you can pass an existing telegram.Video object to send.

Type:str
caption

Optional. Caption of the video to be sent, 0-1024 characters.

Type:str
parse_mode

Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.

Type:str
width

Optional. Video width.

Type:int
height

Optional. Video height.

Type:int
duration

Optional. Video duration.

Type:int
supports_streaming

Optional. Pass True, if the uploaded video is suitable for streaming.

Type:bool
thumb

Optional. 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 90. Ignored if the file is not is passed as a string or file_id.

Type:filelike object
Parameters:
  • media (str) – File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet. Lastly you can pass an existing telegram.Video object to send.
  • caption (str, optional) – Caption of the video to be sent, 0-1024 characters.
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • width (int, optional) – Video width.
  • height (int, optional) – Video height.
  • duration (int, optional) – Video duration.
  • supports_streaming (bool, optional) – Pass True, if the uploaded video is suitable for streaming.
  • thumb (filelike object, optional) – 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 90. Ignored if the file is not is passed as a string or file_id.

Note

When using a telegram.Video for the media attribute. It will take the width, height and duration from that video, unless otherwise specified with the optional arguments.

class telegram.PassportElementError(source, type, message, **kwargs)

Bases: telegram.base.TelegramObject

Baseclass for the PassportElementError* classes.

source

Error source.

Type:str
type

The section of the user’s Telegram Passport which has the error.

Type:str
message

Error message

Type:str
Parameters:
  • source (str) – Error source.
  • type (str) – The section of the user’s Telegram Passport which has the error.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.PassportElementErrorFile(type, file_hash, message, **kwargs)

Bases: telegram.passport.passportelementerrors.PassportElementError

Represents an issue with a document scan. The error is considered resolved when the file with the document scan changes.

type

The section of the user’s Telegram Passport which has the issue, one of “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration”.

Type:str
file_hash

Base64-encoded file hash.

Type:str
message

Error message.

Type:str
Parameters:
  • type (str) – The section of the user’s Telegram Passport which has the issue, one of “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration”.
  • file_hash (str) – Base64-encoded file hash.
  • message (str) – Error message.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.PassportElementErrorReverseSide(type, file_hash, message, **kwargs)

Bases: telegram.passport.passportelementerrors.PassportElementError

Represents an issue with the front side of a document. The error is considered resolved when the file with the reverse side of the document changes.

type

The section of the user’s Telegram Passport which has the issue, one of “passport”, “driver_license”, “identity_card”, “internal_passport”.

Type:str
file_hash

Base64-encoded hash of the file with the reverse side of the document.

Type:str
message

Error message.

Type:str
Parameters:
  • type (str) – The section of the user’s Telegram Passport which has the issue, one of “driver_license”, “identity_card”.
  • file_hash (str) – Base64-encoded hash of the file with the reverse side of the document.
  • message (str) – Error message.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.PassportElementErrorFrontSide(type, file_hash, message, **kwargs)

Bases: telegram.passport.passportelementerrors.PassportElementError

Represents an issue with the front side of a document. The error is considered resolved when the file with the front side of the document changes.

type

The section of the user’s Telegram Passport which has the issue, one of “passport”, “driver_license”, “identity_card”, “internal_passport”.

Type:str
file_hash

Base64-encoded hash of the file with the front side of the document.

Type:str
message

Error message.

Type:str
Parameters:
  • type (str) – The section of the user’s Telegram Passport which has the issue, one of “passport”, “driver_license”, “identity_card”, “internal_passport”.
  • file_hash (str) – Base64-encoded hash of the file with the front side of the document.
  • message (str) – Error message.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.PassportElementErrorFiles(type, file_hashes, message, **kwargs)

Bases: telegram.passport.passportelementerrors.PassportElementError

Represents an issue with a list of scans. The error is considered resolved when the file with the document scan changes.

type

The section of the user’s Telegram Passport which has the issue, one of “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration”.

Type:str
file_hash

Base64-encoded file hash.

Type:str
message

Error message.

Type:str
Parameters:
  • type (str) – The section of the user’s Telegram Passport which has the issue, one of “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration”.
  • file_hashes (List[str]) – List of base64-encoded file hashes.
  • message (str) – Error message.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.PassportElementErrorDataField(type, field_name, data_hash, message, **kwargs)

Bases: telegram.passport.passportelementerrors.PassportElementError

Represents an issue in one of the data fields that was provided by the user. The error is considered resolved when the field’s value changes.

type

The section of the user’s Telegram Passport which has the error, one of “personal_details”, “passport”, “driver_license”, “identity_card”, “internal_passport”, “address”.

Type:str
field_name

Name of the data field which has the error.

Type:str
data_hash

Base64-encoded data hash.

Type:str
message

Error message.

Type:str
Parameters:
  • type (str) – The section of the user’s Telegram Passport which has the error, one of “personal_details”, “passport”, “driver_license”, “identity_card”, “internal_passport”, “address”.
  • field_name (str) – Name of the data field which has the error.
  • data_hash (str) – Base64-encoded data hash.
  • message (str) – Error message.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.PassportElementErrorFile(type, file_hash, message, **kwargs)

Bases: telegram.passport.passportelementerrors.PassportElementError

Represents an issue with a document scan. The error is considered resolved when the file with the document scan changes.

type

The section of the user’s Telegram Passport which has the issue, one of “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration”.

Type:str
file_hash

Base64-encoded file hash.

Type:str
message

Error message.

Type:str
Parameters:
  • type (str) – The section of the user’s Telegram Passport which has the issue, one of “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration”.
  • file_hash (str) – Base64-encoded file hash.
  • message (str) – Error message.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.Credentials(secure_data, nonce, bot=None, **kwargs)

Bases: telegram.base.TelegramObject

secure_data

Credentials for encrypted data

Type:telegram.SecureData
nonce

Bot-specified nonce

Type:str
classmethod de_json(data, bot)
class telegram.DataCredentials(data_hash, secret, **kwargs)

Bases: telegram.passport.credentials._CredentialsBase

These credentials can be used to decrypt encrypted data from the data field in EncryptedPassportData.

Parameters:
  • data_hash (str) – Checksum of encrypted data
  • secret (str) – Secret of encrypted data
hash

Checksum of encrypted data

Type:str
secret

Secret of encrypted data

Type:str
to_dict()
class telegram.SecureData(personal_details=None, passport=None, internal_passport=None, driver_license=None, identity_card=None, address=None, utility_bill=None, bank_statement=None, rental_agreement=None, passport_registration=None, temporary_registration=None, bot=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents the credentials that were used to decrypt the encrypted data. All fields are optional and depend on fields that were requested.

personal_details

Credentials for encrypted personal details.

Type:telegram.SecureValue, optional
passport

Credentials for encrypted passport.

Type:telegram.SecureValue, optional
internal_passport

Credentials for encrypted internal passport.

Type:telegram.SecureValue, optional
driver_license

Credentials for encrypted driver license.

Type:telegram.SecureValue, optional
identity_card

Credentials for encrypted ID card

Type:telegram.SecureValue, optional
address

Credentials for encrypted residential address.

Type:telegram.SecureValue, optional
utility_bill

Credentials for encrypted utility bill.

Type:telegram.SecureValue, optional
bank_statement

Credentials for encrypted bank statement.

Type:telegram.SecureValue, optional
rental_agreement

Credentials for encrypted rental agreement.

Type:telegram.SecureValue, optional
passport_registration

Credentials for encrypted registration from internal passport.

Type:telegram.SecureValue, optional
temporary_registration

Credentials for encrypted temporary registration.

Type:telegram.SecureValue, optional
classmethod de_json(data, bot)
class telegram.FileCredentials(file_hash, secret, **kwargs)

Bases: telegram.passport.credentials._CredentialsBase

These credentials can be used to decrypt encrypted files from the front_side, reverse_side, selfie and files fields in EncryptedPassportData.

Parameters:
  • file_hash (str) – Checksum of encrypted file
  • secret (str) – Secret of encrypted file
hash

Checksum of encrypted file

Type:str
secret

Secret of encrypted file

Type:str
to_dict()
class telegram.IdDocumentData(document_no, expiry_date, bot=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents the data of an identity document.

document_no

Document number.

Type:str
expiry_date

Optional. Date of expiry, in DD.MM.YYYY format.

Type:str
classmethod de_json(data, bot)
class telegram.PersonalDetails(first_name, last_name, birth_date, gender, country_code, residence_country_code, first_name_native=None, last_name_native=None, middle_name=None, middle_name_native=None, bot=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents personal details.

first_name

First Name.

Type:str
middle_name

Optional. First Name.

Type:str
last_name

Last Name.

Type:str
birth_date

Date of birth in DD.MM.YYYY format.

Type:str
gender

Gender, male or female.

Type:str
country_code

Citizenship (ISO 3166-1 alpha-2 country code).

Type:str
residence_country_code

Country of residence (ISO 3166-1 alpha-2 country code).

Type:str
first_name

First Name in the language of the user’s country of residence.

Type:str
middle_name

Optional. Middle Name in the language of the user’s country of residence.

Type:str
last_name

Last Name in the language of the user’s country of residence.

Type:str
classmethod de_json(data, bot)
class telegram.ResidentialAddress(street_line1, street_line2, city, state, country_code, post_code, bot=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents a residential address.

street_line1

First line for the address.

Type:str
street_line2

Optional. Second line for the address.

Type:str
city

City.

Type:str
state

Optional. State.

Type:str
country_code

ISO 3166-1 alpha-2 country code.

Type:str
post_code

Address post code.

Type:str
classmethod de_json(data, bot)
class telegram.InputMediaVideo(media, caption=None, width=None, height=None, duration=None, supports_streaming=None, parse_mode=None, thumb=None)

Bases: telegram.files.inputmedia.InputMedia

Represents a video to be sent.

type

video.

Type:str
media

File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet. Lastly you can pass an existing telegram.Video object to send.

Type:str
caption

Optional. Caption of the video to be sent, 0-1024 characters.

Type:str
parse_mode

Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.

Type:str
width

Optional. Video width.

Type:int
height

Optional. Video height.

Type:int
duration

Optional. Video duration.

Type:int
supports_streaming

Optional. Pass True, if the uploaded video is suitable for streaming.

Type:bool
thumb

Optional. 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 90. Ignored if the file is not is passed as a string or file_id.

Type:filelike object
Parameters:
  • media (str) – File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet. Lastly you can pass an existing telegram.Video object to send.
  • caption (str, optional) – Caption of the video to be sent, 0-1024 characters.
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • width (int, optional) – Video width.
  • height (int, optional) – Video height.
  • duration (int, optional) – Video duration.
  • supports_streaming (bool, optional) – Pass True, if the uploaded video is suitable for streaming.
  • thumb (filelike object, optional) – 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 90. Ignored if the file is not is passed as a string or file_id.

Note

When using a telegram.Video for the media attribute. It will take the width, height and duration from that video, unless otherwise specified with the optional arguments.

class telegram.InputMediaAnimation(media, thumb=None, caption=None, parse_mode=None, width=None, height=None, duration=None)

Bases: telegram.files.inputmedia.InputMedia

Represents an animation file (GIF or H.264/MPEG-4 AVC video without sound) to be sent.

type

animation.

Type:str
media

File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet. Lastly you can pass an existing telegram.Animation object to send.

Type:str
thumb

Optional. 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 90. Ignored if the file is not is passed as a string or file_id.

Type:filelike object
caption

Optional. Caption of the animation to be sent, 0-1024 characters.

Type:str
parse_mode

Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.

Type:str
width

Optional. Animation width.

Type:int
height

Optional. Animation height.

Type:int
duration

Optional. Animation duration.

Type:int
Parameters:
  • media (str) – File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet. Lastly you can pass an existing telegram.Animation object to send.
  • thumb (filelike object, optional) – 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 90. Ignored if the file is not is passed as a string or file_id.
  • caption (str, optional) – Caption of the animation to be sent, 0-1024 characters.
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • width (int, optional) – Animation width.
  • height (int, optional) – Animation height.
  • duration (int, optional) – Animation duration.

Note

When using a telegram.Animation for the media attribute. It will take the width, height and duration from that video, unless otherwise specified with the optional arguments.

class telegram.InputMediaAudio(media, thumb=None, caption=None, parse_mode=None, duration=None, performer=None, title=None)

Bases: telegram.files.inputmedia.InputMedia

Represents an audio file to be treated as music to be sent.

type

audio.

Type:str
media

File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet. Lastly you can pass an existing telegram.Audio object to send.

Type:str
caption

Optional. Caption of the audio to be sent, 0-1024 characters.

Type:str
parse_mode

Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.

Type:str
duration

Duration of the audio in seconds.

Type:int
performer

Optional. Performer of the audio as defined by sender or by audio tags.

Type:str
title

Optional. Title of the audio as defined by sender or by audio tags.

Type:str
thumb

Optional. 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 90. Ignored if the file is not is passed as a string or file_id.

Type:filelike object
Parameters:
  • media (str) – File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet. Lastly you can pass an existing telegram.Document object to send.
  • caption (str, optional) – Caption of the audio to be sent, 0-1024 characters.
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • duration (int) – Duration of the audio in seconds as defined by sender.
  • performer (str, optional) – Performer of the audio as defined by sender or by audio tags.
  • title (str, optional) – Title of the audio as defined by sender or by audio tags.
  • thumb (filelike object, optional) – 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 90. Ignored if the file is not is passed as a string or file_id.

Note

When using a telegram.Audio for the media attribute. It will take the duration, performer and title from that video, unless otherwise specified with the optional arguments.

class telegram.InputMediaDocument(media, thumb=None, caption=None, parse_mode=None)

Bases: telegram.files.inputmedia.InputMedia

Represents a general file to be sent.

type

document.

Type:str
media

File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet. Lastly you can pass an existing telegram.Document object to send.

Type:str
caption

Optional. Caption of the document to be sent, 0-1024 characters.

Type:str
parse_mode

Optional. Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.

Type:str
thumb

Optional. 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 90. Ignored if the file is not is passed as a string or file_id.

Type:filelike object
Parameters:
  • media (str) – File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet. Lastly you can pass an existing telegram.Document object to send.
  • caption (str, optional) – Caption of the document to be sent, 0-1024 characters.
  • parse_mode (str, optional) – Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. See the constants in telegram.ParseMode for the available modes.
  • thumb (filelike object, optional) – 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 90. Ignored if the file is not is passed as a string or file_id.
exception telegram.TelegramDecryptionError(message)

Bases: telegram.error.TelegramError

Something went wrong with decryption.

class telegram.PassportElementErrorSelfie(type, file_hash, message, **kwargs)

Bases: telegram.passport.passportelementerrors.PassportElementError

Represents an issue with the selfie with a document. The error is considered resolved when the file with the selfie changes.

type

The section of the user’s Telegram Passport which has the issue, one of “passport”, “driver_license”, “identity_card”, “internal_passport”.

Type:str
file_hash

Base64-encoded hash of the file with the selfie.

Type:str
message

Error message.

Type:str
Parameters:
  • type (str) – The section of the user’s Telegram Passport which has the issue, one of “passport”, “driver_license”, “identity_card”, “internal_passport”.
  • file_hash (str) – Base64-encoded hash of the file with the selfie.
  • message (str) – Error message.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.PassportElementErrorTranslationFile(type, file_hash, message, **kwargs)

Bases: telegram.passport.passportelementerrors.PassportElementError

Represents an issue with one of the files that constitute the translation of a document. The error is considered resolved when the file changes.

type

Type of element of the user’s Telegram Passport which has the issue, one of “passport”, “driver_license”, “identity_card”, “internal_passport”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration”.

Type:str
file_hash

Base64-encoded hash of the file.

Type:str
message

Error message.

Type:str
Parameters:
  • type (str) – Type of element of the user’s Telegram Passport which has the issue, one of “passport”, “driver_license”, “identity_card”, “internal_passport”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration”.
  • file_hash (str) – Base64-encoded hash of the file.
  • message (str) – Error message.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.PassportElementErrorTranslationFiles(type, file_hashes, message, **kwargs)

Bases: telegram.passport.passportelementerrors.PassportElementError

Represents an issue with the translated version of a document. The error is considered resolved when a file with the document translation change.

type

Type of element of the user’s Telegram Passport which has the issue, one of “passport”, “driver_license”, “identity_card”, “internal_passport”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration”

Type:str
file_hash

Base64-encoded file hash.

Type:str
message

Error message.

Type:str
Parameters:
  • type (str) – Type of element of the user’s Telegram Passport which has the issue, one of “passport”, “driver_license”, “identity_card”, “internal_passport”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration”
  • file_hashes (List[str]) – List of base64-encoded file hashes.
  • message (str) – Error message.
  • **kwargs (dict) – Arbitrary keyword arguments.
class telegram.PassportElementErrorUnspecified(type, element_hash, message, **kwargs)

Bases: telegram.passport.passportelementerrors.PassportElementError

Represents an issue in an unspecified place. The error is considered resolved when new data is added.

type

Type of element of the user’s Telegram Passport which has the issue.

Type:str
element_hash

Base64-encoded element hash.

Type:str
message

Error message.

Type:str
Parameters:
  • type (str) – Type of element of the user’s Telegram Passport which has the issue.
  • element_hash (str) – Base64-encoded element hash.
  • message (str) – Error message.
  • **kwargs (dict) – Arbitrary keyword arguments.