tgram.methods package

Submodules

tgram.methods.add_sticker_to_set module

class tgram.methods.add_sticker_to_set.AddStickerToSet[source]

Bases: object

async add_sticker_to_set(user_id: int, name: str, sticker: InputSticker) bool[source]

Use this method to add a new sticker to a set created by the bot. The format of the added sticker must match the format of the other stickers in the set. Emoji sticker sets can have up to 200 stickers. Animated and video sticker sets can have up to 50 stickers. Static sticker sets can have up to 120 stickers. Returns True on success.

Note

**_sticker, mask_position, emojis parameters are deprecated, use stickers instead

Telegram documentation: https://core.telegram.org/bots/api#addstickertoset

Parameters:
  • user_id (int) – User identifier of created sticker set owner

  • name (str) – Sticker set name

  • emojis (str) – One or more emoji corresponding to the sticker

  • png_sticker (str or 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.

  • tgs_sticker (str or filelike object) – TGS animation with the sticker, uploaded using multipart/form-data.

  • webm_sticker (str or filelike object) – WebM animation with the sticker, uploaded using multipart/form-data.

  • mask_position (tgram.types.MaskPosition) – A JSON-serialized object for position where the mask should be placed on faces

  • sticker (tgram.types.InputSticker) – A JSON-serialized object for sticker to be added to the sticker set

Returns:

On success, True is returned.

Return type:

bool

tgram.methods.answer_callback_query module

class tgram.methods.answer_callback_query.AnswerCallbackQuery[source]

Bases: object

async answer_callback_query(callback_query_id: str, text: str | None = None, show_alert: bool | None = None, url: str | None = None, cache_time: int | None = None) bool[source]

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

Telegram documentation: https://core.telegram.org/bots/api#answercallbackquery

Parameters:
  • callback_query_id (int) – Unique identifier for the query to be answered

  • text (str) – Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters

  • show_alert (bool) – If True, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false.

  • url (str) – 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.

  • cache_time – The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0.

Returns:

On success, True is returned.

Return type:

bool

tgram.methods.answer_inline_query module

class tgram.methods.answer_inline_query.AnswerInlineQuery[source]

Bases: object

async answer_inline_query(inline_query_id: str, results: List[InlineQueryResultCachedAudio | InlineQueryResultCachedDocument | InlineQueryResultCachedGif | InlineQueryResultCachedMpeg4Gif | InlineQueryResultCachedPhoto | InlineQueryResultCachedSticker | InlineQueryResultCachedVideo | InlineQueryResultCachedVoice | InlineQueryResultArticle | InlineQueryResultAudio | InlineQueryResultContact | InlineQueryResultGame | InlineQueryResultDocument | InlineQueryResultGif | InlineQueryResultLocation | InlineQueryResultMpeg4Gif | InlineQueryResultPhoto | InlineQueryResultVenue | InlineQueryResultVideo | InlineQueryResultVoice], cache_time: int = None, is_personal: bool = None, next_offset: str = None, button: InlineQueryResultsButton = None) bool[source]

Use this method to send answers to an inline query. On success, True is returned. No more than 50 results per query are allowed.

Telegram documentation: https://core.telegram.org/bots/api#answerinlinequery

Parameters:
  • inline_query_id (str) – Unique identifier for the answered query

  • results (list of tgram.types.InlineQueryResult) – Array of results for the inline query

  • cache_time (int) – The maximum amount of time in seconds that the result of the inline query may be cached on the server.

  • is_personal (bool) – Pass True, if results may be cached on the server side only for the user that sent the query.

  • next_offset (str) – Pass the offset that a client should send in the next query with the same text to receive more results.

  • switch_pm_parameter (str) – 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. 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.

  • switch_pm_text (str) – Parameter for the start message sent to the bot when user presses the switch button

  • button (tgram.types.InlineQueryResultsButton) – A JSON-serialized object describing a button to be shown above inline query results

Returns:

On success, True is returned.

Return type:

bool

tgram.methods.answer_pre_checkout_query module

class tgram.methods.answer_pre_checkout_query.AnswerPreCheckoutQuery[source]

Bases: object

async answer_pre_checkout_query(pre_checkout_query_id: str, ok: bool, error_message: str | None = None) bool[source]

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

Note

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

Telegram documentation: https://core.telegram.org/bots/api#answerprecheckoutquery

Parameters:
  • pre_checkout_query_id (int) – 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) – Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. “Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!”). Telegram will display this message to the user.

Returns:

On success, True is returned.

Return type:

bool

tgram.methods.answer_shipping_query module

class tgram.methods.answer_shipping_query.AnswerShippingQuery[source]

Bases: object

async answer_shipping_query(shipping_query_id: str, ok: bool, shipping_options: List[ShippingOption] | None = None, error_message: str | None = None) bool[source]

Asks for an answer to a shipping question.

Telegram documentation: https://core.telegram.org/bots/api#answershippingquery

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 of ShippingOption) – Required if ok is True. A JSON-serialized array of available shipping options.

  • error_message (str) – Required if ok is False. Error message in human readable form that explains why it is impossible to complete the order (e.g. “Sorry, delivery to your desired address is unavailable’). Telegram will display this message to the user.

Returns:

On success, True is returned.

Return type:

bool

tgram.methods.answer_web_app_query module

class tgram.methods.answer_web_app_query.AnswerWebAppQuery[source]

Bases: object

async answer_web_app_query(web_app_query_id: str, result: InlineQueryResultCachedAudio | InlineQueryResultCachedDocument | InlineQueryResultCachedGif | InlineQueryResultCachedMpeg4Gif | InlineQueryResultCachedPhoto | InlineQueryResultCachedSticker | InlineQueryResultCachedVideo | InlineQueryResultCachedVoice | InlineQueryResultArticle | InlineQueryResultAudio | InlineQueryResultContact | InlineQueryResultGame | InlineQueryResultDocument | InlineQueryResultGif | InlineQueryResultLocation | InlineQueryResultMpeg4Gif | InlineQueryResultPhoto | InlineQueryResultVenue | InlineQueryResultVideo | InlineQueryResultVoice) SentWebAppMessage[source]

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

Telegram Documentation: https://core.telegram.org/bots/api#answerwebappquery

Parameters:
  • web_app_query_id (str) – Unique identifier for the query to be answered

  • result (tgram.types.InlineQueryResultBase) – A JSON-serialized object describing the message to be sent

Returns:

On success, a SentWebAppMessage object is returned.

Return type:

tgram.types.SentWebAppMessage

tgram.methods.approve_chat_join_request module

class tgram.methods.approve_chat_join_request.ApproveChatJoinRequest[source]

Bases: object

async approve_chat_join_request(chat_id: int | str, user_id: int) bool[source]

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

Telegram documentation: https://core.telegram.org/bots/api#approvechatjoinrequest

Parameters:
  • chat_id (int or str) – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)

  • user_id (int or str) – Unique identifier of the target user

Returns:

True on success.

Return type:

bool

tgram.methods.ask module

class tgram.methods.ask.Ask[source]

Bases: object

async ask(next_step: Callable, update_type: str = 'message', data: dict | None = None, cancel: Callable | None = None, filters: Filter | None = None) None[source]

tgram.methods.ban_chat_member module

class tgram.methods.ban_chat_member.BanChatMember[source]

Bases: object

async ban_chat_member(chat_id: int | str, user_id: int, until_date: int | None = None, revoke_messages: bool | None = None) bool[source]

Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless unbanned first. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#banchatmember

Parameters:
  • chat_id (int or str) – Unique identifier for the target group or username of the target supergroup or channel (in the format @channelusername)

  • user_id (int) – Unique identifier of the target user

  • until_date (int) – 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

  • revoke_messages (bool) – Bool: Pass True to delete all messages from the chat for the user that is being removed. If False, the user will be able to see messages in the group that were sent before the user was removed. Always True for supergroups and channels.

Returns:

Returns True on success.

Return type:

bool

tgram.methods.ban_chat_sender_chat module

class tgram.methods.ban_chat_sender_chat.BanChatSenderChat[source]

Bases: object

async ban_chat_sender_chat(chat_id: int | str, sender_chat_id: int) bool[source]

Use this method to ban a channel chat in a supergroup or a channel. The owner of the chat will not be able to send messages and join live streams on behalf of the chat, unless it is unbanned first. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#banchatsenderchat

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

  • sender_chat_id (int or str) – Unique identifier of the target sender chat

Returns:

True on success.

Return type:

bool

tgram.methods.close module

class tgram.methods.close.Close[source]

Bases: object

async close() bool[source]

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

Telegram documentation: https://core.telegram.org/bots/api#close

Returns:

bool

tgram.methods.close_forum_topic module

class tgram.methods.close_forum_topic.CloseForumTopic[source]

Bases: object

async close_forum_topic(chat_id: int | str, message_thread_id: int) bool[source]

Use this method to close an open topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#closeforumtopic

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

  • message_thread_id (int) – Identifier of the topic to close

Returns:

On success, True is returned.

Return type:

bool

tgram.methods.close_general_forum_topic module

class tgram.methods.close_general_forum_topic.CloseGeneralForumTopic[source]

Bases: object

async close_general_forum_topic(chat_id: int | str) bool[source]

Use this method to close the ‘General’ topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#closegeneralforumtopic

Parameters:

chat_id (int or str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)

tgram.methods.copy_message module

class tgram.methods.copy_message.CopyMessage[source]

Bases: object

async copy_message(chat_id: int | str, from_chat_id: int | str, message_id: int, message_thread_id: int | None = None, caption: str | None = None, parse_mode: str | None = None, caption_entities: List[MessageEntity] | None = None, show_caption_above_media: bool | None = None, disable_notification: bool | None = None, protect_content: bool | None = None, reply_parameters: ReplyParameters | None = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None) MessageId[source]

Use this method to copy messages of any kind.

Telegram documentation: https://core.telegram.org/bots/api#copymessage

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

  • from_chat_id (int or str) – Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)

  • message_id (int) – Message identifier in the chat specified in from_chat_id

  • caption (str) – New caption for media, 0-1024 characters after entities parsing. If not specified, the original caption is kept

  • parse_mode (str) – Mode for parsing entities in the new caption.

  • caption_entities (Array of tgram.types.MessageEntity) – A JSON-serialized list of special entities that appear in the new caption, which can be specified instead of parse_mode

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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) – Timeout in seconds for the request.

  • message_thread_id (int) – Identifier of a message thread, in which the message will be sent

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • show_caption_above_media (bool) – Pass True, if the caption must be shown above the message media. Supported only for animation, photo and video messages.

Returns:

On success, the MessageId of the sent message is returned.

Return type:

tgram.types.MessageID

tgram.methods.copy_messages module

class tgram.methods.copy_messages.CopyMessages[source]

Bases: object

async copy_messages(chat_id: int | str, from_chat_id: int | str, message_ids: List[int], message_thread_id: int | None = None, disable_notification: bool | None = None, protect_content: bool | None = None, remove_caption: bool | None = None) List[MessageId][source]

Use this method to copy messages of any kind. If some of the specified messages can’t be found or copied, they are skipped. Service messages, giveaway messages, giveaway winners messages, and invoice messages can’t be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don’t have a link to the original message. Album grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned.

Telegram documentation: https://core.telegram.org/bots/api#copymessages

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

  • from_chat_id (int or str) – Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)

  • message_ids (list of int) – Message identifiers in the chat specified in from_chat_id

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound

  • message_thread_id (int) – Identifier of a message thread, in which the messages will be sent

  • protect_content (bool) – Protects the contents of the forwarded message from forwarding and saving

  • remove_caption (bool) – Pass True to copy the messages without their captions

Returns:

On success, an array of MessageId of the sent messages is returned.

Return type:

list of tgram.types.MessageID

tgram.methods.create_forum_topic module

class tgram.methods.create_forum_topic.CreateForumTopic[source]

Bases: object

async create_forum_topic(chat_id: int | str, name: str, icon_color: int | None = None, icon_custom_emoji_id: str | None = None) ForumTopic[source]

Use this method to create a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns information about the created topic as a ForumTopic object.

Telegram documentation: https://core.telegram.org/bots/api#createforumtopic

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

  • name (str) – Name of the topic, 1-128 characters

  • icon_color (int) – Color of the topic icon in RGB format. Currently, must be one of 0x6FB9F0, 0xFFD67E, 0xCB86DB, 0x8EEE98, 0xFF93B2, or 0xFB6F5F

  • icon_custom_emoji_id (str) – Custom emoji for the topic icon. Must be an emoji of type “tgs” and must be exactly 1 character long

Returns:

On success, information about the created topic is returned as a ForumTopic object.

Return type:

tgram.types.ForumTopic

tgram.methods.create_new_sticker_set module

class tgram.methods.create_new_sticker_set.CreateNewStickerSet[source]

Bases: object

async create_new_sticker_set(user_id: int, name: str, title: str, stickers: List[InputSticker], sticker_type: str | None = None, needs_repainting: bool | None = None) bool[source]

Use this method to create new sticker set owned by a user. The bot will be able to edit the created sticker set. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#createnewstickerset

Note

Fields *_sticker are deprecated, pass a list of stickers to stickers parameter instead.

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

  • emojis (str) – One or more emoji corresponding to the sticker

  • png_sticker (str) – 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.

  • tgs_sticker (str) – TGS animation with the sticker, uploaded using multipart/form-data.

  • webm_sticker (str) – WebM animation with the sticker, uploaded using multipart/form-data.

  • contains_masks (bool) – Pass True, if a set of mask stickers should be created. Deprecated since Bot API 6.2, use sticker_type instead.

  • sticker_type (str) – Type of stickers in the set, pass “regular”, “mask”, or “custom_emoji”. By default, a regular sticker set is created.

  • mask_position (tgram.types.MaskPosition) – A JSON-serialized object for position where the mask should be placed on faces

  • needs_repainting (bool) – Pass True if stickers in the sticker set must be repainted to the color of text when used in messages, the accent color if used as emoji status, white on chat photos, or another appropriate color based on context; for custom emoji sticker sets only

  • stickers (list of tgram.types.InputSticker) – List of stickers to be added to the set

  • sticker_format (str) – deprecated

Returns:

On success, True is returned.

Return type:

bool

tgram.methods.decline_chat_join_request module

class tgram.methods.decline_chat_join_request.DeclineChatJoinRequest[source]

Bases: object

async decline_chat_join_request(chat_id: int | str, user_id: int) bool[source]

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

Telegram documentation: https://core.telegram.org/bots/api#declinechatjoinrequest

Parameters:
  • chat_id (int or str) – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)

  • user_id (int or str) – Unique identifier of the target user

Returns:

True on success.

Return type:

bool

tgram.methods.delete_chat_photo module

class tgram.methods.delete_chat_photo.DeleteChatPhoto[source]

Bases: object

async delete_chat_photo(chat_id: int | str) bool[source]

Use this method to delete a chat photo. Photos can’t be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. Note: In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’ setting is off in the target group.

Telegram documentation: https://core.telegram.org/bots/api#deletechatphoto

Parameters:

chat_id (int or str) – Int or Str: Unique identifier for the target chat or username of the target channel (in the format @channelusername)

Returns:

True on success.

Return type:

bool

tgram.methods.delete_chat_sticker_set module

class tgram.methods.delete_chat_sticker_set.DeleteChatStickerSet[source]

Bases: object

async delete_chat_sticker_set(chat_id: int | str) bool[source]

Use this method to delete a group sticker set from a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#deletechatstickerset

Parameters:

chat_id (int or str) – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)

Returns:

Returns True on success.

Return type:

bool

tgram.methods.delete_forum_topic module

class tgram.methods.delete_forum_topic.DeleteForumTopic[source]

Bases: object

async delete_forum_topic(chat_id: int | str, message_thread_id: int) bool[source]

Use this method to delete a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#deleteforumtopic

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

  • message_thread_id (int) – Identifier of the topic to delete

Returns:

On success, True is returned.

Return type:

bool

tgram.methods.delete_message module

class tgram.methods.delete_message.DeleteMessage[source]

Bases: object

async delete_message(chat_id: int | str, message_id: int) bool[source]

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

Telegram documentation: https://core.telegram.org/bots/api#deletemessage

Parameters:
  • chat_id (int or 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) – Timeout in seconds for the request.

Returns:

Returns True on success.

Return type:

bool

tgram.methods.delete_messages module

class tgram.methods.delete_messages.DeleteMessages[source]

Bases: object

async delete_messages(chat_id: int | str, message_ids: List[int]) bool[source]

Use this method to delete multiple messages simultaneously. If some of the specified messages can’t be found, they are skipped. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#deletemessages

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

  • message_ids (list of int) – Identifiers of the messages to be deleted

Returns:

Returns True on success.

tgram.methods.delete_my_commands module

class tgram.methods.delete_my_commands.DeleteMyCommands[source]

Bases: object

async delete_my_commands(scope: BotCommandScope | None = None, language_code: str | None = None) bool[source]

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

Telegram documentation: https://core.telegram.org/bots/api#deletemycommands

Parameters:
  • scope (tgram.types.BotCommandScope) – The scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault.

  • language_code (str) – A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands

Returns:

True on success.

Return type:

bool

tgram.methods.delete_sticker_from_set module

class tgram.methods.delete_sticker_from_set.DeleteStickerFromSet[source]

Bases: object

async delete_sticker_from_set(sticker: str) bool[source]

Use this method to delete a sticker from a set created by the bot. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#deletestickerfromset

Parameters:

sticker – File identifier of the sticker

Returns:

On success, True is returned.

Return type:

bool

tgram.methods.delete_sticker_set module

class tgram.methods.delete_sticker_set.DeleteStickerSet[source]

Bases: object

async delete_sticker_set(name: str) bool[source]

Use this method to delete a sticker set. Returns True on success.

Parameters:

name (str) – Sticker set name

Returns:

Returns True on success.

Return type:

bool

tgram.methods.delete_webhook module

class tgram.methods.delete_webhook.DeleteWebhook[source]

Bases: object

async delete_webhook(drop_pending_updates: bool | None = None) bool[source]

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

Telegram documentation: https://core.telegram.org/bots/api#deletewebhook

Parameters:
  • drop_pending_updates – Pass True to drop all pending updates, defaults to None

  • timeout (int, optional) – Request connection timeout, defaults to None

Returns:

Returns True on success.

Return type:

bool

tgram.methods.download_file module

class tgram.methods.download_file.DownloadFile[source]

Bases: object

async download_file(file_id: str, file_path: str | None = None, in_memory: bool | None = None) Path | BytesIO[source]

tgram.methods.edit_forum_topic module

class tgram.methods.edit_forum_topic.EditForumTopic[source]

Bases: object

async edit_forum_topic(chat_id: int | str, message_thread_id: int, name: str | None = None, icon_custom_emoji_id: str | None = None) bool[source]

Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.

Telegram Documentation: https://core.telegram.org/bots/api#editforumtopic

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

  • message_thread_id (int) – Identifier of the topic to edit

  • name (str) – Optional, New name of the topic, 1-128 characters. If not specififed or empty, the current name of the topic will be kept

  • icon_custom_emoji_id (str) – Optional, New unique identifier of the custom emoji shown as the topic icon. Use getForumTopicIconStickers to get all allowed custom emoji identifiers. Pass an empty string to remove the icon. If not specified, the current icon will be kept

Returns:

On success, True is returned.

Return type:

bool

tgram.methods.edit_general_forum_topic module

class tgram.methods.edit_general_forum_topic.EditGeneralForumTopic[source]

Bases: object

async edit_general_forum_topic(chat_id: int | str, name: str) bool[source]

Use this method to edit the name of the ‘General’ topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#editgeneralforumtopic

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

  • name (str) – New topic name, 1-128 characters

tgram.methods.edit_message_caption module

class tgram.methods.edit_message_caption.EditMessageCaption[source]

Bases: object

async edit_message_caption(business_connection_id: str | None = None, chat_id: int | str | None = None, message_id: int | None = None, inline_message_id: str | None = None, caption: str | None = None, parse_mode: str | None = None, caption_entities: List[MessageEntity] | None = None, show_caption_above_media: bool | None = None, reply_markup: InlineKeyboardMarkup | None = None) Message | bool[source]

tgram.methods.edit_message_live_location module

class tgram.methods.edit_message_live_location.EditMessageLiveLocation[source]

Bases: object

async edit_message_live_location(latitude: float, longitude: float, business_connection_id: str | None = None, chat_id: int | str | None = None, message_id: int | None = None, inline_message_id: str | None = None, live_period: int | None = None, horizontal_accuracy: float | None = None, heading: int | None = None, proximity_alert_radius: int | None = None, reply_markup: InlineKeyboardMarkup | None = None) Message | bool[source]

tgram.methods.edit_message_media module

class tgram.methods.edit_message_media.EditMessageMedia[source]

Bases: object

async edit_message_media(media: InputMediaAudio | InputMediaDocument | InputMediaPhoto | InputMediaVideo, business_connection_id: str = None, chat_id: int | str = None, message_id: int = None, inline_message_id: str = None, reply_markup: InlineKeyboardMarkup = None) Message | bool[source]

tgram.methods.edit_message_reply_markup module

class tgram.methods.edit_message_reply_markup.EditMessageReplyMarkup[source]

Bases: object

async edit_message_reply_markup(business_connection_id: str | None = None, chat_id: int | str | None = None, message_id: int | None = None, inline_message_id: str | None = None, reply_markup: InlineKeyboardMarkup | None = None) Message | bool[source]

tgram.methods.edit_message_text module

class tgram.methods.edit_message_text.EditMessageText[source]

Bases: object

async edit_message_text(text: str, business_connection_id: str | None = None, chat_id: int | str | None = None, message_id: int | None = None, inline_message_id: str | None = None, parse_mode: str | None = None, entities: List[MessageEntity] | None = None, link_preview_options: LinkPreviewOptions | None = None, reply_markup: InlineKeyboardMarkup | None = None) Message | bool[source]

tgram.methods.forward_message module

class tgram.methods.forward_message.ForwardMessage[source]

Bases: object

async forward_message(chat_id: int | str, from_chat_id: int | str, message_id: int, message_thread_id: int | None = None, disable_notification: bool | None = None, protect_content: bool | None = None) Message[source]

Use this method to forward messages of any kind.

Telegram documentation: https://core.telegram.org/bots/api#forwardmessage

Parameters:
  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound

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

  • from_chat_id (int or str) – Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)

  • message_id (int) – Message identifier in the chat specified in from_chat_id

  • protect_content (bool) – Protects the contents of the forwarded message from forwarding and saving

  • timeout (int) – Timeout in seconds for the request.

  • message_thread_id (int) – Unique identifier for the target message thread (topic) of the forum; for forum supergroups only

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

tgram.methods.forward_messages module

class tgram.methods.forward_messages.ForwardMessages[source]

Bases: object

async forward_messages(chat_id: int | str, from_chat_id: int | str, message_ids: List[int], message_thread_id: int | None = None, disable_notification: bool | None = None, protect_content: bool | None = None) List[MessageId][source]

Use this method to forward multiple messages of any kind. If some of the specified messages can’t be found or forwarded, they are skipped. Service messages and messages with protected content can’t be forwarded. Album grouping is kept for forwarded messages. On success, an array of MessageId of the sent messages is returned.

Telegram documentation: https://core.telegram.org/bots/api#forwardmessages

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

  • from_chat_id (int or str) – Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)

  • message_ids (list) – Message identifiers in the chat specified in from_chat_id

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound

  • message_thread_id (int) – Identifier of a message thread, in which the messages will be sent

  • protect_content (bool) – Protects the contents of the forwarded message from forwarding and saving

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.MessageID

tgram.methods.get_business_connection module

class tgram.methods.get_business_connection.GetBusinessConnection[source]

Bases: object

async get_business_connection(business_connection_id: str) BusinessConnection[source]

Use this method to get information about the connection of the bot with a business account. Returns a BusinessConnection object on success.

Telegram documentation: https://core.telegram.org/bots/api#getbusinessconnection

Parameters:

business_connection_id (str) – Unique identifier of the business connection

Returns:

Returns a BusinessConnection object on success.

Return type:

tgram.types.BusinessConnection

tgram.methods.get_chat module

class tgram.methods.get_chat.GetChat[source]

Bases: object

async get_chat(chat_id: int | str) ChatFullInfo[source]

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

Telegram documentation: https://core.telegram.org/bots/api#getchat

Parameters:

chat_id (int or str) – Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)

Returns:

Chat information

Return type:

tgram.types.ChatFullInfo

tgram.methods.get_chat_administrators module

class tgram.methods.get_chat_administrators.GetChatAdministrators[source]

Bases: object

async get_chat_administrators(chat_id: int | str) List[ChatMemberAdministrator | ChatMemberOwner][source]

tgram.methods.get_chat_member module

class tgram.methods.get_chat_member.GetChatMember[source]

Bases: object

async get_chat_member(chat_id: int | str, user_id: int) ChatMemberOwner | ChatMemberAdministrator | ChatMemberMember | ChatMemberRestricted | ChatMemberBanned | ChatMemberLeft[source]

tgram.methods.get_chat_member_count module

class tgram.methods.get_chat_member_count.GetChatMemberCount[source]

Bases: object

async get_chat_member_count(chat_id: int | str) int[source]

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

Telegram documentation: https://core.telegram.org/bots/api#getchatmembercount

Parameters:

chat_id (int or str) – Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)

Returns:

Number of members in the chat.

Return type:

int

tgram.methods.get_chat_menu_button module

class tgram.methods.get_chat_menu_button.GetChatMenuButton[source]

Bases: object

async get_chat_menu_button(chat_id: int | None = None) MenuButton[source]

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

Telegram Documentation: https://core.telegram.org/bots/api#getchatmenubutton

Parameters:

chat_id (int or str) – Unique identifier for the target private chat. If not specified, default bot’s menu button will be returned.

Returns:

types.MenuButton

Return type:

tgram.types.MenuButton

tgram.methods.get_custom_emoji_stickers module

class tgram.methods.get_custom_emoji_stickers.GetCustomEmojiStickers[source]

Bases: object

async get_custom_emoji_stickers(custom_emoji_ids: List[str]) List[Sticker][source]

Use this method to get information about custom emoji stickers by their identifiers. Returns an Array of Sticker objects.

Parameters:

custom_emoji_ids (list of str) – List of custom emoji identifiers. At most 200 custom emoji identifiers can be specified.

Returns:

Returns an Array of Sticker objects.

Return type:

list of tgram.types.Sticker

tgram.methods.get_file module

class tgram.methods.get_file.GetFile[source]

Bases: object

async get_file(file_id: str) File[source]

Use this method to get basic info about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size. On success, a File object is returned. 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.

Telegram documentation: https://core.telegram.org/bots/api#getfile

Parameters:

file_id (str) – File identifier

Returns:

tgram.types.File

tgram.methods.get_file_url module

class tgram.methods.get_file_url.GetFileUrl[source]

Bases: object

async get_file_url(file_id: str) str[source]

Get a valid URL for downloading a file.

Parameters:

file_id (str) – File identifier to get download URL for.

Returns:

URL for downloading the file.

Return type:

str

tgram.methods.get_forum_topic_icon_stickers module

class tgram.methods.get_forum_topic_icon_stickers.GetForumTopicIconStickers[source]

Bases: object

async get_forum_topic_icon_stickers() List[Sticker][source]

Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user. Requires no parameters. Returns an Array of Sticker objects.

Telegram documentation: https://core.telegram.org/bots/api#getforumtopiciconstickers

Returns:

On success, a list of StickerSet objects is returned.

Return type:

List[tgram.types.StickerSet]

tgram.methods.get_game_high_scores module

class tgram.methods.get_game_high_scores.GetGameHighScores[source]

Bases: object

async get_game_high_scores(user_id: int, chat_id: int | None = None, message_id: int | None = None, inline_message_id: str | None = None) List[GameHighScore][source]

Use this method to get data for high score tables. Will return the score of the specified user and several of their neighbors in a game. On success, returns an Array of GameHighScore objects.

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

Telegram documentation: https://core.telegram.org/bots/api#getgamehighscores

Parameters:
  • user_id (int) – User identifier

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

  • message_id (int) – Required if inline_message_id is not specified. Identifier of the sent message

  • inline_message_id (str) – Required if chat_id and message_id are not specified. Identifier of the inline message

Returns:

On success, returns an Array of GameHighScore objects.

Return type:

List[types.GameHighScore]

tgram.methods.get_me module

class tgram.methods.get_me.GetMe[source]

Bases: object

async get_me() User[source]

Returns basic information about the bot in form of a User object.

Telegram documentation: https://core.telegram.org/bots/api#getme

tgram.methods.get_my_commands module

class tgram.methods.get_my_commands.GetMyCommands[source]

Bases: object

async get_my_commands(scope: BotCommandScope | None = None, language_code: str | None = None) List[BotCommand][source]

Use this method to get the current list of the bot’s commands. Returns List of BotCommand on success.

Telegram documentation: https://core.telegram.org/bots/api#getmycommands

Parameters:
  • scope (tgram.types.BotCommandScope) – The scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault.

  • language_code (str) – A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands

Returns:

List of BotCommand on success.

Return type:

list of tgram.types.BotCommand

tgram.methods.get_my_default_administrator_rights module

class tgram.methods.get_my_default_administrator_rights.GetMyDefaultAdministratorRights[source]

Bases: object

async get_my_default_administrator_rights(for_channels: bool | None = None) ChatAdministratorRights[source]

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

Telegram documentation: https://core.telegram.org/bots/api#getmydefaultadministratorrights

Parameters:

for_channels (bool) – Pass True to get the default administrator rights of the bot in channels. Otherwise, the default administrator rights of the bot for groups and supergroups will be returned.

Returns:

Returns ChatAdministratorRights on success.

Return type:

tgram.types.ChatAdministratorRights

tgram.methods.get_my_description module

class tgram.methods.get_my_description.GetMyDescription[source]

Bases: object

async get_my_description(language_code: str | None = None) BotDescription[source]

Use this method to get the current bot description for the given user language. Returns BotDescription on success.

Parameters:

language_code (str) – A two-letter ISO 639-1 language code or an empty string

Returns:

tgram.types.BotDescription

tgram.methods.get_my_name module

class tgram.methods.get_my_name.GetMyName[source]

Bases: object

async get_my_name(language_code: str | None = None) BotName[source]

Use this method to get the current bot name for the given user language. Returns BotName on success.

Telegram documentation: https://core.telegram.org/bots/api#getmyname

Parameters:

language_code (str) – Optional. A two-letter ISO 639-1 language code or an empty string

Returns:

tgram.types.BotName

tgram.methods.get_my_short_description module

class tgram.methods.get_my_short_description.GetMyShortDescription[source]

Bases: object

async get_my_short_description(language_code: str | None = None) BotShortDescription[source]

Use this method to get the current bot short description for the given user language. Returns BotShortDescription on success.

Parameters:

language_code (str) – A two-letter ISO 639-1 language code or an empty string

Returns:

tgram.types.BotShortDescription

tgram.methods.get_star_transactions module

class tgram.methods.get_star_transactions.GetStarTransactions[source]

Bases: object

async get_star_transactions(offset: int | None = None, limit: int | None = None) StarTransactions[source]

Returns the bot’s Telegram Star transactions in chronological order.

Telegram documentation: https://core.telegram.org/bots/api#getstartransactions

Parameters:
  • offset (int) – Number of transactions to skip in the response

  • limit (int) – The maximum number of transactions to be retrieved. Values between 1-100 are accepted. Defaults to 100.

Returns:

On success, returns a StarTransactions object.

Return type:

tgram.types.StarTransactions

tgram.methods.get_sticker_set module

class tgram.methods.get_sticker_set.GetStickerSet[source]

Bases: object

async get_sticker_set(name: str) StickerSet[source]

Use this method to get a sticker set. On success, a StickerSet object is returned.

Telegram documentation: https://core.telegram.org/bots/api#getstickerset

Parameters:

name (str) – Sticker set name

Returns:

On success, a StickerSet object is returned.

Return type:

tgram.types.StickerSet

tgram.methods.get_updates module

class tgram.methods.get_updates.GetUpdates[source]

Bases: object

async get_updates(offset: int | None = None, limit: int | None = None, timeout: int | None = None, allowed_updates: List[str] | None = None) List[Update][source]

Use this method to receive incoming updates using long polling (wiki). An Array of Update objects is returned.

Telegram documentation: https://core.telegram.org/bots/api#getupdates

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) – Request connection timeout

  • allowed_updates (list, optional) – Array of string. List the types of updates you want your bot to receive.

  • request_timeout (int, optional) – Timeout in seconds for request.

Returns:

An Array of Update objects is returned.

Return type:

list of tgram.types.Update

tgram.methods.get_user_chat_boosts module

class tgram.methods.get_user_chat_boosts.GetUserChatBoosts[source]

Bases: object

async get_user_chat_boosts(chat_id: int | str, user_id: int) UserChatBoosts[source]

Use this method to get the list of boosts added to a chat by a user. Requires administrator rights in the chat. Returns a UserChatBoosts object.

Telegram documentation: https://core.telegram.org/bots/api#getuserchatboosts

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel

  • user_id (int) – Unique identifier of the target user

Returns:

On success, a UserChatBoosts object is returned.

Return type:

tgram.types.UserChatBoosts

tgram.methods.get_user_profile_photos module

class tgram.methods.get_user_profile_photos.GetUserProfilePhotos[source]

Bases: object

async get_user_profile_photos(user_id: int, offset: int | None = None, limit: int | None = None) UserProfilePhotos[source]

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

Telegram documentation: https://core.telegram.org/bots/api#getuserprofilephotos

Parameters:
  • user_id (int) – Unique identifier of the target user

  • offset (int) – Sequential number of the first photo to be returned. By default, all photos are returned.

  • limit (int) – Limits the number of photos to be retrieved. Values between 1-100 are accepted. Defaults to 100.

Returns:

UserProfilePhotos

Return type:

tgram.types.UserProfilePhotos

tgram.methods.get_webhook_info module

class tgram.methods.get_webhook_info.GetWebhookInfo[source]

Bases: object

async get_webhook_info() WebhookInfo[source]

Use this method to get current webhook status. Requires no parameters. On success, returns a WebhookInfo object. If the bot is using getUpdates, will return an object with the url field empty.

Telegram documentation: https://core.telegram.org/bots/api#getwebhookinfo

Parameters:

timeout (int, optional) – Request connection timeout

Returns:

On success, returns a WebhookInfo object.

Return type:

tgram.types.WebhookInfo

tgram.methods.hide_general_forum_topic module

class tgram.methods.hide_general_forum_topic.HideGeneralForumTopic[source]

Bases: object

async hide_general_forum_topic(chat_id: int | str) bool[source]

Use this method to hide the ‘General’ topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#hidegeneralforumtopic

Parameters:

chat_id (int or str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)

tgram.methods.leave_chat module

class tgram.methods.leave_chat.LeaveChat[source]

Bases: object

async leave_chat(chat_id: int | str) bool[source]

Use this method for your bot to leave a group, supergroup or channel. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#leavechat

Parameters:

chat_id (int or str) – Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)

Returns:

bool

tgram.methods.log_out module

class tgram.methods.log_out.LogOut[source]

Bases: object

async log_out() bool[source]

Use this method to log out from the cloud Bot API server before launching the bot locally. You MUST log out the bot before running it locally, otherwise there is no guarantee that the bot will receive updates. After a successful call, you can immediately log in on a local server, but will not be able to log in back to the cloud Bot API server for 10 minutes. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#logout

Returns:

True on success.

Return type:

bool

tgram.methods.pin_chat_message module

class tgram.methods.pin_chat_message.PinChatMessage[source]

Bases: object

async pin_chat_message(chat_id: int | str, message_id: int, disable_notification: bool | None = None, business_connection_id: str | None = None) bool[source]

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. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#pinchatmessage

Parameters:
  • chat_id (int or 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) – Pass True, if it is not necessary to send a notification to all group members about the new pinned message

  • business_connection_id (str) – Unique identifier of the business connection on behalf of which the message will be pinned

Returns:

True on success.

Return type:

bool

tgram.methods.promote_chat_member module

class tgram.methods.promote_chat_member.PromoteChatMember[source]

Bases: object

async promote_chat_member(chat_id: int | str, user_id: int, is_anonymous: bool | None = None, can_manage_chat: bool | None = None, can_delete_messages: bool | None = None, can_manage_video_chats: bool | None = None, can_restrict_members: bool | None = None, can_promote_members: bool | None = None, can_change_info: bool | None = None, can_invite_users: bool | None = None, can_post_stories: bool | None = None, can_edit_stories: bool | None = None, can_delete_stories: bool | None = None, can_post_messages: bool | None = None, can_edit_messages: bool | None = None, can_pin_messages: bool | None = None, can_manage_topics: bool | None = None) bool[source]

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

Telegram documentation: https://core.telegram.org/bots/api#promotechatmember

Parameters:
  • chat_id (int or 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

  • can_change_info (bool) – Pass True, if the administrator can change chat title, photo and other settings

  • can_post_messages (bool) – Pass True, if the administrator can create channel posts, channels only

  • can_edit_messages (bool) – Pass True, if the administrator can edit messages of other users, channels only

  • can_delete_messages (bool) – Pass True, if the administrator can delete messages of other users

  • can_invite_users (bool) – Pass True, if the administrator can invite new users to the chat

  • can_restrict_members (bool) – Pass True, if the administrator can restrict, ban or unban chat members

  • can_pin_messages (bool) – Pass True, if the administrator can pin messages, supergroups only

  • can_promote_members (bool) – 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)

  • is_anonymous (bool) – Pass True, if the administrator’s presence in the chat is hidden

  • can_manage_chat (bool) – Pass True, if the administrator can access the chat event log, chat statistics, message statistics in channels, see channel members, see anonymous administrators in supergroups and ignore slow mode. Implied by any other administrator privilege

  • can_manage_video_chats (bool) – Pass True, if the administrator can manage voice chats For now, bots can use this privilege only for passing to other administrators.

  • can_manage_voice_chats (bool) – Deprecated, use can_manage_video_chats.

  • can_manage_topics (bool) – Pass True if the user is allowed to create, rename, close, and reopen forum topics, supergroups only

  • can_post_stories (bool) – Pass True if the administrator can create the channel’s stories

  • can_edit_stories (bool) – Pass True if the administrator can edit the channel’s stories

  • can_delete_stories (bool) – Pass True if the administrator can delete the channel’s stories

Returns:

True on success.

Return type:

bool

tgram.methods.refund_star_payment module

class tgram.methods.refund_star_payment.RefundStarPayment[source]

Bases: object

async refund_star_payment(user_id: int, telegram_payment_charge_id: str) bool[source]

Refunds a successful payment in Telegram Stars. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#refundstarpayment

Parameters:
  • user_id (int) – Identifier of the user whose payment will be refunded

  • telegram_payment_charge_id (str) – Telegram payment identifier

Returns:

On success, True is returned.

Return type:

bool

tgram.methods.reopen_forum_topic module

class tgram.methods.reopen_forum_topic.ReopenForumTopic[source]

Bases: object

async reopen_forum_topic(chat_id: int | str, message_thread_id: int) bool[source]

Use this method to reopen a closed topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#reopenforumtopic

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

  • message_thread_id (int) – Identifier of the topic to reopen

Returns:

On success, True is returned.

Return type:

bool

tgram.methods.reopen_general_forum_topic module

class tgram.methods.reopen_general_forum_topic.ReopenGeneralForumTopic[source]

Bases: object

async reopen_general_forum_topic(chat_id: int | str) bool[source]

Use this method to reopen the ‘General’ topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#reopengeneralforumtopic

Parameters:

chat_id (int or str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)

tgram.methods.replace_sticker_in_set module

class tgram.methods.replace_sticker_in_set.ReplaceStickerInSet[source]

Bases: object

async replace_sticker_in_set(user_id: int, name: str, old_sticker: str, sticker: InputSticker) bool[source]
Use this method to replace an existing sticker in a sticker set with a new one. The method is equivalent to calling deleteStickerFromSet, then addStickerToSet,

then setStickerPositionInSet. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#replaceStickerInSet

Parameters:
  • user_id (int) – User identifier of the sticker set owner

  • name (str) – Sticker set name

  • old_sticker (str) – File identifier of the replaced sticker

  • sticker (tgram.types.InputSticker) – A JSON-serialized object with information about the added sticker. If exactly the same sticker had already been added to the set, then the set remains unchanged.

Returns:

Returns True on success.

Return type:

bool

tgram.methods.restrict_chat_member module

class tgram.methods.restrict_chat_member.RestrictChatMember[source]

Bases: object

async restrict_chat_member(chat_id: int | str, user_id: int, permissions: ChatPermissions, use_independent_chat_permissions: bool | None = None, until_date: int | None = None) bool[source]

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

Telegram documentation: https://core.telegram.org/bots/api#restrictchatmember

Warning

Individual parameters are deprecated and will be removed, use ‘permissions’ instead

Parameters:
  • chat_id (int or str) – Unique identifier for the target group or username of the target supergroup or channel (in the format @channelusername)

  • user_id (int) – Unique identifier of the target user

  • until_date (int, 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) – deprecated

  • can_send_media_messages (bool) – deprecated

  • can_send_polls (bool) – deprecated

  • can_send_other_messages (bool) – deprecated

  • can_add_web_page_previews (bool) – deprecated

  • can_change_info (bool) – deprecated

  • can_invite_users (bool) – deprecated

  • can_pin_messages (bool) – deprecated

  • use_independent_chat_permissions (bool, optional) – Pass True if chat permissions are set independently. Otherwise, the can_send_other_messages and can_add_web_page_previews permissions will imply the can_send_messages, can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, and can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission.

  • permissions (tgram.types.ChatPermissions) – Pass ChatPermissions object to set all permissions at once. Use this parameter instead of passing all boolean parameters to avoid backward compatibility problems in future.

Returns:

True on success

Return type:

bool

tgram.methods.send_animation module

class tgram.methods.send_animation.SendAnimation[source]

Bases: object

async send_animation(chat_id: int | str, animation: Path | bytes | str, business_connection_id: str | None = None, message_thread_id: int | None = None, duration: int | None = None, width: int | None = None, height: int | None = None, thumbnail: Path | bytes | str | None = None, caption: str | None = None, parse_mode: str | None = None, caption_entities: List[MessageEntity] | None = None, show_caption_above_media: bool | None = None, has_spoiler: bool | None = None, disable_notification: bool | None = None, protect_content: bool | None = None, message_effect_id: str | None = None, reply_parameters: ReplyParameters | None = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None) Message[source]

Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). On success, the sent Message is returned. Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future.

Telegram documentation: https://core.telegram.org/bots/api#sendanimation

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

  • animation (str or tgram.types.InputFile) – Animation to send. Pass a file_id as String to send an animation that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an animation from the Internet, or upload a new animation using multipart/form-data.

  • duration (int) – Duration of sent animation in seconds

  • width (int) – Animation width

  • height (int) – Animation height

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

  • caption (str) – Animation caption (may also be used when resending animation by file_id), 0-1024 characters after entities parsing

  • parse_mode (str) – Mode for parsing entities in the animation caption

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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.

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • timeout (int) – Timeout in seconds for the request.

  • caption_entities (list of tgram.types.MessageEntity) – List of special entities that appear in the caption, which can be specified instead of parse_mode

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • message_thread_id (int) – Identifier of a message thread, in which the video will be sent

  • has_spoiler (bool) – Pass True, if the animation should be sent as a spoiler

  • thumb (str or tgram.types.InputFile) – Deprecated. Use thumbnail instead

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Identifier of a business connection, in which the message will be sent

  • message_effect_id (str) – Unique identifier of the message effect

  • show_caption_above_media (bool) – Pass True, if the caption must be shown above the message media. Supported only for animation, photo and video messages.

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

tgram.methods.send_audio module

class tgram.methods.send_audio.SendAudio[source]

Bases: object

async send_audio(chat_id: int | str, audio: Path | bytes | str, business_connection_id: str | None = None, message_thread_id: int | None = None, caption: str | None = None, parse_mode: str | None = None, caption_entities: List[MessageEntity] | None = None, duration: int | None = None, performer: str | None = None, title: str | None = None, thumbnail: Path | bytes | str | None = None, disable_notification: bool | None = None, protect_content: bool | None = None, message_effect_id: str | None = None, reply_parameters: ReplyParameters | None = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None) Message[source]

Use this method to send audio files, if you want Telegram clients to display them in the music player. Your audio must be in the .MP3 or .M4A 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 send_voice method instead.

Telegram documentation: https://core.telegram.org/bots/api#sendaudio

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

  • audio (str or tgram.types.InputFile) – 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. Audio must be in the .MP3 or .M4A format.

  • caption (str) – Audio caption, 0-1024 characters after entities parsing

  • duration (int) – Duration of the audio in seconds

  • performer (str) – Performer

  • title (str) – Track name

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply)

  • parse_mode (str) – Mode for parsing entities in the audio caption. See formatting options for more details.

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • timeout (int) – Timeout in seconds for the request.

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

  • caption_entities (list of tgram.types.MessageEntity) – A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • message_thread_id (int) – Identifier of a message thread, in which the message will be sent

  • thumb (str or tgram.types.InputFile) – Deprecated. Use thumbnail instead

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Unique identifier for the target business connection

  • message_effect_id (str) – Unique identifier for the message effect

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

tgram.methods.send_chat_action module

class tgram.methods.send_chat_action.SendChatAction[source]

Bases: object

async send_chat_action(chat_id: int | str, action: str, business_connection_id: str | None = None, message_thread_id: int | None = None) bool[source]

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

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

Telegram documentation: https://core.telegram.org/bots/api#sendchataction

Parameters:
  • chat_id (int or str) – Unique identifier for the target chat or username of the target channel

  • action (str) – Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_voice or upload_voice for voice notes, upload_document for general files, choose_sticker for stickers, find_location for location data, record_video_note or upload_video_note for video notes.

  • timeout (int) – Timeout in seconds for the request.

  • message_thread_id (int) – The thread to which the message will be sent(supergroups only)

  • business_connection_id (str) – Identifier of a business connection, in which the message will be sent

Returns:

Returns True on success.

Return type:

bool

tgram.methods.send_contact module

class tgram.methods.send_contact.SendContact[source]

Bases: object

async send_contact(chat_id: int | str, phone_number: str, first_name: str, business_connection_id: str | None = None, message_thread_id: int | None = None, last_name: str | None = None, vcard: str | None = None, disable_notification: bool | None = None, protect_content: bool | None = None, message_effect_id: str | None = None, reply_parameters: ReplyParameters | None = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None) Message[source]

Use this method to send phone contacts. On success, the sent Message is returned.

Telegram documentation: https://core.telegram.org/bots/api#sendcontact

Parameters:
  • chat_id (int or str) – Unique identifier for the target chat or username of the target channel

  • phone_number (str) – Contact’s phone number

  • first_name (str) – Contact’s first name

  • last_name (str) – Contact’s last name

  • vcard (str) – Additional data about the contact in the form of a vCard, 0-2048 bytes

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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) – Timeout in seconds for the request.

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if one of the specified replied-to messages is not found.

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • message_thread_id (int) – The thread to which the message will be sent

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Identifier of a business connection, in which the message will be sent

  • message_effect_id (str) – Unique identifier of the message effect

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

tgram.methods.send_dice module

class tgram.methods.send_dice.SendDice[source]

Bases: object

async send_dice(chat_id: int | str, business_connection_id: str | None = None, message_thread_id: int | None = None, emoji: str | None = None, disable_notification: bool | None = None, protect_content: bool | None = None, message_effect_id: str | None = None, reply_parameters: ReplyParameters | None = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None) Message[source]

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

Telegram documentation: https://core.telegram.org/bots/api#senddice

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

  • emoji (str) – Emoji on which the dice throw animation is based. Currently, must be one of “🎲”, “🎯”, “🏀”, “⚽”, “🎳”, or “🎰”. Dice can have values 1-6 for “🎲”, “🎯” and “🎳”, values 1-5 for “🏀” and “⚽”, and values 1-64 for “🎰”. Defaults to “🎲”

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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) – Timeout in seconds for the request.

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • protect_content (bool) – Protects the contents of the sent message from forwarding

  • message_thread_id (int) – The identifier of a message thread, unique within the chat to which the message with the thread identifier belongs

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Unique identifier for the target business connection

  • message_effect_id (str) – Unique identifier for the message effect

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

tgram.methods.send_document module

class tgram.methods.send_document.SendDocument[source]

Bases: object

async send_document(chat_id: int | str, document: Path | bytes | str, business_connection_id: str | None = None, message_thread_id: int | None = None, thumbnail: Path | bytes | str | None = None, caption: str | None = None, parse_mode: str | None = None, caption_entities: List[MessageEntity] | None = None, disable_content_type_detection: bool | None = None, disable_notification: bool | None = None, protect_content: bool | None = None, message_effect_id: str | None = None, reply_parameters: ReplyParameters | None = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None) Message[source]

Use this method to send general files.

Telegram documentation: https://core.telegram.org/bots/api#senddocument

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

  • document (str or tgram.types.InputFile) – (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

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

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

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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.

  • parse_mode (str) – Mode for parsing entities in the document caption

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • timeout (int) – Timeout in seconds for the request.

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

  • caption_entities (list of tgram.types.MessageEntity) – A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • visible_file_name (str) – allows to define file name that will be visible in the Telegram instead of original file name

  • disable_content_type_detection (bool) – Disables automatic server-side content type detection for files uploaded using multipart/form-data

  • data (str) – function typo miss compatibility: do not use it

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • message_thread_id (int) – Identifier of a message thread, in which the message will be sent

  • thumb (str or tgram.types.InputFile) – Deprecated. Use thumbnail instead

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Unique identifier for the target business connection

  • message_effect_id (str) – Unique identifier for the message effect

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

tgram.methods.send_game module

class tgram.methods.send_game.SendGame[source]

Bases: object

async send_game(chat_id: int, game_short_name: str, business_connection_id: str | None = None, message_thread_id: int | None = None, disable_notification: bool | None = None, protect_content: bool | None = None, message_effect_id: str | None = None, reply_parameters: ReplyParameters | None = None, reply_markup: InlineKeyboardMarkup | None = None) Message[source]

Used to send the game.

Telegram documentation: https://core.telegram.org/bots/api#sendgame

Parameters:
  • chat_id (int or 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) – Sends the message silently. Users will receive a notification with no sound.

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • reply_markup (InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply) – 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) – Timeout in seconds for waiting for a response from the bot.

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if one of the specified replied-to messages is not found.

  • protect_content (bool) – Pass True, if content of the message needs to be protected from being viewed by the bot.

  • message_thread_id (int) – Identifier of the thread to which the message will be sent.

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Identifier of the business connection.

  • message_effect_id (str) – Identifier of the message effect.

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

tgram.methods.send_invoice module

class tgram.methods.send_invoice.SendInvoice[source]

Bases: object

async send_invoice(chat_id: int | str, title: str, description: str, payload: str, currency: str, prices: List[LabeledPrice], message_thread_id: int | None = None, provider_token: str | None = None, max_tip_amount: int | None = None, suggested_tip_amounts: List[int] | None = None, start_parameter: str | None = None, provider_data: str | None = None, photo_url: str | None = None, photo_size: int | None = None, photo_width: int | None = None, photo_height: int | None = None, need_name: bool | None = None, need_phone_number: bool | None = None, need_email: bool | None = None, need_shipping_address: bool | None = None, send_phone_number_to_provider: bool | None = None, send_email_to_provider: bool | None = None, is_flexible: bool | None = None, disable_notification: bool | None = None, protect_content: bool | None = None, message_effect_id: str | None = None, reply_parameters: ReplyParameters | None = None, reply_markup: InlineKeyboardMarkup | None = None) Message[source]

Sends invoice.

Telegram documentation: https://core.telegram.org/bots/api#sendinvoice

Parameters:
  • chat_id (int or str) – Unique identifier for the target private chat

  • title (str) – Product name, 1-32 characters

  • description (str) – Product description, 1-255 characters

  • invoice_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; Pass None to omit the parameter to use “XTR” currency

  • currency (str) – Three-letter ISO 4217 currency code, see https://core.telegram.org/bots/payments#supported-currencies

  • prices (List[tgram.types.LabeledPrice]) – Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)

  • start_parameter (str) – Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter

  • photo_url (str) – 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 (int) – Photo size in bytes

  • photo_width (int) – Photo width

  • photo_height (int) – Photo height

  • need_name (bool) – Pass True, if you require the user’s full name to complete the order

  • need_phone_number (bool) – Pass True, if you require the user’s phone number to complete the order

  • need_email (bool) – Pass True, if you require the user’s email to complete the order

  • need_shipping_address (bool) – Pass True, if you require the user’s shipping address to complete the order

  • is_flexible (bool) – Pass True, if the final price depends on the shipping method

  • send_phone_number_to_provider (bool) – Pass True, if user’s phone number should be sent to provider

  • send_email_to_provider (bool) – Pass True, if user’s email address should be sent to provider

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • reply_markup (str) – A JSON-serialized object for an inline keyboard. If empty, one ‘Pay total price’ button will be shown. If not empty, the first button must be a Pay button

  • provider_data (str) – A JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider.

  • timeout (int) – Timeout of a request, defaults to None

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • max_tip_amount (int) – The maximum accepted amount for tips in the smallest units of the currency

  • suggested_tip_amounts (list of int) – A JSON-serialized array of suggested amounts of tips in the smallest units of the currency. At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount.

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • message_thread_id (int) – The identifier of a message thread, in which the invoice message will be sent

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • message_effect_id (str) – The identifier of a message effect to be applied to the message

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

tgram.methods.send_location module

class tgram.methods.send_location.SendLocation[source]

Bases: object

async send_location(chat_id: int | str, latitude: float, longitude: float, business_connection_id: str | None = None, message_thread_id: int | None = None, horizontal_accuracy: float | None = None, live_period: int | None = None, heading: int | None = None, proximity_alert_radius: int | None = None, disable_notification: bool | None = None, protect_content: bool | None = None, message_effect_id: str | None = None, reply_parameters: ReplyParameters | None = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None) Message[source]

Use this method to send point on the map. On success, the sent Message is returned.

Telegram documentation: https://core.telegram.org/bots/api#sendlocation

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

  • latitude (float) – Latitude of the location

  • longitude (float) – Longitude of the location

  • live_period (int) – Period in seconds during which the location will be updated (see Live Locations, should be between 60 and 86400, or 0x7FFFFFFF for live locations that can be edited indefinitely.

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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.

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • timeout (int) – Timeout in seconds for the request.

  • horizontal_accuracy (float) – The radius of uncertainty for the location, measured in meters; 0-1500

  • heading (int) – For live locations, a direction in which the user is moving, in degrees. Must be between 1 and 360 if specified.

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

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • message_thread_id (int) – Identifier of a message thread, in which the message will be sent

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Identifier of a business connection, in which the message will be sent

  • message_effect_id (str) – Unique identifier of the message effect

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

tgram.methods.send_media_from_file_id module

class tgram.methods.send_media_from_file_id.SendMediaFromFileId[source]

Bases: object

async send_media_from_file_id(chat_id: int | str, file_id: str, business_connection_id: str | None = None, message_thread_id: int | None = None, caption: str | None = None, parse_mode: str | None = None, caption_entities: List[MessageEntity] | None = None, show_caption_above_media: bool | None = None, disable_notification: bool | None = None, protect_content: bool | None = None, message_effect_id: str | None = None, reply_parameters: ReplyParameters | None = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None) Message[source]

tgram.methods.send_media_group module

class tgram.methods.send_media_group.SendMediaGroup[source]

Bases: object

async send_media_group(chat_id: int | str, media: List[InputMediaAudio | InputMediaDocument | InputMediaPhoto | InputMediaVideo], business_connection_id: str = None, message_thread_id: int = None, disable_notification: bool = None, protect_content: bool = None, message_effect_id: str = None, reply_parameters: ReplyParameters = None) List[Message][source]

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

Telegram documentation: https://core.telegram.org/bots/api#sendmediagroup

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

  • media (list of tgram.types.InputMedia) – A JSON-serialized array describing messages to be sent, must include 2-10 items

  • disable_notification (bool) – Sends the messages silently. Users will receive a notification with no sound.

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • timeout (int) – Timeout in seconds for the request.

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • message_thread_id (int) – Identifier of a message thread, in which the messages will be sent

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Identifier of a business connection, in which the message will be sent

  • message_effect_id (str) – Unique identifier of the message effect

Returns:

On success, an array of Messages that were sent is returned.

Return type:

List[types.Message]

tgram.methods.send_message module

class tgram.methods.send_message.SendMessage[source]

Bases: object

async send_message(chat_id: int | str, text: str, business_connection_id: str | None = None, message_thread_id: int | None = None, parse_mode: str | None = None, entities: List[MessageEntity] | None = None, link_preview_options: LinkPreviewOptions | None = None, disable_notification: bool | None = None, protect_content: bool | None = None, message_effect_id: str | None = None, reply_parameters: ReplyParameters | None = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None) Message[source]

Use this method to send text messages.

Warning: Do not send more than about 4096 characters each message, otherwise you’ll risk an HTTP 414 error. If you must send more than 4096 characters, use the split_string or smart_split function in util.py.

Telegram documentation: https://core.telegram.org/bots/api#sendmessage

Parameters:
  • chat_id (int or 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

  • parse_mode (str) – Mode for parsing entities in the message text.

  • entities (Array of tgram.types.MessageEntity) – List of special entities that appear in message text, which can be specified instead of parse_mode

  • disable_web_page_preview (bool) – Deprecated - Use link_preview_options instead.

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • protect_content (bool) – If True, the message content will be hidden for all users except for the target user

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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) – Timeout in seconds for the request.

  • message_thread_id (int) – Unique identifier for the target message thread (topic) of the forum; for forum supergroups only

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • link_preview_options (tgram.types.LinkPreviewOptions) – Options for previewing links.

  • business_connection_id (str) – Unique identifier for the target business connection

  • message_effect_id (str) – Unique identifier for the message effect

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

tgram.methods.send_paid_media module

class tgram.methods.send_paid_media.SendPaidMedia[source]

Bases: object

async send_paid_media(chat_id: int | str, star_count: int, media: List[InputPaidMediaPhoto | InputPaidMediaVideo], payload: str = None, caption: str = None, parse_mode: str = None, caption_entities: List[MessageEntity] = None, show_caption_above_media: bool = None, disable_notification: bool = None, protect_content: bool = None, reply_parameters: ReplyParameters = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply = None, business_connection_id: str = None) Message[source]

Use this method to send paid media to channel chats. On success, the sent Message is returned.

Telegram documentation: https://core.telegram.org/bots/api#sendpaidmedia

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

  • star_count (int) – The number of Telegram Stars that must be paid to buy access to the media

  • media (list of tgram.types.InputPaidMedia) – A JSON-serialized array describing the media to be sent; up to 10 items

  • caption (str) – Media caption, 0-1024 characters after entities parsing

  • payload (str) – Bot-defined paid media payload, 0-128 bytes. This will not be displayed to the user, use it for your internal processes.

  • parse_mode (str) – Mode for parsing entities in the media caption

  • caption_entities (list of tgram.types.MessageEntity) – List of special entities that appear in the caption, which can be specified instead of parse_mode

  • show_caption_above_media (bool) – Pass True, if the caption must be shown above the message media

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • protect_content (str) – Protects the contents of the sent message from forwarding and saving

  • reply_parameters (tgram.types.ReplyParameters) – Description of the message to reply to

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user

  • business_connection_id – Unique identifier of the business connection on behalf of which the message will be sent

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

tgram.methods.send_photo module

class tgram.methods.send_photo.SendPhoto[source]

Bases: object

async send_photo(chat_id: int | str, photo: Path | bytes | str, business_connection_id: str | None = None, message_thread_id: int | None = None, caption: str | None = None, parse_mode: str | None = None, caption_entities: List[MessageEntity] | None = None, show_caption_above_media: bool | None = None, has_spoiler: bool | None = None, disable_notification: bool | None = None, protect_content: bool | None = None, message_effect_id: str | None = None, reply_parameters: ReplyParameters | None = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None) Message[source]

Use this method to send photos. On success, the sent Message is returned.

Telegram documentation: https://core.telegram.org/bots/api#sendphoto

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

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

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

  • parse_mode (str) – Mode for parsing entities in the photo caption.

  • caption_entities (list of tgram.types.MessageEntity) – A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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) – Timeout in seconds for the request.

  • message_thread_id (int) – Identifier of a message thread, in which the message will be sent

  • has_spoiler (bool) – Pass True, if the photo should be sent as a spoiler

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Unique identifier for the target business connection

  • message_effect_id (str) – Unique identifier for the message effect

  • show_caption_above_media (bool) – Pass True, if the caption must be shown above the message media. Supported only for animation, photo and video messages.

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

tgram.methods.send_poll module

class tgram.methods.send_poll.SendPoll[source]

Bases: object

async send_poll(chat_id: int | str, question: str, options: List[InputPollOption], business_connection_id: str | None = None, message_thread_id: int | None = None, question_parse_mode: str | None = None, question_entities: List[MessageEntity] | None = None, is_anonymous: bool | None = None, type: str | None = None, allows_multiple_answers: bool | None = None, correct_option_id: int | None = None, explanation: str | None = None, explanation_parse_mode: str | None = None, explanation_entities: List[MessageEntity] | None = None, open_period: int | None = None, close_date: int | None = None, is_closed: bool | None = None, disable_notification: bool | None = None, protect_content: bool | None = None, message_effect_id: str | None = None, reply_parameters: ReplyParameters | None = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None) Message[source]

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

Telegram documentation: https://core.telegram.org/bots/api#sendpoll

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel

  • question (str) – Poll question, 1-300 characters

  • options (list of InputPollOption) – A JSON-serialized list of 2-10 answer options

  • is_anonymous (bool) – True, if the poll needs to be anonymous, defaults to True

  • type (str) – Poll type, “quiz” or “regular”, defaults to “regular”

  • allows_multiple_answers (bool) – True, if the poll allows multiple answers, ignored for polls in quiz mode, defaults to False

  • correct_option_id (int) – 0-based identifier of the correct answer option. Available only for polls in quiz mode, defaults to None

  • explanation (str) – Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters with at most 2 line feeds after entities parsing

  • explanation_parse_mode (str) – Mode for parsing entities in the explanation. See formatting options for more details.

  • open_period (int) – Amount of time in seconds the poll will be active after creation, 5-600. Can’t be used together with close_date.

  • close_date (int | datetime) – Point in time (Unix timestamp) when the poll will be automatically closed.

  • is_closed (bool) – Pass True, if the poll needs to be immediately closed. This can be useful for poll preview.

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the poll allows multiple options to be voted simultaneously.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply) – 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) – Timeout in seconds for waiting for a response from the user.

  • explanation_entities (list of MessageEntity) – A JSON-serialized list of special entities that appear in the explanation, which can be specified instead of parse_mode

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • message_thread_id (int) – The identifier of a message thread, in which the poll will be sent

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Identifier of the business connection to send the message through

  • question_parse_mode (str) – Mode for parsing entities in the question. See formatting options for more details. Currently, only custom emoji entities are allowed

  • question_entities (list of MessageEntity) – A JSON-serialized list of special entities that appear in the poll question. It can be specified instead of question_parse_mode

  • message_effect_id (str) – Identifier of the message effect to apply to the sent message

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

tgram.methods.send_sticker module

class tgram.methods.send_sticker.SendSticker[source]

Bases: object

async send_sticker(chat_id: int | str, sticker: Path | bytes | str, business_connection_id: str | None = None, message_thread_id: int | None = None, emoji: str | None = None, disable_notification: bool | None = None, protect_content: bool | None = None, message_effect_id: str | None = None, reply_parameters: ReplyParameters | None = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None) Message[source]

Use this method to send static .WEBP, animated .TGS, or video .WEBM stickers. On success, the sent Message is returned.

Telegram documentation: https://core.telegram.org/bots/api#sendsticker

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

  • sticker (str or tgram.types.InputFile) – 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.

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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.

  • disable_notification (bool) – to disable the notification

  • timeout (int) – Timeout in seconds for the request.

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • data (str) – function typo miss compatibility: do not use it

  • message_thread_id (int) – Identifier of a message thread, in which the message will be sent

  • emoji (str) – Emoji associated with the sticker; only for just uploaded stickers

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Unique identifier for the target business connection

  • message_effect_id (str) – Unique identifier for the message effect

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

tgram.methods.send_venue module

class tgram.methods.send_venue.SendVenue[source]

Bases: object

async send_venue(chat_id: int | str, latitude: float, longitude: float, title: str, address: str, business_connection_id: str | None = None, message_thread_id: int | None = None, foursquare_id: str | None = None, foursquare_type: str | None = None, google_place_id: str | None = None, google_place_type: str | None = None, disable_notification: bool | None = None, protect_content: bool | None = None, message_effect_id: str | None = None, reply_parameters: ReplyParameters | None = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None) Message[source]

Use this method to send information about a venue. On success, the sent Message is returned.

Telegram documentation: https://core.telegram.org/bots/api#sendvenue

Parameters:
  • chat_id (int or str) – Unique identifier for the target chat or username of the target channel

  • latitude (float) – Latitude of the venue

  • longitude (float) – Longitude of the venue

  • title (str) – Name of the venue

  • address (str) – Address of the venue

  • foursquare_id (str) – Foursquare identifier of the venue

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

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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) – Timeout in seconds for the request.

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if one of the specified replied-to messages is not found.

  • google_place_id (str) – Google Places identifier of the venue

  • google_place_type (str) – Google Places type of the venue.

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • message_thread_id (int) – The thread to which the message will be sent

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Identifier of a business connection, in which the message will be sent

  • message_effect_id (str) – Unique identifier of the message effect

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

tgram.methods.send_video module

class tgram.methods.send_video.SendVideo[source]

Bases: object

async send_video(chat_id: int | str, video: Path | bytes | str, business_connection_id: str | None = None, message_thread_id: int | None = None, duration: int | None = None, width: int | None = None, height: int | None = None, thumbnail: Path | bytes | str | None = None, caption: str | None = None, parse_mode: str | None = None, caption_entities: List[MessageEntity] | None = None, show_caption_above_media: bool | None = None, has_spoiler: bool | None = None, supports_streaming: bool | None = None, disable_notification: bool | None = None, protect_content: bool | None = None, message_effect_id: str | None = None, reply_parameters: ReplyParameters | None = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None) Message[source]

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

Telegram documentation: https://core.telegram.org/bots/api#sendvideo

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

  • video (str or tgram.types.InputFile) – Video to send. You can either pass a file_id as String to resend a video that is already on the Telegram servers, or upload a new video file using multipart/form-data.

  • duration (int) – Duration of sent video in seconds

  • width (int) – Video width

  • height (int) – Video height

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

  • caption (str) – Video caption (may also be used when resending videos by file_id), 0-1024 characters after entities parsing

  • parse_mode (str) – Mode for parsing entities in the video caption

  • caption_entities (list of tgram.types.MessageEntity) – List of special entities that appear in the caption, which can be specified instead of parse_mode

  • supports_streaming (bool) – Pass True, if the uploaded video is suitable for streaming

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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) – Timeout in seconds for the request.

  • data (str) – function typo miss compatibility: do not use it

  • message_thread_id (int) – Identifier of a message thread, in which the video will be sent

  • has_spoiler (bool) – Pass True, if the video should be sent as a spoiler

  • thumb (str or tgram.types.InputFile) – Deprecated. Use thumbnail instead

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Identifier of a business connection, in which the message will be sent

  • message_effect_id (str) – Unique identifier of the message effect

  • show_caption_above_media (bool) – Pass True, if the caption must be shown above the message media. Supported only for animation, photo and video messages.

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

tgram.methods.send_video_note module

class tgram.methods.send_video_note.SendVideoNote[source]

Bases: object

async send_video_note(chat_id: int | str, video_note: Path | bytes | str, business_connection_id: str | None = None, message_thread_id: int | None = None, duration: int | None = None, length: int | None = None, thumbnail: Path | bytes | str | None = None, disable_notification: bool | None = None, protect_content: bool | None = None, message_effect_id: str | None = None, reply_parameters: ReplyParameters | None = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None) Message[source]

As of v.4.0, Telegram clients support rounded square MPEG4 videos of up to 1 minute long. Use this method to send video messages. On success, the sent Message is returned.

Telegram documentation: https://core.telegram.org/bots/api#sendvideonote

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

  • data (str or tgram.types.InputFile) – 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. Sending video notes by a URL is currently unsupported

  • duration (int) – Duration of sent video in seconds

  • length (int) – Video width and height, i.e. diameter of the video message

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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.

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • timeout (int) – Timeout in seconds for the request.

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

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • message_thread_id (int) – Identifier of a message thread, in which the video note will be sent

  • thumb (str or tgram.types.InputFile) – Deprecated. Use thumbnail instead

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Identifier of a business connection, in which the message will be sent

  • message_effect_id (str) – Unique identifier of the message effect

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

tgram.methods.send_voice module

class tgram.methods.send_voice.SendVoice[source]

Bases: object

async send_voice(chat_id: int | str, voice: Path | bytes | str, business_connection_id: str | None = None, message_thread_id: int | None = None, caption: str | None = None, parse_mode: str | None = None, caption_entities: List[MessageEntity] | None = None, duration: int | None = None, disable_notification: bool | None = None, protect_content: bool | None = None, message_effect_id: str | None = None, reply_parameters: ReplyParameters | None = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None = None) Message[source]

Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .OGG file encoded with OPUS, or in .MP3 format, or in .M4A format (other formats may be sent as Audio or Document). On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.

Telegram documentation: https://core.telegram.org/bots/api#sendvoice

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

  • voice (str or tgram.types.InputFile) – Audio 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.

  • caption (str) – Voice message caption, 0-1024 characters after entities parsing

  • duration (int) – Duration of the voice message in seconds

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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.

  • parse_mode (str) – Mode for parsing entities in the voice message caption. See formatting options for more details.

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • timeout (int) – Timeout in seconds for the request.

  • caption_entities (list of tgram.types.MessageEntity) – A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • message_thread_id (int) – Identifier of a message thread, in which the message will be sent

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Unique identifier for the target business connection

  • message_effect_id (str) – Unique identifier for the message effect

Returns:

On success, the sent Message is returned.

tgram.methods.set_chat_administrator_custom_title module

class tgram.methods.set_chat_administrator_custom_title.SetChatAdministratorCustomTitle[source]

Bases: object

async set_chat_administrator_custom_title(chat_id: int | str, user_id: int, custom_title: str) bool[source]

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

Telegram documentation: https://core.telegram.org/bots/api#setchatadministratorcustomtitle

Parameters:
  • chat_id (int or 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

  • custom_title (str) – New custom title for the administrator; 0-16 characters, emoji are not allowed

Returns:

True on success.

Return type:

bool

tgram.methods.set_chat_description module

class tgram.methods.set_chat_description.SetChatDescription[source]

Bases: object

async set_chat_description(chat_id: int | str, description: str | None = None) bool[source]

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

Telegram documentation: https://core.telegram.org/bots/api#setchatdescription

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

  • description (str) – Str: New chat description, 0-255 characters

Returns:

True on success.

Return type:

bool

tgram.methods.set_chat_menu_button module

class tgram.methods.set_chat_menu_button.SetChatMenuButton[source]

Bases: object

async set_chat_menu_button(chat_id: int | None = None, menu_button: MenuButton | None = None) bool[source]

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

Telegram documentation: https://core.telegram.org/bots/api#setchatmenubutton

Parameters:
  • chat_id (int or str) – Unique identifier for the target private chat. If not specified, default bot’s menu button will be changed.

  • menu_button (tgram.types.MenuButton) – A JSON-serialized object for the new bot’s menu button. Defaults to MenuButtonDefault

Returns:

True on success.

Return type:

bool

tgram.methods.set_chat_permissions module

class tgram.methods.set_chat_permissions.SetChatPermissions[source]

Bases: object

async set_chat_permissions(chat_id: int | str, permissions: ChatPermissions, use_independent_chat_permissions: bool | None = None) bool[source]

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

Telegram documentation: https://core.telegram.org/bots/api#setchatpermissions

Parameters:
  • chat_id (int or str) – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)

  • permissions (tgram.types..ChatPermissions) – New default chat permissions

  • use_independent_chat_permissions (bool) – Pass True if chat permissions are set independently. Otherwise, the can_send_other_messages and can_add_web_page_previews permissions will imply the can_send_messages, can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, and can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission.

Returns:

True on success

Return type:

bool

tgram.methods.set_chat_photo module

class tgram.methods.set_chat_photo.SetChatPhoto[source]

Bases: object

async set_chat_photo(chat_id: int | str, photo: Path | bytes | str) bool[source]

Use this method to set a new profile photo for the chat. Photos can’t be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. Note: In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’ setting is off in the target group.

Telegram documentation: https://core.telegram.org/bots/api#setchatphoto

Parameters:
  • chat_id (int or str) – Int or Str: Unique identifier for the target chat or username of the target channel (in the format @channelusername)

  • photo (typing.Union[file_like, str]) – InputFile: New chat photo, uploaded using multipart/form-data

Returns:

True on success.

Return type:

bool

tgram.methods.set_chat_sticker_set module

class tgram.methods.set_chat_sticker_set.SetChatStickerSet[source]

Bases: object

async set_chat_sticker_set(chat_id: int | str, sticker_set_name: str) bool[source]

Use this method to set a new group sticker set for a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#setchatstickerset

Parameters:
  • chat_id (int or 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

Returns:

StickerSet object

Return type:

tgram.types.StickerSet

tgram.methods.set_chat_title module

class tgram.methods.set_chat_title.SetChatTitle[source]

Bases: object

async set_chat_title(chat_id: int | str, title: str) bool[source]

Use this method to change the title of a chat. Titles can’t be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. Note: In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’ setting is off in the target group.

Telegram documentation: https://core.telegram.org/bots/api#setchattitle

Parameters:
  • chat_id (int or 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

Returns:

True on success.

Return type:

bool

tgram.methods.set_custom_emoji_sticker_set_thumbnail module

class tgram.methods.set_custom_emoji_sticker_set_thumbnail.SetCustomEmojiStickerSetThumbnail[source]

Bases: object

async set_custom_emoji_sticker_set_thumbnail(name: str, custom_emoji_id: str | None = None) bool[source]

Use this method to set the thumbnail of a custom emoji sticker set. Returns True on success.

Parameters:
  • name (str) – Sticker set name

  • custom_emoji_id (str) – Custom emoji identifier of a sticker from the sticker set; pass an empty string to drop the thumbnail and use the first sticker as the thumbnail.

Returns:

Returns True on success.

Return type:

bool

tgram.methods.set_game_score module

class tgram.methods.set_game_score.SetGameScore[source]

Bases: object

async set_game_score(user_id: int, score: int, force: bool | None = None, disable_edit_message: bool | None = None, chat_id: int | None = None, message_id: int | None = None, inline_message_id: str | None = None) Message | bool[source]

tgram.methods.set_message_reaction module

class tgram.methods.set_message_reaction.SetMessageReaction[source]

Bases: object

async set_message_reaction(chat_id: int | str, message_id: int, reaction: List[ReactionTypeCustomEmoji | ReactionTypeEmoji | ReactionTypePaid] = None, is_big: bool = None) bool[source]

Use this method to change the chosen reactions on a message. Service messages can’t be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#setmessagereaction

Parameters:
  • chat_id (int or str) – Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)

  • message_id (int) – Identifier of the message to set reaction to

  • reaction (list of tgram.types.ReactionType) – New list of reaction types to set on the message. Currently, as non-premium users, bots can set up to one reaction per message. A custom emoji reaction can be used if it is either already present on the message or explicitly allowed by chat administrators.

  • is_big (bool) – Pass True to set the reaction with a big animation

Returns:

bool

tgram.methods.set_my_commands module

class tgram.methods.set_my_commands.SetMyCommands[source]

Bases: object

async set_my_commands(commands: List[BotCommand], scope: BotCommandScope | None = None, language_code: str | None = None) bool[source]

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

Telegram documentation: https://core.telegram.org/bots/api#setmycommands

Parameters:
  • commands (list of tgram.types.BotCommand) – List of BotCommand. At most 100 commands can be specified.

  • scope (tgram.types.BotCommandScope) – The scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault.

  • language_code (str) – A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands

Returns:

True on success.

Return type:

bool

tgram.methods.set_my_default_administrator_rights module

class tgram.methods.set_my_default_administrator_rights.SetMyDefaultAdministratorRights[source]

Bases: object

async set_my_default_administrator_rights(rights: ChatAdministratorRights | None = None, for_channels: bool | None = None) bool[source]

Use this method to change the default administrator rights requested by the bot when it’s added as an administrator to groups or channels. These rights will be suggested to users, but they are are free to modify the list before adding the bot. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#setmydefaultadministratorrights

Parameters:
  • rights (tgram.types.ChatAdministratorRights) – A JSON-serialized object describing new default administrator rights. If not specified, the default administrator rights will be cleared.

  • for_channels (bool) – Pass True to change the default administrator rights of the bot in channels. Otherwise, the default administrator rights of the bot for groups and supergroups will be changed.

Returns:

True on success.

Return type:

bool

tgram.methods.set_my_description module

class tgram.methods.set_my_description.SetMyDescription[source]

Bases: object

async set_my_description(description: str | None = None, language_code: str | None = None) bool[source]

Use this method to change the bot’s description, which is shown in the chat with the bot if the chat is empty. Returns True on success.

Parameters:
  • description (str) – New bot description; 0-512 characters. Pass an empty string to remove the dedicated description for the given language.

  • language_code (str) – A two-letter ISO 639-1 language code. If empty, the description will be applied to all users for whose language there is no dedicated description.

Returns:

True on success.

tgram.methods.set_my_name module

class tgram.methods.set_my_name.SetMyName[source]

Bases: object

async set_my_name(name: str | None = None, language_code: str | None = None) bool[source]

Use this method to change the bot’s name. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#setmyname

Parameters:
  • name (str) – Optional. New bot name; 0-64 characters. Pass an empty string to remove the dedicated name for the given language.

  • language_code (str) – Optional. A two-letter ISO 639-1 language code. If empty, the name will be shown to all users for whose language there is no dedicated name.

Returns:

True on success.

tgram.methods.set_my_short_description module

class tgram.methods.set_my_short_description.SetMyShortDescription[source]

Bases: object

async set_my_short_description(short_description: str | None = None, language_code: str | None = None) bool[source]

Use this method to change the bot’s short description, which is shown on the bot’s profile page and is sent together with the link when users share the bot. Returns True on success.

Parameters:
  • short_description (str) – New short description for the bot; 0-120 characters. Pass an empty string to remove the dedicated short description for the given language.

  • language_code (str) – A two-letter ISO 639-1 language code. If empty, the short description will be applied to all users for whose language there is no dedicated short description.

Returns:

True on success.

tgram.methods.set_passport_data_errors module

class tgram.methods.set_passport_data_errors.SetPassportDataErrors[source]

Bases: object

async set_passport_data_errors(user_id: int, errors: List[PassportElementError]) bool[source]

tgram.methods.set_sticker_emoji_list module

class tgram.methods.set_sticker_emoji_list.SetStickerEmojiList[source]

Bases: object

async set_sticker_emoji_list(sticker: str, emoji_list: List[str]) bool[source]

Use this method to set the emoji list of a sticker set. Returns True on success.

Parameters:
  • name (str) – Sticker set name

  • emoji_list (list of str) – List of emojis

Returns:

Returns True on success.

Return type:

bool

tgram.methods.set_sticker_keywords module

class tgram.methods.set_sticker_keywords.SetStickerKeywords[source]

Bases: object

async set_sticker_keywords(sticker: str, keywords: List[str] | None = None) bool[source]

Use this method to change search keywords assigned to a regular or custom emoji sticker. The sticker must belong to a sticker set created by the bot. Returns True on success.

Parameters:
  • sticker (str) – File identifier of the sticker.

  • keywords (list of str) – A JSON-serialized list of 0-20 search keywords for the sticker with total length of up to 64 characters

Returns:

On success, True is returned.

Return type:

bool

tgram.methods.set_sticker_mask_position module

class tgram.methods.set_sticker_mask_position.SetStickerMaskPosition[source]

Bases: object

async set_sticker_mask_position(sticker: str, mask_position: MaskPosition | None = None) bool[source]

Use this method to change the mask position of a mask sticker. The sticker must belong to a sticker set that was created by the bot. Returns True on success.

Parameters:
  • sticker (str) – File identifier of the sticker.

  • mask_position (tgram.types.MaskPosition) – A JSON-serialized object for position where the mask should be placed on faces.

Returns:

Returns True on success.

Return type:

bool

tgram.methods.set_sticker_position_in_set module

class tgram.methods.set_sticker_position_in_set.SetStickerPositionInSet[source]

Bases: object

async set_sticker_position_in_set(sticker: str, position: int) bool[source]

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

Telegram documentation: https://core.telegram.org/bots/api#setstickerpositioninset

Parameters:
  • sticker (str) – File identifier of the sticker

  • position (int) – New sticker position in the set, zero-based

Returns:

On success, True is returned.

Return type:

bool

tgram.methods.set_sticker_set_thumbnail module

class tgram.methods.set_sticker_set_thumbnail.SetStickerSetThumbnail[source]

Bases: object

async set_sticker_set_thumbnail(name: str, user_id: int, format: str, thumbnail: Path | bytes | str | None = None) bool[source]

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

Telegram documentation: https://core.telegram.org/bots/api#setstickersetthumbnail

Parameters:
  • name (str) – Sticker set name

  • user_id (int) – User identifier

  • thumbnail (filelike object) – A .WEBP or .PNG image with the thumbnail, must be up to 128 kilobytes in size and have a width and height of exactly 100px, or a .TGS animation with a thumbnail up to 32 kilobytes in size (see https://core.telegram.org/stickers#animated-sticker-requirements for animated sticker technical requirements), or a WEBM video with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/stickers#video-sticker-requirements for video sticker technical requirements. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files ». Animated and video sticker set thumbnails can’t be uploaded via HTTP URL. If omitted, then the thumbnail is dropped and the first sticker is used as the thumbnail.

Returns:

On success, True is returned.

Return type:

bool

tgram.methods.set_sticker_set_title module

class tgram.methods.set_sticker_set_title.SetStickerSetTitle[source]

Bases: object

async set_sticker_set_title(name: str, title: str) bool[source]

Use this method to set the title of a created sticker set. Returns True on success.

Parameters:
  • name (str) – Sticker set name

  • title (str) – New sticker set title

Returns:

Returns True on success.

Return type:

bool

tgram.methods.set_webhook module

class tgram.methods.set_webhook.SetWebhook[source]

Bases: object

async set_webhook(url: str, certificate: Path | bytes | str | None = None, ip_address: str | None = None, max_connections: int | None = None, allowed_updates: List[str] | None = None, drop_pending_updates: bool | None = None, secret_token: str | None = None) bool[source]

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

If you’d like to make sure that the webhook was set by you, you can specify secret data in the parameter secret_token. If specified, the request will contain a header “X-Telegram-Bot-Api-Secret-Token” with the secret token as content.

Telegram Documentation: https://core.telegram.org/bots/api#setwebhook

Parameters:
  • url (str, optional) – HTTPS URL to send updates to. Use an empty string to remove webhook integration, defaults to None

  • certificate (str, optional) – Upload your public key certificate so that the root certificate in use can be checked, defaults to None

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

  • allowed_updates (list, optional) –

    A JSON-serialized list of the update types you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all update types except chat_member (default). If not specified, the previous setting will be used.

    Please note that this parameter doesn’t affect updates created before the call to the setWebhook, so unwanted updates may be received for a short period of time. Defaults to None

  • ip_address (str, optional) – The fixed IP address which will be used to send webhook requests instead of the IP address resolved through DNS, defaults to None

  • drop_pending_updates (bool, optional) – Pass True to drop all pending updates, defaults to None

  • timeout (int, optional) – Timeout of a request, defaults to None

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

Returns:

True on success.

Return type:

bool if the request was successful.

tgram.methods.stop_message_live_location module

class tgram.methods.stop_message_live_location.StopMessageLiveLocation[source]

Bases: object

async stop_message_live_location(business_connection_id: str | None = None, chat_id: int | str | None = None, message_id: int | None = None, inline_message_id: str | None = None, reply_markup: InlineKeyboardMarkup | None = None) Message | bool[source]

tgram.methods.stop_poll module

class tgram.methods.stop_poll.StopPoll[source]

Bases: object

async stop_poll(chat_id: int | str, message_id: int, business_connection_id: str | None = None, reply_markup: InlineKeyboardMarkup | None = None) Poll[source]

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

Telegram documentation: https://core.telegram.org/bots/api#stoppoll

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel

  • message_id (int) – Identifier of the original message with the poll

  • reply_markup (InlineKeyboardMarkup) – A JSON-serialized object for a new message markup.

  • business_connection_id (str) – Identifier of the business connection to send the message through

Returns:

On success, the stopped Poll is returned.

Return type:

tgram.types.Poll

tgram.methods.unban_chat_member module

class tgram.methods.unban_chat_member.UnbanChatMember[source]

Bases: object

async unban_chat_member(chat_id: int | str, user_id: int, only_if_banned: bool | None = None) bool[source]

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

Telegram documentation: https://core.telegram.org/bots/api#unbanchatmember

Parameters:
  • chat_id (int or str) – Unique identifier for the target group or username of the target supergroup or channel (in the format @username)

  • user_id (int) – Unique identifier of the target user

  • only_if_banned (bool) – Do nothing if the user is not banned

Returns:

True on success

Return type:

bool

tgram.methods.unban_chat_sender_chat module

class tgram.methods.unban_chat_sender_chat.UnbanChatSenderChat[source]

Bases: object

async unban_chat_sender_chat(chat_id: int | str, sender_chat_id: int) bool[source]

Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an administrator for this to work and must have the appropriate administrator rights. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#unbanchatsenderchat

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

  • sender_chat_id (int or str) – Unique identifier of the target sender chat.

Returns:

True on success.

Return type:

bool

tgram.methods.unhide_general_forum_topic module

class tgram.methods.unhide_general_forum_topic.UnhideGeneralForumTopic[source]

Bases: object

async unhide_general_forum_topic(chat_id: int | str) bool[source]

Use this method to unhide the ‘General’ topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#unhidegeneralforumtopic

Parameters:

chat_id (int or str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)

tgram.methods.unpin_all_chat_messages module

class tgram.methods.unpin_all_chat_messages.UnpinAllChatMessages[source]

Bases: object

async unpin_all_chat_messages(chat_id: int | str) bool[source]

Use this method to unpin a all pinned messages in a supergroup chat. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#unpinallchatmessages

Parameters:

chat_id (int or str) – Int or Str: Unique identifier for the target chat or username of the target channel (in the format @channelusername)

Returns:

True on success.

Return type:

bool

tgram.methods.unpin_all_forum_topic_messages module

class tgram.methods.unpin_all_forum_topic_messages.UnpinAllForumTopicMessages[source]

Bases: object

async unpin_all_forum_topic_messages(chat_id: int | str, message_thread_id: int) bool[source]

Use this method to clear the list of pinned messages in a forum topic. The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#unpinallforumtopicmessages

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

  • message_thread_id (int) – Identifier of the topic

Returns:

On success, True is returned.

Return type:

bool

tgram.methods.unpin_all_general_forum_topic_messages module

class tgram.methods.unpin_all_general_forum_topic_messages.UnpinAllGeneralForumTopicMessages[source]

Bases: object

async unpin_all_general_forum_topic_messages(chat_id: int | str) bool[source]

Use this method to clear the list of pinned messages in a General forum topic. The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#unpinAllGeneralForumTopicMessages

Parameters:

chat_id (int | str) – Unique identifier for the target chat or username of chat

Returns:

On success, True is returned.

Return type:

bool

tgram.methods.unpin_chat_message module

class tgram.methods.unpin_chat_message.UnpinChatMessage[source]

Bases: object

async unpin_chat_message(chat_id: int | str, message_id: int | None = None, business_connection_id: str | None = None) bool[source]

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

Telegram documentation: https://core.telegram.org/bots/api#unpinchatmessage

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

  • message_id (int) – Int: Identifier of a message to unpin

  • business_connection_id (str) – Unique identifier of the business connection on behalf of which the message will be pinned

Returns:

True on success.

Return type:

bool

tgram.methods.upload_sticker_file module

class tgram.methods.upload_sticker_file.UploadStickerFile[source]

Bases: object

async upload_sticker_file(user_id: int, sticker: Path | bytes | str, sticker_format: str) File[source]

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

Telegram documentation: https://core.telegram.org/bots/api#uploadstickerfile

Parameters:
  • user_id (int) – User identifier of sticker set owner

  • png_sticker (filelike object) – DEPRECATED: 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.

  • sticker (tgram.types.InputFile) – A file with the sticker in .WEBP, .PNG, .TGS, or .WEBM format. See https://core.telegram.org/stickers for technical requirements. More information on Sending Files »

  • sticker_format (str) – One of “static”, “animated”, “video”.

Returns:

On success, the sent file is returned.

Return type:

tgram.types.File

Module contents

class tgram.methods.TelegramBotMethods[source]

Bases: AddStickerToSet, AnswerCallbackQuery, AnswerInlineQuery, AnswerPreCheckoutQuery, AnswerShippingQuery, AnswerWebAppQuery, ApproveChatJoinRequest, Ask, BanChatMember, BanChatSenderChat, Close, CloseForumTopic, CloseGeneralForumTopic, CopyMessage, CopyMessages, CreateChatInviteLink, CreateChatSubscriptionInviteLink, CreateForumTopic, CreateInvoiceLink, CreateNewStickerSet, DeclineChatJoinRequest, DeleteChatPhoto, DeleteChatStickerSet, DeleteForumTopic, DeleteMessage, DeleteMessages, DeleteMyCommands, DeleteStickerFromSet, DeleteStickerSet, DeleteWebhook, DownloadFile, EditChatInviteLink, EditChatSubscriptionInviteLink, EditForumTopic, EditGeneralForumTopic, EditMessageCaption, EditMessageLiveLocation, EditMessageMedia, EditMessageReplyMarkup, EditMessageText, ExportChatInviteLink, ForwardMessage, ForwardMessages, GetBusinessConnection, GetChat, GetChatAdministrators, GetChatMember, GetChatMemberCount, GetChatMenuButton, GetCustomEmojiStickers, GetFile, GetFileUrl, GetForumTopicIconStickers, GetGameHighScores, GetMe, GetMyCommands, GetMyDefaultAdministratorRights, GetMyDescription, GetMyName, GetMyShortDescription, GetStarTransactions, GetStickerSet, GetUpdates, GetUserChatBoosts, GetUserProfilePhotos, GetWebhookInfo, HideGeneralForumTopic, LeaveChat, LogOut, PinChatMessage, PromoteChatMember, RefundStarPayment, ReopenForumTopic, ReopenGeneralForumTopic, ReplaceStickerInSet, RestrictChatMember, RevokeChatInviteLink, SendAnimation, SendAudio, SendChatAction, SendContact, SendDice, SendDocument, SendGame, SendInvoice, SendLocation, SendMediaFromFileId, SendMediaGroup, SendMessage, SendPaidMedia, SendPhoto, SendPoll, SendSticker, SendVenue, SendVideo, SendVideoNote, SendVoice, SetChatAdministratorCustomTitle, SetChatDescription, SetChatMenuButton, SetChatPermissions, SetChatPhoto, SetChatStickerSet, SetChatTitle, SetCustomEmojiStickerSetThumbnail, SetGameScore, SetMessageReaction, SetMyCommands, SetMyDefaultAdministratorRights, SetMyDescription, SetMyName, SetMyShortDescription, SetPassportDataErrors, SetStickerEmojiList, SetStickerKeywords, SetStickerMaskPosition, SetStickerPositionInSet, SetStickerSetThumbnail, SetStickerSetTitle, SetWebhook, StopMessageLiveLocation, StopPoll, UnbanChatMember, UnbanChatSenderChat, UnhideGeneralForumTopic, UnpinAllChatMessages, UnpinAllForumTopicMessages, UnpinAllGeneralForumTopicMessages, UnpinChatMessage, UnRestrictChatMember, UploadStickerFile, Runner

add_sticker_to_set(user_id: int, name: str, sticker: InputSticker) bool

Use this method to add a new sticker to a set created by the bot. The format of the added sticker must match the format of the other stickers in the set. Emoji sticker sets can have up to 200 stickers. Animated and video sticker sets can have up to 50 stickers. Static sticker sets can have up to 120 stickers. Returns True on success.

Note

**_sticker, mask_position, emojis parameters are deprecated, use stickers instead

Telegram documentation: https://core.telegram.org/bots/api#addstickertoset

Parameters:
  • user_id (int) – User identifier of created sticker set owner

  • name (str) – Sticker set name

  • emojis (str) – One or more emoji corresponding to the sticker

  • png_sticker (str or 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.

  • tgs_sticker (str or filelike object) – TGS animation with the sticker, uploaded using multipart/form-data.

  • webm_sticker (str or filelike object) – WebM animation with the sticker, uploaded using multipart/form-data.

  • mask_position (tgram.types.MaskPosition) – A JSON-serialized object for position where the mask should be placed on faces

  • sticker (tgram.types.InputSticker) – A JSON-serialized object for sticker to be added to the sticker set

Returns:

On success, True is returned.

Return type:

bool

answer_callback_query(callback_query_id: str, text: str = None, show_alert: bool = None, url: str = None, cache_time: int = None) bool

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.

Telegram documentation: https://core.telegram.org/bots/api#answercallbackquery

Parameters:
  • callback_query_id (int) – Unique identifier for the query to be answered

  • text (str) – Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters

  • show_alert (bool) – If True, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to false.

  • url (str) – 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.

  • cache_time – The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0.

Returns:

On success, True is returned.

Return type:

bool

answer_inline_query(inline_query_id: str, results: List[InlineQueryResultCachedAudio | InlineQueryResultCachedDocument | InlineQueryResultCachedGif | InlineQueryResultCachedMpeg4Gif | InlineQueryResultCachedPhoto | InlineQueryResultCachedSticker | InlineQueryResultCachedVideo | InlineQueryResultCachedVoice | InlineQueryResultArticle | InlineQueryResultAudio | InlineQueryResultContact | InlineQueryResultGame | InlineQueryResultDocument | InlineQueryResultGif | InlineQueryResultLocation | InlineQueryResultMpeg4Gif | InlineQueryResultPhoto | InlineQueryResultVenue | InlineQueryResultVideo | InlineQueryResultVoice], cache_time: int = None, is_personal: bool = None, next_offset: str = None, button: InlineQueryResultsButton = None) bool

Use this method to send answers to an inline query. On success, True is returned. No more than 50 results per query are allowed.

Telegram documentation: https://core.telegram.org/bots/api#answerinlinequery

Parameters:
  • inline_query_id (str) – Unique identifier for the answered query

  • results (list of tgram.types.InlineQueryResult) – Array of results for the inline query

  • cache_time (int) – The maximum amount of time in seconds that the result of the inline query may be cached on the server.

  • is_personal (bool) – Pass True, if results may be cached on the server side only for the user that sent the query.

  • next_offset (str) – Pass the offset that a client should send in the next query with the same text to receive more results.

  • switch_pm_parameter (str) – 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. 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.

  • switch_pm_text (str) – Parameter for the start message sent to the bot when user presses the switch button

  • button (tgram.types.InlineQueryResultsButton) – A JSON-serialized object describing a button to be shown above inline query results

Returns:

On success, True is returned.

Return type:

bool

answer_pre_checkout_query(pre_checkout_query_id: str, ok: bool, error_message: str = None) bool

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. On success, True is returned.

Note

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

Telegram documentation: https://core.telegram.org/bots/api#answerprecheckoutquery

Parameters:
  • pre_checkout_query_id (int) – 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) – Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. “Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!”). Telegram will display this message to the user.

Returns:

On success, True is returned.

Return type:

bool

answer_shipping_query(shipping_query_id: str, ok: bool, shipping_options: List[ShippingOption] = None, error_message: str = None) bool

Asks for an answer to a shipping question.

Telegram documentation: https://core.telegram.org/bots/api#answershippingquery

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 of ShippingOption) – Required if ok is True. A JSON-serialized array of available shipping options.

  • error_message (str) – Required if ok is False. Error message in human readable form that explains why it is impossible to complete the order (e.g. “Sorry, delivery to your desired address is unavailable’). Telegram will display this message to the user.

Returns:

On success, True is returned.

Return type:

bool

answer_web_app_query(web_app_query_id: str, result: InlineQueryResultCachedAudio | InlineQueryResultCachedDocument | InlineQueryResultCachedGif | InlineQueryResultCachedMpeg4Gif | InlineQueryResultCachedPhoto | InlineQueryResultCachedSticker | InlineQueryResultCachedVideo | InlineQueryResultCachedVoice | InlineQueryResultArticle | InlineQueryResultAudio | InlineQueryResultContact | InlineQueryResultGame | InlineQueryResultDocument | InlineQueryResultGif | InlineQueryResultLocation | InlineQueryResultMpeg4Gif | InlineQueryResultPhoto | InlineQueryResultVenue | InlineQueryResultVideo | InlineQueryResultVoice) SentWebAppMessage

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

Telegram Documentation: https://core.telegram.org/bots/api#answerwebappquery

Parameters:
  • web_app_query_id (str) – Unique identifier for the query to be answered

  • result (tgram.types.InlineQueryResultBase) – A JSON-serialized object describing the message to be sent

Returns:

On success, a SentWebAppMessage object is returned.

Return type:

tgram.types.SentWebAppMessage

approve_chat_join_request(chat_id: int | str, user_id: int) bool

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

Telegram documentation: https://core.telegram.org/bots/api#approvechatjoinrequest

Parameters:
  • chat_id (int or str) – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)

  • user_id (int or str) – Unique identifier of the target user

Returns:

True on success.

Return type:

bool

ask(next_step: Callable, update_type: str = 'message', data: dict = None, cancel: Callable = None, filters: Filter = None) None
ban_chat_member(chat_id: int | str, user_id: int, until_date: int = None, revoke_messages: bool = None) bool

Use this method to ban a user in a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the chat on their own using invite links, etc., unless unbanned first. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#banchatmember

Parameters:
  • chat_id (int or str) – Unique identifier for the target group or username of the target supergroup or channel (in the format @channelusername)

  • user_id (int) – Unique identifier of the target user

  • until_date (int) – 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

  • revoke_messages (bool) – Bool: Pass True to delete all messages from the chat for the user that is being removed. If False, the user will be able to see messages in the group that were sent before the user was removed. Always True for supergroups and channels.

Returns:

Returns True on success.

Return type:

bool

ban_chat_sender_chat(chat_id: int | str, sender_chat_id: int) bool

Use this method to ban a channel chat in a supergroup or a channel. The owner of the chat will not be able to send messages and join live streams on behalf of the chat, unless it is unbanned first. The bot must be an administrator in the supergroup or channel for this to work and must have the appropriate administrator rights. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#banchatsenderchat

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

  • sender_chat_id (int or str) – Unique identifier of the target sender chat

Returns:

True on success.

Return type:

bool

close() bool

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

Telegram documentation: https://core.telegram.org/bots/api#close

Returns:

bool

close_forum_topic(chat_id: int | str, message_thread_id: int) bool

Use this method to close an open topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#closeforumtopic

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

  • message_thread_id (int) – Identifier of the topic to close

Returns:

On success, True is returned.

Return type:

bool

close_general_forum_topic(chat_id: int | str) bool

Use this method to close the ‘General’ topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#closegeneralforumtopic

Parameters:

chat_id (int or str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)

copy_message(chat_id: int | str, from_chat_id: int | str, message_id: int, message_thread_id: int = None, caption: str = None, parse_mode: str = None, caption_entities: List[MessageEntity] = None, show_caption_above_media: bool = None, disable_notification: bool = None, protect_content: bool = None, reply_parameters: ReplyParameters = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply = None) MessageId

Use this method to copy messages of any kind.

Telegram documentation: https://core.telegram.org/bots/api#copymessage

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

  • from_chat_id (int or str) – Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)

  • message_id (int) – Message identifier in the chat specified in from_chat_id

  • caption (str) – New caption for media, 0-1024 characters after entities parsing. If not specified, the original caption is kept

  • parse_mode (str) – Mode for parsing entities in the new caption.

  • caption_entities (Array of tgram.types.MessageEntity) – A JSON-serialized list of special entities that appear in the new caption, which can be specified instead of parse_mode

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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) – Timeout in seconds for the request.

  • message_thread_id (int) – Identifier of a message thread, in which the message will be sent

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • show_caption_above_media (bool) – Pass True, if the caption must be shown above the message media. Supported only for animation, photo and video messages.

Returns:

On success, the MessageId of the sent message is returned.

Return type:

tgram.types.MessageID

copy_messages(chat_id: int | str, from_chat_id: int | str, message_ids: List[int], message_thread_id: int = None, disable_notification: bool = None, protect_content: bool = None, remove_caption: bool = None) List[MessageId]

Use this method to copy messages of any kind. If some of the specified messages can’t be found or copied, they are skipped. Service messages, giveaway messages, giveaway winners messages, and invoice messages can’t be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don’t have a link to the original message. Album grouping is kept for copied messages. On success, an array of MessageId of the sent messages is returned.

Telegram documentation: https://core.telegram.org/bots/api#copymessages

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

  • from_chat_id (int or str) – Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)

  • message_ids (list of int) – Message identifiers in the chat specified in from_chat_id

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound

  • message_thread_id (int) – Identifier of a message thread, in which the messages will be sent

  • protect_content (bool) – Protects the contents of the forwarded message from forwarding and saving

  • remove_caption (bool) – Pass True to copy the messages without their captions

Returns:

On success, an array of MessageId of the sent messages is returned.

Return type:

list of tgram.types.MessageID

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

Telegram documentation: https://core.telegram.org/bots/api#createchatinvitelink

Parameters:
  • chat_id (int or str) – Id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)

  • name (str) – Invite link name; 0-32 characters

  • expire_date (int) – Point in time (Unix timestamp) when the link will expire

  • member_limit (int) – Maximum number of users that can be members of the chat simultaneously

  • creates_join_request (bool) – True, if users joining the chat via the link need to be approved by chat administrators. If True, member_limit can’t be specified

Returns:

Returns the new invite link as ChatInviteLink object.

Return type:

tgram.types.ChatInviteLink

Use this method to create a subscription invite link for a channel chat. The bot must have the can_invite_users administrator rights. The link can be edited using the method editChatSubscriptionInviteLink or revoked using the method revokeChatInviteLink.

Telegram documentation: https://core.telegram.org/bots/api#createchatsubscriptioninvitelink

Parameters:
  • chat_id (int or str) – Id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)

  • subscription_period (int) – The number of seconds the subscription will be active for before the next payment. Currently, it must always be 2592000 (30 days).

  • subscription_price (int) – The amount of Telegram Stars a user must pay initially and after each subsequent subscription period to be a member of the chat; 1-2500

  • name (str) – Invite link name; 0-32 characters

Returns:

Returns the new invite link as ChatInviteLink object.

Return type:

tgram.types.ChatInviteLink

create_forum_topic(chat_id: int | str, name: str, icon_color: int = None, icon_custom_emoji_id: str = None) ForumTopic

Use this method to create a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns information about the created topic as a ForumTopic object.

Telegram documentation: https://core.telegram.org/bots/api#createforumtopic

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

  • name (str) – Name of the topic, 1-128 characters

  • icon_color (int) – Color of the topic icon in RGB format. Currently, must be one of 0x6FB9F0, 0xFFD67E, 0xCB86DB, 0x8EEE98, 0xFF93B2, or 0xFB6F5F

  • icon_custom_emoji_id (str) – Custom emoji for the topic icon. Must be an emoji of type “tgs” and must be exactly 1 character long

Returns:

On success, information about the created topic is returned as a ForumTopic object.

Return type:

tgram.types.ForumTopic

Use this method to create a link for an invoice. Returns the created invoice link as String on success.

Telegram documentation: https://core.telegram.org/bots/api#createinvoicelink

Parameters:
  • title (str) – Product name, 1-32 characters

  • description (str) – Product description, 1-255 characters

  • 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; Pass None to omit the parameter to use “XTR” currency

  • currency (str) – Three-letter ISO 4217 currency code, see https://core.telegram.org/bots/payments#supported-currencies

  • prices (list of tgram.types.LabeledPrice) – Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)

  • max_tip_amount (int) – The maximum accepted amount for tips in the smallest units of the currency

  • suggested_tip_amounts (list of int) – A JSON-serialized array of suggested amounts of tips in the smallest units of the currency. At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount.

  • provider_data (str) – A JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider.

  • photo_url (str) – URL of the product photo for the invoice. Can be a photo of the goods or a photo of the invoice. People like it better when they see a photo of what they are paying for.

  • photo_size (int) – Photo size in bytes

  • photo_width (int) – Photo width

  • photo_height (int) – Photo height

  • need_name (bool) – Pass True, if you require the user’s full name to complete the order

  • need_phone_number (bool) – Pass True, if you require the user’s phone number to complete the order

  • need_email (bool) – Pass True, if you require the user’s email to complete the order

  • need_shipping_address (bool) – Pass True, if you require the user’s shipping address to complete the order

  • send_phone_number_to_provider (bool) – Pass True, if user’s phone number should be sent to provider

  • send_email_to_provider (bool) – Pass True, if user’s email address should be sent to provider

  • is_flexible (bool) – Pass True, if the final price depends on the shipping method

Returns:

Created invoice link as String on success.

Return type:

str

create_new_sticker_set(user_id: int, name: str, title: str, stickers: List[InputSticker], sticker_type: str = None, needs_repainting: bool = None) bool

Use this method to create new sticker set owned by a user. The bot will be able to edit the created sticker set. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#createnewstickerset

Note

Fields *_sticker are deprecated, pass a list of stickers to stickers parameter instead.

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

  • emojis (str) – One or more emoji corresponding to the sticker

  • png_sticker (str) – 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.

  • tgs_sticker (str) – TGS animation with the sticker, uploaded using multipart/form-data.

  • webm_sticker (str) – WebM animation with the sticker, uploaded using multipart/form-data.

  • contains_masks (bool) – Pass True, if a set of mask stickers should be created. Deprecated since Bot API 6.2, use sticker_type instead.

  • sticker_type (str) – Type of stickers in the set, pass “regular”, “mask”, or “custom_emoji”. By default, a regular sticker set is created.

  • mask_position (tgram.types.MaskPosition) – A JSON-serialized object for position where the mask should be placed on faces

  • needs_repainting (bool) – Pass True if stickers in the sticker set must be repainted to the color of text when used in messages, the accent color if used as emoji status, white on chat photos, or another appropriate color based on context; for custom emoji sticker sets only

  • stickers (list of tgram.types.InputSticker) – List of stickers to be added to the set

  • sticker_format (str) – deprecated

Returns:

On success, True is returned.

Return type:

bool

decline_chat_join_request(chat_id: int | str, user_id: int) bool

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

Telegram documentation: https://core.telegram.org/bots/api#declinechatjoinrequest

Parameters:
  • chat_id (int or str) – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)

  • user_id (int or str) – Unique identifier of the target user

Returns:

True on success.

Return type:

bool

delete_chat_photo(chat_id: int | str) bool

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. Returns True on success. Note: In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’ setting is off in the target group.

Telegram documentation: https://core.telegram.org/bots/api#deletechatphoto

Parameters:

chat_id (int or str) – Int or Str: Unique identifier for the target chat or username of the target channel (in the format @channelusername)

Returns:

True on success.

Return type:

bool

delete_chat_sticker_set(chat_id: int | str) bool

Use this method to delete a group sticker set from a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#deletechatstickerset

Parameters:

chat_id (int or str) – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)

Returns:

Returns True on success.

Return type:

bool

delete_forum_topic(chat_id: int | str, message_thread_id: int) bool

Use this method to delete a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#deleteforumtopic

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

  • message_thread_id (int) – Identifier of the topic to delete

Returns:

On success, True is returned.

Return type:

bool

delete_message(chat_id: int | str, message_id: int) bool

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

Telegram documentation: https://core.telegram.org/bots/api#deletemessage

Parameters:
  • chat_id (int or 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) – Timeout in seconds for the request.

Returns:

Returns True on success.

Return type:

bool

delete_messages(chat_id: int | str, message_ids: List[int]) bool

Use this method to delete multiple messages simultaneously. If some of the specified messages can’t be found, they are skipped. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#deletemessages

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

  • message_ids (list of int) – Identifiers of the messages to be deleted

Returns:

Returns True on success.

delete_my_commands(scope: BotCommandScope = None, language_code: str = None) bool

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

Telegram documentation: https://core.telegram.org/bots/api#deletemycommands

Parameters:
  • scope (tgram.types.BotCommandScope) – The scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault.

  • language_code (str) – A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands

Returns:

True on success.

Return type:

bool

delete_sticker_from_set(sticker: str) bool

Use this method to delete a sticker from a set created by the bot. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#deletestickerfromset

Parameters:

sticker – File identifier of the sticker

Returns:

On success, True is returned.

Return type:

bool

delete_sticker_set(name: str) bool

Use this method to delete a sticker set. Returns True on success.

Parameters:

name (str) – Sticker set name

Returns:

Returns True on success.

Return type:

bool

delete_webhook(drop_pending_updates: bool = None) bool

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

Telegram documentation: https://core.telegram.org/bots/api#deletewebhook

Parameters:
  • drop_pending_updates – Pass True to drop all pending updates, defaults to None

  • timeout (int, optional) – Request connection timeout, defaults to None

Returns:

Returns True on success.

Return type:

bool

download_file(file_id: str, file_path: str = None, in_memory: bool = None) Path | BytesIO

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

Telegram documentation: https://core.telegram.org/bots/api#editchatinvitelink

Parameters:
  • chat_id (int or str) – Id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)

  • name (str) – Invite link name; 0-32 characters

  • invite_link (str) – The invite link to edit

  • expire_date (int) – Point in time (Unix timestamp) when the link will expire

  • member_limit (int) – Maximum number of users that can be members of the chat simultaneously

  • creates_join_request (bool) – True, if users joining the chat via the link need to be approved by chat administrators. If True, member_limit can’t be specified

Returns:

Returns the new invite link as ChatInviteLink object.

Return type:

tgram.types.ChatInviteLink

Use this method to edit a subscription invite link created by the bot. The bot must have the can_invite_users administrator rights.

Telegram documentation: https://core.telegram.org/bots/api#editchatsubscriptioninvitelink

Parameters:
  • chat_id (int or str) – Id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)

  • invite_link (str) – The invite link to edit

  • name (str) – Invite link name; 0-32 characters

Returns:

Returns the new invite link as ChatInviteLink object.

Return type:

tgram.types.ChatInviteLink

edit_forum_topic(chat_id: int | str, message_thread_id: int, name: str = None, icon_custom_emoji_id: str = None) bool

Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.

Telegram Documentation: https://core.telegram.org/bots/api#editforumtopic

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

  • message_thread_id (int) – Identifier of the topic to edit

  • name (str) – Optional, New name of the topic, 1-128 characters. If not specififed or empty, the current name of the topic will be kept

  • icon_custom_emoji_id (str) – Optional, New unique identifier of the custom emoji shown as the topic icon. Use getForumTopicIconStickers to get all allowed custom emoji identifiers. Pass an empty string to remove the icon. If not specified, the current icon will be kept

Returns:

On success, True is returned.

Return type:

bool

edit_general_forum_topic(chat_id: int | str, name: str) bool

Use this method to edit the name of the ‘General’ topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#editgeneralforumtopic

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

  • name (str) – New topic name, 1-128 characters

edit_message_caption(business_connection_id: str = None, chat_id: int | str = None, message_id: int = None, inline_message_id: str = None, caption: str = None, parse_mode: str = None, caption_entities: List[MessageEntity] = None, show_caption_above_media: bool = None, reply_markup: InlineKeyboardMarkup = None) Message | bool
edit_message_live_location(latitude: float, longitude: float, business_connection_id: str = None, chat_id: int | str = None, message_id: int = None, inline_message_id: str = None, live_period: int = None, horizontal_accuracy: float = None, heading: int = None, proximity_alert_radius: int = None, reply_markup: InlineKeyboardMarkup = None) Message | bool
edit_message_media(media: InputMediaAudio | InputMediaDocument | InputMediaPhoto | InputMediaVideo, business_connection_id: str = None, chat_id: int | str = None, message_id: int = None, inline_message_id: str = None, reply_markup: InlineKeyboardMarkup = None) Message | bool
edit_message_reply_markup(business_connection_id: str = None, chat_id: int | str = None, message_id: int = None, inline_message_id: str = None, reply_markup: InlineKeyboardMarkup = None) Message | bool
edit_message_text(text: str, business_connection_id: str = None, chat_id: int | str = None, message_id: int = None, inline_message_id: str = None, parse_mode: str = None, entities: List[MessageEntity] = None, link_preview_options: LinkPreviewOptions = None, reply_markup: InlineKeyboardMarkup = None) Message | bool

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.

Telegram documentation: https://core.telegram.org/bots/api#exportchatinvitelink

Parameters:

chat_id (int or str) – Id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)

Returns:

exported invite link as String on success.

Return type:

str

forward_message(chat_id: int | str, from_chat_id: int | str, message_id: int, message_thread_id: int = None, disable_notification: bool = None, protect_content: bool = None) Message

Use this method to forward messages of any kind.

Telegram documentation: https://core.telegram.org/bots/api#forwardmessage

Parameters:
  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound

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

  • from_chat_id (int or str) – Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)

  • message_id (int) – Message identifier in the chat specified in from_chat_id

  • protect_content (bool) – Protects the contents of the forwarded message from forwarding and saving

  • timeout (int) – Timeout in seconds for the request.

  • message_thread_id (int) – Unique identifier for the target message thread (topic) of the forum; for forum supergroups only

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

forward_messages(chat_id: int | str, from_chat_id: int | str, message_ids: List[int], message_thread_id: int = None, disable_notification: bool = None, protect_content: bool = None) List[MessageId]

Use this method to forward multiple messages of any kind. If some of the specified messages can’t be found or forwarded, they are skipped. Service messages and messages with protected content can’t be forwarded. Album grouping is kept for forwarded messages. On success, an array of MessageId of the sent messages is returned.

Telegram documentation: https://core.telegram.org/bots/api#forwardmessages

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

  • from_chat_id (int or str) – Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername)

  • message_ids (list) – Message identifiers in the chat specified in from_chat_id

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound

  • message_thread_id (int) – Identifier of a message thread, in which the messages will be sent

  • protect_content (bool) – Protects the contents of the forwarded message from forwarding and saving

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.MessageID

get_business_connection(business_connection_id: str) BusinessConnection

Use this method to get information about the connection of the bot with a business account. Returns a BusinessConnection object on success.

Telegram documentation: https://core.telegram.org/bots/api#getbusinessconnection

Parameters:

business_connection_id (str) – Unique identifier of the business connection

Returns:

Returns a BusinessConnection object on success.

Return type:

tgram.types.BusinessConnection

get_chat(chat_id: int | str) ChatFullInfo

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.). Returns a Chat object on success.

Telegram documentation: https://core.telegram.org/bots/api#getchat

Parameters:

chat_id (int or str) – Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)

Returns:

Chat information

Return type:

tgram.types.ChatFullInfo

get_chat_administrators(chat_id: int | str) List[ChatMemberAdministrator | ChatMemberOwner]
get_chat_member(chat_id: int | str, user_id: int) ChatMemberOwner | ChatMemberAdministrator | ChatMemberMember | ChatMemberRestricted | ChatMemberBanned | ChatMemberLeft
get_chat_member_count(chat_id: int | str) int

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

Telegram documentation: https://core.telegram.org/bots/api#getchatmembercount

Parameters:

chat_id (int or str) – Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)

Returns:

Number of members in the chat.

Return type:

int

get_chat_menu_button(chat_id: int = None) MenuButton

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

Telegram Documentation: https://core.telegram.org/bots/api#getchatmenubutton

Parameters:

chat_id (int or str) – Unique identifier for the target private chat. If not specified, default bot’s menu button will be returned.

Returns:

types.MenuButton

Return type:

tgram.types.MenuButton

get_custom_emoji_stickers(custom_emoji_ids: List[str]) List[Sticker]

Use this method to get information about custom emoji stickers by their identifiers. Returns an Array of Sticker objects.

Parameters:

custom_emoji_ids (list of str) – List of custom emoji identifiers. At most 200 custom emoji identifiers can be specified.

Returns:

Returns an Array of Sticker objects.

Return type:

list of tgram.types.Sticker

get_file(file_id: str) File

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. On success, a File object is returned. 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.

Telegram documentation: https://core.telegram.org/bots/api#getfile

Parameters:

file_id (str) – File identifier

Returns:

tgram.types.File

get_file_url(file_id: str) str

Get a valid URL for downloading a file.

Parameters:

file_id (str) – File identifier to get download URL for.

Returns:

URL for downloading the file.

Return type:

str

get_forum_topic_icon_stickers() List[Sticker]

Use this method to get custom emoji stickers, which can be used as a forum topic icon by any user. Requires no parameters. Returns an Array of Sticker objects.

Telegram documentation: https://core.telegram.org/bots/api#getforumtopiciconstickers

Returns:

On success, a list of StickerSet objects is returned.

Return type:

List[tgram.types.StickerSet]

get_game_high_scores(user_id: int, chat_id: int = None, message_id: int = None, inline_message_id: str = None) List[GameHighScore]

Use this method to get data for high score tables. Will return the score of the specified user and several of their neighbors in a game. On success, returns an Array of GameHighScore objects.

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

Telegram documentation: https://core.telegram.org/bots/api#getgamehighscores

Parameters:
  • user_id (int) – User identifier

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

  • message_id (int) – Required if inline_message_id is not specified. Identifier of the sent message

  • inline_message_id (str) – Required if chat_id and message_id are not specified. Identifier of the inline message

Returns:

On success, returns an Array of GameHighScore objects.

Return type:

List[types.GameHighScore]

get_me() User

Returns basic information about the bot in form of a User object.

Telegram documentation: https://core.telegram.org/bots/api#getme

get_my_commands(scope: BotCommandScope = None, language_code: str = None) List[BotCommand]

Use this method to get the current list of the bot’s commands. Returns List of BotCommand on success.

Telegram documentation: https://core.telegram.org/bots/api#getmycommands

Parameters:
  • scope (tgram.types.BotCommandScope) – The scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault.

  • language_code (str) – A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands

Returns:

List of BotCommand on success.

Return type:

list of tgram.types.BotCommand

get_my_default_administrator_rights(for_channels: bool = None) ChatAdministratorRights

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

Telegram documentation: https://core.telegram.org/bots/api#getmydefaultadministratorrights

Parameters:

for_channels (bool) – Pass True to get the default administrator rights of the bot in channels. Otherwise, the default administrator rights of the bot for groups and supergroups will be returned.

Returns:

Returns ChatAdministratorRights on success.

Return type:

tgram.types.ChatAdministratorRights

get_my_description(language_code: str = None) BotDescription

Use this method to get the current bot description for the given user language. Returns BotDescription on success.

Parameters:

language_code (str) – A two-letter ISO 639-1 language code or an empty string

Returns:

tgram.types.BotDescription

get_my_name(language_code: str = None) BotName

Use this method to get the current bot name for the given user language. Returns BotName on success.

Telegram documentation: https://core.telegram.org/bots/api#getmyname

Parameters:

language_code (str) – Optional. A two-letter ISO 639-1 language code or an empty string

Returns:

tgram.types.BotName

get_my_short_description(language_code: str = None) BotShortDescription

Use this method to get the current bot short description for the given user language. Returns BotShortDescription on success.

Parameters:

language_code (str) – A two-letter ISO 639-1 language code or an empty string

Returns:

tgram.types.BotShortDescription

get_star_transactions(offset: int = None, limit: int = None) StarTransactions

Returns the bot’s Telegram Star transactions in chronological order.

Telegram documentation: https://core.telegram.org/bots/api#getstartransactions

Parameters:
  • offset (int) – Number of transactions to skip in the response

  • limit (int) – The maximum number of transactions to be retrieved. Values between 1-100 are accepted. Defaults to 100.

Returns:

On success, returns a StarTransactions object.

Return type:

tgram.types.StarTransactions

get_sticker_set(name: str) StickerSet

Use this method to get a sticker set. On success, a StickerSet object is returned.

Telegram documentation: https://core.telegram.org/bots/api#getstickerset

Parameters:

name (str) – Sticker set name

Returns:

On success, a StickerSet object is returned.

Return type:

tgram.types.StickerSet

get_updates(offset: int = None, limit: int = None, timeout: int = None, allowed_updates: List[str] = None) List[Update]

Use this method to receive incoming updates using long polling (wiki). An Array of Update objects is returned.

Telegram documentation: https://core.telegram.org/bots/api#getupdates

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) – Request connection timeout

  • allowed_updates (list, optional) – Array of string. List the types of updates you want your bot to receive.

  • request_timeout (int, optional) – Timeout in seconds for request.

Returns:

An Array of Update objects is returned.

Return type:

list of tgram.types.Update

get_user_chat_boosts(chat_id: int | str, user_id: int) UserChatBoosts

Use this method to get the list of boosts added to a chat by a user. Requires administrator rights in the chat. Returns a UserChatBoosts object.

Telegram documentation: https://core.telegram.org/bots/api#getuserchatboosts

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel

  • user_id (int) – Unique identifier of the target user

Returns:

On success, a UserChatBoosts object is returned.

Return type:

tgram.types.UserChatBoosts

get_user_profile_photos(user_id: int, offset: int = None, limit: int = None) UserProfilePhotos

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

Telegram documentation: https://core.telegram.org/bots/api#getuserprofilephotos

Parameters:
  • user_id (int) – Unique identifier of the target user

  • offset (int) – Sequential number of the first photo to be returned. By default, all photos are returned.

  • limit (int) – Limits the number of photos to be retrieved. Values between 1-100 are accepted. Defaults to 100.

Returns:

UserProfilePhotos

Return type:

tgram.types.UserProfilePhotos

get_webhook_info() WebhookInfo

Use this method to get current webhook status. Requires no parameters. On success, returns a WebhookInfo object. If the bot is using getUpdates, will return an object with the url field empty.

Telegram documentation: https://core.telegram.org/bots/api#getwebhookinfo

Parameters:

timeout (int, optional) – Request connection timeout

Returns:

On success, returns a WebhookInfo object.

Return type:

tgram.types.WebhookInfo

hide_general_forum_topic(chat_id: int | str) bool

Use this method to hide the ‘General’ topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#hidegeneralforumtopic

Parameters:

chat_id (int or str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)

leave_chat(chat_id: int | str) bool

Use this method for your bot to leave a group, supergroup or channel. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#leavechat

Parameters:

chat_id (int or str) – Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)

Returns:

bool

log_out() bool

Use this method to log out from the cloud Bot API server before launching the bot locally. You MUST log out the bot before running it locally, otherwise there is no guarantee that the bot will receive updates. After a successful call, you can immediately log in on a local server, but will not be able to log in back to the cloud Bot API server for 10 minutes. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#logout

Returns:

True on success.

Return type:

bool

pin_chat_message(chat_id: int | str, message_id: int, disable_notification: bool = None, business_connection_id: str = None) bool

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. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#pinchatmessage

Parameters:
  • chat_id (int or 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) – Pass True, if it is not necessary to send a notification to all group members about the new pinned message

  • business_connection_id (str) – Unique identifier of the business connection on behalf of which the message will be pinned

Returns:

True on success.

Return type:

bool

promote_chat_member(chat_id: int | str, user_id: int, is_anonymous: bool = None, can_manage_chat: bool = None, can_delete_messages: bool = None, can_manage_video_chats: bool = None, can_restrict_members: bool = None, can_promote_members: bool = None, can_change_info: bool = None, can_invite_users: bool = None, can_post_stories: bool = None, can_edit_stories: bool = None, can_delete_stories: bool = None, can_post_messages: bool = None, can_edit_messages: bool = None, can_pin_messages: bool = None, can_manage_topics: bool = None) bool

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.

Telegram documentation: https://core.telegram.org/bots/api#promotechatmember

Parameters:
  • chat_id (int or 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

  • can_change_info (bool) – Pass True, if the administrator can change chat title, photo and other settings

  • can_post_messages (bool) – Pass True, if the administrator can create channel posts, channels only

  • can_edit_messages (bool) – Pass True, if the administrator can edit messages of other users, channels only

  • can_delete_messages (bool) – Pass True, if the administrator can delete messages of other users

  • can_invite_users (bool) – Pass True, if the administrator can invite new users to the chat

  • can_restrict_members (bool) – Pass True, if the administrator can restrict, ban or unban chat members

  • can_pin_messages (bool) – Pass True, if the administrator can pin messages, supergroups only

  • can_promote_members (bool) – 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)

  • is_anonymous (bool) – Pass True, if the administrator’s presence in the chat is hidden

  • can_manage_chat (bool) – Pass True, if the administrator can access the chat event log, chat statistics, message statistics in channels, see channel members, see anonymous administrators in supergroups and ignore slow mode. Implied by any other administrator privilege

  • can_manage_video_chats (bool) – Pass True, if the administrator can manage voice chats For now, bots can use this privilege only for passing to other administrators.

  • can_manage_voice_chats (bool) – Deprecated, use can_manage_video_chats.

  • can_manage_topics (bool) – Pass True if the user is allowed to create, rename, close, and reopen forum topics, supergroups only

  • can_post_stories (bool) – Pass True if the administrator can create the channel’s stories

  • can_edit_stories (bool) – Pass True if the administrator can edit the channel’s stories

  • can_delete_stories (bool) – Pass True if the administrator can delete the channel’s stories

Returns:

True on success.

Return type:

bool

refund_star_payment(user_id: int, telegram_payment_charge_id: str) bool

Refunds a successful payment in Telegram Stars. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#refundstarpayment

Parameters:
  • user_id (int) – Identifier of the user whose payment will be refunded

  • telegram_payment_charge_id (str) – Telegram payment identifier

Returns:

On success, True is returned.

Return type:

bool

reopen_forum_topic(chat_id: int | str, message_thread_id: int) bool

Use this method to reopen a closed topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#reopenforumtopic

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

  • message_thread_id (int) – Identifier of the topic to reopen

Returns:

On success, True is returned.

Return type:

bool

reopen_general_forum_topic(chat_id: int | str) bool

Use this method to reopen the ‘General’ topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#reopengeneralforumtopic

Parameters:

chat_id (int or str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)

replace_sticker_in_set(user_id: int, name: str, old_sticker: str, sticker: InputSticker) bool
Use this method to replace an existing sticker in a sticker set with a new one. The method is equivalent to calling deleteStickerFromSet, then addStickerToSet,

then setStickerPositionInSet. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#replaceStickerInSet

Parameters:
  • user_id (int) – User identifier of the sticker set owner

  • name (str) – Sticker set name

  • old_sticker (str) – File identifier of the replaced sticker

  • sticker (tgram.types.InputSticker) – A JSON-serialized object with information about the added sticker. If exactly the same sticker had already been added to the set, then the set remains unchanged.

Returns:

Returns True on success.

Return type:

bool

restrict_chat_member(chat_id: int | str, user_id: int, permissions: ChatPermissions, use_independent_chat_permissions: bool = None, until_date: int = None) bool

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.

Telegram documentation: https://core.telegram.org/bots/api#restrictchatmember

Warning

Individual parameters are deprecated and will be removed, use ‘permissions’ instead

Parameters:
  • chat_id (int or str) – Unique identifier for the target group or username of the target supergroup or channel (in the format @channelusername)

  • user_id (int) – Unique identifier of the target user

  • until_date (int, 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) – deprecated

  • can_send_media_messages (bool) – deprecated

  • can_send_polls (bool) – deprecated

  • can_send_other_messages (bool) – deprecated

  • can_add_web_page_previews (bool) – deprecated

  • can_change_info (bool) – deprecated

  • can_invite_users (bool) – deprecated

  • can_pin_messages (bool) – deprecated

  • use_independent_chat_permissions (bool, optional) – Pass True if chat permissions are set independently. Otherwise, the can_send_other_messages and can_add_web_page_previews permissions will imply the can_send_messages, can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, and can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission.

  • permissions (tgram.types.ChatPermissions) – Pass ChatPermissions object to set all permissions at once. Use this parameter instead of passing all boolean parameters to avoid backward compatibility problems in future.

Returns:

True on success

Return type:

bool

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

Telegram documentation: https://core.telegram.org/bots/api#revokechatinvitelink

Parameters:
  • chat_id (int or str) – Id: Unique identifier for the target chat or username of the target channel (in the format @channelusername)

  • invite_link (str) – The invite link to revoke

Returns:

Returns the new invite link as ChatInviteLink object.

Return type:

tgram.types.ChatInviteLink

run(main: Coroutine | None = None) Any

Use this method to run a couroutine function or handle new updates.

Parameters:

main (Coroutine) – The couroutine function.

Return type:

Any

send_animation(chat_id: int | str, animation: Path | bytes | str, business_connection_id: str = None, message_thread_id: int = None, duration: int = None, width: int = None, height: int = None, thumbnail: Path | bytes | str = None, caption: str = None, parse_mode: str = None, caption_entities: List[MessageEntity] = None, show_caption_above_media: bool = None, has_spoiler: bool = None, disable_notification: bool = None, protect_content: bool = None, message_effect_id: str = None, reply_parameters: ReplyParameters = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply = None) Message

Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). On success, the sent Message is returned. Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future.

Telegram documentation: https://core.telegram.org/bots/api#sendanimation

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

  • animation (str or tgram.types.InputFile) – Animation to send. Pass a file_id as String to send an animation that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get an animation from the Internet, or upload a new animation using multipart/form-data.

  • duration (int) – Duration of sent animation in seconds

  • width (int) – Animation width

  • height (int) – Animation height

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

  • caption (str) – Animation caption (may also be used when resending animation by file_id), 0-1024 characters after entities parsing

  • parse_mode (str) – Mode for parsing entities in the animation caption

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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.

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • timeout (int) – Timeout in seconds for the request.

  • caption_entities (list of tgram.types.MessageEntity) – List of special entities that appear in the caption, which can be specified instead of parse_mode

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • message_thread_id (int) – Identifier of a message thread, in which the video will be sent

  • has_spoiler (bool) – Pass True, if the animation should be sent as a spoiler

  • thumb (str or tgram.types.InputFile) – Deprecated. Use thumbnail instead

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Identifier of a business connection, in which the message will be sent

  • message_effect_id (str) – Unique identifier of the message effect

  • show_caption_above_media (bool) – Pass True, if the caption must be shown above the message media. Supported only for animation, photo and video messages.

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

send_audio(chat_id: int | str, audio: Path | bytes | str, business_connection_id: str = None, message_thread_id: int = None, caption: str = None, parse_mode: str = None, caption_entities: List[MessageEntity] = None, duration: int = None, performer: str = None, title: str = None, thumbnail: Path | bytes | str = None, disable_notification: bool = None, protect_content: bool = None, message_effect_id: str = None, reply_parameters: ReplyParameters = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply = None) Message

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 or .M4A 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 send_voice method instead.

Telegram documentation: https://core.telegram.org/bots/api#sendaudio

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

  • audio (str or tgram.types.InputFile) – 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. Audio must be in the .MP3 or .M4A format.

  • caption (str) – Audio caption, 0-1024 characters after entities parsing

  • duration (int) – Duration of the audio in seconds

  • performer (str) – Performer

  • title (str) – Track name

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply)

  • parse_mode (str) – Mode for parsing entities in the audio caption. See formatting options for more details.

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • timeout (int) – Timeout in seconds for the request.

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

  • caption_entities (list of tgram.types.MessageEntity) – A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • message_thread_id (int) – Identifier of a message thread, in which the message will be sent

  • thumb (str or tgram.types.InputFile) – Deprecated. Use thumbnail instead

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Unique identifier for the target business connection

  • message_effect_id (str) – Unique identifier for the message effect

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

send_chat_action(chat_id: int | str, action: str, business_connection_id: str = None, message_thread_id: int = None) bool

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

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

Telegram documentation: https://core.telegram.org/bots/api#sendchataction

Parameters:
  • chat_id (int or str) – Unique identifier for the target chat or username of the target channel

  • action (str) – Type of action to broadcast. Choose one, depending on what the user is about to receive: typing for text messages, upload_photo for photos, record_video or upload_video for videos, record_voice or upload_voice for voice notes, upload_document for general files, choose_sticker for stickers, find_location for location data, record_video_note or upload_video_note for video notes.

  • timeout (int) – Timeout in seconds for the request.

  • message_thread_id (int) – The thread to which the message will be sent(supergroups only)

  • business_connection_id (str) – Identifier of a business connection, in which the message will be sent

Returns:

Returns True on success.

Return type:

bool

send_contact(chat_id: int | str, phone_number: str, first_name: str, business_connection_id: str = None, message_thread_id: int = None, last_name: str = None, vcard: str = None, disable_notification: bool = None, protect_content: bool = None, message_effect_id: str = None, reply_parameters: ReplyParameters = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply = None) Message

Use this method to send phone contacts. On success, the sent Message is returned.

Telegram documentation: https://core.telegram.org/bots/api#sendcontact

Parameters:
  • chat_id (int or str) – Unique identifier for the target chat or username of the target channel

  • phone_number (str) – Contact’s phone number

  • first_name (str) – Contact’s first name

  • last_name (str) – Contact’s last name

  • vcard (str) – Additional data about the contact in the form of a vCard, 0-2048 bytes

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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) – Timeout in seconds for the request.

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if one of the specified replied-to messages is not found.

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • message_thread_id (int) – The thread to which the message will be sent

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Identifier of a business connection, in which the message will be sent

  • message_effect_id (str) – Unique identifier of the message effect

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

send_dice(chat_id: int | str, business_connection_id: str = None, message_thread_id: int = None, emoji: str = None, disable_notification: bool = None, protect_content: bool = None, message_effect_id: str = None, reply_parameters: ReplyParameters = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply = None) Message

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

Telegram documentation: https://core.telegram.org/bots/api#senddice

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

  • emoji (str) – Emoji on which the dice throw animation is based. Currently, must be one of “🎲”, “🎯”, “🏀”, “⚽”, “🎳”, or “🎰”. Dice can have values 1-6 for “🎲”, “🎯” and “🎳”, values 1-5 for “🏀” and “⚽”, and values 1-64 for “🎰”. Defaults to “🎲”

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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) – Timeout in seconds for the request.

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • protect_content (bool) – Protects the contents of the sent message from forwarding

  • message_thread_id (int) – The identifier of a message thread, unique within the chat to which the message with the thread identifier belongs

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Unique identifier for the target business connection

  • message_effect_id (str) – Unique identifier for the message effect

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

send_document(chat_id: int | str, document: Path | bytes | str, business_connection_id: str = None, message_thread_id: int = None, thumbnail: Path | bytes | str = None, caption: str = None, parse_mode: str = None, caption_entities: List[MessageEntity] = None, disable_content_type_detection: bool = None, disable_notification: bool = None, protect_content: bool = None, message_effect_id: str = None, reply_parameters: ReplyParameters = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply = None) Message

Use this method to send general files.

Telegram documentation: https://core.telegram.org/bots/api#senddocument

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

  • document (str or tgram.types.InputFile) – (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

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

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

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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.

  • parse_mode (str) – Mode for parsing entities in the document caption

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • timeout (int) – Timeout in seconds for the request.

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

  • caption_entities (list of tgram.types.MessageEntity) – A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • visible_file_name (str) – allows to define file name that will be visible in the Telegram instead of original file name

  • disable_content_type_detection (bool) – Disables automatic server-side content type detection for files uploaded using multipart/form-data

  • data (str) – function typo miss compatibility: do not use it

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • message_thread_id (int) – Identifier of a message thread, in which the message will be sent

  • thumb (str or tgram.types.InputFile) – Deprecated. Use thumbnail instead

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Unique identifier for the target business connection

  • message_effect_id (str) – Unique identifier for the message effect

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

send_game(chat_id: int, game_short_name: str, business_connection_id: str = None, message_thread_id: int = None, disable_notification: bool = None, protect_content: bool = None, message_effect_id: str = None, reply_parameters: ReplyParameters = None, reply_markup: InlineKeyboardMarkup = None) Message

Used to send the game.

Telegram documentation: https://core.telegram.org/bots/api#sendgame

Parameters:
  • chat_id (int or 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) – Sends the message silently. Users will receive a notification with no sound.

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • reply_markup (InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or ForceReply) – 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) – Timeout in seconds for waiting for a response from the bot.

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if one of the specified replied-to messages is not found.

  • protect_content (bool) – Pass True, if content of the message needs to be protected from being viewed by the bot.

  • message_thread_id (int) – Identifier of the thread to which the message will be sent.

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Identifier of the business connection.

  • message_effect_id (str) – Identifier of the message effect.

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

send_invoice(chat_id: int | str, title: str, description: str, payload: str, currency: str, prices: List[LabeledPrice], message_thread_id: int = None, provider_token: str = None, max_tip_amount: int = None, suggested_tip_amounts: List[int] = None, start_parameter: str = None, provider_data: str = None, photo_url: str = None, photo_size: int = None, photo_width: int = None, photo_height: int = None, need_name: bool = None, need_phone_number: bool = None, need_email: bool = None, need_shipping_address: bool = None, send_phone_number_to_provider: bool = None, send_email_to_provider: bool = None, is_flexible: bool = None, disable_notification: bool = None, protect_content: bool = None, message_effect_id: str = None, reply_parameters: ReplyParameters = None, reply_markup: InlineKeyboardMarkup = None) Message

Sends invoice.

Telegram documentation: https://core.telegram.org/bots/api#sendinvoice

Parameters:
  • chat_id (int or str) – Unique identifier for the target private chat

  • title (str) – Product name, 1-32 characters

  • description (str) – Product description, 1-255 characters

  • invoice_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; Pass None to omit the parameter to use “XTR” currency

  • currency (str) – Three-letter ISO 4217 currency code, see https://core.telegram.org/bots/payments#supported-currencies

  • prices (List[tgram.types.LabeledPrice]) – Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)

  • start_parameter (str) – Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter

  • photo_url (str) – 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 (int) – Photo size in bytes

  • photo_width (int) – Photo width

  • photo_height (int) – Photo height

  • need_name (bool) – Pass True, if you require the user’s full name to complete the order

  • need_phone_number (bool) – Pass True, if you require the user’s phone number to complete the order

  • need_email (bool) – Pass True, if you require the user’s email to complete the order

  • need_shipping_address (bool) – Pass True, if you require the user’s shipping address to complete the order

  • is_flexible (bool) – Pass True, if the final price depends on the shipping method

  • send_phone_number_to_provider (bool) – Pass True, if user’s phone number should be sent to provider

  • send_email_to_provider (bool) – Pass True, if user’s email address should be sent to provider

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • reply_markup (str) – A JSON-serialized object for an inline keyboard. If empty, one ‘Pay total price’ button will be shown. If not empty, the first button must be a Pay button

  • provider_data (str) – A JSON-serialized data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider.

  • timeout (int) – Timeout of a request, defaults to None

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • max_tip_amount (int) – The maximum accepted amount for tips in the smallest units of the currency

  • suggested_tip_amounts (list of int) – A JSON-serialized array of suggested amounts of tips in the smallest units of the currency. At most 4 suggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceed max_tip_amount.

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • message_thread_id (int) – The identifier of a message thread, in which the invoice message will be sent

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • message_effect_id (str) – The identifier of a message effect to be applied to the message

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

send_location(chat_id: int | str, latitude: float, longitude: float, business_connection_id: str = None, message_thread_id: int = None, horizontal_accuracy: float = None, live_period: int = None, heading: int = None, proximity_alert_radius: int = None, disable_notification: bool = None, protect_content: bool = None, message_effect_id: str = None, reply_parameters: ReplyParameters = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply = None) Message

Use this method to send point on the map. On success, the sent Message is returned.

Telegram documentation: https://core.telegram.org/bots/api#sendlocation

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

  • latitude (float) – Latitude of the location

  • longitude (float) – Longitude of the location

  • live_period (int) – Period in seconds during which the location will be updated (see Live Locations, should be between 60 and 86400, or 0x7FFFFFFF for live locations that can be edited indefinitely.

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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.

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • timeout (int) – Timeout in seconds for the request.

  • horizontal_accuracy (float) – The radius of uncertainty for the location, measured in meters; 0-1500

  • heading (int) – For live locations, a direction in which the user is moving, in degrees. Must be between 1 and 360 if specified.

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

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • message_thread_id (int) – Identifier of a message thread, in which the message will be sent

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Identifier of a business connection, in which the message will be sent

  • message_effect_id (str) – Unique identifier of the message effect

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

send_media_from_file_id(chat_id: int | str, file_id: str, business_connection_id: str = None, message_thread_id: int = None, caption: str = None, parse_mode: str = None, caption_entities: List[MessageEntity] = None, show_caption_above_media: bool = None, disable_notification: bool = None, protect_content: bool = None, message_effect_id: str = None, reply_parameters: ReplyParameters = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply = None) Message
send_media_group(chat_id: int | str, media: List[InputMediaAudio | InputMediaDocument | InputMediaPhoto | InputMediaVideo], business_connection_id: str = None, message_thread_id: int = None, disable_notification: bool = None, protect_content: bool = None, message_effect_id: str = None, reply_parameters: ReplyParameters = None) List[Message]

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

Telegram documentation: https://core.telegram.org/bots/api#sendmediagroup

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

  • media (list of tgram.types.InputMedia) – A JSON-serialized array describing messages to be sent, must include 2-10 items

  • disable_notification (bool) – Sends the messages silently. Users will receive a notification with no sound.

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • timeout (int) – Timeout in seconds for the request.

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • message_thread_id (int) – Identifier of a message thread, in which the messages will be sent

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Identifier of a business connection, in which the message will be sent

  • message_effect_id (str) – Unique identifier of the message effect

Returns:

On success, an array of Messages that were sent is returned.

Return type:

List[types.Message]

send_message(chat_id: int | str, text: str, business_connection_id: str = None, message_thread_id: int = None, parse_mode: str = None, entities: List[MessageEntity] = None, link_preview_options: LinkPreviewOptions = None, disable_notification: bool = None, protect_content: bool = None, message_effect_id: str = None, reply_parameters: ReplyParameters = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply = None) Message

Use this method to send text messages.

Warning: Do not send more than about 4096 characters each message, otherwise you’ll risk an HTTP 414 error. If you must send more than 4096 characters, use the split_string or smart_split function in util.py.

Telegram documentation: https://core.telegram.org/bots/api#sendmessage

Parameters:
  • chat_id (int or 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

  • parse_mode (str) – Mode for parsing entities in the message text.

  • entities (Array of tgram.types.MessageEntity) – List of special entities that appear in message text, which can be specified instead of parse_mode

  • disable_web_page_preview (bool) – Deprecated - Use link_preview_options instead.

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • protect_content (bool) – If True, the message content will be hidden for all users except for the target user

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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) – Timeout in seconds for the request.

  • message_thread_id (int) – Unique identifier for the target message thread (topic) of the forum; for forum supergroups only

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • link_preview_options (tgram.types.LinkPreviewOptions) – Options for previewing links.

  • business_connection_id (str) – Unique identifier for the target business connection

  • message_effect_id (str) – Unique identifier for the message effect

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

send_paid_media(chat_id: int | str, star_count: int, media: List[InputPaidMediaPhoto | InputPaidMediaVideo], payload: str = None, caption: str = None, parse_mode: str = None, caption_entities: List[MessageEntity] = None, show_caption_above_media: bool = None, disable_notification: bool = None, protect_content: bool = None, reply_parameters: ReplyParameters = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply = None, business_connection_id: str = None) Message

Use this method to send paid media to channel chats. On success, the sent Message is returned.

Telegram documentation: https://core.telegram.org/bots/api#sendpaidmedia

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

  • star_count (int) – The number of Telegram Stars that must be paid to buy access to the media

  • media (list of tgram.types.InputPaidMedia) – A JSON-serialized array describing the media to be sent; up to 10 items

  • caption (str) – Media caption, 0-1024 characters after entities parsing

  • payload (str) – Bot-defined paid media payload, 0-128 bytes. This will not be displayed to the user, use it for your internal processes.

  • parse_mode (str) – Mode for parsing entities in the media caption

  • caption_entities (list of tgram.types.MessageEntity) – List of special entities that appear in the caption, which can be specified instead of parse_mode

  • show_caption_above_media (bool) – Pass True, if the caption must be shown above the message media

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • protect_content (str) – Protects the contents of the sent message from forwarding and saving

  • reply_parameters (tgram.types.ReplyParameters) – Description of the message to reply to

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove a reply keyboard or to force a reply from the user

  • business_connection_id – Unique identifier of the business connection on behalf of which the message will be sent

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

send_photo(chat_id: int | str, photo: Path | bytes | str, business_connection_id: str = None, message_thread_id: int = None, caption: str = None, parse_mode: str = None, caption_entities: List[MessageEntity] = None, show_caption_above_media: bool = None, has_spoiler: bool = None, disable_notification: bool = None, protect_content: bool = None, message_effect_id: str = None, reply_parameters: ReplyParameters = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply = None) Message

Use this method to send photos. On success, the sent Message is returned.

Telegram documentation: https://core.telegram.org/bots/api#sendphoto

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

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

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

  • parse_mode (str) – Mode for parsing entities in the photo caption.

  • caption_entities (list of tgram.types.MessageEntity) – A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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) – Timeout in seconds for the request.

  • message_thread_id (int) – Identifier of a message thread, in which the message will be sent

  • has_spoiler (bool) – Pass True, if the photo should be sent as a spoiler

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Unique identifier for the target business connection

  • message_effect_id (str) – Unique identifier for the message effect

  • show_caption_above_media (bool) – Pass True, if the caption must be shown above the message media. Supported only for animation, photo and video messages.

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

send_poll(chat_id: int | str, question: str, options: List[InputPollOption], business_connection_id: str = None, message_thread_id: int = None, question_parse_mode: str = None, question_entities: List[MessageEntity] = None, is_anonymous: bool = None, type: str = None, allows_multiple_answers: bool = None, correct_option_id: int = None, explanation: str = None, explanation_parse_mode: str = None, explanation_entities: List[MessageEntity] = None, open_period: int = None, close_date: int = None, is_closed: bool = None, disable_notification: bool = None, protect_content: bool = None, message_effect_id: str = None, reply_parameters: ReplyParameters = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply = None) Message

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

Telegram documentation: https://core.telegram.org/bots/api#sendpoll

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel

  • question (str) – Poll question, 1-300 characters

  • options (list of InputPollOption) – A JSON-serialized list of 2-10 answer options

  • is_anonymous (bool) – True, if the poll needs to be anonymous, defaults to True

  • type (str) – Poll type, “quiz” or “regular”, defaults to “regular”

  • allows_multiple_answers (bool) – True, if the poll allows multiple answers, ignored for polls in quiz mode, defaults to False

  • correct_option_id (int) – 0-based identifier of the correct answer option. Available only for polls in quiz mode, defaults to None

  • explanation (str) – Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters with at most 2 line feeds after entities parsing

  • explanation_parse_mode (str) – Mode for parsing entities in the explanation. See formatting options for more details.

  • open_period (int) – Amount of time in seconds the poll will be active after creation, 5-600. Can’t be used together with close_date.

  • close_date (int | datetime) – Point in time (Unix timestamp) when the poll will be automatically closed.

  • is_closed (bool) – Pass True, if the poll needs to be immediately closed. This can be useful for poll preview.

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the poll allows multiple options to be voted simultaneously.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply) – 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) – Timeout in seconds for waiting for a response from the user.

  • explanation_entities (list of MessageEntity) – A JSON-serialized list of special entities that appear in the explanation, which can be specified instead of parse_mode

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • message_thread_id (int) – The identifier of a message thread, in which the poll will be sent

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Identifier of the business connection to send the message through

  • question_parse_mode (str) – Mode for parsing entities in the question. See formatting options for more details. Currently, only custom emoji entities are allowed

  • question_entities (list of MessageEntity) – A JSON-serialized list of special entities that appear in the poll question. It can be specified instead of question_parse_mode

  • message_effect_id (str) – Identifier of the message effect to apply to the sent message

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

send_sticker(chat_id: int | str, sticker: Path | bytes | str, business_connection_id: str = None, message_thread_id: int = None, emoji: str = None, disable_notification: bool = None, protect_content: bool = None, message_effect_id: str = None, reply_parameters: ReplyParameters = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply = None) Message

Use this method to send static .WEBP, animated .TGS, or video .WEBM stickers. On success, the sent Message is returned.

Telegram documentation: https://core.telegram.org/bots/api#sendsticker

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

  • sticker (str or tgram.types.InputFile) – 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.

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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.

  • disable_notification (bool) – to disable the notification

  • timeout (int) – Timeout in seconds for the request.

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • data (str) – function typo miss compatibility: do not use it

  • message_thread_id (int) – Identifier of a message thread, in which the message will be sent

  • emoji (str) – Emoji associated with the sticker; only for just uploaded stickers

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Unique identifier for the target business connection

  • message_effect_id (str) – Unique identifier for the message effect

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

send_venue(chat_id: int | str, latitude: float, longitude: float, title: str, address: str, business_connection_id: str = None, message_thread_id: int = None, foursquare_id: str = None, foursquare_type: str = None, google_place_id: str = None, google_place_type: str = None, disable_notification: bool = None, protect_content: bool = None, message_effect_id: str = None, reply_parameters: ReplyParameters = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply = None) Message

Use this method to send information about a venue. On success, the sent Message is returned.

Telegram documentation: https://core.telegram.org/bots/api#sendvenue

Parameters:
  • chat_id (int or str) – Unique identifier for the target chat or username of the target channel

  • latitude (float) – Latitude of the venue

  • longitude (float) – Longitude of the venue

  • title (str) – Name of the venue

  • address (str) – Address of the venue

  • foursquare_id (str) – Foursquare identifier of the venue

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

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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) – Timeout in seconds for the request.

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if one of the specified replied-to messages is not found.

  • google_place_id (str) – Google Places identifier of the venue

  • google_place_type (str) – Google Places type of the venue.

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • message_thread_id (int) – The thread to which the message will be sent

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Identifier of a business connection, in which the message will be sent

  • message_effect_id (str) – Unique identifier of the message effect

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

send_video(chat_id: int | str, video: Path | bytes | str, business_connection_id: str = None, message_thread_id: int = None, duration: int = None, width: int = None, height: int = None, thumbnail: Path | bytes | str = None, caption: str = None, parse_mode: str = None, caption_entities: List[MessageEntity] = None, show_caption_above_media: bool = None, has_spoiler: bool = None, supports_streaming: bool = None, disable_notification: bool = None, protect_content: bool = None, message_effect_id: str = None, reply_parameters: ReplyParameters = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply = None) Message

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

Telegram documentation: https://core.telegram.org/bots/api#sendvideo

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

  • video (str or tgram.types.InputFile) – Video to send. You can either pass a file_id as String to resend a video that is already on the Telegram servers, or upload a new video file using multipart/form-data.

  • duration (int) – Duration of sent video in seconds

  • width (int) – Video width

  • height (int) – Video height

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

  • caption (str) – Video caption (may also be used when resending videos by file_id), 0-1024 characters after entities parsing

  • parse_mode (str) – Mode for parsing entities in the video caption

  • caption_entities (list of tgram.types.MessageEntity) – List of special entities that appear in the caption, which can be specified instead of parse_mode

  • supports_streaming (bool) – Pass True, if the uploaded video is suitable for streaming

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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) – Timeout in seconds for the request.

  • data (str) – function typo miss compatibility: do not use it

  • message_thread_id (int) – Identifier of a message thread, in which the video will be sent

  • has_spoiler (bool) – Pass True, if the video should be sent as a spoiler

  • thumb (str or tgram.types.InputFile) – Deprecated. Use thumbnail instead

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Identifier of a business connection, in which the message will be sent

  • message_effect_id (str) – Unique identifier of the message effect

  • show_caption_above_media (bool) – Pass True, if the caption must be shown above the message media. Supported only for animation, photo and video messages.

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

send_video_note(chat_id: int | str, video_note: Path | bytes | str, business_connection_id: str = None, message_thread_id: int = None, duration: int = None, length: int = None, thumbnail: Path | bytes | str = None, disable_notification: bool = None, protect_content: bool = None, message_effect_id: str = None, reply_parameters: ReplyParameters = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply = None) Message

As of v.4.0, Telegram clients support rounded square MPEG4 videos of up to 1 minute long. Use this method to send video messages. On success, the sent Message is returned.

Telegram documentation: https://core.telegram.org/bots/api#sendvideonote

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

  • data (str or tgram.types.InputFile) – 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. Sending video notes by a URL is currently unsupported

  • duration (int) – Duration of sent video in seconds

  • length (int) – Video width and height, i.e. diameter of the video message

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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.

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • timeout (int) – Timeout in seconds for the request.

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

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • message_thread_id (int) – Identifier of a message thread, in which the video note will be sent

  • thumb (str or tgram.types.InputFile) – Deprecated. Use thumbnail instead

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Identifier of a business connection, in which the message will be sent

  • message_effect_id (str) – Unique identifier of the message effect

Returns:

On success, the sent Message is returned.

Return type:

tgram.types.Message

send_voice(chat_id: int | str, voice: Path | bytes | str, business_connection_id: str = None, message_thread_id: int = None, caption: str = None, parse_mode: str = None, caption_entities: List[MessageEntity] = None, duration: int = None, disable_notification: bool = None, protect_content: bool = None, message_effect_id: str = None, reply_parameters: ReplyParameters = None, reply_markup: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply = None) Message

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, or in .MP3 format, or in .M4A format (other formats may be sent as Audio or Document). On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.

Telegram documentation: https://core.telegram.org/bots/api#sendvoice

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

  • voice (str or tgram.types.InputFile) – Audio 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.

  • caption (str) – Voice message caption, 0-1024 characters after entities parsing

  • duration (int) – Duration of the voice message in seconds

  • reply_to_message_id (int) – Deprecated - Use reply_parameters instead. If the message is a reply, ID of the original message

  • reply_markup (tgram.types.InlineKeyboardMarkup or tgram.types.ReplyKeyboardMarkup or tgram.types.ReplyKeyboardRemove or tgram.types.ForceReply) – 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.

  • parse_mode (str) – Mode for parsing entities in the voice message caption. See formatting options for more details.

  • disable_notification (bool) – Sends the message silently. Users will receive a notification with no sound.

  • timeout (int) – Timeout in seconds for the request.

  • caption_entities (list of tgram.types.MessageEntity) – A JSON-serialized list of special entities that appear in the caption, which can be specified instead of parse_mode

  • allow_sending_without_reply (bool) – Deprecated - Use reply_parameters instead. Pass True, if the message should be sent even if the specified replied-to message is not found

  • protect_content (bool) – Protects the contents of the sent message from forwarding and saving

  • message_thread_id (int) – Identifier of a message thread, in which the message will be sent

  • reply_parameters (tgram.types.ReplyParameters) – Reply parameters.

  • business_connection_id (str) – Unique identifier for the target business connection

  • message_effect_id (str) – Unique identifier for the message effect

Returns:

On success, the sent Message is returned.

set_chat_administrator_custom_title(chat_id: int | str, user_id: int, custom_title: str) bool

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

Telegram documentation: https://core.telegram.org/bots/api#setchatadministratorcustomtitle

Parameters:
  • chat_id (int or 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

  • custom_title (str) – New custom title for the administrator; 0-16 characters, emoji are not allowed

Returns:

True on success.

Return type:

bool

set_chat_description(chat_id: int | str, description: str = None) bool

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.

Telegram documentation: https://core.telegram.org/bots/api#setchatdescription

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

  • description (str) – Str: New chat description, 0-255 characters

Returns:

True on success.

Return type:

bool

set_chat_menu_button(chat_id: int = None, menu_button: MenuButton = None) bool

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

Telegram documentation: https://core.telegram.org/bots/api#setchatmenubutton

Parameters:
  • chat_id (int or str) – Unique identifier for the target private chat. If not specified, default bot’s menu button will be changed.

  • menu_button (tgram.types.MenuButton) – A JSON-serialized object for the new bot’s menu button. Defaults to MenuButtonDefault

Returns:

True on success.

Return type:

bool

set_chat_permissions(chat_id: int | str, permissions: ChatPermissions, use_independent_chat_permissions: bool = None) bool

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

Telegram documentation: https://core.telegram.org/bots/api#setchatpermissions

Parameters:
  • chat_id (int or str) – Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)

  • permissions (tgram.types..ChatPermissions) – New default chat permissions

  • use_independent_chat_permissions (bool) – Pass True if chat permissions are set independently. Otherwise, the can_send_other_messages and can_add_web_page_previews permissions will imply the can_send_messages, can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, and can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission.

Returns:

True on success

Return type:

bool

set_chat_photo(chat_id: int | str, photo: Path | bytes | str) bool

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. Returns True on success. Note: In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’ setting is off in the target group.

Telegram documentation: https://core.telegram.org/bots/api#setchatphoto

Parameters:
  • chat_id (int or str) – Int or Str: Unique identifier for the target chat or username of the target channel (in the format @channelusername)

  • photo (typing.Union[file_like, str]) – InputFile: New chat photo, uploaded using multipart/form-data

Returns:

True on success.

Return type:

bool

set_chat_sticker_set(chat_id: int | str, sticker_set_name: str) bool

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 administrator rights. Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#setchatstickerset

Parameters:
  • chat_id (int or 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

Returns:

StickerSet object

Return type:

tgram.types.StickerSet

set_chat_title(chat_id: int | str, title: str) bool

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. Returns True on success. Note: In regular groups (non-supergroups), this method will only work if the ‘All Members Are Admins’ setting is off in the target group.

Telegram documentation: https://core.telegram.org/bots/api#setchattitle

Parameters:
  • chat_id (int or 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

Returns:

True on success.

Return type:

bool

set_custom_emoji_sticker_set_thumbnail(name: str, custom_emoji_id: str = None) bool

Use this method to set the thumbnail of a custom emoji sticker set. Returns True on success.

Parameters:
  • name (str) – Sticker set name

  • custom_emoji_id (str) – Custom emoji identifier of a sticker from the sticker set; pass an empty string to drop the thumbnail and use the first sticker as the thumbnail.

Returns:

Returns True on success.

Return type:

bool

set_game_score(user_id: int, score: int, force: bool = None, disable_edit_message: bool = None, chat_id: int = None, message_id: int = None, inline_message_id: str = None) Message | bool
set_message_reaction(chat_id: int | str, message_id: int, reaction: List[ReactionTypeCustomEmoji | ReactionTypeEmoji | ReactionTypePaid] = None, is_big: bool = None) bool

Use this method to change the chosen reactions on a message. Service messages can’t be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#setmessagereaction

Parameters:
  • chat_id (int or str) – Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername)

  • message_id (int) – Identifier of the message to set reaction to

  • reaction (list of tgram.types.ReactionType) – New list of reaction types to set on the message. Currently, as non-premium users, bots can set up to one reaction per message. A custom emoji reaction can be used if it is either already present on the message or explicitly allowed by chat administrators.

  • is_big (bool) – Pass True to set the reaction with a big animation

Returns:

bool

set_my_commands(commands: List[BotCommand], scope: BotCommandScope = None, language_code: str = None) bool

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

Telegram documentation: https://core.telegram.org/bots/api#setmycommands

Parameters:
  • commands (list of tgram.types.BotCommand) – List of BotCommand. At most 100 commands can be specified.

  • scope (tgram.types.BotCommandScope) – The scope of users for which the commands are relevant. Defaults to BotCommandScopeDefault.

  • language_code (str) – A two-letter ISO 639-1 language code. If empty, commands will be applied to all users from the given scope, for whose language there are no dedicated commands

Returns:

True on success.

Return type:

bool

set_my_default_administrator_rights(rights: ChatAdministratorRights = None, for_channels: bool = None) bool

Use this method to change the default administrator rights requested by the bot when it’s added as an administrator to groups or channels. These rights will be suggested to users, but they are are free to modify the list before adding the bot. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#setmydefaultadministratorrights

Parameters:
  • rights (tgram.types.ChatAdministratorRights) – A JSON-serialized object describing new default administrator rights. If not specified, the default administrator rights will be cleared.

  • for_channels (bool) – Pass True to change the default administrator rights of the bot in channels. Otherwise, the default administrator rights of the bot for groups and supergroups will be changed.

Returns:

True on success.

Return type:

bool

set_my_description(description: str = None, language_code: str = None) bool

Use this method to change the bot’s description, which is shown in the chat with the bot if the chat is empty. Returns True on success.

Parameters:
  • description (str) – New bot description; 0-512 characters. Pass an empty string to remove the dedicated description for the given language.

  • language_code (str) – A two-letter ISO 639-1 language code. If empty, the description will be applied to all users for whose language there is no dedicated description.

Returns:

True on success.

set_my_name(name: str = None, language_code: str = None) bool

Use this method to change the bot’s name. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#setmyname

Parameters:
  • name (str) – Optional. New bot name; 0-64 characters. Pass an empty string to remove the dedicated name for the given language.

  • language_code (str) – Optional. A two-letter ISO 639-1 language code. If empty, the name will be shown to all users for whose language there is no dedicated name.

Returns:

True on success.

set_my_short_description(short_description: str = None, language_code: str = None) bool

Use this method to change the bot’s short description, which is shown on the bot’s profile page and is sent together with the link when users share the bot. Returns True on success.

Parameters:
  • short_description (str) – New short description for the bot; 0-120 characters. Pass an empty string to remove the dedicated short description for the given language.

  • language_code (str) – A two-letter ISO 639-1 language code. If empty, the short description will be applied to all users for whose language there is no dedicated short description.

Returns:

True on success.

set_passport_data_errors(user_id: int, errors: List[PassportElementError]) bool
set_sticker_emoji_list(sticker: str, emoji_list: List[str]) bool

Use this method to set the emoji list of a sticker set. Returns True on success.

Parameters:
  • name (str) – Sticker set name

  • emoji_list (list of str) – List of emojis

Returns:

Returns True on success.

Return type:

bool

set_sticker_keywords(sticker: str, keywords: List[str] = None) bool

Use this method to change search keywords assigned to a regular or custom emoji sticker. The sticker must belong to a sticker set created by the bot. Returns True on success.

Parameters:
  • sticker (str) – File identifier of the sticker.

  • keywords (list of str) – A JSON-serialized list of 0-20 search keywords for the sticker with total length of up to 64 characters

Returns:

On success, True is returned.

Return type:

bool

set_sticker_mask_position(sticker: str, mask_position: MaskPosition = None) bool

Use this method to change the mask position of a mask sticker. The sticker must belong to a sticker set that was created by the bot. Returns True on success.

Parameters:
  • sticker (str) – File identifier of the sticker.

  • mask_position (tgram.types.MaskPosition) – A JSON-serialized object for position where the mask should be placed on faces.

Returns:

Returns True on success.

Return type:

bool

set_sticker_position_in_set(sticker: str, position: int) bool

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

Telegram documentation: https://core.telegram.org/bots/api#setstickerpositioninset

Parameters:
  • sticker (str) – File identifier of the sticker

  • position (int) – New sticker position in the set, zero-based

Returns:

On success, True is returned.

Return type:

bool

set_sticker_set_thumbnail(name: str, user_id: int, format: str, thumbnail: Path | bytes | str = None) bool

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

Telegram documentation: https://core.telegram.org/bots/api#setstickersetthumbnail

Parameters:
  • name (str) – Sticker set name

  • user_id (int) – User identifier

  • thumbnail (filelike object) – A .WEBP or .PNG image with the thumbnail, must be up to 128 kilobytes in size and have a width and height of exactly 100px, or a .TGS animation with a thumbnail up to 32 kilobytes in size (see https://core.telegram.org/stickers#animated-sticker-requirements for animated sticker technical requirements), or a WEBM video with the thumbnail up to 32 kilobytes in size; see https://core.telegram.org/stickers#video-sticker-requirements for video sticker technical requirements. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data. More information on Sending Files ». Animated and video sticker set thumbnails can’t be uploaded via HTTP URL. If omitted, then the thumbnail is dropped and the first sticker is used as the thumbnail.

Returns:

On success, True is returned.

Return type:

bool

set_sticker_set_title(name: str, title: str) bool

Use this method to set the title of a created sticker set. Returns True on success.

Parameters:
  • name (str) – Sticker set name

  • title (str) – New sticker set title

Returns:

Returns True on success.

Return type:

bool

set_webhook(url: str, certificate: Path | bytes | str = None, ip_address: str = None, max_connections: int = None, allowed_updates: List[str] = None, drop_pending_updates: bool = None, secret_token: str = None) bool

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

If you’d like to make sure that the webhook was set by you, you can specify secret data in the parameter secret_token. If specified, the request will contain a header “X-Telegram-Bot-Api-Secret-Token” with the secret token as content.

Telegram Documentation: https://core.telegram.org/bots/api#setwebhook

Parameters:
  • url (str, optional) – HTTPS URL to send updates to. Use an empty string to remove webhook integration, defaults to None

  • certificate (str, optional) – Upload your public key certificate so that the root certificate in use can be checked, defaults to None

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

  • allowed_updates (list, optional) –

    A JSON-serialized list of the update types you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all update types except chat_member (default). If not specified, the previous setting will be used.

    Please note that this parameter doesn’t affect updates created before the call to the setWebhook, so unwanted updates may be received for a short period of time. Defaults to None

  • ip_address (str, optional) – The fixed IP address which will be used to send webhook requests instead of the IP address resolved through DNS, defaults to None

  • drop_pending_updates (bool, optional) – Pass True to drop all pending updates, defaults to None

  • timeout (int, optional) – Timeout of a request, defaults to None

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

Returns:

True on success.

Return type:

bool if the request was successful.

stop() Literal[True]

Use this method to stop getting and handling new updates.

Return type:

bool

stop_message_live_location(business_connection_id: str = None, chat_id: int | str = None, message_id: int = None, inline_message_id: str = None, reply_markup: InlineKeyboardMarkup = None) Message | bool
stop_poll(chat_id: int | str, message_id: int, business_connection_id: str = None, reply_markup: InlineKeyboardMarkup = None) Poll

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

Telegram documentation: https://core.telegram.org/bots/api#stoppoll

Parameters:
  • chat_id (int | str) – Unique identifier for the target chat or username of the target channel

  • message_id (int) – Identifier of the original message with the poll

  • reply_markup (InlineKeyboardMarkup) – A JSON-serialized object for a new message markup.

  • business_connection_id (str) – Identifier of the business connection to send the message through

Returns:

On success, the stopped Poll is returned.

Return type:

tgram.types.Poll

unban_chat_member(chat_id: int | str, user_id: int, only_if_banned: bool = None) bool

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

Telegram documentation: https://core.telegram.org/bots/api#unbanchatmember

Parameters:
  • chat_id (int or str) – Unique identifier for the target group or username of the target supergroup or channel (in the format @username)

  • user_id (int) – Unique identifier of the target user

  • only_if_banned (bool) – Do nothing if the user is not banned

Returns:

True on success

Return type:

bool

unban_chat_sender_chat(chat_id: int | str, sender_chat_id: int) bool

Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an administrator for this to work and must have the appropriate administrator rights. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#unbanchatsenderchat

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

  • sender_chat_id (int or str) – Unique identifier of the target sender chat.

Returns:

True on success.

Return type:

bool

unhide_general_forum_topic(chat_id: int | str) bool

Use this method to unhide the ‘General’ topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#unhidegeneralforumtopic

Parameters:

chat_id (int or str) – Unique identifier for the target chat or username of the target channel (in the format @channelusername)

unpin_all_chat_messages(chat_id: int | str) bool

Use this method to unpin a all pinned messages in a supergroup chat. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#unpinallchatmessages

Parameters:

chat_id (int or str) – Int or Str: Unique identifier for the target chat or username of the target channel (in the format @channelusername)

Returns:

True on success.

Return type:

bool

unpin_all_forum_topic_messages(chat_id: int | str, message_thread_id: int) bool

Use this method to clear the list of pinned messages in a forum topic. The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#unpinallforumtopicmessages

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

  • message_thread_id (int) – Identifier of the topic

Returns:

On success, True is returned.

Return type:

bool

unpin_all_general_forum_topic_messages(chat_id: int | str) bool

Use this method to clear the list of pinned messages in a General forum topic. The bot must be an administrator in the chat for this to work and must have the can_pin_messages administrator right in the supergroup. Returns True on success.

Telegram documentation: https://core.telegram.org/bots/api#unpinAllGeneralForumTopicMessages

Parameters:

chat_id (int | str) – Unique identifier for the target chat or username of chat

Returns:

On success, True is returned.

Return type:

bool

unpin_chat_message(chat_id: int | str, message_id: int = None, business_connection_id: str = None) bool

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

Telegram documentation: https://core.telegram.org/bots/api#unpinchatmessage

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

  • message_id (int) – Int: Identifier of a message to unpin

  • business_connection_id (str) – Unique identifier of the business connection on behalf of which the message will be pinned

Returns:

True on success.

Return type:

bool

unrestrict_chat_member(chat_id: int | str, user_id: int, use_independent_chat_permissions: bool = None) bool

Use this method to unrestrict 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. Telegram documentation: https://core.telegram.org/bots/api#restrictchatmember

Parameters:
  • chat_id (int or str) – Unique identifier for the target group or username of the target supergroup or channel (in the format @channelusername)

  • user_id (int) – Unique identifier of the target user

  • use_independent_chat_permissions (bool, optional) – Pass True if chat permissions are set independently. Otherwise, the can_send_other_messages and can_add_web_page_previews permissions will imply the can_send_messages, can_send_audios, can_send_documents, can_send_photos, can_send_videos, can_send_video_notes, and can_send_voice_notes permissions; the can_send_polls permission will imply the can_send_messages permission.

Returns:

True on success

Return type:

bool

upload_sticker_file(user_id: int, sticker: Path | bytes | str, sticker_format: str) File

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

Telegram documentation: https://core.telegram.org/bots/api#uploadstickerfile

Parameters:
  • user_id (int) – User identifier of sticker set owner

  • png_sticker (filelike object) – DEPRECATED: 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.

  • sticker (tgram.types.InputFile) – A file with the sticker in .WEBP, .PNG, .TGS, or .WEBM format. See https://core.telegram.org/stickers for technical requirements. More information on Sending Files »

  • sticker_format (str) – One of “static”, “animated”, “video”.

Returns:

On success, the sent file is returned.

Return type:

tgram.types.File