Module contents

Modules that provide various util

class spotted.utils.EventInfo(bot, ctx, update=None, message=None, query=None)[source]

Bases: object

Class that contains all the relevant information related to an event

async answer_callback_query(text=None)[source]

Calls the answer_callback_query method of the bot class, while also handling the exception

Parameters:

text (str | None, default: None) – Text to show to the user

property args: list[str]

Return the args of the message that caused the update. If the update was caused by a callback, the callback data is splitted by ‘,’ and returned

property bot: Bot

Instance of the telegram bot

property bot_data: dict

Data related to the bot. Is not persistent between restarts

property callback_key: str

Return the args of the message that caused the update. If the update was caused by a callback, the callback data is splitted by ‘,’ and returned

property chat_id: int | None

Id of the chat where the event happened

property chat_type: str | None

Type of the chat where the event happened

property context: CallbackContext

Context generated by some event

async edit_inline_keyboard(chat_id=None, message_id=None, new_keyboard=None)[source]

Generic wrapper used to edit the inline keyboard of a message with the telegram bot, while also handling the exception

Parameters:
  • chat_id (int | None, default: None) – id of the chat the message to edit belongs to or the current chat if None

  • message_id (int | None, default: None) – id of the message to edit. It is the current message if left None

  • new_keyboard (InlineKeyboardMarkup | None, default: None) – new inline keyboard to assign to the message

property forward_from_chat_id: int | None

Id of the original chat the message has been forwarded from

property forward_from_id: int | None

Id of the original message that has been forwarded

classmethod from_callback(update, ctx)[source]

Instance of EventInfo created by a callback update

Parameters:
  • update (Update) – update event

  • context – context passed by the handler

Returns:

EventInfo – instance of the class

classmethod from_job(ctx)[source]

Instance of EventInfo created by a job update

Parameters:

context – context passed by the handler

Returns:

EventInfo – instance of the class

classmethod from_message(update, ctx)[source]

Instance of EventInfo created by a message update

Parameters:
  • update (Update) – update event

  • context – context passed by the handler

Returns:

EventInfo – instance of the class

property inline_keyboard: InlineKeyboardMarkup | None

InlineKeyboard attached to the message

property is_forward_from_channel: bool

Whether the message has been forwarded from a channel

property is_forward_from_chat: bool

Whether the message has been forwarded from a chat

property is_forward_from_user: bool

Whether the message has been forwarded from a user

property is_forwarded_post: bool

Whether the message is in fact a forwarded post from the channel to the group

property is_private_chat: bool | None

Whether the chat is private or not

property is_valid_message_type: bool

Whether or not the type of the message is supported

property message: Message | None

Message that caused the update

property message_id: int | None

Id of the message that caused the update

property query_data: str | None

Data associated with the query that caused the update

property query_id: str | None

Id of the query that caused the update

property reply_markup: InlineKeyboardMarkup | None

Reply_markup of the message that caused the update

async send_post_to_admins()[source]

Sends the post to the admin group, so it can be approved

Returns:

bool – whether or not the operation was successful

async send_post_to_channel(user_id)[source]

Sends the post to the channel, so it can be enjoyed by the users (and voted, if comments are disabled)

async send_post_to_channel_group()[source]

If comments are enabled, sends the post to the group associated to the channel, allowing the author to be credited and other users to report the spot or follow it.

async show_admins_votes(pending_post, reason=None)[source]

After a post is been approved or rejected, shows the admins that approved or rejected it and edit the message to show the admin’s votes

Parameters:
  • pending_post (PendingPost) – post to show the admin’s votes for

  • reason (str | None, default: None) – reason for the rejection, currently used on autoreply

property text: str | None

Text of the message that caused the update

property update: Update | None

Update generated by some event

property user_data: dict | None

Data related to the user. Is not persistent between restarts

property user_id: int | None

Id of the user that caused the update

property user_name: str | None

Name of the user that caused the update

property user_username: str | None

Username of the user that caused the update

spotted.utils.conv_cancel(family)[source]

Creates a function used to handle the /cancel command in the conversation. Invoking /cancel will exit the conversation immediately

Parameters:

family (str) – family of the command

Returns:

Callable[[Any, Any], Coroutine[Any, Any, int]] – function used to handle the /cancel command

spotted.utils.conv_fail(family)[source]

Creates a function used to handle any error in the conversation

Parameters:

family (str) – family of the command

Returns:

Callable[[tuple[Update, CallbackContext] | EventInfo, str, int | None], Coroutine[Any, Any, int | None]] – function used to handle the error

spotted.utils.get_approve_kb(pending_post=None, approve=-1, reject=-1, credited_username=None)[source]

Generates the InlineKeyboard for the pending post. If the pending post is None, the keyboard will be generated with 0 votes. Otherwise, the keyboard will be generated with the correct number of votes. To avoid unnecessary queries, the number of votes can be passed as an argument and will be assumed to be correct.

Parameters:
  • pending_post (PendingPost | None, default: None) – existing pending post to which the keyboard is attached

  • approve (int, default: -1) – number of approve votes known in advance

  • reject (int, default: -1) – number of reject votes known in advance

  • credited_username (str | None, default: None) – username of the user who credited the post if it was credited

Returns:

InlineKeyboardMarkup – new inline keyboard

spotted.utils.get_confirm_kb()[source]

Generates the InlineKeyboard to confirm the creation of the post

Returns:

InlineKeyboardMarkup – new inline keyboard

spotted.utils.get_paused_kb(page, items_per_page)[source]

Generates the InlineKeyboard for the paused post

Parameters:

page (int) – page of the autoreplies

Returns:

InlineKeyboardMarkup – autoreplies keyboard append with resume button

spotted.utils.get_preview_kb()[source]

Generates the InlineKeyboard to choose if the post should be previewed or not

Returns:

InlineKeyboardMarkup – new inline keyboard

spotted.utils.get_published_post_kb()[source]

Generates the InlineKeyboard for the published post adding the report button if needed

Returns:

InlineKeyboardMarkup | None – new inline keyboard

spotted.utils.get_settings_kb()[source]

Generates the InlineKeyboard to edit the settings

Returns:

InlineKeyboardMarkup – new inline keyboard

spotted.utils.get_user_by_id_or_index(user_id_or_idx, users_list)[source]

Get a user either by their user_id or by their index in a given list of users. The index is specified by prefixing the number with a ‘#’ character. For example, ‘#0’ would refer to the first user in the list. On the other hand, if the input is a number without the ‘#’ prefix, it will be treated as a user_id.

Parameters:
  • user_id_or_idx (str) – The user_id or index to look for. If it starts with ‘#’, it will be treated as an index.

  • users_list (list[User]) – The list of users to search through when looking for an index.

Returns:

User | None – The User object corresponding to the given user_id or index, or None if no such user exists.

spotted.utils package

Submodules

spotted.utils.constants module

Constants used by the util module

spotted.utils.conversation_util module

Common functions needed in conversation handlers

class spotted.utils.conversation_util.Any(*args, **kwargs)[source]

Bases: object

Special type indicating an unconstrained type.

  • Any is compatible with every type.

  • Any assumed to have all methods.

  • All values assumed to be instances of Any.

Note that all the above statements are true from the point of view of static type checkers. At runtime, Any should not be used with instance checks.

class spotted.utils.conversation_util.CallbackContext(application, chat_id=None, user_id=None)[source]

Bases: Generic[BT, UD, CD, BD]

This is a context object passed to the callback called by telegram.ext.BaseHandler or by the telegram.ext.Application in an error handler added by telegram.ext.Application.add_error_handler or to the callback of a telegram.ext.Job.

Note

telegram.ext.Application will create a single context for an entire update. This means that if you got 2 handlers in different groups and they both get called, they will receive the same CallbackContext object (of course with proper attributes like matches differing). This allows you to add custom attributes in a lower handler group callback, and then subsequently access those attributes in a higher handler group callback. Note that the attributes on CallbackContext might change in the future, so make sure to use a fairly unique name for the attributes.

Warning

Do not combine custom attributes with telegram.ext.BaseHandler.block set to False or telegram.ext.Application.concurrent_updates set to True. Due to how those work, it will almost certainly execute the callbacks for an update out of order, and the attributes that you think you added will not be present.

This class is a Generic class and accepts four type variables:

  1. The type of bot. Must be telegram.Bot or a subclass of that class.

  2. The type of user_data (if user_data is not None).

  3. The type of chat_data (if chat_data is not None).

  4. The type of bot_data (if bot_data is not None).

Examples

  • Context Types Bot

  • Custom Webhook Bot

See also

telegram.ext.ContextTypes.DEFAULT_TYPE, Job Queue <Extensions---JobQueue>

Parameters:
  • application (Application[TypeVar(BT, bound= Bot), TypeVar(ST, bound= CallbackContext[Any, Any, Any, Any]), TypeVar(UD), TypeVar(CD), TypeVar(BD), Any]) – The application associated with this context.

  • chat_id (int | None, default: None) –

    The ID of the chat associated with this object. Used to provide chat_data.

    Added in version 20.0.

  • user_id (int | None, default: None) –

    The ID of the user associated with this object. Used to provide user_data.

    Added in version 20.0.

coroutine

Optional. Only present in error handlers if the error was caused by an awaitable run with Application.create_task() or a handler callback with block=False.

Type:

awaitable

matches

Optional. If the associated update originated from a filters.Regex, this will contain a list of match objects for every pattern where re.search(pattern, string) returned a match. Note that filters short circuit, so combined regex filters will not always be evaluated.

Type:

list[re.Match]

args

Optional. Arguments passed to a command if the associated update is handled by telegram.ext.CommandHandler, telegram.ext.PrefixHandler or telegram.ext.StringCommandHandler. It contains a list of the words in the text after the command, using any whitespace string as a delimiter.

Type:

list[str]

error

Optional. The error that was raised. Only present when passed to an error handler registered with telegram.ext.Application.add_error_handler.

Type:

Exception

job

Optional. The job which originated this callback. Only present when passed to the callback of telegram.ext.Job or in error handlers if the error is caused by a job.

Changed in version 20.0: job is now also present in error handlers if the error is caused by a job.

Type:

telegram.ext.Job

property application: Application[BT, ST, UD, CD, BD, Any]

The application associated with this context.

Type:

telegram.ext.Application

args: list[str] | None
property bot: BT

The bot associated with this context.

Type:

telegram.Bot

property bot_data: BD

Optional. An object that can be used to keep any data in. For each update it will be the same ContextTypes.bot_data. Defaults to dict.

See also

Storing Bot, User and Chat Related Data            <Storing-bot%2C-user-and-chat-related-data>

Type:

ContextTypes.bot_data

property chat_data: CD | None

Optional. An object that can be used to keep any data in. For each update from the same chat id it will be the same ContextTypes.chat_data. Defaults to dict.

Warning

When a group chat migrates to a supergroup, its chat id will change and the chat_data needs to be transferred. For details see our wiki page <Storing-bot,-user-and-chat-related-data#chat-migration>.

See also

Storing Bot, User and Chat Related Data            <Storing-bot%2C-user-and-chat-related-data>

Changed in version 20.0: The chat data is now also present in error handlers if the error is caused by a job.

Type:

ContextTypes.chat_data

coroutine: Generator[Future[object] | None, None, Any] | Awaitable[Any] | None
drop_callback_data(callback_query)[source]

Deletes the cached data for the specified callback query.

Added in version 13.6.

Note

Will not raise exceptions in case the data is not found in the cache. Will raise KeyError in case the callback query can not be found in the cache.

See also

Arbitrary callback_data <Arbitrary-callback_data>

Parameters:

callback_query (CallbackQuery) – The callback query.

Raises:

KeyError | RuntimeErrorKeyError, if the callback query can not be found in the cache and RuntimeError, if the bot doesn’t allow for arbitrary callback data.

Return type:

None

error: Exception | None
classmethod from_error(update, error, application, job=None, coroutine=None)[source]

Constructs an instance of telegram.ext.CallbackContext to be passed to the error handlers.

Changed in version 20.0: Removed arguments async_args and async_kwargs.

Parameters:
  • update (object) – The update associated with the error. May be None, e.g. for errors in job callbacks.

  • error (Exception) – The error.

  • application (Application[TypeVar(BT, bound= Bot), TypeVar(CCT, bound= CallbackContext[Any, Any, Any, Any]), TypeVar(UD), TypeVar(CD), TypeVar(BD), Any]) – The application associated with this context.

  • job (Job[Any] | None, default: None) –

    The job associated with the error.

    Added in version 20.0.

  • coroutine (Generator[Future[object] | None, None, Any] | Awaitable[Any] | None, default: None) –

    The awaitable associated with this error if the error was caused by a coroutine run with Application.create_task() or a handler callback with block=False.

    Added in version 20.0.

    Changed in version 20.2: Accepts asyncio.Future and generator-based coroutine functions.

Returns:

TypeVar(CCT, bound= CallbackContext[Any, Any, Any, Any])telegram.ext.CallbackContext

classmethod from_job(job, application)[source]

Constructs an instance of telegram.ext.CallbackContext to be passed to a job callback.

See also

telegram.ext.JobQueue()

Parameters:
  • job (Job[TypeVar(CCT, bound= CallbackContext[Any, Any, Any, Any])]) – The job.

  • application (Application[Any, TypeVar(CCT, bound= CallbackContext[Any, Any, Any, Any]), Any, Any, Any, Any]) – The application associated with this context.

Returns:

TypeVar(CCT, bound= CallbackContext[Any, Any, Any, Any])telegram.ext.CallbackContext

classmethod from_update(update, application)[source]

Constructs an instance of telegram.ext.CallbackContext to be passed to the handlers.

Parameters:
Returns:

TypeVar(CCT, bound= CallbackContext[Any, Any, Any, Any])telegram.ext.CallbackContext

job: Job[Any] | None
property job_queue: JobQueue[ST] | None

The JobQueue used by the telegram.ext.Application.

See also

Job Queue <Extensions---JobQueue>

Type:

telegram.ext.JobQueue

property match: Match[str] | None

The first match from matches. Useful if you are only filtering using a single regex filter. Returns None if matches is empty.

Type:

re.Match

matches: list[Match[str]] | None
async refresh_data()[source]

If application uses persistence, calls telegram.ext.BasePersistence.refresh_bot_data() on bot_data, telegram.ext.BasePersistence.refresh_chat_data() on chat_data and telegram.ext.BasePersistence.refresh_user_data() on user_data, if appropriate.

Will be called by telegram.ext.Application.process_update() and telegram.ext.Job.run().

Added in version 13.6.

Return type:

None

update(data)[source]

Updates self.__slots__ with the passed data.

Parameters:

data (dict[str, object]) – The data.

Return type:

None

property update_queue: Queue[object]

The asyncio.Queue instance used by the telegram.ext.Application and (usually) the telegram.ext.Updater associated with this context.

Type:

asyncio.Queue

property user_data: UD | None

Optional. An object that can be used to keep any data in. For each update from the same user it will be the same ContextTypes.user_data. Defaults to dict.

See also

Storing Bot, User and Chat Related Data            <Storing-bot%2C-user-and-chat-related-data>

Changed in version 20.0: The user data is now also present in error handlers if the error is caused by a job.

Type:

ContextTypes.user_data

class spotted.utils.conversation_util.Coroutine[source]

Bases: Awaitable

close()[source]

Raise GeneratorExit inside coroutine.

abstractmethod send(value)[source]

Send a value into the coroutine. Return next yielded value or raise StopIteration.

abstractmethod throw(typ, val=None, tb=None)[source]

Raise an exception in the coroutine. Return next yielded value or raise StopIteration.

class spotted.utils.conversation_util.EventInfo(bot, ctx, update=None, message=None, query=None)[source]

Bases: object

Class that contains all the relevant information related to an event

async answer_callback_query(text=None)[source]

Calls the answer_callback_query method of the bot class, while also handling the exception

Parameters:

text (str | None, default: None) – Text to show to the user

property args: list[str]

Return the args of the message that caused the update. If the update was caused by a callback, the callback data is splitted by ‘,’ and returned

property bot: Bot

Instance of the telegram bot

property bot_data: dict

Data related to the bot. Is not persistent between restarts

property callback_key: str

Return the args of the message that caused the update. If the update was caused by a callback, the callback data is splitted by ‘,’ and returned

property chat_id: int | None

Id of the chat where the event happened

property chat_type: str | None

Type of the chat where the event happened

property context: CallbackContext

Context generated by some event

async edit_inline_keyboard(chat_id=None, message_id=None, new_keyboard=None)[source]

Generic wrapper used to edit the inline keyboard of a message with the telegram bot, while also handling the exception

Parameters:
  • chat_id (int | None, default: None) – id of the chat the message to edit belongs to or the current chat if None

  • message_id (int | None, default: None) – id of the message to edit. It is the current message if left None

  • new_keyboard (InlineKeyboardMarkup | None, default: None) – new inline keyboard to assign to the message

property forward_from_chat_id: int | None

Id of the original chat the message has been forwarded from

property forward_from_id: int | None

Id of the original message that has been forwarded

classmethod from_callback(update, ctx)[source]

Instance of EventInfo created by a callback update

Parameters:
  • update (Update) – update event

  • context – context passed by the handler

Returns:

EventInfo – instance of the class

classmethod from_job(ctx)[source]

Instance of EventInfo created by a job update

Parameters:

context – context passed by the handler

Returns:

EventInfo – instance of the class

classmethod from_message(update, ctx)[source]

Instance of EventInfo created by a message update

Parameters:
  • update (Update) – update event

  • context – context passed by the handler

Returns:

EventInfo – instance of the class

property inline_keyboard: InlineKeyboardMarkup | None

InlineKeyboard attached to the message

property is_forward_from_channel: bool

Whether the message has been forwarded from a channel

property is_forward_from_chat: bool

Whether the message has been forwarded from a chat

property is_forward_from_user: bool

Whether the message has been forwarded from a user

property is_forwarded_post: bool

Whether the message is in fact a forwarded post from the channel to the group

property is_private_chat: bool | None

Whether the chat is private or not

property is_valid_message_type: bool

Whether or not the type of the message is supported

property message: Message | None

Message that caused the update

property message_id: int | None

Id of the message that caused the update

property query_data: str | None

Data associated with the query that caused the update

property query_id: str | None

Id of the query that caused the update

property reply_markup: InlineKeyboardMarkup | None

Reply_markup of the message that caused the update

async send_post_to_admins()[source]

Sends the post to the admin group, so it can be approved

Returns:

bool – whether or not the operation was successful

async send_post_to_channel(user_id)[source]

Sends the post to the channel, so it can be enjoyed by the users (and voted, if comments are disabled)

async send_post_to_channel_group()[source]

If comments are enabled, sends the post to the group associated to the channel, allowing the author to be credited and other users to report the spot or follow it.

async show_admins_votes(pending_post, reason=None)[source]

After a post is been approved or rejected, shows the admins that approved or rejected it and edit the message to show the admin’s votes

Parameters:
  • pending_post (PendingPost) – post to show the admin’s votes for

  • reason (str | None, default: None) – reason for the rejection, currently used on autoreply

property text: str | None

Text of the message that caused the update

property update: Update | None

Update generated by some event

property user_data: dict | None

Data related to the user. Is not persistent between restarts

property user_id: int | None

Id of the user that caused the update

property user_name: str | None

Name of the user that caused the update

property user_username: str | None

Username of the user that caused the update

class spotted.utils.conversation_util.ParseMode(*values)[source]

Bases: StringEnum

This enum contains the available parse modes. The enum members of this enumeration are instances of str and can be treated as such.

Added in version 20.0.

HTML = 'HTML'

HTML parse mode.

Type:

str

MARKDOWN = 'Markdown'

Markdown parse mode.

Note

MARKDOWN is a legacy mode, retained by Telegram for backward compatibility. You should use MARKDOWN_V2 instead.

Type:

str

MARKDOWN_V2 = 'MarkdownV2'

Markdown parse mode version 2.

Type:

str

class spotted.utils.conversation_util.Update(update_id, message=None, edited_message=None, channel_post=None, edited_channel_post=None, inline_query=None, chosen_inline_result=None, callback_query=None, shipping_query=None, pre_checkout_query=None, poll=None, poll_answer=None, my_chat_member=None, chat_member=None, chat_join_request=None, chat_boost=None, removed_chat_boost=None, message_reaction=None, message_reaction_count=None, business_connection=None, business_message=None, edited_business_message=None, deleted_business_messages=None, purchased_paid_media=None, *, api_kwargs=None)[source]

Bases: TelegramObject

This object represents an incoming update.

Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their update_id is equal.

Note

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

See also

Your First Bot <Extensions---Your-first-Bot>

Parameters:
  • update_id (int) – The update’s unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order. If there are no new updates for at least a week, then identifier of the next update will be chosen randomly instead of sequentially.

  • message (Message | None, default: None) – New incoming message of any kind - text, photo, sticker, etc.

  • edited_message (Message | None, default: None) – New version of a message that is known to the bot and was edited. This update may at times be triggered by changes to message fields that are either unavailable or not actively used by your bot.

  • channel_post (Message | None, default: None) – New incoming channel post of any kind - text, photo, sticker, etc.

  • edited_channel_post (Message | None, default: None) – New version of a channel post that is known to the bot and was edited. This update may at times be triggered by changes to message fields that are either unavailable or not actively used by your bot.

  • inline_query (InlineQuery | None, default: None) – New incoming inline query.

  • chosen_inline_result (ChosenInlineResult | None, default: None) – The result of an inline query that was chosen by a user and sent to their chat partner.

  • callback_query (CallbackQuery | None, default: None) – New incoming callback query.

  • shipping_query (ShippingQuery | None, default: None) – New incoming shipping query. Only for invoices with flexible price.

  • pre_checkout_query (PreCheckoutQuery | None, default: None) – New incoming pre-checkout query. Contains full information about checkout.

  • poll (Poll | None, default: None) – New poll state. Bots receive only updates about manually stopped polls and polls, which are sent by the bot.

  • poll_answer (PollAnswer | None, default: None) – A user changed their answer in a non-anonymous poll. Bots receive new votes only in polls that were sent by the bot itself.

  • my_chat_member (ChatMemberUpdated | None, default: None) –

    The bot’s chat member status was updated in a chat. For private chats, this update is received only when the bot is blocked or unblocked by the user.

    Added in version 13.4.

  • chat_member (ChatMemberUpdated | None, default: None) –

    A chat member’s status was updated in a chat. The bot must be an administrator in the chat and must explicitly specify CHAT_MEMBER in the list of telegram.ext.Application.run_polling.allowed_updates to receive these updates (see telegram.Bot.get_updates(), telegram.Bot.set_webhook(), telegram.ext.Application.run_polling() and telegram.ext.Application.run_webhook()).

    Added in version 13.4.

  • chat_join_request (ChatJoinRequest | None, default: None) –

    A request to join the chat has been sent. The bot must have the telegram.ChatPermissions.can_invite_users administrator right in the chat to receive these updates.

    Added in version 13.8.

  • chat_boost (ChatBoostUpdated | None, default: None) –

    A chat boost was added or changed. The bot must be an administrator in the chat to receive these updates.

    Added in version 20.8.

  • removed_chat_boost (ChatBoostRemoved | None, default: None) –

    A boost was removed from a chat. The bot must be an administrator in the chat to receive these updates.

    Added in version 20.8.

  • message_reaction (MessageReactionUpdated | None, default: None) –

    A reaction to a message was changed by a user. The bot must be an administrator in the chat and must explicitly specify MESSAGE_REACTION in the list of telegram.ext.Application.run_polling.allowed_updates to receive these updates (see telegram.Bot.get_updates(), telegram.Bot.set_webhook(), telegram.ext.Application.run_polling() and telegram.ext.Application.run_webhook()). The update isn’t received for reactions set by bots.

    Added in version 20.8.

  • message_reaction_count (MessageReactionCountUpdated | None, default: None) –

    Reactions to a message with anonymous reactions were changed. The bot must be an administrator in the chat and must explicitly specify MESSAGE_REACTION_COUNT in the list of telegram.ext.Application.run_polling.allowed_updates to receive these updates (see telegram.Bot.get_updates(), telegram.Bot.set_webhook(), telegram.ext.Application.run_polling() and telegram.ext.Application.run_webhook()). The updates are grouped and can be sent with delay up to a few minutes.

    Added in version 20.8.

  • business_connection (BusinessConnection | None, default: None) –

    The bot was connected to or disconnected from a business account, or a user edited an existing connection with the bot.

    Added in version 21.1.

  • business_message (Message | None, default: None) –

    New message from a connected business account.

    Added in version 21.1.

  • edited_business_message (Message | None, default: None) –

    New version of a message from a connected business account.

    Added in version 21.1.

  • deleted_business_messages (BusinessMessagesDeleted | None, default: None) –

    Messages were deleted from a connected business account.

    Added in version 21.1.

  • purchased_paid_media (PaidMediaPurchased | None, default: None) –

    A user purchased paid media with a non-empty payload sent by the bot in a non-channel chat.

    Added in version 21.6.

update_id

The update’s unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order. If there are no new updates for at least a week, then identifier of the next update will be chosen randomly instead of sequentially.

Type:

int

message

Optional. New incoming message of any kind - text, photo, sticker, etc.

Type:

telegram.Message

edited_message

Optional. New version of a message that is known to the bot and was edited. This update may at times be triggered by changes to message fields that are either unavailable or not actively used by your bot.

Type:

telegram.Message

channel_post

Optional. New incoming channel post of any kind - text, photo, sticker, etc.

Type:

telegram.Message

edited_channel_post

Optional. New version of a channel post that is known to the bot and was edited. This update may at times be triggered by changes to message fields that are either unavailable or not actively used by your bot.

Type:

telegram.Message

inline_query

Optional. New incoming inline query.

Type:

telegram.InlineQuery

chosen_inline_result

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

Type:

telegram.ChosenInlineResult

callback_query

Optional. New incoming callback query.

Examples

Arbitrary Callback Data Bot

Type:

telegram.CallbackQuery

shipping_query

Optional. New incoming shipping query. Only for invoices with flexible price.

Type:

telegram.ShippingQuery

pre_checkout_query

Optional. New incoming pre-checkout query. Contains full information about checkout.

Type:

telegram.PreCheckoutQuery

poll

Optional. New poll state. Bots receive only updates about manually stopped polls and polls, which are sent by the bot.

Type:

telegram.Poll

poll_answer

Optional. A user changed their answer in a non-anonymous poll. Bots receive new votes only in polls that were sent by the bot itself.

Type:

telegram.PollAnswer

my_chat_member

Optional. The bot’s chat member status was updated in a chat. For private chats, this update is received only when the bot is blocked or unblocked by the user.

Added in version 13.4.

Type:

telegram.ChatMemberUpdated

chat_member

Optional. A chat member’s status was updated in a chat. The bot must be an administrator in the chat and must explicitly specify CHAT_MEMBER in the list of telegram.ext.Application.run_polling.allowed_updates to receive these updates (see telegram.Bot.get_updates(), telegram.Bot.set_webhook(), telegram.ext.Application.run_polling() and telegram.ext.Application.run_webhook()).

Added in version 13.4.

Type:

telegram.ChatMemberUpdated

chat_join_request

Optional. A request to join the chat has been sent. The bot must have the telegram.ChatPermissions.can_invite_users administrator right in the chat to receive these updates.

Added in version 13.8.

Type:

telegram.ChatJoinRequest

chat_boost

Optional. A chat boost was added or changed. The bot must be an administrator in the chat to receive these updates.

Added in version 20.8.

Type:

telegram.ChatBoostUpdated

removed_chat_boost

Optional. A boost was removed from a chat. The bot must be an administrator in the chat to receive these updates.

Added in version 20.8.

Type:

telegram.ChatBoostRemoved

message_reaction

Optional. A reaction to a message was changed by a user. The bot must be an administrator in the chat and must explicitly specify MESSAGE_REACTION in the list of telegram.ext.Application.run_polling.allowed_updates to receive these updates (see telegram.Bot.get_updates(), telegram.Bot.set_webhook(), telegram.ext.Application.run_polling() and telegram.ext.Application.run_webhook()). The update isn’t received for reactions set by bots.

Added in version 20.8.

Type:

telegram.MessageReactionUpdated

message_reaction_count

Optional. Reactions to a message with anonymous reactions were changed. The bot must be an administrator in the chat and must explicitly specify MESSAGE_REACTION_COUNT in the list of telegram.ext.Application.run_polling.allowed_updates to receive these updates (see telegram.Bot.get_updates(), telegram.Bot.set_webhook(), telegram.ext.Application.run_polling() and telegram.ext.Application.run_webhook()). The updates are grouped and can be sent with delay up to a few minutes.

Added in version 20.8.

Type:

telegram.MessageReactionCountUpdated

business_connection

Optional. The bot was connected to or disconnected from a business account, or a user edited an existing connection with the bot.

Added in version 21.1.

Type:

telegram.BusinessConnection

business_message

Optional. New message from a connected business account.

Added in version 21.1.

Type:

telegram.Message

edited_business_message

Optional. New version of a message from a connected business account.

Added in version 21.1.

Type:

telegram.Message

deleted_business_messages

Optional. Messages were deleted from a connected business account.

Added in version 21.1.

Type:

telegram.BusinessMessagesDeleted

purchased_paid_media

Optional. A user purchased paid media with a non-empty payload sent by the bot in a non-channel chat.

Added in version 21.6.

Type:

telegram.PaidMediaPurchased

ALL_TYPES: Final[list[str]] = [<UpdateType.MESSAGE>, <UpdateType.EDITED_MESSAGE>, <UpdateType.CHANNEL_POST>, <UpdateType.EDITED_CHANNEL_POST>, <UpdateType.INLINE_QUERY>, <UpdateType.CHOSEN_INLINE_RESULT>, <UpdateType.CALLBACK_QUERY>, <UpdateType.SHIPPING_QUERY>, <UpdateType.PRE_CHECKOUT_QUERY>, <UpdateType.POLL>, <UpdateType.POLL_ANSWER>, <UpdateType.MY_CHAT_MEMBER>, <UpdateType.CHAT_MEMBER>, <UpdateType.CHAT_JOIN_REQUEST>, <UpdateType.CHAT_BOOST>, <UpdateType.REMOVED_CHAT_BOOST>, <UpdateType.MESSAGE_REACTION>, <UpdateType.MESSAGE_REACTION_COUNT>, <UpdateType.BUSINESS_CONNECTION>, <UpdateType.BUSINESS_MESSAGE>, <UpdateType.EDITED_BUSINESS_MESSAGE>, <UpdateType.DELETED_BUSINESS_MESSAGES>, <UpdateType.PURCHASED_PAID_MEDIA>]

A list of all available update types.

Added in version 13.5.

Type:

list[str]

BUSINESS_CONNECTION: Final[str] = 'business_connection'

telegram.constants.UpdateType.BUSINESS_CONNECTION

Added in version 21.1.

BUSINESS_MESSAGE: Final[str] = 'business_message'

telegram.constants.UpdateType.BUSINESS_MESSAGE

Added in version 21.1.

CALLBACK_QUERY: Final[str] = 'callback_query'

telegram.constants.UpdateType.CALLBACK_QUERY

Added in version 13.5.

CHANNEL_POST: Final[str] = 'channel_post'

telegram.constants.UpdateType.CHANNEL_POST

Added in version 13.5.

CHAT_BOOST: Final[str] = 'chat_boost'

telegram.constants.UpdateType.CHAT_BOOST

Added in version 20.8.

CHAT_JOIN_REQUEST: Final[str] = 'chat_join_request'

telegram.constants.UpdateType.CHAT_JOIN_REQUEST

Added in version 13.8.

CHAT_MEMBER: Final[str] = 'chat_member'

telegram.constants.UpdateType.CHAT_MEMBER

Added in version 13.5.

CHOSEN_INLINE_RESULT: Final[str] = 'chosen_inline_result'

telegram.constants.UpdateType.CHOSEN_INLINE_RESULT

Added in version 13.5.

DELETED_BUSINESS_MESSAGES: Final[str] = 'deleted_business_messages'

telegram.constants.UpdateType.DELETED_BUSINESS_MESSAGES

Added in version 21.1.

EDITED_BUSINESS_MESSAGE: Final[str] = 'edited_business_message'

telegram.constants.UpdateType.EDITED_BUSINESS_MESSAGE

Added in version 21.1.

EDITED_CHANNEL_POST: Final[str] = 'edited_channel_post'

telegram.constants.UpdateType.EDITED_CHANNEL_POST

Added in version 13.5.

EDITED_MESSAGE: Final[str] = 'edited_message'

telegram.constants.UpdateType.EDITED_MESSAGE

Added in version 13.5.

INLINE_QUERY: Final[str] = 'inline_query'

telegram.constants.UpdateType.INLINE_QUERY

Added in version 13.5.

MESSAGE: Final[str] = 'message'

telegram.constants.UpdateType.MESSAGE

Added in version 13.5.

MESSAGE_REACTION: Final[str] = 'message_reaction'

telegram.constants.UpdateType.MESSAGE_REACTION

Added in version 20.8.

MESSAGE_REACTION_COUNT: Final[str] = 'message_reaction_count'

telegram.constants.UpdateType.MESSAGE_REACTION_COUNT

Added in version 20.8.

MY_CHAT_MEMBER: Final[str] = 'my_chat_member'

telegram.constants.UpdateType.MY_CHAT_MEMBER

Added in version 13.5.

POLL: Final[str] = 'poll'

telegram.constants.UpdateType.POLL

Added in version 13.5.

POLL_ANSWER: Final[str] = 'poll_answer'

telegram.constants.UpdateType.POLL_ANSWER

Added in version 13.5.

PRE_CHECKOUT_QUERY: Final[str] = 'pre_checkout_query'

telegram.constants.UpdateType.PRE_CHECKOUT_QUERY

Added in version 13.5.

PURCHASED_PAID_MEDIA: Final[str] = 'purchased_paid_media'

telegram.constants.UpdateType.PURCHASED_PAID_MEDIA

Added in version 21.6.

REMOVED_CHAT_BOOST: Final[str] = 'removed_chat_boost'

telegram.constants.UpdateType.REMOVED_CHAT_BOOST

Added in version 20.8.

SHIPPING_QUERY: Final[str] = 'shipping_query'

telegram.constants.UpdateType.SHIPPING_QUERY

Added in version 13.5.

business_connection: BusinessConnection | None
business_message: Message | None
callback_query: CallbackQuery | None
channel_post: Message | None
chat_boost: ChatBoostUpdated | None
chat_join_request: ChatJoinRequest | None
chat_member: ChatMemberUpdated | None
chosen_inline_result: ChosenInlineResult | None
classmethod de_json(data, bot=None)[source]

See telegram.TelegramObject.de_json().

Return type:

Update

deleted_business_messages: BusinessMessagesDeleted | None
edited_business_message: Message | None
edited_channel_post: Message | None
edited_message: Message | None
property effective_chat: Chat | None

The chat that this update was sent in, no matter what kind of update this is. If no chat is associated with this update, this gives None. This is the case, if inline_query, chosen_inline_result, callback_query from inline messages, shipping_query, pre_checkout_query, poll, poll_answer, business_connection, or purchased_paid_media is present.

Changed in version 21.1: This property now also considers business_message, edited_business_message, and deleted_business_messages.

Example

If message is present, this will give telegram.Message.chat.

Type:

telegram.Chat

property effective_message: Message | None
The message included in this update, no matter what kind of

update this is. More precisely, this will be the message contained in message, edited_message, channel_post, edited_channel_post or callback_query (i.e. telegram.CallbackQuery.message) or None, if none of those are present.

Changed in version 21.1: This property now also considers business_message, and edited_business_message.

Tip

This property will only ever return objects of type telegram.Message or None, never telegram.MaybeInaccessibleMessage or telegram.InaccessibleMessage. Currently, this is only relevant for callback_query, as telegram.CallbackQuery.message is the only attribute considered by this property that can be an object of these types.

Type:

telegram.Message

property effective_sender: User | Chat | None

The user or chat that sent this update, no matter what kind of update this is.

Note

If no user whatsoever is associated with this update, this gives None. This is the case if any of

is present.

Example

Added in version 21.1.

Type:

telegram.User or telegram.Chat

property effective_user: User | None

The user that sent this update, no matter what kind of update this is. If no user is associated with this update, this gives None. This is the case if any of

is present.

Changed in version 21.1: This property now also considers business_connection, business_message and edited_business_message.

Changed in version 21.6: This property now also considers purchased_paid_media.

Example

Type:

telegram.User

inline_query: InlineQuery | None
message: Message | None
message_reaction: MessageReactionUpdated | None
message_reaction_count: MessageReactionCountUpdated | None
my_chat_member: ChatMemberUpdated | None
poll: Poll | None
poll_answer: PollAnswer | None
pre_checkout_query: PreCheckoutQuery | None
purchased_paid_media: PaidMediaPurchased | None
removed_chat_boost: ChatBoostRemoved | None
shipping_query: ShippingQuery | None
update_id: int
spotted.utils.conversation_util.conv_cancel(family)[source]

Creates a function used to handle the /cancel command in the conversation. Invoking /cancel will exit the conversation immediately

Parameters:

family (str) – family of the command

Returns:

Callable[[Any, Any], Coroutine[Any, Any, int]] – function used to handle the /cancel command

spotted.utils.conversation_util.conv_fail(family)[source]

Creates a function used to handle any error in the conversation

Parameters:

family (str) – family of the command

Returns:

Callable[[tuple[Update, CallbackContext] | EventInfo, str, int | None], Coroutine[Any, Any, int | None]] – function used to handle the error

spotted.utils.conversation_util.read_md(file_name)[source]

Read the contents of a markdown file. The path is data/markdown. It also will replace the following parts of the text:

  • {channel_tag} -> Config.settings[‘post’][‘channel_tag’]

  • {bot_tag} -> Config.settings[‘bot_tag’]

Parameters:

file_name (str) – name of the file

Returns:

str – contents of the file

spotted.utils.info_util module

Common info needed in both command and callback handlers

exception spotted.utils.info_util.BadRequest(message)[source]

Bases: NetworkError

Raised when Telegram could not process the request correctly.

class spotted.utils.info_util.Bot(token, base_url='https://api.telegram.org/bot', base_file_url='https://api.telegram.org/file/bot', request=None, get_updates_request=None, private_key=None, private_key_password=None, local_mode=False)[source]

Bases: TelegramObject, AbstractAsyncContextManager[Bot]

This object represents a Telegram Bot.

Instances of this class can be used as asyncio context managers, where

async with bot:
    # code

is roughly equivalent to

try:
    await bot.initialize()
    # code
finally:
    await bot.shutdown()

See also

__aenter__() and __aexit__().

Note

  • Most bot methods have the argument api_kwargs which allows passing arbitrary keywords to the Telegram API. This can be used to access new features of the API before they are incorporated into PTB. The limitations to this argument are the same as the ones described in do_api_request().

  • Bots should not be serialized since if you for e.g. change the bots token, then your serialized instance will not reflect that change. Trying to pickle a bot instance will raise pickle.PicklingError. Trying to deepcopy a bot instance will raise TypeError.

Examples

Raw API Bot

See also

Your First Bot <Extensions---Your-first-Bot>, Builder Pattern <Builder-Pattern>

Added in version 13.2: Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their bot is equal.

Changed in version 20.0:

  • Removed the deprecated methods kick_chat_member, kickChatMember, get_chat_members_count and getChatMembersCount.

  • Removed the deprecated property commands.

  • Removed the deprecated defaults parameter. If you want to use telegram.ext.Defaults, please use the subclass telegram.ext.ExtBot instead.

  • Attempting to pickle a bot instance will now raise pickle.PicklingError.

  • Attempting to deepcopy a bot instance will now raise TypeError.

  • The following are now keyword-only arguments in Bot methods: location, filename, venue, contact, {read, write, connect, pool}_timeout, api_kwargs. Use a named argument for those, and notice that some positional arguments changed position as a result.

  • For uploading files, file paths are now always accepted. If local_mode is False, the file contents will be read in binary mode and uploaded. Otherwise, the file path will be passed in the file URI scheme.

Changed in version 20.5: Removed deprecated methods set_sticker_set_thumb and setStickerSetThumb. Use set_sticker_set_thumbnail() and setStickerSetThumbnail() instead.

Parameters:
  • token (str) – Bot’s unique authentication token.

  • base_url (str | Callable[[str], str], default: 'https://api.telegram.org/bot') –

    Telegram Bot API service URL. If the string contains {token}, it will be replaced with the bot’s token. If a callable is passed, it will be called with the bot’s token as the only argument and must return the base URL. Otherwise, the token will be appended to the string. Defaults to "https://api.telegram.org/bot".

    Tip

    Customizing the base URL can be used to run a bot against Local Bot API Server <Local-Bot-API-Server> or using Telegrams test environment.

    Example:

    "https://api.telegram.org/bot{token}/test"

    Changed in version 21.11: Supports callable input and string formatting.

  • base_file_url (str | Callable[[str], str], default: 'https://api.telegram.org/file/bot') –

    Telegram Bot API file URL. If the string contains {token}, it will be replaced with the bot’s token. If a callable is passed, it will be called with the bot’s token as the only argument and must return the base URL. Otherwise, the token will be appended to the string. Defaults to "https://api.telegram.org/bot".

    Tip

    Customizing the base URL can be used to run a bot against Local Bot API Server <Local-Bot-API-Server> or using Telegrams test environment.

    Example:

    "https://api.telegram.org/file/bot{token}/test"

    Changed in version 21.11: Supports callable input and string formatting.

  • request (BaseRequest | None, default: None) – Pre initialized telegram.request.BaseRequest instances. Will be used for all bot methods except for get_updates(). If not passed, an instance of telegram.request.HTTPXRequest will be used.

  • get_updates_request (BaseRequest | None, default: None) – Pre initialized telegram.request.BaseRequest instances. Will be used exclusively for get_updates(). If not passed, an instance of telegram.request.HTTPXRequest will be used.

  • private_key (bytes | None, default: None) – Private key for decryption of telegram passport data.

  • private_key_password (bytes | None, default: None) – Password for above private key.

  • local_mode (bool, default: False) –

    Set to True, if the base_url is the URI of a Local Bot API Server that runs with the --local flag. Currently, the only effect of this is that files are uploaded using their local path in the file URI scheme. Defaults to False.

    Added in version 20.0..

Note

For complete information on Bot methods and their usage, see the python-telegram-bot Bot API documentation.

async addStickerToSet(user_id, name, sticker, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for add_sticker_to_set()

Return type:

bool

async add_sticker_to_set(user_id, name, sticker, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 telegram.constants.StickerSetLimit.MAX_EMOJI_STICKERS stickers. Other sticker sets can have up to telegram.constants.StickerSetLimit.MAX_STATIC_STICKERS stickers.

Changed in version 20.2: Since Bot API 6.6, the parameter sticker replace the parameters png_sticker, tgs_sticker, webm_sticker, emojis, and mask_position.

Changed in version 20.5: Removed deprecated parameters png_sticker, tgs_sticker, webm_sticker, emojis, and mask_position.

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

  • name (str) – Sticker set name.

  • sticker (InputSticker) –

    An object with information about the added sticker. If exactly the same sticker had already been added to the set, then the set isn’t changed.

    Added in version 20.2.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async answerCallbackQuery(callback_query_id, text=None, show_alert=None, url=None, cache_time=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for answer_callback_query()

Return type:

bool

async answerInlineQuery(inline_query_id, results, cache_time=None, is_personal=None, next_offset=None, button=None, *, current_offset=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for answer_inline_query()

Return type:

bool

async answerPreCheckoutQuery(pre_checkout_query_id, ok, error_message=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for answer_pre_checkout_query()

Return type:

bool

async answerShippingQuery(shipping_query_id, ok, shipping_options=None, error_message=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for answer_shipping_query()

Return type:

bool

async answerWebAppQuery(web_app_query_id, result, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for answer_web_app_query()

Return type:

SentWebAppMessage

async answer_callback_query(callback_query_id, text=None, show_alert=None, url=None, cache_time=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. Alternatively, the user can be redirected to the specified Game URL. For this option to work, you must first create a game for your bot via @BotFather and accept the terms. Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.

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

  • text (str | None, default: None) – Text of the notification. If not specified, nothing will be shown to the user, 0-telegram.CallbackQuery.MAX_ANSWER_TEXT_LENGTH characters.

  • show_alert (bool | None, default: None) – 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 | None, default: None) –

    URL that will be opened by the user’s client. If you have created a Game and accepted the conditions via @BotFather, specify the URL that opens your game - note that this will only work if the query comes from a callback game button. Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.

  • cache_time (int | timedelta | None, default: None) –

    The maximum amount of time in seconds that the result of the callback query may be cached client-side. Defaults to 0.

    Changed in version 21.11: |time-period-input|

Returns:

boolbool On success, True is returned.

Raises:

telegram.error.TelegramError

async answer_inline_query(inline_query_id, results, cache_time=None, is_personal=None, next_offset=None, button=None, *, current_offset=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Warning

In most use cases current_offset should not be passed manually. Instead of calling this method directly, use the shortcut telegram.InlineQuery.answer() with telegram.InlineQuery.answer.auto_pagination set to True, which will take care of passing the correct value.

See also

Working with Files and Media <Working-with-Files-and-Media>

Changed in version 20.5: Removed deprecated arguments switch_pm_text and switch_pm_parameter.

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

  • results (Sequence[InlineQueryResult] | Callable[[int], Sequence[InlineQueryResult] | None]) – A list of results for the inline query. In case current_offset is passed, results may also be a callable that accepts the current page index starting from 0. It must return either a list of telegram.InlineQueryResult instances or None if there are no more results.

  • cache_time (int | timedelta | None, default: None) –

    The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300.

    Changed in version 21.11: |time-period-input|

  • is_personal (bool | None, default: None) – Pass True, if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query.

  • next_offset (str | None, default: None) – Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don’t support pagination. Offset length can’t exceed telegram.InlineQuery.MAX_OFFSET_LENGTH bytes.

  • button (InlineQueryResultsButton | None, default: None) –

    A button to be shown above the inline query results.

    Added in version 20.3.

Keyword Arguments:

current_offset (str, optional) – The telegram.InlineQuery.offset of the inline query to answer. If passed, PTB will automatically take care of the pagination for you, i.e. pass the correct next_offset and truncate the results list/get the results from the callable you passed.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async answer_pre_checkout_query(pre_checkout_query_id, ok, error_message=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Note

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

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

  • ok (bool) – Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems.

  • error_message (str | None, default: None) – 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

Returns:

bool

Raises:

telegram.error.TelegramError

async answer_shipping_query(shipping_query_id, ok, shipping_options=None, error_message=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

If you sent an invoice requesting a shipping address and the parameter send_invoice.is_flexible was specified, the Bot API will send an telegram.Update with a telegram.Update.shipping_query field to the bot. Use this method to reply to shipping queries.

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

  • ok (bool) – Specify True if delivery to the specified address is possible and False if there are any problems (for example, if delivery to the specified address is not possible).

  • shipping_options (Sequence[ShippingOption] | None, default: None) –

    Required if ok is True. A sequence of available shipping options.

    Changed in version 20.0: |sequenceargs|

  • error_message (str | None, default: None) – 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.

Returns:

bool

Raises:

telegram.error.TelegramError

async answer_web_app_query(web_app_query_id, result, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Added in version 20.0.

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

  • result (InlineQueryResult) – An object describing the message to be sent.

Returns:

On success, a sent telegram.SentWebAppMessage is returned.

Returns:

SentWebAppMessage

Raises:

telegram.error.TelegramError

async approveChatJoinRequest(chat_id, user_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for approve_chat_join_request()

Return type:

bool

async approveSuggestedPost(chat_id, message_id, send_date=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for approve_suggested_post()

Return type:

bool

async approve_chat_join_request(chat_id, user_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 telegram.ChatPermissions.can_invite_users administrator right.

Added in version 13.8.

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async approve_suggested_post(chat_id, message_id, send_date=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to approve a suggested post in a direct messages chat. The bot must have the can_post_messages administrator right in the corresponding channel chat.

Added in version 22.4.

Parameters:
  • chat_id (int) – Unique identifier of the target direct messages chat.

  • message_id (int) – Identifier of a suggested post message to approve.

  • send_date (int | datetime | None, default: None) –

    Date when the post is expected to be published; omit if the date has already been specified when the suggested post was created. If specified, then the date must be not more than telegram.constants.SuggestedPost.MAX_SEND_DATE seconds (30 days) in the future.

    |tz-naive-dtms|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async banChatMember(chat_id, user_id, until_date=None, revoke_messages=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for ban_chat_member()

Return type:

bool

async banChatSenderChat(chat_id, sender_chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for ban_chat_sender_chat()

Return type:

bool

async ban_chat_member(chat_id, user_id, until_date=None, revoke_messages=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 13.7.

Parameters:
  • chat_id (str | int) – 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 | datetime | None, default: None) – Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever. Applied for supergroups and channels only. |tz-naive-dtms|

  • revoke_messages (bool | None, default: None) –

    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.

    Added in version 13.4.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async ban_chat_sender_chat(chat_id, sender_chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 13.9.

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

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

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

property base_file_url: str

Telegram Bot API file URL, built from Bot.base_file_url and Bot.token.

Added in version 20.0.

Type:

str

property base_url: str

Telegram Bot API service URL, built from Bot.base_url and Bot.token.

Added in version 20.0.

Type:

str

property bot: User

User instance for the bot as returned by get_me().

Warning

This value is the cached return value of get_me(). If the bots profile is changed during runtime, this value won’t reflect the changes until get_me() is called again.

See also

initialize()

Type:

telegram.User

property can_join_groups: bool

Bot’s telegram.User.can_join_groups attribute. Shortcut for the corresponding attribute of bot.

Type:

bool

property can_read_all_group_messages: bool

Bot’s telegram.User.can_read_all_group_messages attribute. Shortcut for the corresponding attribute of bot.

Type:

bool

async close(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async closeForumTopic(chat_id, message_thread_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for close_forum_topic()

Return type:

bool

async closeGeneralForumTopic(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for close_general_forum_topic()

Return type:

bool

async close_forum_topic(chat_id, message_thread_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 ~telegram.ChatAdministratorRights.can_manage_topics administrator rights, unless it is the creator of the topic.

Added in version 20.0.

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async close_general_forum_topic(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 20.0.

Parameters:

chat_id (str | int) – |chat_id_group|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async convertGiftToStars(business_connection_id, owned_gift_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for convert_gift_to_stars()

Return type:

bool

async convert_gift_to_stars(business_connection_id, owned_gift_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Converts a given regular gift to Telegram Stars. Requires the can_convert_gifts_to_stars business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection

  • owned_gift_id (str) – Unique identifier of the regular gift that should be converted to Telegram Stars.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async copyMessage(chat_id, from_chat_id, message_id, caption=None, parse_mode=None, caption_entities=None, disable_notification=None, reply_markup=None, protect_content=None, message_thread_id=None, reply_parameters=None, show_caption_above_media=None, allow_paid_broadcast=None, video_start_timestamp=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for copy_message()

Return type:

MessageId

async copyMessages(chat_id, from_chat_id, message_ids, disable_notification=None, protect_content=None, message_thread_id=None, remove_caption=None, direct_messages_topic_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for copy_messages()

Return type:

tuple[MessageId, ...]

async copy_message(chat_id, from_chat_id, message_id, caption=None, parse_mode=None, caption_entities=None, disable_notification=None, reply_markup=None, protect_content=None, message_thread_id=None, reply_parameters=None, show_caption_above_media=None, allow_paid_broadcast=None, video_start_timestamp=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to copy messages of any kind. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can’t be copied. The method is analogous to the method forward_message(), but the copied message doesn’t have a link to the original message.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

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

  • video_start_timestamp (int | None, default: None) –

    New start timestamp for the copied video in the message

    Added in version 21.11.

  • caption (str | None, default: None) – New caption for media, 0-telegram.constants.MessageLimit.CAPTION_LENGTH characters after entities parsing. If not specified, the original caption is kept.

  • parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – Mode for parsing entities in the new caption. See the constants in telegram.constants.ParseMode for the available modes.

  • caption_entities (Sequence[MessageEntity] | None, default: None) –

    |caption_entities|

    Changed in version 20.0: |sequenceargs|

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • show_caption_above_media (bool | None, default: None) –

    Pass |show_cap_above_med|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
Returns:

On success, the telegram.MessageId of the sent

message is returned.

Returns:

MessageId

Raises:

telegram.error.TelegramError

async copy_messages(chat_id, from_chat_id, message_ids, disable_notification=None, protect_content=None, message_thread_id=None, remove_caption=None, direct_messages_topic_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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, paid media 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 telegram.Poll.correct_option_id is known to the bot. The method is analogous to the method forward_messages(), but the copied messages don’t have a link to the original message. Album grouping is kept for copied messages.

Added in version 20.8.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

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

  • message_ids (Sequence[int]) – A list of telegram.constants.BulkRequestLimit.MIN_LIMIT - telegram.constants.BulkRequestLimit.MAX_LIMIT identifiers of messages in the chat from_chat_id to copy. The identifiers must be specified in a strictly increasing order.

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |protect_content|

  • message_thread_id (int | None, default: None) – |message_thread_id_arg|

  • remove_caption (bool | None, default: None) – Pass True to copy the messages without their captions.

  • direct_messages_topic_id (int | None, default: None) –

    Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat.

    Added in version 22.4.

Returns:

On success, a tuple of MessageId of the sent messages is returned.

Returns:

tuple[MessageId, ...]

Raises:

telegram.error.TelegramError

Alias for create_chat_invite_link()

Return type:

ChatInviteLink

Alias for create_chat_subscription_invite_link()

Return type:

ChatInviteLink

async createForumTopic(chat_id, name, icon_color=None, icon_custom_emoji_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for create_forum_topic()

Return type:

ForumTopic

Alias for create_invoice_link()

Return type:

str

async createNewStickerSet(user_id, name, title, stickers, sticker_type=None, needs_repainting=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for create_new_sticker_set()

Return type:

bool

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

Note

When joining public groups via an invite link, Telegram clients may display the usual “Join” button, effectively ignoring the invite link. In particular, the parameter creates_join_request has no effect in this case. However, this behavior is undocument and may be subject to change. See this GitHub thread for some discussion.

Added in version 13.4.

Parameters:
  • chat_id (str | int) – |chat_id_channel|

  • expire_date (int | datetime | None, default: None) – Date when the link will expire. Integer input will be interpreted as Unix timestamp. |tz-naive-dtms|

  • member_limit (int | None, default: None) – Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; telegram.constants.ChatInviteLinkLimit.MIN_MEMBER_LIMIT- telegram.constants.ChatInviteLinkLimit.MAX_MEMBER_LIMIT.

  • name (str | None, default: None) –

    Invite link name; 0-telegram.constants.ChatInviteLinkLimit.NAME_LENGTH characters.

    Added in version 13.8.

  • creates_join_request (bool | None, default: None) –

    True, if users joining the chat via the link need to be approved by chat administrators. If True, member_limit can’t be specified.

    Added in version 13.8.

Returns:

ChatInviteLinktelegram.ChatInviteLink

Raises:

telegram.error.TelegramError

Use this method to create a subscription invite link for a channel chat. The bot must have the can_invite_users administrator right. The link can be edited using the edit_chat_subscription_invite_link() or revoked using the revoke_chat_invite_link().

Added in version 21.5.

Parameters:
  • chat_id (str | int) – |chat_id_channel|

  • subscription_period (int | timedelta) –

    The number of seconds the subscription will be active for before the next payment. Currently, it must always be telegram.constants.ChatSubscriptionLimit.SUBSCRIPTION_PERIOD (30 days).

    Changed in version 21.11: |time-period-input|

  • subscription_price (int) – The number of Telegram Stars a user must pay initially and after each subsequent subscription period to be a member of the chat; telegram.constants.ChatSubscriptionLimit.MIN_PRICE- telegram.constants.ChatSubscriptionLimit.MAX_PRICE.

  • name (str | None, default: None) – Invite link name; 0-telegram.constants.ChatInviteLinkLimit.NAME_LENGTH characters.

Returns:

ChatInviteLinktelegram.ChatInviteLink

Raises:

telegram.error.TelegramError

async create_forum_topic(chat_id, name, icon_color=None, icon_custom_emoji_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 ~telegram.ChatAdministratorRights.can_manage_topics administrator rights.

Added in version 20.0.

Parameters:
Returns:

ForumTopictelegram.ForumTopic

Raises:

telegram.error.TelegramError

Use this method to create a link for an invoice.

Added in version 20.0.

Parameters:
  • business_connection_id (str | None, default: None) –

    |business_id_str| For payments in |tg_stars| only.

    Added in version 21.8.

  • title (str) – Product name. telegram.Invoice.MIN_TITLE_LENGTH- telegram.Invoice.MAX_TITLE_LENGTH characters.

  • description (str) – Product description. telegram.Invoice.MIN_DESCRIPTION_LENGTH- telegram.Invoice.MAX_DESCRIPTION_LENGTH characters.

  • payload (str) – Bot-defined invoice payload. telegram.Invoice.MIN_PAYLOAD_LENGTH- telegram.Invoice.MAX_PAYLOAD_LENGTH bytes. This will not be displayed to the user, use it for your internal processes.

  • provider_token (str | None, default: None) –

    Payments provider token, obtained via @BotFather. Pass an empty string for payments in |tg_stars|.

    Changed in version 21.11: Bot API 7.4 made this parameter is optional and this is now reflected in the function signature.

  • currency (str) – Three-letter ISO 4217 currency code, see more on currencies. Pass XTR for payments in |tg_stars|.

  • prices (Sequence[LabeledPrice]) –

    Price breakdown, a sequence of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.). Must contain exactly one item for payments in |tg_stars|.

    Changed in version 20.0: |sequenceargs|

  • subscription_period (int | timedelta | None, default: None) –

    The time the subscription will be active for before the next payment, either as number of seconds or as datetime.timedelta object. The currency must be set to “XTR” (Telegram Stars) if the parameter is used. Currently, it must always be telegram.constants.InvoiceLimit.SUBSCRIPTION_PERIOD if specified. Any number of subscriptions can be active for a given bot at the same time, including multiple concurrent subscriptions from the same user. Subscription price must not exceed telegram.constants.InvoiceLimit.SUBSCRIPTION_MAX_PRICE Telegram Stars.

    Added in version 21.8.

  • max_tip_amount (int | None, default: None) – The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0. Not supported for payments in |tg_stars|.

  • suggested_tip_amounts (Sequence[int] | None, default: None) –

    An array of suggested amounts of tips in the smallest units of the currency (integer, not float/double). At most telegram.Invoice.MAX_TIP_AMOUNTS 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.

    Changed in version 20.0: |sequenceargs|

  • provider_data (str | object | None, default: None) – Data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider. When an object is passed, it will be encoded as JSON.

  • photo_url (str | None, default: None) – URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service.

  • photo_size (int | None, default: None) – Photo size in bytes.

  • photo_width (int | None, default: None) – Photo width.

  • photo_height (int | None, default: None) – Photo height.

  • need_name (bool | None, default: None) – Pass True, if you require the user’s full name to complete the order. Ignored for payments in |tg_stars|.

  • need_phone_number (bool | None, default: None) – Pass True, if you require the user’s phone number to complete the order. Ignored for payments in |tg_stars|.

  • need_email (bool | None, default: None) – Pass True, if you require the user’s email address to complete the order. Ignored for payments in |tg_stars|.

  • need_shipping_address (bool | None, default: None) – Pass True, if you require the user’s shipping address to complete the order. Ignored for payments in |tg_stars|.

  • send_phone_number_to_provider (bool | None, default: None) – Pass True, if user’s phone number should be sent to provider. Ignored for payments in |tg_stars|.

  • send_email_to_provider (bool | None, default: None) – Pass True, if user’s email address should be sent to provider. Ignored for payments in |tg_stars|.

  • is_flexible (bool | None, default: None) – Pass True, if the final price depends on the shipping method. Ignored for payments in |tg_stars|.

Returns:

On success, the created invoice link is returned.

Returns:

str

async create_new_sticker_set(user_id, name, title, stickers, sticker_type=None, needs_repainting=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Changed in version 20.0: The parameter contains_masks has been removed. Use sticker_type instead.

Changed in version 20.2: Since Bot API 6.6, the parameters stickers and sticker_format replace the parameters png_sticker, tgs_sticker,``webm_sticker``, emojis, and mask_position.

Changed in version 20.5: Removed the deprecated parameters mentioned above and adjusted the order of the parameters.

Removed in version 21.2: Removed the deprecated parameter sticker_format.

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. telegram.constants.StickerLimit.MIN_NAME_AND_TITLE- telegram.constants.StickerLimit.MAX_NAME_AND_TITLE characters.

  • title (str) – Sticker set title, telegram.constants.StickerLimit.MIN_NAME_AND_TITLE- telegram.constants.StickerLimit.MAX_NAME_AND_TITLE characters.

  • stickers (Sequence[InputSticker]) –

    A sequence of telegram.constants.StickerSetLimit.MIN_INITIAL_STICKERS- telegram.constants.StickerSetLimit.MAX_INITIAL_STICKERS initial stickers to be added to the sticker set.

    Added in version 20.2.

  • sticker_type (str | None, default: None) –

    Type of stickers in the set, pass telegram.Sticker.REGULAR or telegram.Sticker.MASK, or telegram.Sticker.CUSTOM_EMOJI. By default, a regular sticker set is created

    Added in version 20.0.

  • needs_repainting (bool | None, default: None) –

    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.

    Added in version 20.2.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async declineChatJoinRequest(chat_id, user_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for decline_chat_join_request()

Return type:

bool

async declineSuggestedPost(chat_id, message_id, comment=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for decline_suggested_post()

Return type:

bool

async decline_chat_join_request(chat_id, user_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 telegram.ChatPermissions.can_invite_users administrator right.

Added in version 13.8.

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async decline_suggested_post(chat_id, message_id, comment=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to decline a suggested post in a direct messages chat. The bot must have the can_manage_direct_messages administrator right in the corresponding channel chat.

Added in version 22.4.

Parameters:
  • chat_id (int) – Unique identifier of the target direct messages chat.

  • message_id (int) – Identifier of a suggested post message to decline.

  • comment (str | None, default: None) – Comment for the creator of the suggested post. 0-telegram.constants.SuggestedPost.MAX_COMMENT_LENGTH characters.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async deleteBusinessMessages(business_connection_id, message_ids, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for delete_business_messages()

Return type:

bool

async deleteChatPhoto(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for delete_chat_photo()

Return type:

bool

async deleteChatStickerSet(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for delete_chat_sticker_set()

Return type:

bool

async deleteForumTopic(chat_id, message_thread_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for delete_forum_topic()

Return type:

bool

async deleteMessage(chat_id, message_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for delete_message()

Return type:

bool

async deleteMessages(chat_id, message_ids, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for delete_messages()

Return type:

bool

async deleteMyCommands(scope=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for delete_my_commands()

Return type:

bool

async deleteStickerFromSet(sticker, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for delete_sticker_from_set()

Return type:

bool

async deleteStickerSet(name, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for delete_sticker_set()

Return type:

bool

async deleteStory(business_connection_id, story_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for delete_story()

Return type:

bool

async deleteWebhook(drop_pending_updates=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for delete_webhook()

Return type:

bool

async delete_business_messages(business_connection_id, message_ids, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Delete messages on behalf of a business account. Requires the can_delete_sent_messages business bot right to delete messages sent by the bot itself, or the can_delete_all_messages business bot right to delete any message.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection on behalf of which to delete the messages

  • message_ids (Sequence[int]) – A list of telegram.constants.BulkRequestLimit.MIN_LIMIT- telegram.constants.BulkRequestLimit.MAX_LIMIT identifiers of messages to delete. See delete_message() for limitations on which messages can be deleted.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async delete_chat_photo(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Parameters:

chat_id (str | int) – |chat_id_channel|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async delete_chat_sticker_set(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 telegram.ChatFullInfo.can_set_sticker_set optionally returned in get_chat() requests to check if the bot can use this method.

Parameters:

chat_id (str | int) – |chat_id_group|

Returns:

On success, True is returned.

Returns:

bool

async delete_forum_topic(chat_id, message_thread_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to delete a forum topic along with all its messages in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have ~telegram.ChatAdministratorRights.can_delete_messages administrator rights.

Added in version 20.0.

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async delete_message(chat_id, message_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

  • Service messages about a supergroup, channel, or forum topic creation can’t be deleted.

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

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async delete_messages(chat_id, message_ids, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 20.8.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • message_ids (Sequence[int]) – A list of telegram.constants.BulkRequestLimit.MIN_LIMIT- telegram.constants.BulkRequestLimit.MAX_LIMIT identifiers of messages to delete. See delete_message() for limitations on which messages can be deleted.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async delete_my_commands(scope=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Added in version 13.7.

Parameters:
  • scope (BotCommandScope | None, default: None) – An object, describing scope of users for which the commands are relevant. Defaults to telegram.BotCommandScopeDefault.

  • language_code (str | None, default: None) – 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:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async delete_sticker_from_set(sticker, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Parameters:

sticker (str | Sticker) –

File identifier of the sticker or the sticker object.

Changed in version 21.10: Accepts also telegram.Sticker instances.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async delete_sticker_set(name, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 20.2.

Parameters:

name (str) – Sticker set name.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async delete_story(business_connection_id, story_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Deletes a story previously posted by the bot on behalf of a managed business account. Requires the can_manage_stories business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection.

  • story_id (int) – Unique identifier of the story to delete.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async delete_webhook(drop_pending_updates=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to remove webhook integration if you decide to switch back to get_updates().

Parameters:

drop_pending_updates (bool | None, default: None) – Pass True to drop all pending updates.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async do_api_request(endpoint, api_kwargs=None, return_type=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None)[source]

Do a request to the Telegram API.

This method is here to make it easier to use new API methods that are not yet supported by this library.

Hint

Since PTB does not know which arguments are passed to this method, some caution is necessary in terms of PTBs utility functionalities. In particular

  • passing objects of any class defined in the telegram module is supported

  • when uploading files, a telegram.InputFile must be passed as the value for the corresponding argument. Passing a file path or file-like object will not work. File paths will work only in combination with ~Bot.local_mode.

  • when uploading files, PTB can still correctly determine that a special write timeout value should be used instead of the default telegram.request.HTTPXRequest.write_timeout.

  • insertion of default values specified via telegram.ext.Defaults will not work (only relevant for telegram.ext.ExtBot).

  • The only exception is telegram.ext.Defaults.tzinfo, which will be correctly applied to datetime.datetime objects.

Added in version 20.8.

Parameters:
  • endpoint (str) – The API endpoint to use, e.g. getMe or get_me.

  • api_kwargs (dict[str, Any] | None, default: None) – The keyword arguments to pass to the API call. If not specified, no arguments are passed.

  • return_type (type[TelegramObject] | None, default: None) – If specified, the result of the API call will be deserialized into an instance of this class or tuple of instances of this class. If not specified, the raw result of the API call will be returned.

Returns:

Any – The result of the API call. If return_type is not specified, this is a dict or bool, otherwise an instance of return_type or a tuple of return_type.

Raises:

telegram.error.TelegramError

Alias for edit_chat_invite_link()

Return type:

ChatInviteLink

Alias for edit_chat_subscription_invite_link()

Return type:

ChatInviteLink

async editForumTopic(chat_id, message_thread_id, name=None, icon_custom_emoji_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for edit_forum_topic()

Return type:

bool

async editGeneralForumTopic(chat_id, name, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for edit_general_forum_topic()

Return type:

bool

async editMessageCaption(chat_id=None, message_id=None, inline_message_id=None, caption=None, reply_markup=None, parse_mode=None, caption_entities=None, show_caption_above_media=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for edit_message_caption()

Return type:

Message | bool

async editMessageChecklist(business_connection_id, chat_id, message_id, checklist, reply_markup=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for edit_message_checklist()

Return type:

Message

async editMessageLiveLocation(chat_id=None, message_id=None, inline_message_id=None, latitude=None, longitude=None, reply_markup=None, horizontal_accuracy=None, heading=None, proximity_alert_radius=None, live_period=None, business_connection_id=None, *, location=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for edit_message_live_location()

Return type:

Message | bool

async editMessageMedia(media, chat_id=None, message_id=None, inline_message_id=None, reply_markup=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for edit_message_media()

Return type:

Message | bool

async editMessageReplyMarkup(chat_id=None, message_id=None, inline_message_id=None, reply_markup=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for edit_message_reply_markup()

Return type:

Message | bool

async editMessageText(text, chat_id=None, message_id=None, inline_message_id=None, parse_mode=None, reply_markup=None, entities=None, link_preview_options=None, business_connection_id=None, *, disable_web_page_preview=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for edit_message_text()

Return type:

Message | bool

async editStory(business_connection_id, story_id, content, caption=None, parse_mode=None, caption_entities=None, areas=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for edit_story()

Return type:

Story

async editUserStarSubscription(user_id, telegram_payment_charge_id, is_canceled, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for edit_user_star_subscription()

Return type:

bool

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.

Note

Though not stated explicitly in the official docs, Telegram changes not only the optional parameters that are explicitly passed, but also replaces all other optional parameters to the default values. However, since not documented, this behaviour may change unbeknown to PTB.

Added in version 13.4.

Parameters:
  • chat_id (str | int) – |chat_id_channel|

  • invite_link (str | ChatInviteLink) –

    The invite link to edit.

    Changed in version 20.0: Now also accepts telegram.ChatInviteLink instances.

  • expire_date (int | datetime | None, default: None) – Date when the link will expire. |tz-naive-dtms|

  • member_limit (int | None, default: None) – Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; telegram.constants.ChatInviteLinkLimit.MIN_MEMBER_LIMIT- telegram.constants.ChatInviteLinkLimit.MAX_MEMBER_LIMIT.

  • name (str | None, default: None) –

    Invite link name; 0-telegram.constants.ChatInviteLinkLimit.NAME_LENGTH characters.

    Added in version 13.8.

  • creates_join_request (bool | None, default: None) –

    True, if users joining the chat via the link need to be approved by chat administrators. If True, member_limit can’t be specified.

    Added in version 13.8.

Returns:

ChatInviteLinktelegram.ChatInviteLink

Raises:

telegram.error.TelegramError

Use this method to edit a subscription invite link created by the bot. The bot must have telegram.ChatPermissions.can_invite_users administrator right.

Added in version 21.5.

Parameters:
  • chat_id (str | int) – |chat_id_channel|

  • invite_link (str | ChatInviteLink) – The invite link to edit.

  • name (str | None, default: None) –

    Invite link name; 0-telegram.constants.ChatInviteLinkLimit.NAME_LENGTH characters.

    Tip

    Omitting this argument removes the name of the invite link.

Returns:

ChatInviteLinktelegram.ChatInviteLink

Raises:

telegram.error.TelegramError

async edit_forum_topic(chat_id, message_thread_id, name=None, icon_custom_emoji_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 the ~telegram.ChatAdministratorRights.can_manage_topics administrator rights, unless it is the creator of the topic.

Added in version 20.0.

Parameters:
  • chat_id (str | int) – |chat_id_group|

  • message_thread_id (int) – |message_thread_id|

  • name (str | None, default: None) – New topic name, telegram.constants.ForumTopicLimit.MIN_NAME_LENGTH- telegram.constants.ForumTopicLimit.MAX_NAME_LENGTH characters. If not specified or empty, the current name of the topic will be kept.

  • icon_custom_emoji_id (str | None, default: None) – New unique identifier of the custom emoji shown as the topic icon. Use get_forum_topic_icon_stickers() 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.

Returns:

bool

Raises:

telegram.error.TelegramError

async edit_general_forum_topic(chat_id, name, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 the can_manage_topics administrator rights.

Added in version 20.0.

Parameters:
  • chat_id (str | int) – |chat_id_group|

  • name (str) – New topic name, telegram.constants.ForumTopicLimit.MIN_NAME_LENGTH- telegram.constants.ForumTopicLimit.MAX_NAME_LENGTH characters.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async edit_message_caption(chat_id=None, message_id=None, inline_message_id=None, caption=None, reply_markup=None, parse_mode=None, caption_entities=None, show_caption_above_media=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to edit captions of messages.

Parameters:
  • chat_id (int | str | None, default: None) – Required if inline_message_id is not specified. |chat_id_channel|

  • message_id (int | None, default: None) – Required if inline_message_id is not specified. Identifier of the message to edit.

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

  • caption (str | None, default: None) – New caption of the message, 0-telegram.constants.MessageLimit.CAPTION_LENGTH characters after entities parsing.

  • parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – |parse_mode|

  • caption_entities (Sequence[MessageEntity] | None, default: None) –

    |caption_entities|

    Changed in version 20.0: |sequenceargs|

  • reply_markup (InlineKeyboardMarkup | None, default: None) – An object for an inline keyboard.

  • show_caption_above_media (bool | None, default: None) –

    Pass |show_cap_above_med|

    Added in version 21.3.

  • business_connection_id (str | None, default: None) –

    |business_id_str_edit|

    Added in version 21.4.

Returns:

On success, if edited message is not an inline message, the edited message is returned, otherwise True is returned.

Returns:

Message | bool

Raises:

telegram.error.TelegramError

async edit_message_checklist(business_connection_id, chat_id, message_id, checklist, reply_markup=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to edit a checklist on behalf of a connected business account.

Added in version 22.3.

Parameters:
  • business_connection_id (str) – |business_id_str|

  • chat_id (int) – Unique identifier for the target chat.

  • message_id (int) – Unique identifier for the target message.

  • checklist (InputChecklist) – The new checklist.

  • reply_markup (InlineKeyboardMarkup | None, default: None) – An object for the new inline keyboard for the message.

Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async edit_message_live_location(chat_id=None, message_id=None, inline_message_id=None, latitude=None, longitude=None, reply_markup=None, horizontal_accuracy=None, heading=None, proximity_alert_radius=None, live_period=None, business_connection_id=None, *, location=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Note

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

Parameters:
  • chat_id (int | str | None, default: None) – Required if inline_message_id is not specified. |chat_id_channel|

  • message_id (int | None, default: None) – Required if inline_message_id is not specified. Identifier of the message to edit.

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

  • latitude (float | None, default: None) – Latitude of location.

  • longitude (float | None, default: None) – Longitude of location.

  • horizontal_accuracy (float | None, default: None) – The radius of uncertainty for the location, measured in meters; 0-telegram.constants.LocationLimit.HORIZONTAL_ACCURACY.

  • heading (int | None, default: None) – Direction in which the user is moving, in degrees. Must be between telegram.constants.LocationLimit.MIN_HEADING and telegram.constants.LocationLimit.MAX_HEADING if specified.

  • proximity_alert_radius (int | None, default: None) – Maximum distance for proximity alerts about approaching another chat member, in meters. Must be between telegram.constants.LocationLimit.MIN_PROXIMITY_ALERT_RADIUS and telegram.constants.LocationLimit.MAX_PROXIMITY_ALERT_RADIUS if specified.

  • reply_markup (InlineKeyboardMarkup | None, default: None) – An object for a new inline keyboard.

  • live_period (int | timedelta | None, default: None) –

    New period in seconds during which the location can be updated, starting from the message send date. If telegram.constants.LocationLimit.LIVE_PERIOD_FOREVER is specified, then the location can be updated forever. Otherwise, the new value must not exceed the current live_period by more than a day, and the live location expiration date must remain within the next 90 days. If not specified, then live_period remains unchanged

    Added in version 21.2..

    Changed in version 21.11: |time-period-input|

  • business_connection_id (str | None, default: None) –

    |business_id_str_edit|

    Added in version 21.4.

Keyword Arguments:

location (telegram.Location, optional) – The location to send.

Returns:

On success, if edited message is not an inline message, the edited message is returned, otherwise True is returned.

Returns:

Message | bool

async edit_message_media(media, chat_id=None, message_id=None, inline_message_id=None, reply_markup=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to edit animation, audio, document, photo, or video messages, or to add media to text messages. If a message is part of a message album, then it can be edited only to an audio for audio albums, only to a document for document albums and to a photo or a video otherwise. When an inline message is edited, a new file can’t be uploaded; use a previously uploaded file via its file_id or specify a URL.

See also

Working with Files and Media <Working-with-Files-and-Media>

Parameters:
  • media (InputMedia) – An object for a new media content of the message.

  • chat_id (int | str | None, default: None) – Required if inline_message_id is not specified. |chat_id_channel|

  • message_id (int | None, default: None) – Required if inline_message_id is not specified. Identifier of the message to edit.

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

  • reply_markup (InlineKeyboardMarkup | None, default: None) – An object for an inline keyboard.

  • business_connection_id (str | None, default: None) –

    |business_id_str_edit|

    Added in version 21.4.

Returns:

On success, if edited message is not an inline message, the edited Message is returned, otherwise True is returned.

Returns:

Message | bool

Raises:

telegram.error.TelegramError

async edit_message_reply_markup(chat_id=None, message_id=None, inline_message_id=None, reply_markup=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Parameters:
  • chat_id (int | str | None, default: None) – Required if inline_message_id is not specified. |chat_id_channel|

  • message_id (int | None, default: None) – Required if inline_message_id is not specified. Identifier of the message to edit.

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

  • reply_markup (InlineKeyboardMarkup | None, default: None) – An object for an inline keyboard.

  • business_connection_id (str | None, default: None) –

    |business_id_str_edit|

    Added in version 21.4.

Returns:

On success, if edited message is not an inline message, the edited message is returned, otherwise True is returned.

Returns:

Message | bool

Raises:

telegram.error.TelegramError

async edit_message_text(text, chat_id=None, message_id=None, inline_message_id=None, parse_mode=None, reply_markup=None, entities=None, link_preview_options=None, business_connection_id=None, *, disable_web_page_preview=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to edit text and game messages.

Parameters:
  • chat_id (int | str | None, default: None) – Required if inline_message_id is not specified. |chat_id_channel|

  • message_id (int | None, default: None) – Required if inline_message_id is not specified. Identifier of the message to edit.

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

  • text (str) – New text of the message, telegram.constants.MessageLimit.MIN_TEXT_LENGTH- telegram.constants.MessageLimit.MAX_TEXT_LENGTH characters after entities parsing.

  • parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – |parse_mode|

  • entities (Sequence[MessageEntity] | None, default: None) –

    Sequence of special entities that appear in message text, which can be specified instead of parse_mode.

    Changed in version 20.0: |sequenceargs|

  • link_preview_options (DefaultValue[DVValueType] | LinkPreviewOptions | DefaultValue[None] | None, default: None) –

    Link preview generation options for the message. Mutually exclusive with disable_web_page_preview.

    Added in version 20.8.

  • reply_markup (InlineKeyboardMarkup | None, default: None) – An object for an inline keyboard.

  • business_connection_id (str | None, default: None) –

    |business_id_str_edit|

    Added in version 21.4.

Keyword Arguments:

disable_web_page_preview (bool, optional) –

Disables link previews for links in this message. Convenience parameter for setting link_preview_options. Mutually exclusive with link_preview_options.

Changed in version 20.8: Bot API 7.0 introduced link_preview_options replacing this argument. PTB will automatically convert this argument to that one, but for advanced options, please use link_preview_options directly.

Changed in version 21.0: |keyword_only_arg|

Returns:

On success, if edited message is not an inline message, the edited message is returned, otherwise True is returned.

Returns:

Message | bool

Raises:
async edit_story(business_connection_id, story_id, content, caption=None, parse_mode=None, caption_entities=None, areas=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Edits a story previously posted by the bot on behalf of a managed business account. Requires the can_manage_stories business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection.

  • story_id (int) – Unique identifier of the story to edit.

  • content (InputStoryContent) – Content of the story.

  • caption (str | None, default: None) – Caption of the story, 0-~telegram.constants.StoryLimit.CAPTION_LENGTH characters after entities parsing.

  • parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – Mode for parsing entities in the story caption. See the constants in telegram.constants.ParseMode for the available modes.

  • caption_entities (Sequence[MessageEntity] | None, default: None) – |caption_entities|

  • areas (Sequence[StoryArea] | None, default: None) –

    Sequence of clickable areas to be shown on the story.

    Note

    Each type of clickable area in areas has its own maximum limit:

Returns:

StoryStory

Raises:

telegram.error.TelegramError

async edit_user_star_subscription(user_id, telegram_payment_charge_id, is_canceled, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Allows the bot to cancel or re-enable extension of a subscription paid in Telegram Stars.

Added in version 21.8.

Parameters:
  • user_id (int) – Identifier of the user whose subscription will be edited.

  • telegram_payment_charge_id (str) – Telegram payment identifier for the subscription.

  • is_canceled (bool) – Pass True to cancel extension of the user subscription; the subscription must be active up to the end of the current subscription period. Pass False to allow the user to re-enable a subscription that was previously canceled by the bot.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

Alias for export_chat_invite_link()

Return type:

str

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

Note

Each administrator in a chat generates their own invite links. Bots can’t use invite links generated by other administrators. If you want your bot to work with invite links, it will need to generate its own link using export_chat_invite_link() or by calling the get_chat() method. If your bot needs to generate a new primary invite link replacing its previous one, use export_chat_invite_link() again.

Parameters:

chat_id (str | int) – |chat_id_channel|

Returns:

New invite link on success.

Returns:

str

Raises:

telegram.error.TelegramError

property first_name: str

Bot’s first name. Shortcut for the corresponding attribute of bot.

Type:

str

async forwardMessage(chat_id, from_chat_id, message_id, disable_notification=None, protect_content=None, message_thread_id=None, video_start_timestamp=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for forward_message()

Return type:

Message

async forwardMessages(chat_id, from_chat_id, message_ids, disable_notification=None, protect_content=None, message_thread_id=None, direct_messages_topic_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for forward_messages()

Return type:

tuple[MessageId, ...]

async forward_message(chat_id, from_chat_id, message_id, disable_notification=None, protect_content=None, message_thread_id=None, video_start_timestamp=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to forward messages of any kind. Service messages can’t be forwarded.

Note

Since the release of Bot API 5.5 it can be impossible to forward messages from some chats. Use the attributes telegram.Message.has_protected_content and telegram.ChatFullInfo.has_protected_content to check this.

As a workaround, it is still possible to use copy_message(). However, this behaviour is undocumented and might be changed by Telegram.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

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

  • video_start_timestamp (int | None, default: None) –

    New start timestamp for the forwarded video in the message

    Added in version 21.11.

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    An object containing the parameters of the suggested post to send; for direct messages chats only.

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    Identifier of the direct messages topic to which the message will be forwarded; required if the message is forwarded to a direct messages chat.

    Added in version 22.4.

Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async forward_messages(chat_id, from_chat_id, message_ids, disable_notification=None, protect_content=None, message_thread_id=None, direct_messages_topic_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to forward 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.

Added in version 20.8.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

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

  • message_ids (Sequence[int]) – A list of telegram.constants.BulkRequestLimit.MIN_LIMIT- telegram.constants.BulkRequestLimit.MAX_LIMIT identifiers of messages in the chat from_chat_id to forward. The identifiers must be specified in a strictly increasing order.

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |protect_content|

  • message_thread_id (int | None, default: None) – |message_thread_id_arg|

  • direct_messages_topic_id (int | None, default: None) –

    Identifier of the direct messages topic to which the messages will be forwarded; required if the messages are forwarded to a direct messages chat.

    Added in version 22.4.

Returns:

On success, a tuple of MessageId of sent messages is returned.

Returns:

tuple[MessageId, ...]

Raises:

telegram.error.TelegramError

async getAvailableGifts(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_available_gifts()

Return type:

Gifts

async getBusinessAccountGifts(business_connection_id, exclude_unsaved=None, exclude_saved=None, exclude_unlimited=None, exclude_limited=None, exclude_unique=None, sort_by_price=None, offset=None, limit=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_business_account_gifts()

Return type:

OwnedGifts

async getBusinessAccountStarBalance(business_connection_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_business_account_star_balance()

Return type:

StarAmount

async getBusinessConnection(business_connection_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_business_connection()

Return type:

BusinessConnection

async getChat(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_chat()

Return type:

ChatFullInfo

async getChatAdministrators(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_chat_administrators()

Return type:

tuple[ChatMember, ...]

async getChatMember(chat_id, user_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_chat_member()

Return type:

ChatMember

async getChatMemberCount(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_chat_member_count()

Return type:

int

async getChatMenuButton(chat_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_chat_menu_button()

Return type:

MenuButton

async getCustomEmojiStickers(custom_emoji_ids, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_custom_emoji_stickers()

Return type:

tuple[Sticker, ...]

async getFile(file_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_file()

Return type:

File

async getForumTopicIconStickers(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_forum_topic_icon_stickers()

Return type:

tuple[Sticker, ...]

async getGameHighScores(user_id, chat_id=None, message_id=None, inline_message_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_game_high_scores()

Return type:

tuple[GameHighScore, ...]

async getMe(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_me()

Return type:

User

async getMyCommands(scope=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_my_commands()

Return type:

tuple[BotCommand, ...]

async getMyDefaultAdministratorRights(for_channels=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_my_default_administrator_rights()

Return type:

ChatAdministratorRights

async getMyDescription(language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_my_description()

Return type:

BotDescription

async getMyName(language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_my_name()

Return type:

BotName

async getMyShortDescription(language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_my_short_description()

Return type:

BotShortDescription

async getMyStarBalance(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_my_star_balance()

Return type:

StarAmount

async getStarTransactions(offset=None, limit=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_star_transactions()

Return type:

StarTransactions

async getStickerSet(name, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_sticker_set()

Return type:

StickerSet

async getUpdates(offset=None, limit=None, timeout=None, allowed_updates=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_updates()

Return type:

tuple[Update, ...]

async getUserChatBoosts(chat_id, user_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_user_chat_boosts()

Return type:

UserChatBoosts

async getUserProfilePhotos(user_id, offset=None, limit=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_user_profile_photos()

Return type:

UserProfilePhotos

async getWebhookInfo(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_webhook_info()

Return type:

WebhookInfo

async get_available_gifts(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Returns the list of gifts that can be sent by the bot to users and channel chats. Requires no parameters.

Added in version 21.8.

Returns:

Giftstelegram.Gifts

Raises:

telegram.error.TelegramError

async get_business_account_gifts(business_connection_id, exclude_unsaved=None, exclude_saved=None, exclude_unlimited=None, exclude_limited=None, exclude_unique=None, sort_by_price=None, offset=None, limit=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Returns the gifts received and owned by a managed business account. Requires the can_view_gifts_and_stars business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection.

  • exclude_unsaved (bool | None, default: None) – Pass True to exclude gifts that aren’t saved to the account’s profile page.

  • exclude_saved (bool | None, default: None) – Pass True to exclude gifts that are saved to the account’s profile page.

  • exclude_unlimited (bool | None, default: None) – Pass True to exclude gifts that can be purchased an unlimited number of times.

  • exclude_limited (bool | None, default: None) – Pass True to exclude gifts that can be purchased a limited number of times.

  • exclude_unique (bool | None, default: None) – Pass True to exclude unique gifts.

  • sort_by_price (bool | None, default: None) – Pass True to sort results by gift price instead of send date. Sorting is applied before pagination.

  • offset (str | None, default: None) – Offset of the first entry to return as received from the previous request; use empty string to get the first chunk of results.

  • limit (int | None, default: None) – The maximum number of gifts to be returned; telegram.constants.BusinessLimit.MIN_GIFT_RESULTS- telegram.constants.BusinessLimit.MAX_GIFT_RESULTS. Defaults to telegram.constants.BusinessLimit.MAX_GIFT_RESULTS.

Returns:

OwnedGiftstelegram.OwnedGifts

Raises:

telegram.error.TelegramError

async get_business_account_star_balance(business_connection_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Returns the amount of Telegram Stars owned by a managed business account. Requires the can_view_gifts_and_stars business bot right.

Added in version 22.1.

Parameters:

business_connection_id (str) – Unique identifier of the business connection.

Returns:

StarAmounttelegram.StarAmount

Raises:

telegram.error.TelegramError

async get_business_connection(business_connection_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to get information about the connection of the bot with a business account.

Added in version 21.1.

Parameters:

business_connection_id (str) – Unique identifier of the business connection.

Returns:

On success, the object containing the business

connection information is returned.

Returns:

BusinessConnection

Raises:

telegram.error.TelegramError

async get_chat(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.).

Changed in version 21.2: In accordance to Bot API 7.3, this method now returns a telegram.ChatFullInfo.

Parameters:

chat_id (str | int) – |chat_id_channel|

Returns:

ChatFullInfotelegram.ChatFullInfo

Raises:

telegram.error.TelegramError

async get_chat_administrators(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Changed in version 20.0: Returns a tuple instead of a list.

Parameters:

chat_id (str | int) – |chat_id_channel|

Returns:

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

Returns:

tuple[ChatMember, ...]

Raises:

telegram.error.TelegramError

async get_chat_member(chat_id, user_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to get information about a member of a chat. The method is only guaranteed to work for other users if the bot is an administrator in the chat.

Parameters:
Returns:

ChatMembertelegram.ChatMember

Raises:

telegram.error.TelegramError

async get_chat_member_count(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 13.7.

Parameters:

chat_id (str | int) – |chat_id_channel|

Returns:

Number of members in the chat.

Returns:

int

Raises:

telegram.error.TelegramError

async get_chat_menu_button(chat_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 20.0.

Parameters:

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

Returns:

On success, the current menu button is returned.

Returns:

MenuButton

async get_custom_emoji_stickers(custom_emoji_ids, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Changed in version 20.0: Returns a tuple instead of a list.

Parameters:

custom_emoji_ids (Sequence[str]) –

Sequence of custom emoji identifiers. At most telegram.constants.CustomEmojiStickerLimit.CUSTOM_EMOJI_IDENTIFIER_LIMIT custom emoji identifiers can be specified.

Changed in version 20.0: |sequenceargs|

Returns:

tuple[Sticker, ...] – tuple[telegram.Sticker]

Raises:

telegram.error.TelegramError

async get_file(file_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 telegram.constants.FileSizeLimit.FILESIZE_DOWNLOAD in size. The file can then be e.g. downloaded with telegram.File.download_to_drive(). 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.

Note

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

See also

Working with Files and Media <Working-with-Files-and-Media>

Parameters:

file_id (str | Animation | Audio | ChatPhoto | Document | PhotoSize | Sticker | Video | VideoNote | Voice) – Either the file identifier or an object that has a file_id attribute to get file information about.

Returns:

Filetelegram.File

Raises:

telegram.error.TelegramError

async get_forum_topic_icon_stickers(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 20.0.

Returns:

tuple[Sticker, ...] – tuple[telegram.Sticker]

Raises:

telegram.error.TelegramError

async get_game_high_scores(user_id, chat_id=None, message_id=None, inline_message_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Note

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 his neighbors are not among them. Please note that this behavior is subject to change.

Changed in version 20.0: Returns a tuple instead of a list.

Parameters:
  • user_id (int) – Target user id.

  • chat_id (int | None, default: None) – Required if inline_message_id is not specified. Unique identifier for the target chat.

  • message_id (int | None, default: None) – Required if inline_message_id is not specified. Identifier of the sent message.

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

Returns:

tuple[GameHighScore, ...] – tuple[telegram.GameHighScore]

Raises:

telegram.error.TelegramError

async get_me(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Returns:

A telegram.User instance representing that bot if the credentials are valid, None otherwise.

Returns:

User

Raises:

telegram.error.TelegramError

async get_my_commands(scope=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to get the current list of the bot’s commands for the given scope and user language.

Changed in version 20.0: Returns a tuple instead of a list.

Parameters:
Returns:

On success, the commands set for the bot. An empty tuple is returned if commands are not set.

Returns:

tuple[BotCommand, ...]

Raises:

telegram.error.TelegramError

async get_my_default_administrator_rights(for_channels=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to get the current default administrator rights of the bot.

Added in version 20.0.

Parameters:

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

Returns:

On success.

Returns:

ChatAdministratorRights

Raises:

telegram.error.TelegramError

async get_my_description(language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to get the current bot description for the given user language.

Parameters:

language_code (str | None, default: None) – A two-letter ISO 639-1 language code or an empty string.

Returns:

On success, the bot description is returned.

Returns:

BotDescription

Raises:

telegram.error.TelegramError

async get_my_name(language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to get the current bot name for the given user language.

Parameters:

language_code (str | None, default: None) – A two-letter ISO 639-1 language code or an empty string.

Returns:

On success, the bot name is returned.

Returns:

BotName

Raises:

telegram.error.TelegramError

async get_my_short_description(language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to get the current bot short description for the given user language.

Parameters:

language_code (str | None, default: None) – A two-letter ISO 639-1 language code or an empty string.

Returns:

On success, the bot short description is

returned.

Returns:

BotShortDescription

Raises:

telegram.error.TelegramError

async get_my_star_balance(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

A method to get the current Telegram Stars balance of the bot. Requires no parameters.

Added in version 22.3.

Returns:

StarAmounttelegram.StarAmount

Raises:

telegram.error.TelegramError

async get_star_transactions(offset=None, limit=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 21.4.

Parameters:
  • offset (int | None, default: None) – Number of transactions to skip in the response.

  • limit (int | None, default: None) – The maximum number of transactions to be retrieved. Values between telegram.constants.StarTransactionsLimit.MIN_LIMIT- telegram.constants.StarTransactionsLimit.MAX_LIMIT are accepted. Defaults to telegram.constants.StarTransactionsLimit.MAX_LIMIT.

Returns:

On success.

Returns:

StarTransactions

Raises:

telegram.error.TelegramError

async get_sticker_set(name, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to get a sticker set.

Parameters:

name (str) – Name of the sticker set.

Returns:

StickerSettelegram.StickerSet

Raises:

telegram.error.TelegramError

async get_updates(offset=None, limit=None, timeout=None, allowed_updates=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to receive incoming updates using long polling.

Note

  1. This method will not work if an outgoing webhook is set up.

  2. In order to avoid getting duplicate updates, recalculate offset after each server response.

  3. To take full advantage of this library take a look at telegram.ext.Updater

Changed in version 20.0: Returns a tuple instead of a list.

Parameters:
  • offset (int | None, default: None) – 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 this method is called with an offset higher than its telegram.Update.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 be forgotten.

  • limit (int | None, default: None) – Limits the number of updates to be retrieved. Values between telegram.constants.PollingLimit.MIN_LIMIT- telegram.constants.PollingLimit.MAX_LIMIT are accepted. Defaults to 100.

  • timeout (int | timedelta | None, default: None) –

    Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be positive, short polling should be used for testing purposes only.

    Changed in version v22.2: |time-period-input|

  • allowed_updates (Sequence[str] | None, default: None) –

    A sequence the types of updates you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See telegram.Update for a complete list of available update types. Specify an empty sequence to receive all updates except telegram.Update.chat_member, telegram.Update.message_reaction and telegram.Update.message_reaction_count (default). If not specified, the previous setting will be used. Please note that this parameter doesn’t affect updates created before the call to the get_updates, so unwanted updates may be received for a short period of time.

    Changed in version 20.0: |sequenceargs|

Returns:

tuple[Update, ...] – tuple[telegram.Update]

Raises:

telegram.error.TelegramError

async get_user_chat_boosts(chat_id, user_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 20.8.

Parameters:
Returns:

On success, the object containing the list of boosts

is returned.

Returns:

UserChatBoosts

Raises:

telegram.error.TelegramError

async get_user_profile_photos(user_id, offset=None, limit=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

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

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

  • limit (int | None, default: None) – Limits the number of photos to be retrieved. Values between telegram.constants.UserProfilePhotosLimit.MIN_LIMIT- telegram.constants.UserProfilePhotosLimit.MAX_LIMIT are accepted. Defaults to 100.

Returns:

UserProfilePhotostelegram.UserProfilePhotos

Raises:

telegram.error.TelegramError

async get_webhook_info(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

If the bot is using get_updates(), will return an object with the telegram.WebhookInfo.url field empty.

Returns:

WebhookInfotelegram.WebhookInfo

async giftPremiumSubscription(user_id, month_count, star_count, text=None, text_parse_mode=None, text_entities=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for gift_premium_subscription()

Return type:

bool

async gift_premium_subscription(user_id, month_count, star_count, text=None, text_parse_mode=None, text_entities=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Gifts a Telegram Premium subscription to the given user.

Added in version 22.1.

Parameters:
  • user_id (int) – Unique identifier of the target user who will receive a Telegram Premium subscription.

  • month_count (int) – Number of months the Telegram Premium subscription will be active for the user; must be one of telegram.constants.PremiumSubscription.MONTH_COUNT_THREE, telegram.constants.PremiumSubscription.MONTH_COUNT_SIX, or telegram.constants.PremiumSubscription.MONTH_COUNT_TWELVE.

  • star_count (int) – Number of Telegram Stars to pay for the Telegram Premium subscription; must be telegram.constants.PremiumSubscription.STARS_THREE_MONTHS for telegram.constants.PremiumSubscription.MONTH_COUNT_THREE months, telegram.constants.PremiumSubscription.STARS_SIX_MONTHS for telegram.constants.PremiumSubscription.MONTH_COUNT_SIX months, and telegram.constants.PremiumSubscription.STARS_TWELVE_MONTHS for telegram.constants.PremiumSubscription.MONTH_COUNT_TWELVE months.

  • text (str | None, default: None) – Text that will be shown along with the service message about the subscription; 0-telegram.constants.PremiumSubscription.MAX_TEXT_LENGTH characters.

  • text_parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – Mode for parsing entities. See telegram.constants.ParseMode and formatting options for more details. Entities other than BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, SPOILER, and CUSTOM_EMOJI are ignored.

  • text_entities (Sequence[MessageEntity] | None, default: None) – A list of special entities that appear in the gift text. It can be specified instead of text_parse_mode. Entities other than BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, SPOILER, and CUSTOM_EMOJI are ignored.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async hideGeneralForumTopic(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for hide_general_forum_topic()

Return type:

bool

async hide_general_forum_topic(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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. The topic will be automatically closed if it was open.

Added in version 20.0.

Parameters:

chat_id (str | int) – |chat_id_group|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

property id: int

Unique identifier for this bot. Shortcut for the corresponding attribute of bot.

Type:

int

async initialize()[source]

Initialize resources used by this class. Currently calls get_me() to cache bot and calls telegram.request.BaseRequest.initialize() for the request objects used by this bot.

See also

shutdown()

Added in version 20.0.

Return type:

None

property last_name: str

Optional. Bot’s last name. Shortcut for the corresponding attribute of bot.

Type:

str

async leaveChat(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for leave_chat()

Return type:

bool

async leave_chat(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Parameters:

chat_id (str | int) – |chat_id_channel|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

Convenience property. Returns the t.me link of the bot.

Type:

str

property local_mode: bool

Whether this bot is running in local mode.

Added in version 20.0.

Type:

bool

async logOut(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for log_out()

Return type:

bool

async log_out(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

property name: str

Bot’s @username. Shortcut for the corresponding attribute of bot.

Type:

str

async pinChatMessage(chat_id, message_id, disable_notification=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for pin_chat_message()

Return type:

bool

async pin_chat_message(chat_id, message_id, disable_notification=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Parameters:
  • chat_id (str | int) – |chat_id_channel|

  • message_id (int) – Identifier of a message to pin.

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – Pass True, if it is not necessary to send a notification to all chat members about the new pinned message. Notifications are always disabled in channels and private chats.

  • business_connection_id (str | None, default: None) –

    Unique identifier of the business connection on behalf of which the message will be pinned.

    Added in version 21.5.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async postStory(business_connection_id, content, active_period, caption=None, parse_mode=None, caption_entities=None, areas=None, post_to_chat_page=None, protect_content=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for post_story()

Return type:

Story

async post_story(business_connection_id, content, active_period, caption=None, parse_mode=None, caption_entities=None, areas=None, post_to_chat_page=None, protect_content=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Posts a story on behalf of a managed business account. Requires the can_manage_stories business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection.

  • content (InputStoryContent) – Content of the story.

  • active_period (int | timedelta) – Period after which the story is moved to the archive, in seconds; must be one of ~telegram.constants.StoryLimit.ACTIVITY_SIX_HOURS, ~telegram.constants.StoryLimit.ACTIVITY_TWELVE_HOURS, ~telegram.constants.StoryLimit.ACTIVITY_ONE_DAY, or ~telegram.constants.StoryLimit.ACTIVITY_TWO_DAYS.

  • caption (str | None, default: None) – Caption of the story, 0-~telegram.constants.StoryLimit.CAPTION_LENGTH characters after entities parsing.

  • parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – Mode for parsing entities in the story caption. See the constants in telegram.constants.ParseMode for the available modes.

  • caption_entities (Sequence[MessageEntity] | None, default: None) – |caption_entities|

  • areas (Sequence[StoryArea] | None, default: None) –

    Sequence of clickable areas to be shown on the story.

    Note

    Each type of clickable area in areas has its own maximum limit:

  • post_to_chat_page (bool | None, default: None) – Pass True to keep the story accessible after it expires.

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – Pass True if the content of the story must be protected from forwarding and screenshotting

Returns:

StoryStory

Raises:

telegram.error.TelegramError

property private_key: Any | None

Deserialized private key for decryption of telegram passport data.

Added in version 20.0.

async promoteChatMember(chat_id, user_id, can_change_info=None, can_post_messages=None, can_edit_messages=None, can_delete_messages=None, can_invite_users=None, can_restrict_members=None, can_pin_messages=None, can_promote_members=None, is_anonymous=None, can_manage_chat=None, can_manage_video_chats=None, can_manage_topics=None, can_post_stories=None, can_edit_stories=None, can_delete_stories=None, can_manage_direct_messages=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for promote_chat_member()

Return type:

bool

async promote_chat_member(chat_id, user_id, can_change_info=None, can_post_messages=None, can_edit_messages=None, can_delete_messages=None, can_invite_users=None, can_restrict_members=None, can_pin_messages=None, can_promote_members=None, is_anonymous=None, can_manage_chat=None, can_manage_video_chats=None, can_manage_topics=None, can_post_stories=None, can_edit_stories=None, can_delete_stories=None, can_manage_direct_messages=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Changed in version 20.0: The argument can_manage_voice_chats was renamed to can_manage_video_chats in accordance to Bot API 6.0.

Parameters:
  • chat_id (str | int) – |chat_id_channel|

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

  • is_anonymous (bool | None, default: None) – Pass True, if the administrator’s presence in the chat is hidden.

  • can_manage_chat (bool | None, default: None) –

    Pass True, if the administrator can access the chat event log, get boost list, see hidden supergroup and channel members, report spam messages and ignore slow mode. Implied by any other administrator privilege.

    Added in version 13.4.

  • can_manage_video_chats (bool | None, default: None) –

    Pass True, if the administrator can manage video chats.

    Added in version 20.0.

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

  • can_post_messages (bool | None, default: None) – Pass True, if the administrator can post messages in the channel, or access channel statistics; for channels only.

  • can_edit_messages (bool | None, default: None) – Pass True, if the administrator can edit messages of other users and can pin messages, for channels only.

  • can_delete_messages (bool | None, default: None) – Pass True, if the administrator can delete messages of other users.

  • can_invite_users (bool | None, default: None) – Pass True, if the administrator can invite new users to the chat.

  • can_restrict_members (bool | None, default: None) – Pass True, if the administrator can restrict, ban or unban chat members, or access supergroup statistics.

  • can_pin_messages (bool | None, default: None) – Pass True, if the administrator can pin messages, for supergroups only.

  • can_promote_members (bool | None, default: None) – Pass True, if the administrator can add new administrators with a subset of their own privileges or demote administrators that they have promoted, directly or indirectly (promoted by administrators that were appointed by the user).

  • can_manage_topics (bool | None, default: None) –

    Pass True, if the user is allowed to create, rename, close, and reopen forum topics; for supergroups only.

    Added in version 20.0.

  • can_post_stories (bool | None, default: None) –

    Pass True, if the administrator can post stories to the chat.

    Added in version 20.6.

  • can_edit_stories (bool | None, default: None) –

    Pass True, if the administrator can edit stories posted by other users, post stories to the chat page, pin chat stories, and access the chat’s story archive

    Added in version 20.6.

  • can_delete_stories (bool | None, default: None) –

    Pass True, if the administrator can delete stories posted by other users.

    Added in version 20.6.

  • can_manage_direct_messages (bool | None, default: None) –

    Pass True, if the administrator can manage direct messages within the channel and decline suggested posts; for channels only

    Added in version 22.4.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async readBusinessMessage(business_connection_id, chat_id, message_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for read_business_message()

Return type:

bool

async read_business_message(business_connection_id, chat_id, message_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Marks incoming message as read on behalf of a business account. Requires the can_read_messages business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection on behalf of which to read the message.

  • chat_id (int) – Unique identifier of the chat in which the message was received. The chat must have been active in the last ~telegram.constants.BusinessLimit.CHAT_ACTIVITY_TIMEOUT seconds.

  • message_id (int) – Unique identifier of the message to mark as read.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async refundStarPayment(user_id, telegram_payment_charge_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for refund_star_payment()

Return type:

bool

async refund_star_payment(user_id, telegram_payment_charge_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Refunds a successful payment in |tg_stars|.

Added in version 21.3.

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

  • telegram_payment_charge_id (str) – Telegram payment identifier.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async removeBusinessAccountProfilePhoto(business_connection_id, is_public=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for remove_business_account_profile_photo()

Return type:

bool

async removeChatVerification(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for remove_chat_verification()

Return type:

bool

async removeUserVerification(user_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for remove_user_verification()

Return type:

bool

async remove_business_account_profile_photo(business_connection_id, is_public=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Removes the current profile photo of a managed business account. Requires the can_edit_profile_photo business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection.

  • is_public (bool | None, default: None) – Pass True to remove the public photo, which will be visible even if the main photo is hidden by the business account’s privacy settings. After the main photo is removed, the previous profile photo (if present) becomes the main photo.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async remove_chat_verification(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Removes verification from a chat that is currently verified |org-verify| represented by the bot.

Added in version 21.10.

Parameters:

chat_id (int | str) – |chat_id_channel|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async remove_user_verification(user_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Removes verification from a user who is currently verified |org-verify| represented by the bot.

Added in version 21.10.

Parameters:

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

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async reopenForumTopic(chat_id, message_thread_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for reopen_forum_topic()

Return type:

bool

async reopenGeneralForumTopic(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for reopen_general_forum_topic()

Return type:

bool

async reopen_forum_topic(chat_id, message_thread_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 ~telegram.ChatAdministratorRights.can_manage_topics administrator rights, unless it is the creator of the topic.

Added in version 20.0.

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async reopen_general_forum_topic(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to reopen a closed ‘General’ topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights. The topic will be automatically unhidden if it was hidden.

Added in version 20.0.

Parameters:

chat_id (str | int) – |chat_id_group|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async replaceStickerInSet(user_id, name, old_sticker, sticker, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for replace_sticker_in_set()

Return type:

bool

async replace_sticker_in_set(user_id, name, old_sticker, sticker, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to replace an existing sticker in a sticker set with a new one. The method is equivalent to calling delete_sticker_from_set(), then add_sticker_to_set(), then set_sticker_position_in_set().

Added in version 21.1.

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

  • name (str) – Sticker set name.

  • old_sticker (str | Sticker) –

    File identifier of the replaced sticker or the sticker object itself.

    Changed in version 21.10: Accepts also telegram.Sticker instances.

  • sticker (InputSticker) – An 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:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

property request: BaseRequest

The BaseRequest object used by this bot.

Warning

Requests to the Bot API are made by the various methods of this class. This attribute should not be used manually.

async restrictChatMember(chat_id, user_id, permissions, until_date=None, use_independent_chat_permissions=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for restrict_chat_member()

Return type:

bool

async restrict_chat_member(chat_id, user_id, permissions, until_date=None, use_independent_chat_permissions=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

Alias for revoke_chat_invite_link()

Return type:

ChatInviteLink

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

Added in version 13.4.

Parameters:
Returns:

ChatInviteLinktelegram.ChatInviteLink

Raises:

telegram.error.TelegramError

async savePreparedInlineMessage(user_id, result, allow_user_chats=None, allow_bot_chats=None, allow_group_chats=None, allow_channel_chats=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for save_prepared_inline_message()

Return type:

PreparedInlineMessage

async save_prepared_inline_message(user_id, result, allow_user_chats=None, allow_bot_chats=None, allow_group_chats=None, allow_channel_chats=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Stores a message that can be sent by a user of a Mini App.

Added in version 21.8.

Parameters:
  • user_id (int) – Unique identifier of the target user that can use the prepared message.

  • result (InlineQueryResult) – The result to store.

  • allow_user_chats (bool | None, default: None) – Pass True if the message can be sent to private chats with users

  • allow_bot_chats (bool | None, default: None) – Pass True if the message can be sent to private chats with bots

  • allow_group_chats (bool | None, default: None) – Pass True if the message can be sent to group and supergroup chats

  • allow_channel_chats (bool | None, default: None) – Pass True if the message can be sent to channels

Returns:

On success, the prepared message is returned.

Returns:

PreparedInlineMessage

Raises:

telegram.error.TelegramError

async sendAnimation(chat_id, animation, duration=None, width=None, height=None, caption=None, parse_mode=None, disable_notification=None, reply_markup=None, caption_entities=None, protect_content=None, message_thread_id=None, has_spoiler=None, thumbnail=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, show_caption_above_media=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_animation()

Return type:

Message

async sendAudio(chat_id, audio, duration=None, performer=None, title=None, caption=None, disable_notification=None, reply_markup=None, parse_mode=None, caption_entities=None, protect_content=None, message_thread_id=None, thumbnail=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_audio()

Return type:

Message

async sendChatAction(chat_id, action, message_thread_id=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_chat_action()

Return type:

bool

async sendChecklist(business_connection_id, chat_id, checklist, disable_notification=None, protect_content=None, message_effect_id=None, reply_parameters=None, reply_markup=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_checklist()

Return type:

Message

async sendContact(chat_id, phone_number=None, first_name=None, last_name=None, disable_notification=None, reply_markup=None, vcard=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, contact=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_contact()

Return type:

Message

async sendDice(chat_id, disable_notification=None, reply_markup=None, emoji=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_dice()

Return type:

Message

async sendDocument(chat_id, document, caption=None, disable_notification=None, reply_markup=None, parse_mode=None, disable_content_type_detection=None, caption_entities=None, protect_content=None, message_thread_id=None, thumbnail=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_document()

Return type:

Message

async sendGame(chat_id, game_short_name, disable_notification=None, reply_markup=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_game()

Return type:

Message

async sendGift(gift_id, text=None, text_parse_mode=None, text_entities=None, pay_for_upgrade=None, chat_id=None, user_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_gift()

Return type:

bool

async sendInvoice(chat_id, title, description, payload, currency, prices, provider_token=None, start_parameter=None, photo_url=None, photo_size=None, photo_width=None, photo_height=None, need_name=None, need_phone_number=None, need_email=None, need_shipping_address=None, is_flexible=None, disable_notification=None, reply_markup=None, provider_data=None, send_phone_number_to_provider=None, send_email_to_provider=None, max_tip_amount=None, suggested_tip_amounts=None, protect_content=None, message_thread_id=None, reply_parameters=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_invoice()

Return type:

Message

async sendLocation(chat_id, latitude=None, longitude=None, disable_notification=None, reply_markup=None, live_period=None, horizontal_accuracy=None, heading=None, proximity_alert_radius=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, location=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_location()

Return type:

Message

async sendMediaGroup(chat_id, media, disable_notification=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None, caption=None, parse_mode=None, caption_entities=None)

Alias for send_media_group()

Return type:

tuple[Message, ...]

async sendMessage(chat_id, text, parse_mode=None, entities=None, disable_notification=None, protect_content=None, reply_markup=None, message_thread_id=None, link_preview_options=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, disable_web_page_preview=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_message()

Return type:

Message

async sendPaidMedia(chat_id, star_count, media, caption=None, parse_mode=None, caption_entities=None, show_caption_above_media=None, disable_notification=None, protect_content=None, reply_parameters=None, reply_markup=None, business_connection_id=None, payload=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, message_thread_id=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_paid_media()

Return type:

Message

async sendPhoto(chat_id, photo, caption=None, disable_notification=None, reply_markup=None, parse_mode=None, caption_entities=None, protect_content=None, message_thread_id=None, has_spoiler=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, show_caption_above_media=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_photo()

Return type:

Message

async sendPoll(chat_id, question, options, is_anonymous=None, type=None, allows_multiple_answers=None, correct_option_id=None, is_closed=None, disable_notification=None, reply_markup=None, explanation=None, explanation_parse_mode=None, open_period=None, close_date=None, explanation_entities=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, question_parse_mode=None, question_entities=None, message_effect_id=None, allow_paid_broadcast=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_poll()

Return type:

Message

async sendSticker(chat_id, sticker, disable_notification=None, reply_markup=None, protect_content=None, message_thread_id=None, emoji=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_sticker()

Return type:

Message

async sendVenue(chat_id, latitude=None, longitude=None, title=None, address=None, foursquare_id=None, disable_notification=None, reply_markup=None, foursquare_type=None, google_place_id=None, google_place_type=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, venue=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_venue()

Return type:

Message

async sendVideo(chat_id, video, duration=None, caption=None, disable_notification=None, reply_markup=None, width=None, height=None, parse_mode=None, supports_streaming=None, caption_entities=None, protect_content=None, message_thread_id=None, has_spoiler=None, thumbnail=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, show_caption_above_media=None, cover=None, start_timestamp=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_video()

Return type:

Message

async sendVideoNote(chat_id, video_note, duration=None, length=None, disable_notification=None, reply_markup=None, protect_content=None, message_thread_id=None, thumbnail=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_video_note()

Return type:

Message

async sendVoice(chat_id, voice, duration=None, caption=None, disable_notification=None, reply_markup=None, parse_mode=None, caption_entities=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_voice()

Return type:

Message

async send_animation(chat_id, animation, duration=None, width=None, height=None, caption=None, parse_mode=None, disable_notification=None, reply_markup=None, caption_entities=None, protect_content=None, message_thread_id=None, has_spoiler=None, thumbnail=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, show_caption_above_media=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). Bots can currently send animation files of up to telegram.constants.FileSizeLimit.FILESIZE_UPLOAD in size, this limit may be changed in the future.

Note

thumbnail will be ignored for small files, for which Telegram can easily generate thumbnails. However, this behaviour is undocumented and might be changed by Telegram.

See also

Working with Files and Media <Working-with-Files-and-Media>

Changed in version 20.5: Removed deprecated argument thumb. Use thumbnail instead.

Parameters:
Keyword Arguments:
  • allow_sending_without_reply (bool, optional) –

    |allow_sending_without_reply| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • reply_to_message_id (int, optional) –

    |reply_to_msg_id| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • filename (str, optional) –

    Custom file name for the animation, when uploading a new file. Convenience parameter, useful e.g. when sending files generated by the tempfile module.

    Added in version 13.1.

Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_audio(chat_id, audio, duration=None, performer=None, title=None, caption=None, disable_notification=None, reply_markup=None, parse_mode=None, caption_entities=None, protect_content=None, message_thread_id=None, thumbnail=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Bots can currently send audio files of up to telegram.constants.FileSizeLimit.FILESIZE_UPLOAD in size, this limit may be changed in the future.

For sending voice messages, use the send_voice() method instead.

See also

Working with Files and Media <Working-with-Files-and-Media>

Changed in version 20.5: Removed deprecated argument thumb. Use thumbnail instead.

Parameters:
Keyword Arguments:
  • allow_sending_without_reply (bool, optional) –

    |allow_sending_without_reply| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • reply_to_message_id (int, optional) –

    |reply_to_msg_id| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • filename (str, optional) –

    Custom file name for the audio, when uploading a new file. Convenience parameter, useful e.g. when sending files generated by the tempfile module.

    Added in version 13.1.

Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_chat_action(chat_id, action, message_thread_id=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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). Telegram only recommends using this method when a response from the bot will take a noticeable amount of time to arrive.

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async send_checklist(business_connection_id, chat_id, checklist, disable_notification=None, protect_content=None, message_effect_id=None, reply_parameters=None, reply_markup=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send a checklist on behalf of a connected business account.

Added in version 22.3.

Parameters:
Keyword Arguments:
  • allow_sending_without_reply (bool, optional) – |allow_sending_without_reply| Mutually exclusive with reply_parameters, which this is a convenience parameter for

  • reply_to_message_id (int, optional) – |reply_to_msg_id| Mutually exclusive with reply_parameters, which this is a convenience parameter for

Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_contact(chat_id, phone_number=None, first_name=None, last_name=None, disable_notification=None, reply_markup=None, vcard=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, contact=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send phone contacts.

Note

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

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • phone_number (str | None, default: None) – Contact’s phone number.

  • first_name (str | None, default: None) – Contact’s first name.

  • last_name (str | None, default: None) – Contact’s last name.

  • vcard (str | None, default: None) – Additional data about the contact in the form of a vCard, 0-telegram.constants.ContactLimit.VCARD bytes.

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_dice(chat_id, disable_notification=None, reply_markup=None, emoji=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send an animated emoji that will display a random value.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user

  • emoji (str | None, default: None) –

    Emoji on which the dice throw animation is based. Currently, must be one of telegram.constants.DiceEmoji. Dice can have values telegram.Dice.MIN_VALUE-telegram.Dice.MAX_VALUE_BOWLING for telegram.Dice.DICE, telegram.Dice.DARTS and telegram.Dice.BOWLING, values telegram.Dice.MIN_VALUE-telegram.Dice.MAX_VALUE_BASKETBALL for telegram.Dice.BASKETBALL and telegram.Dice.FOOTBALL, and values telegram.Dice.MIN_VALUE- telegram.Dice.MAX_VALUE_SLOT_MACHINE for telegram.Dice.SLOT_MACHINE. Defaults to telegram.Dice.DICE.

    Changed in version 13.4: Added the telegram.Dice.BOWLING emoji.

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_document(chat_id, document, caption=None, disable_notification=None, reply_markup=None, parse_mode=None, disable_content_type_detection=None, caption_entities=None, protect_content=None, message_thread_id=None, thumbnail=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send general files.

Bots can currently send files of any type of up to telegram.constants.FileSizeLimit.FILESIZE_UPLOAD in size, this limit may be changed in the future.

See also

Working with Files and Media <Working-with-Files-and-Media>

Changed in version 20.5: Removed deprecated argument thumb. Use thumbnail instead.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • document (str | Path | IO[bytes] | InputFile | bytes | Document) –

    File to send. |fileinput| Lastly you can pass an existing telegram.Document object to send.

    Note

    Sending by URL will currently only work GIF, PDF & ZIP files.

    Changed in version 13.2: Accept bytes as input.

    Changed in version 20.0: File paths as input is also accepted for bots not running in ~telegram.Bot.local_mode.

  • caption (str | None, default: None) – Document caption (may also be used when resending documents by file_id), 0-telegram.constants.MessageLimit.CAPTION_LENGTH characters after entities parsing.

  • disable_content_type_detection (bool | None, default: None) – Disables automatic server-side content type detection for files uploaded using multipart/form-data.

  • parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – |parse_mode|

  • caption_entities (Sequence[MessageEntity] | None, default: None) –

    |caption_entities|

    Changed in version 20.0: |sequenceargs|

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • thumbnail (str | Path | IO[bytes] | InputFile | bytes | None, default: None) –

    |thumbdocstring|

    Added in version 20.2.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
  • allow_sending_without_reply (bool, optional) –

    |allow_sending_without_reply| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • reply_to_message_id (int, optional) –

    |reply_to_msg_id| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • filename (str, optional) – Custom file name for the document, when uploading a new file. Convenience parameter, useful e.g. when sending files generated by the tempfile module.

Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_game(chat_id, game_short_name, disable_notification=None, reply_markup=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send a game.

Parameters:
  • chat_id (int) – Unique identifier for the target chat.

  • 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 (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | None, default: None) – An object for a new inline keyboard. If empty, one “Play game_title” button will be shown. If not empty, the first button must launch the game.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

Keyword Arguments:
Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_gift(gift_id, text=None, text_parse_mode=None, text_entities=None, pay_for_upgrade=None, chat_id=None, user_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Sends a gift to the given user or channel chat. The gift can’t be converted to Telegram Stars by the receiver.

Added in version 21.8.

Changed in version 22.1: Bot API 8.3 made user_id optional. In version 22.1, the methods signature was changed accordingly.

Parameters:
  • gift_id (str | Gift) – Identifier of the gift or a Gift object

  • user_id (int | None, default: None) –

    Required if chat_id is not specified. Unique identifier of the target user that will receive the gift.

    Changed in version 21.11: Now optional.

  • chat_id (int | str | None, default: None) –

    Required if user_id is not specified. |chat_id_channel| It will receive the gift.

    Added in version 21.11.

  • text (str | None, default: None) – Text that will be shown along with the gift; 0- telegram.constants.GiftLimit.MAX_TEXT_LENGTH characters

  • text_parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – Mode for parsing entities. See telegram.constants.ParseMode and formatting options for more details. Entities other than BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, SPOILER, and CUSTOM_EMOJI are ignored.

  • text_entities (Sequence[MessageEntity] | None, default: None) – A list of special entities that appear in the gift text. It can be specified instead of text_parse_mode. Entities other than BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, SPOILER, and CUSTOM_EMOJI are ignored.

  • pay_for_upgrade (bool | None, default: None) –

    Pass True to pay for the gift upgrade from the bot’s balance, thereby making the upgrade free for the receiver.

    Added in version 21.10.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async send_invoice(chat_id, title, description, payload, currency, prices, provider_token=None, start_parameter=None, photo_url=None, photo_size=None, photo_width=None, photo_height=None, need_name=None, need_phone_number=None, need_email=None, need_shipping_address=None, is_flexible=None, disable_notification=None, reply_markup=None, provider_data=None, send_phone_number_to_provider=None, send_email_to_provider=None, max_tip_amount=None, suggested_tip_amounts=None, protect_content=None, message_thread_id=None, reply_parameters=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send invoices.

Warning

As of API 5.2 start_parameter is an optional argument and therefore the order of the arguments had to be changed. Use keyword arguments to make sure that the arguments are passed correctly.

Changed in version 13.5: As of Bot API 5.2, the parameter start_parameter is optional.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • title (str) – Product name. telegram.Invoice.MIN_TITLE_LENGTH- telegram.Invoice.MAX_TITLE_LENGTH characters.

  • description (str) – Product description. telegram.Invoice.MIN_DESCRIPTION_LENGTH- telegram.Invoice.MAX_DESCRIPTION_LENGTH characters.

  • payload (str) – Bot-defined invoice payload. telegram.Invoice.MIN_PAYLOAD_LENGTH- telegram.Invoice.MAX_PAYLOAD_LENGTH bytes. This will not be displayed to the user, use it for your internal processes.

  • provider_token (str | None, default: None) –

    Payments provider token, obtained via @BotFather. Pass an empty string for payments in |tg_stars|.

    Changed in version 21.11: Bot API 7.4 made this parameter is optional and this is now reflected in the function signature.

  • currency (str) –

    Three-letter ISO 4217 currency code, see more on currencies. Pass XTR for payment in |tg_stars|.

  • prices (Sequence[LabeledPrice]) –

    Price breakdown, a sequence of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.). Must contain exactly one item for payment in |tg_stars|.

    Changed in version 20.0: |sequenceargs|

  • max_tip_amount (int | None, default: None) –

    The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0. Not supported for payment in |tg_stars|.

    Added in version 13.5.

  • suggested_tip_amounts (Sequence[int] | None, default: None) –

    An array of suggested amounts of tips in the smallest units of the currency (integer, not float/double). At most telegram.Invoice.MAX_TIP_AMOUNTS 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.

    Added in version 13.5.

    Changed in version 20.0: |sequenceargs|

  • start_parameter (str | None, default: None) –

    Unique deep-linking parameter. If left empty, forwarded copies of the sent message will have a Pay button, allowing multiple users to pay directly from the forwarded message, using the same invoice. If non-empty, forwarded copies of the sent message will have a URL button with a deep link to the bot (instead of a Pay button), with the value used as the start parameter.

    Changed in version 13.5: As of Bot API 5.2, this parameter is optional.

  • provider_data (str | object | None, default: None) – data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider. When an object is passed, it will be encoded as JSON.

  • photo_url (str | None, default: None) – 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 | None, default: None) – Photo size.

  • photo_width (int | None, default: None) – Photo width.

  • photo_height (int | None, default: None) – Photo height.

  • need_name (bool | None, default: None) – Pass True, if you require the user’s full name to complete the order. Ignored for payments in |tg_stars|.

  • need_phone_number (bool | None, default: None) – Pass True, if you require the user’s phone number to complete the order. Ignored for payments in |tg_stars|.

  • need_email (bool | None, default: None) – Pass True, if you require the user’s email to complete the order. Ignored for payments in |tg_stars|.

  • need_shipping_address (bool | None, default: None) – Pass True, if you require the user’s shipping address to complete the order. Ignored for payments in |tg_stars|.

  • send_phone_number_to_provider (bool | None, default: None) – Pass True, if user’s phone number should be sent to provider. Ignored for payments in |tg_stars|.

  • send_email_to_provider (bool | None, default: None) – Pass True, if user’s email address should be sent to provider. Ignored for payments in |tg_stars|.

  • is_flexible (bool | None, default: None) – Pass True, if the final price depends on the shipping method. Ignored for payments in |tg_stars|.

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | None, default: None) – An 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.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_location(chat_id, latitude=None, longitude=None, disable_notification=None, reply_markup=None, live_period=None, horizontal_accuracy=None, heading=None, proximity_alert_radius=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, location=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send point on the map.

Note

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

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • latitude (float | None, default: None) – Latitude of location.

  • longitude (float | None, default: None) – Longitude of location.

  • horizontal_accuracy (float | None, default: None) – The radius of uncertainty for the location, measured in meters; 0-telegram.constants.LocationLimit.HORIZONTAL_ACCURACY.

  • live_period (int | timedelta | None, default: None) –

    Period in seconds for which the location will be updated, should be between telegram.constants.LocationLimit.MIN_LIVE_PERIOD and telegram.constants.LocationLimit.MAX_LIVE_PERIOD, or telegram.constants.LocationLimit.LIVE_PERIOD_FOREVER for live locations that can be edited indefinitely.

    Changed in version 21.11: |time-period-input|

  • heading (int | None, default: None) – For live locations, a direction in which the user is moving, in degrees. Must be between telegram.constants.LocationLimit.MIN_HEADING and telegram.constants.LocationLimit.MAX_HEADING if specified.

  • proximity_alert_radius (int | None, default: None) – For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. Must be between telegram.constants.LocationLimit.MIN_PROXIMITY_ALERT_RADIUS and telegram.constants.LocationLimit.MAX_PROXIMITY_ALERT_RADIUS if specified.

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_media_group(chat_id, media, disable_notification=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None, caption=None, parse_mode=None, caption_entities=None)[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.

Note

If you supply a caption (along with either parse_mode or caption_entities), then items in media must have no captions, and vice versa.

See also

Working with Files and Media <Working-with-Files-and-Media>

Changed in version 20.0: Returns a tuple instead of a list.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • media (Sequence[InputMediaAudio | InputMediaDocument | InputMediaPhoto | InputMediaVideo]) –

    An array describing messages to be sent, must include telegram.constants.MediaGroupLimit.MIN_MEDIA_LENGTH- telegram.constants.MediaGroupLimit.MAX_MEDIA_LENGTH items.

    Changed in version 20.0: |sequenceargs|

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • direct_messages_topic_id (int | None, default: None) –

    Identifier of the direct messages topic to which the messages will be sent; required if the messages are sent to a direct messages chat.

    Added in version 22.4.

Keyword Arguments:
  • allow_sending_without_reply (bool, optional) –

    |allow_sending_without_reply| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • reply_to_message_id (int, optional) –

    |reply_to_msg_id| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • caption (str, optional) –

    Caption that will be added to the first element of media, so that it will be used as caption for the whole media group. Defaults to None.

    Added in version 20.0.

  • parse_mode (str | None, optional) –

    Parse mode for caption. See the constants in telegram.constants.ParseMode for the available modes.

    Added in version 20.0.

  • caption_entities (Sequence[telegram.MessageEntity], optional) –

    List of special entities for caption, which can be specified instead of parse_mode. Defaults to None.

    Added in version 20.0.

Returns:

An array of the sent Messages.

Returns:

tuple[Message, ...]

Raises:

telegram.error.TelegramError

async send_message(chat_id, text, parse_mode=None, entities=None, disable_notification=None, protect_content=None, reply_markup=None, message_thread_id=None, link_preview_options=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, disable_web_page_preview=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send text messages.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • text (str) – Text of the message to be sent. Max telegram.constants.MessageLimit.MAX_TEXT_LENGTH characters after entities parsing.

  • parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – |parse_mode|

  • entities (Sequence[MessageEntity] | None, default: None) –

    Sequence of special entities that appear in message text, which can be specified instead of parse_mode.

    Changed in version 20.0: |sequenceargs|

  • link_preview_options (DefaultValue[DVValueType] | LinkPreviewOptions | DefaultValue[None] | None, default: None) –

    Link preview generation options for the message. Mutually exclusive with disable_web_page_preview.

    Added in version 20.8.

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
  • allow_sending_without_reply (bool, optional) –

    |allow_sending_without_reply| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • reply_to_message_id (int, optional) –

    |reply_to_msg_id| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • disable_web_page_preview (bool, optional) –

    Disables link previews for links in this message. Convenience parameter for setting link_preview_options. Mutually exclusive with link_preview_options.

    Changed in version 20.8: Bot API 7.0 introduced link_preview_options replacing this argument. PTB will automatically convert this argument to that one, but for advanced options, please use link_preview_options directly.

    Changed in version 21.0: |keyword_only_arg|

Returns:

On success, the sent message is returned.

Returns:

Message

Raises:
async send_paid_media(chat_id, star_count, media, caption=None, parse_mode=None, caption_entities=None, show_caption_above_media=None, disable_notification=None, protect_content=None, reply_parameters=None, reply_markup=None, business_connection_id=None, payload=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, message_thread_id=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send paid media.

Added in version 21.4.

Parameters:
  • chat_id (str | int) – |chat_id_channel| If the chat is a channel, all Telegram Star proceeds from this media will be credited to the chat’s balance. Otherwise, they will be credited to the bot’s balance.

  • star_count (int) – The number of Telegram Stars that must be paid to buy access to the media; telegram.constants.InvoiceLimit.MIN_STAR_COUNT - telegram.constants.InvoiceLimit.MAX_STAR_COUNT.

  • media (Sequence[InputPaidMedia]) – A list describing the media to be sent; up to telegram.constants.MediaGroupLimit.MAX_MEDIA_LENGTH items.

  • payload (str | None, default: None) –

    Bot-defined paid media payload, 0-telegram.constants.InvoiceLimit.MAX_PAYLOAD_LENGTH bytes. This will not be displayed to the user, use it for your internal processes.

    Added in version 21.6.

  • caption (str | None, default: None) – Caption of the media to be sent, 0-telegram.constants.MessageLimit.CAPTION_LENGTH characters.

  • parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – |parse_mode|

  • caption_entities (Sequence[MessageEntity] | None, default: None) – |caption_entities|

  • show_caption_above_media (bool | None, default: None) – Pass |show_cap_above_med|

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |protect_content|

  • reply_parameters (ReplyParameters | None, default: None) – |reply_parameters|

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.5.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 22.4.

Keyword Arguments:
  • allow_sending_without_reply (bool, optional) – |allow_sending_without_reply| Mutually exclusive with reply_parameters, which this is a convenience parameter for

  • reply_to_message_id (int, optional) – |reply_to_msg_id| Mutually exclusive with reply_parameters, which this is a convenience parameter for

Returns:

On success, the sent message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_photo(chat_id, photo, caption=None, disable_notification=None, reply_markup=None, parse_mode=None, caption_entities=None, protect_content=None, message_thread_id=None, has_spoiler=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, show_caption_above_media=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send photos.

See also

Working with Files and Media <Working-with-Files-and-Media>

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • photo (str | Path | IO[bytes] | InputFile | bytes | PhotoSize) –

    Photo to send. |fileinput| Lastly you can pass an existing telegram.PhotoSize object to send.

    Caution

    • The photo must be at most 10MB in size.

    • The photo’s width and height must not exceed 10000 in total.

    • Width and height ratio must be at most 20.

    Changed in version 13.2: Accept bytes as input.

    Changed in version 20.0: File paths as input is also accepted for bots not running in ~telegram.Bot.local_mode.

  • caption (str | None, default: None) – Photo caption (may also be used when resending photos by file_id), 0-telegram.constants.MessageLimit.CAPTION_LENGTH characters after entities parsing.

  • parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – |parse_mode|

  • caption_entities (Sequence[MessageEntity] | None, default: None) –

    |caption_entities|

    Changed in version 20.0: |sequenceargs|

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • has_spoiler (bool | None, default: None) –

    Pass True if the photo needs to be covered with a spoiler animation.

    Added in version 20.0.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • show_caption_above_media (bool | None, default: None) –

    Pass |show_cap_above_med|

    Added in version 21.3.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
  • allow_sending_without_reply (bool, optional) –

    |allow_sending_without_reply| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • reply_to_message_id (int, optional) –

    |reply_to_msg_id| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • filename (str, optional) –

    Custom file name for the photo, when uploading a new file. Convenience parameter, useful e.g. when sending files generated by the tempfile module.

    Added in version 13.1.

Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_poll(chat_id, question, options, is_anonymous=None, type=None, allows_multiple_answers=None, correct_option_id=None, is_closed=None, disable_notification=None, reply_markup=None, explanation=None, explanation_parse_mode=None, open_period=None, close_date=None, explanation_entities=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, question_parse_mode=None, question_entities=None, message_effect_id=None, allow_paid_broadcast=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send a native poll.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • question (str) – Poll question, telegram.Poll.MIN_QUESTION_LENGTH- telegram.Poll.MAX_QUESTION_LENGTH characters.

  • options (Sequence[str | InputPollOption]) –

    Sequence of telegram.Poll.MIN_OPTION_NUMBER- telegram.Poll.MAX_OPTION_NUMBER answer options. Each option may either be a string with telegram.Poll.MIN_OPTION_LENGTH- telegram.Poll.MAX_OPTION_LENGTH characters or an InputPollOption object. Strings are converted to InputPollOption objects automatically.

    Changed in version 20.0: |sequenceargs|

    Changed in version 21.2: Bot API 7.3 adds support for InputPollOption objects.

  • is_anonymous (bool | None, default: None) – True, if the poll needs to be anonymous, defaults to True.

  • type (str | None, default: None) – Poll type, telegram.Poll.QUIZ or telegram.Poll.REGULAR, defaults to telegram.Poll.REGULAR.

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

  • correct_option_id (Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None, default: None) – 0-based identifier of the correct answer option, required for polls in quiz mode.

  • explanation (str | None, default: None) – Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-telegram.Poll.MAX_EXPLANATION_LENGTH characters with at most telegram.Poll.MAX_EXPLANATION_LINE_FEEDS line feeds after entities parsing.

  • explanation_parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – Mode for parsing entities in the explanation. See the constants in telegram.constants.ParseMode for the available modes.

  • explanation_entities (Sequence[MessageEntity] | None, default: None) –

    Sequence of special entities that appear in message text, which can be specified instead of explanation_parse_mode.

    Changed in version 20.0: |sequenceargs|

  • open_period (int | timedelta | None, default: None) –

    Amount of time in seconds the poll will be active after creation, telegram.Poll.MIN_OPEN_PERIOD- telegram.Poll.MAX_OPEN_PERIOD. Can’t be used together with close_date.

    Changed in version 21.11: |time-period-input|

  • close_date (int | datetime | None, default: None) – Point in time (Unix timestamp) when the poll will be automatically closed. Must be at least telegram.Poll.MIN_OPEN_PERIOD and no more than telegram.Poll.MAX_OPEN_PERIOD seconds in the future. Can’t be used together with open_period. |tz-naive-dtms|

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

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • question_parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) –

    Mode for parsing entities in the question. See the constants in telegram.constants.ParseMode for the available modes. Currently, only custom emoji entities are allowed.

    Added in version 21.2.

  • question_entities (Sequence[MessageEntity] | None, default: None) –

    Special entities that appear in the poll question. It can be specified instead of question_parse_mode.

    Added in version 21.2.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

Keyword Arguments:
Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_sticker(chat_id, sticker, disable_notification=None, reply_markup=None, protect_content=None, message_thread_id=None, emoji=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send static .WEBP, animated .TGS, or video .WEBM stickers.

See also

Working with Files and Media <Working-with-Files-and-Media>

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • sticker (str | Path | IO[bytes] | InputFile | bytes | Sticker) –

    Sticker to send. |fileinput| Video stickers can only be sent by a file_id. Video and animated stickers can’t be sent via an HTTP URL.

    Lastly you can pass an existing telegram.Sticker object to send.

    Changed in version 13.2: Accept bytes as input.

    Changed in version 20.0: File paths as input is also accepted for bots not running in ~telegram.Bot.local_mode.

  • emoji (str | None, default: None) –

    Emoji associated with the sticker; only for just uploaded stickers

    Added in version 20.2.

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_venue(chat_id, latitude=None, longitude=None, title=None, address=None, foursquare_id=None, disable_notification=None, reply_markup=None, foursquare_type=None, google_place_id=None, google_place_type=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, venue=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send information about a venue.

Note

  • You can either supply venue, or latitude, longitude, title and address and optionally foursquare_id and foursquare_type or optionally google_place_id and google_place_type.

  • Foursquare details and Google Place details are mutually exclusive. However, this behaviour is undocumented and might be changed by Telegram.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • latitude (float | None, default: None) – Latitude of venue.

  • longitude (float | None, default: None) – Longitude of venue.

  • title (str | None, default: None) – Name of the venue.

  • address (str | None, default: None) – Address of the venue.

  • foursquare_id (str | None, default: None) – Foursquare identifier of the venue.

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

  • google_place_id (str | None, default: None) – Google Places identifier of the venue.

  • google_place_type (str | None, default: None) – Google Places type of the venue. (See supported types.)

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_video(chat_id, video, duration=None, caption=None, disable_notification=None, reply_markup=None, width=None, height=None, parse_mode=None, supports_streaming=None, caption_entities=None, protect_content=None, message_thread_id=None, has_spoiler=None, thumbnail=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, show_caption_above_media=None, cover=None, start_timestamp=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Bots can currently send video files of up to telegram.constants.FileSizeLimit.FILESIZE_UPLOAD in size, this limit may be changed in the future.

Note

thumbnail will be ignored for small video files, for which Telegram can easily generate thumbnails. However, this behaviour is undocumented and might be changed by Telegram.

See also

Working with Files and Media <Working-with-Files-and-Media>

Changed in version 20.5: Removed deprecated argument thumb. Use thumbnail instead.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • video (str | Path | IO[bytes] | InputFile | bytes | Video) –

    Video file to send. |fileinput| Lastly you can pass an existing telegram.Video object to send.

    Changed in version 13.2: Accept bytes as input.

    Changed in version 20.0: File paths as input is also accepted for bots not running in ~telegram.Bot.local_mode.

  • duration (int | timedelta | None, default: None) –

    Duration of sent video in seconds.

    Changed in version 21.11: |time-period-input|

  • width (int | None, default: None) – Video width.

  • height (int | None, default: None) – Video height.

  • cover (str | Path | IO[bytes] | InputFile | bytes | None, default: None) –

    Cover for the video in the message. |fileinputnopath|

    Added in version 21.11.

  • start_timestamp (int | None, default: None) –

    Start timestamp for the video in the message.

    Added in version 21.11.

  • caption (str | None, default: None) – Video caption (may also be used when resending videos by file_id), 0-telegram.constants.MessageLimit.CAPTION_LENGTH characters after entities parsing.

  • parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – |parse_mode|

  • caption_entities (Sequence[MessageEntity] | None, default: None) –

    |caption_entities|

    Changed in version 20.0: |sequenceargs|

  • supports_streaming (bool | None, default: None) – Pass True, if the uploaded video is suitable for streaming.

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • has_spoiler (bool | None, default: None) –

    Pass True if the video needs to be covered with a spoiler animation.

    Added in version 20.0.

  • thumbnail (str | Path | IO[bytes] | InputFile | bytes | None, default: None) –

    |thumbdocstring|

    Added in version 20.2.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • show_caption_above_media (bool | None, default: None) –

    Pass |show_cap_above_med|

    Added in version 21.3.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
  • allow_sending_without_reply (bool, optional) –

    |allow_sending_without_reply| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • reply_to_message_id (int, optional) –

    |reply_to_msg_id| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • filename (str, optional) –

    Custom file name for the video, when uploading a new file. Convenience parameter, useful e.g. when sending files generated by the tempfile module.

    Added in version 13.1.

Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_video_note(chat_id, video_note, duration=None, length=None, disable_notification=None, reply_markup=None, protect_content=None, message_thread_id=None, thumbnail=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Note

thumbnail will be ignored for small video files, for which Telegram can easily generate thumbnails. However, this behaviour is undocumented and might be changed by Telegram.

See also

Working with Files and Media <Working-with-Files-and-Media>

Changed in version 20.5: Removed deprecated argument thumb. Use thumbnail instead.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • video_note (str | Path | IO[bytes] | InputFile | bytes | VideoNote) –

    Video note to send. Pass a file_id as String to send a video note that exists on the Telegram servers (recommended) or upload a new video using multipart/form-data. |uploadinput| Lastly you can pass an existing telegram.VideoNote object to send. Sending video notes by a URL is currently unsupported.

    Changed in version 13.2: Accept bytes as input.

    Changed in version 20.0: File paths as input is also accepted for bots not running in ~telegram.Bot.local_mode.

  • duration (int | timedelta | None, default: None) –

    Duration of sent video in seconds.

    Changed in version 21.11: |time-period-input|

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

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • thumbnail (str | Path | IO[bytes] | InputFile | bytes | None, default: None) –

    |thumbdocstring|

    Added in version 20.2.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
  • allow_sending_without_reply (bool, optional) –

    |allow_sending_without_reply| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • reply_to_message_id (int, optional) –

    |reply_to_msg_id| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • filename (str, optional) –

    Custom file name for the video note, when uploading a new file. Convenience parameter, useful e.g. when sending files generated by the tempfile module.

    Added in version 13.1.

Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_voice(chat_id, voice, duration=None, caption=None, disable_notification=None, reply_markup=None, parse_mode=None, caption_entities=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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). Bots can currently send voice messages of up to telegram.constants.FileSizeLimit.FILESIZE_UPLOAD in size, this limit may be changed in the future.

Note

To use this method, the file must have the type audio/ogg and be no more than telegram.constants.FileSizeLimit.VOICE_NOTE_FILE_SIZE in size. telegram.constants.FileSizeLimit.VOICE_NOTE_FILE_SIZE- telegram.constants.FileSizeLimit.FILESIZE_DOWNLOAD voice notes will be sent as files.

See also

Working with Files and Media <Working-with-Files-and-Media>

Parameters:
Keyword Arguments:
  • allow_sending_without_reply (bool, optional) –

    |allow_sending_without_reply| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • reply_to_message_id (int, optional) –

    |reply_to_msg_id| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • filename (str, optional) –

    Custom file name for the voice, when uploading a new file. Convenience parameter, useful e.g. when sending files generated by the tempfile module.

    Added in version 13.1.

Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async setBusinessAccountBio(business_connection_id, bio=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_business_account_bio()

Return type:

bool

async setBusinessAccountGiftSettings(business_connection_id, show_gift_button, accepted_gift_types, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_business_account_gift_settings()

Return type:

bool

async setBusinessAccountName(business_connection_id, first_name, last_name=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_business_account_name()

Return type:

bool

async setBusinessAccountProfilePhoto(business_connection_id, photo, is_public=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_business_account_profile_photo()

Return type:

bool

async setBusinessAccountUsername(business_connection_id, username=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_business_account_username()

Return type:

bool

async setChatAdministratorCustomTitle(chat_id, user_id, custom_title, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_chat_administrator_custom_title()

Return type:

bool

async setChatDescription(chat_id, description=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_chat_description()

Return type:

bool

async setChatMenuButton(chat_id=None, menu_button=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_chat_menu_button()

Return type:

bool

async setChatPermissions(chat_id, permissions, use_independent_chat_permissions=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_chat_permissions()

Return type:

bool

async setChatPhoto(chat_id, photo, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_chat_photo()

Return type:

bool

async setChatStickerSet(chat_id, sticker_set_name, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_chat_sticker_set()

Return type:

bool

async setChatTitle(chat_id, title, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_chat_title()

Return type:

bool

async setCustomEmojiStickerSetThumbnail(name, custom_emoji_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_custom_emoji_sticker_set_thumbnail()

Return type:

bool

async setGameScore(user_id, score, chat_id=None, message_id=None, inline_message_id=None, force=None, disable_edit_message=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_game_score()

Return type:

Message | bool

async setMessageReaction(chat_id, message_id, reaction=None, is_big=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_message_reaction()

Return type:

bool

async setMyCommands(commands, scope=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_my_commands()

Return type:

bool

async setMyDefaultAdministratorRights(rights=None, for_channels=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_my_default_administrator_rights()

Return type:

bool

async setMyDescription(description=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_my_description()

Return type:

bool

async setMyName(name=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_my_name()

Return type:

bool

async setMyShortDescription(short_description=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_my_short_description()

Return type:

bool

async setPassportDataErrors(user_id, errors, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_passport_data_errors()

Return type:

bool

async setStickerEmojiList(sticker, emoji_list, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_sticker_emoji_list()

Return type:

bool

async setStickerKeywords(sticker, keywords=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_sticker_keywords()

Return type:

bool

async setStickerMaskPosition(sticker, mask_position=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_sticker_mask_position()

Return type:

bool

async setStickerPositionInSet(sticker, position, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_sticker_position_in_set()

Return type:

bool

async setStickerSetThumbnail(name, user_id, format, thumbnail=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_sticker_set_thumbnail()

Return type:

bool

async setStickerSetTitle(name, title, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_sticker_set_title()

Return type:

bool

async setUserEmojiStatus(user_id, emoji_status_custom_emoji_id=None, emoji_status_expiration_date=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_user_emoji_status()

Return type:

bool

async setWebhook(url, certificate=None, max_connections=None, allowed_updates=None, ip_address=None, drop_pending_updates=None, secret_token=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_webhook()

Return type:

bool

async set_business_account_bio(business_connection_id, bio=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Changes the bio of a managed business account. Requires the can_edit_bio business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection.

  • bio (str | None, default: None) – The new value of the bio for the business account; 0-telegram.constants.BusinessLimit.MAX_BIO_LENGTH characters.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_business_account_gift_settings(business_connection_id, show_gift_button, accepted_gift_types, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Changes the privacy settings pertaining to incoming gifts in a managed business account. Requires the can_change_gift_settings business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection

  • show_gift_button (bool) – Pass True, if a button for sending a gift to the user or by the business account must always be shown in the input field.

  • accepted_gift_types (AcceptedGiftTypes) – Types of gifts accepted by the business account.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_business_account_name(business_connection_id, first_name, last_name=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Changes the first and last name of a managed business account. Requires the can_edit_name business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection

  • first_name (str) – New first name of the business account; telegram.constants.BusinessLimit.MIN_NAME_LENGTH- telegram.constants.BusinessLimit.MAX_NAME_LENGTH characters.

  • last_name (str | None, default: None) – New last name of the business account; 0-telegram.constants.BusinessLimit.MAX_NAME_LENGTH characters.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_business_account_profile_photo(business_connection_id, photo, is_public=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Changes the profile photo of a managed business account. Requires the can_edit_profile_photo business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection.

  • photo (InputProfilePhoto) – The new profile photo to set.

  • is_public (bool | None, default: None) – Pass True to set the public photo, which will be visible even if the main photo is hidden by the business account’s privacy settings. An account can have only one public photo.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_business_account_username(business_connection_id, username=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Changes the username of a managed business account. Requires the can_edit_username business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection.

  • username (str | None, default: None) – New business account username; 0-telegram.constants.BusinessLimit.MAX_USERNAME_LENGTH characters.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_chat_administrator_custom_title(chat_id, user_id, custom_title, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to set a custom title for administrators promoted by the bot in a supergroup. The bot must be an administrator for this to work.

Parameters:
  • chat_id (int | str) – |chat_id_group|

  • user_id (int) – Unique identifier of the target administrator.

  • custom_title (str) – New custom title for the administrator; 0-telegram.constants.ChatLimit.CHAT_ADMINISTRATOR_CUSTOM_TITLE_LENGTH characters, emoji are not allowed.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_chat_description(chat_id, description=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Parameters:
  • chat_id (str | int) – |chat_id_channel|

  • description (str | None, default: None) – New chat description, 0-telegram.constants.ChatLimit.CHAT_DESCRIPTION_LENGTH characters.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_chat_menu_button(chat_id=None, menu_button=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 20.0.

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

  • menu_button (MenuButton | None, default: None) – An object for the new bot’s menu button. Defaults to telegram.MenuButtonDefault.

Returns:

On success, True is returned.

Returns:

bool

async set_chat_permissions(chat_id, permissions, use_independent_chat_permissions=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 telegram.ChatMemberAdministrator.can_restrict_members admin rights.

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_chat_photo(chat_id, photo, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_chat_sticker_set(chat_id, sticker_set_name, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to set a new group sticker set for a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Use the field telegram.ChatFullInfo.can_set_sticker_set optionally returned in get_chat() requests to check if the bot can use this method.

Parameters:
  • chat_id (str | int) – |chat_id_group|

  • sticker_set_name (str) – Name of the sticker set to be set as the group sticker set.

Returns:

On success, True is returned.

Returns:

bool

async set_chat_title(chat_id, title, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Parameters:
  • chat_id (str | int) – |chat_id_channel|

  • title (str) – New chat title, telegram.constants.ChatLimit.MIN_CHAT_TITLE_LENGTH- telegram.constants.ChatLimit.MAX_CHAT_TITLE_LENGTH characters.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_custom_emoji_sticker_set_thumbnail(name, custom_emoji_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to set the thumbnail of a custom emoji sticker set.

Added in version 20.2.

Parameters:
  • name (str) – Sticker set name.

  • custom_emoji_id (str | None, default: None) – 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:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_game_score(user_id, score, chat_id=None, message_id=None, inline_message_id=None, force=None, disable_edit_message=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Parameters:
  • user_id (int) – User identifier.

  • score (int) – New score, must be non-negative.

  • force (bool | None, default: None) – Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters.

  • disable_edit_message (bool | None, default: None) – Pass True, if the game message should not be automatically edited to include the current scoreboard.

  • chat_id (int | None, default: None) – Required if inline_message_id is not specified. Unique identifier for the target chat.

  • message_id (int | None, default: None) – Required if inline_message_id is not specified. Identifier of the sent message.

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

Returns:

The edited message. If the message is not an inline message , True.

Returns:

Message | bool

Raises:

telegram.error.TelegramError – If the new score is not greater than the user’s current score in the chat and force is False.

async set_message_reaction(chat_id, message_id, reaction=None, is_big=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to change the chosen reactions on a message. Service messages of some types 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. Bots can’t use paid reactions.

Added in version 20.8.

Parameters:
  • chat_id (str | int) – |chat_id_channel|

  • message_id (int) – Identifier of the target message. If the message belongs to a media group, the reaction is set to the first non-deleted message in the group instead.

  • reaction (Sequence[ReactionType | str] | ReactionType | str | None, default: None) –

    A 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. Paid reactions can’t be used by bots.

    Tip

    Passed str values will be converted to either telegram.ReactionTypeEmoji or telegram.ReactionTypeCustomEmoji depending on whether they are listed in ReactionEmoji.

  • is_big (bool | None, default: None) – Pass True to set the reaction with a big animation.

Returns:

boolbool On success, True is returned.

Raises:

telegram.error.TelegramError

async set_my_commands(commands, scope=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to change the list of the bot’s commands. See the Telegram docs for more details about bot commands.

Parameters:
  • commands (Sequence[BotCommand | tuple[str, str]]) –

    A sequence of bot commands to be set as the list of the bot’s commands. At most telegram.constants.BotCommandLimit.MAX_COMMAND_NUMBER commands can be specified.

    Note

    If you pass in a sequence of tuple, the order of elements in each tuple must correspond to the order of positional arguments to create a BotCommand instance.

    Changed in version 20.0: |sequenceargs|

  • scope (BotCommandScope | None, default: None) –

    An object, describing scope of users for which the commands are relevant. Defaults to telegram.BotCommandScopeDefault.

    Added in version 13.7.

  • language_code (str | None, default: None) –

    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.

    Added in version 13.7.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_my_default_administrator_rights(rights=None, for_channels=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 free to modify the list before adding the bot.

Added in version 20.0.

Parameters:
  • rights (ChatAdministratorRights | None, default: None) – A telegram.ChatAdministratorRights object describing new default administrator rights. If not specified, the default administrator rights will be cleared.

  • for_channels (bool | None, default: None) – 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:

Returns True on success.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_my_description(description=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 20.2.

Parameters:
  • description (str | None, default: None) – New bot description; 0-telegram.constants.BotDescriptionLimit.MAX_DESCRIPTION_LENGTH characters. Pass an empty string to remove the dedicated description for the given language.

  • language_code (str | None, default: None) – 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:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_my_name(name=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to change the bot’s name.

Added in version 20.3.

Parameters:
  • name (str | None, default: None) –

    New bot name; 0-telegram.constants.BotNameLimit.MAX_NAME_LENGTH characters. Pass an empty string to remove the dedicated name for the given language.

    Caution

    If language_code is not specified, a name must be specified.

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

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_my_short_description(short_description=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Added in version 20.2.

Parameters:
  • short_description (str | None, default: None) – New short description for the bot; 0-telegram.constants.BotDescriptionLimit.MAX_SHORT_DESCRIPTION_LENGTH characters. Pass an empty string to remove the dedicated description for the given language.

  • language_code (str | None, default: None) – 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:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_passport_data_errors(user_id, errors, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

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

Parameters:
  • user_id (int) – User identifier

  • errors (Sequence[PassportElementError]) –

    A Sequence describing the errors.

    Changed in version 20.0: |sequenceargs|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_sticker_emoji_list(sticker, emoji_list, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to change the list of emoji assigned to a regular or custom emoji sticker. The sticker must belong to a sticker set created by the bot.

Added in version 20.2.

Parameters:
  • sticker (str | Sticker) –

    File identifier of the sticker or the sticker object.

    Changed in version 21.10: Accepts also telegram.Sticker instances.

  • emoji_list (Sequence[str]) – A sequence of telegram.constants.StickerLimit.MIN_STICKER_EMOJI- telegram.constants.StickerLimit.MAX_STICKER_EMOJI emoji associated with the sticker.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_sticker_keywords(sticker, keywords=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Added in version 20.2.

Parameters:
  • sticker (str | Sticker) –

    File identifier of the sticker or the sticker object.

    Changed in version 21.10: Accepts also telegram.Sticker instances.

  • keywords (Sequence[str] | None, default: None) – A sequence of 0-telegram.constants.StickerLimit.MAX_SEARCH_KEYWORDS search keywords for the sticker with total length up to telegram.constants.StickerLimit.MAX_KEYWORD_LENGTH characters.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_sticker_mask_position(sticker, mask_position=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Added in version 20.2.

Parameters:
  • sticker (str | Sticker) –

    File identifier of the sticker or the sticker object.

    Changed in version 21.10: Accepts also telegram.Sticker instances.

  • mask_position (MaskPosition | None, default: None) – A object with the position where the mask should be placed on faces. Omit the parameter to remove the mask position.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_sticker_position_in_set(sticker, position, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Parameters:
  • sticker (str | Sticker) –

    File identifier of the sticker or the sticker object.

    Changed in version 21.10: Accepts also telegram.Sticker instances.

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

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_sticker_set_thumbnail(name, user_id, format, thumbnail=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to set the thumbnail of a regular or mask sticker set. The format of the thumbnail file must match the format of the stickers in the set.

Added in version 20.2.

Changed in version 21.1: As per Bot API 7.2, the new argument format will be required, and thus the order of the arguments had to be changed.

Parameters:
  • name (str) – Sticker set name

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

  • format (str) –

    Format of the added sticker, must be one of telegram.constants.StickerFormat.STATIC for a .WEBP or .PNG image, telegram.constants.StickerFormat.ANIMATED for a .TGS animation, telegram.constants.StickerFormat.VIDEO for a .WEBM video.

    Added in version 21.1.

  • thumbnail (str | Path | IO[bytes] | InputFile | bytes | None, default: None) –

    A .WEBP or .PNG image with the thumbnail, must be up to telegram.constants.StickerSetLimit.MAX_STATIC_THUMBNAIL_SIZE kilobytes in size and have width and height of exactly telegram.constants.StickerSetLimit.STATIC_THUMB_DIMENSIONS px, or a .TGS animation with the thumbnail up to telegram.constants.StickerSetLimit.MAX_ANIMATED_THUMBNAIL_SIZE kilobytes in size; see the docs for animated sticker technical requirements, or a .WEBM video with the thumbnail up to telegram.constants.StickerSetLimit.MAX_ANIMATED_THUMBNAIL_SIZE kilobytes in size; see this for video sticker technical requirements.

    |fileinput|

    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.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_sticker_set_title(name, title, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to set the title of a created sticker set.

Added in version 20.2.

Parameters:
  • name (str) – Sticker set name.

  • title (str) – Sticker set title, telegram.constants.StickerLimit.MIN_NAME_AND_TITLE- telegram.constants.StickerLimit.MAX_NAME_AND_TITLE characters.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_user_emoji_status(user_id, emoji_status_custom_emoji_id=None, emoji_status_expiration_date=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Changes the emoji status for a given user that previously allowed the bot to manage their emoji status via the Mini App method requestEmojiStatusAccess .

Added in version 21.8.

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

  • emoji_status_custom_emoji_id (str | None, default: None) – Custom emoji identifier of the emoji status to set. Pass an empty string to remove the status.

  • emoji_status_expiration_date (int | datetime | None, default: None) – Expiration date of the emoji status, if any, as unix timestamp or datetime.datetime object. |tz-naive-dtms|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_webhook(url, certificate=None, max_connections=None, allowed_updates=None, ip_address=None, drop_pending_updates=None, secret_token=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, Telegram will send an HTTPS POST request to the specified url, containing An Update. In case of an unsuccessful request (a request with response HTTP status code <https://en.wikipedia.org/wiki/List_of_HTTP_status_codes>`_different from ``2XY`), Telegram will repeat the request and give up after a reasonable amount of attempts.

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.

Note

  1. You will not be able to receive updates using get_updates() for long as an outgoing webhook is set up.

  2. To use a self-signed certificate, you need to upload your public key certificate using certificate parameter. Please upload as InputFile, sending a String will not work.

  3. Ports currently supported for Webhooks: telegram.constants.SUPPORTED_WEBHOOK_PORTS.

If you’re having any trouble setting up webhooks, please check out this guide to Webhooks.

Examples

Custom Webhook Bot

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

  • certificate (str | Path | IO[bytes] | InputFile | bytes | None, default: None) – Upload your public key certificate so that the root certificate in use can be checked. See our self-signed guide                <Webhooks#creating-a-self-signed-certificate-using-openssl> for details. |uploadinputnopath|

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

  • max_connections (int | None, default: None) – Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, telegram.constants.WebhookLimit.MIN_CONNECTIONS_LIMIT- telegram.constants.WebhookLimit.MAX_CONNECTIONS_LIMIT. Defaults to 40. Use lower values to limit the load on your bot’s server, and higher values to increase your bot’s throughput.

  • allowed_updates (Sequence[str] | None, default: None) –

    A sequence of the types of updates you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See telegram.Update for a complete list of available update types. Specify an empty sequence to receive all updates except telegram.Update.chat_member, telegram.Update.message_reaction and telegram.Update.message_reaction_count (default). If not specified, the previous setting will be used. Please note that this parameter doesn’t affect updates created before the call to the set_webhook, so unwanted update may be received for a short period of time.

    Changed in version 20.0: |sequenceargs|

  • drop_pending_updates (bool | None, default: None) – Pass True to drop all pending updates.

  • secret_token (str | None, default: None) –

    A secret token to be sent in a header X-Telegram-Bot-Api-Secret-Token in every webhook request, telegram.constants.WebhookLimit.MIN_SECRET_TOKEN_LENGTH- telegram.constants.WebhookLimit.MAX_SECRET_TOKEN_LENGTH 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.

    Added in version 20.0.

Returns:

boolbool On success, True is returned.

Raises:

telegram.error.TelegramError

async shutdown()[source]

Stop & clear resources used by this class. Currently just calls telegram.request.BaseRequest.shutdown() for the request objects used by this bot.

See also

initialize()

Added in version 20.0.

Return type:

None

async stopMessageLiveLocation(chat_id=None, message_id=None, inline_message_id=None, reply_markup=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for stop_message_live_location()

Return type:

Message | bool

async stopPoll(chat_id, message_id, reply_markup=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for stop_poll()

Return type:

Poll

async stop_message_live_location(chat_id=None, message_id=None, inline_message_id=None, reply_markup=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Parameters:
  • chat_id (int | str | None, default: None) – Required if inline_message_id is not specified. |chat_id_channel|

  • message_id (int | None, default: None) – Required if inline_message_id is not specified. Identifier of the sent message with live location to stop.

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

  • reply_markup (InlineKeyboardMarkup | None, default: None) – An object for a new inline keyboard.

  • business_connection_id (str | None, default: None) –

    |business_id_str_edit|

    Added in version 21.4.

Returns:

On success, if edited message is not an inline message, the edited message is returned, otherwise True is returned.

Returns:

Message | bool

async stop_poll(chat_id, message_id, reply_markup=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to stop a poll which was sent by the bot.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

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

  • reply_markup (InlineKeyboardMarkup | None, default: None) – An object for a new message inline keyboard.

  • business_connection_id (str | None, default: None) –

    |business_id_str_edit|

    Added in version 21.4.

Returns:

On success, the stopped Poll is returned.

Returns:

Poll

Raises:

telegram.error.TelegramError

property supports_inline_queries: bool

Bot’s telegram.User.supports_inline_queries attribute. Shortcut for the corresponding attribute of bot.

Type:

bool

to_dict(recursive=True)[source]

See telegram.TelegramObject.to_dict().

Return type:

dict[str, Any]

property token: str

Bot’s unique authentication token.

Added in version 20.0.

Type:

str

async transferBusinessAccountStars(business_connection_id, star_count, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for transfer_business_account_stars()

Return type:

bool

async transferGift(business_connection_id, owned_gift_id, new_owner_chat_id, star_count=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for transfer_gift()

Return type:

bool

async transfer_business_account_stars(business_connection_id, star_count, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Transfers Telegram Stars from the business account balance to the bot’s balance. Requires the can_transfer_stars business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection

  • star_count (int) – Number of Telegram Stars to transfer; ~telegram.constants.BusinessLimit.MIN_STAR_COUNT-~telegram.constants.BusinessLimit.MAX_STAR_COUNT

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async transfer_gift(business_connection_id, owned_gift_id, new_owner_chat_id, star_count=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Transfers an owned unique gift to another user. Requires the can_transfer_and_upgrade_gifts business bot right. Requires can_transfer_stars business bot right if the transfer is paid.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection

  • owned_gift_id (str) – Unique identifier of the regular gift that should be transferred.

  • new_owner_chat_id (int) – Unique identifier of the chat which will own the gift. The chat must be active in the last ~telegram.constants.BusinessLimit.CHAT_ACTIVITY_TIMEOUT seconds.

  • star_count (int | None, default: None) – The amount of Telegram Stars that will be paid for the transfer from the business account balance. If positive, then the can_transfer_stars business bot right is required.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async unbanChatMember(chat_id, user_id, only_if_banned=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for unban_chat_member()

Return type:

bool

async unbanChatSenderChat(chat_id, sender_chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for unban_chat_sender_chat()

Return type:

bool

async unban_chat_member(chat_id, user_id, only_if_banned=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Parameters:
  • chat_id (str | int) – |chat_id_channel|

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

  • only_if_banned (bool | None, default: None) – Do nothing if the user is not banned.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async unban_chat_sender_chat(chat_id, sender_chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to unban a previously banned channel in a supergroup or channel. The bot must be an administrator for this to work and must have the appropriate administrator rights.

Added in version 13.9.

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async unhideGeneralForumTopic(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for unhide_general_forum_topic()

Return type:

bool

async unhide_general_forum_topic(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Added in version 20.0.

Parameters:

chat_id (str | int) – |chat_id_group|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async unpinAllChatMessages(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for unpin_all_chat_messages()

Return type:

bool

async unpinAllForumTopicMessages(chat_id, message_thread_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for unpin_all_forum_topic_messages()

Return type:

bool

async unpinAllGeneralForumTopicMessages(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for unpin_all_general_forum_topic_messages()

Return type:

bool

async unpinChatMessage(chat_id, message_id=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for unpin_chat_message()

Return type:

bool

async unpin_all_chat_messages(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to clear the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the ~telegram.ChatAdministratorRights.can_pin_messages admin right in a supergroup or can_edit_messages admin right in a channel.

Parameters:

chat_id (str | int) – |chat_id_channel|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async unpin_all_forum_topic_messages(chat_id, message_thread_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 ~telegram.ChatAdministratorRights.can_pin_messages administrator rights in the supergroup.

Added in version 20.0.

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async unpin_all_general_forum_topic_messages(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 ~telegram.ChatAdministratorRights.can_pin_messages administrator rights in the supergroup.

Added in version 20.5.

Parameters:

chat_id (str | int) – |chat_id_group|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async unpin_chat_message(chat_id, message_id=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Parameters:
  • chat_id (str | int) – |chat_id_channel|

  • message_id (int | None, default: None) – Identifier of the message to unpin. Required if business_connection_id is specified. If not specified, the most recent pinned message (by sending date) will be unpinned.

  • business_connection_id (str | None, default: None) –

    Unique identifier of the business connection on behalf of which the message will be unpinned.

    Added in version 21.5.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async upgradeGift(business_connection_id, owned_gift_id, keep_original_details=None, star_count=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for upgrade_gift()

Return type:

bool

async upgrade_gift(business_connection_id, owned_gift_id, keep_original_details=None, star_count=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Upgrades a given regular gift to a unique gift. Requires the can_transfer_and_upgrade_gifts business bot right. Additionally requires the can_transfer_stars business bot right if the upgrade is paid.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection

  • owned_gift_id (str) – Unique identifier of the regular gift that should be upgraded to a unique one.

  • keep_original_details (bool | None, default: None) – Pass True to keep the original gift text, sender and receiver in the upgraded gift

  • star_count (int | None, default: None) – The amount of Telegram Stars that will be paid for the upgrade from the business account balance. If gift.prepaid_upgrade_star_count > 0, then pass 0, otherwise, the can_transfer_stars business bot right is required and telegram.Gift.upgrade_star_count must be passed.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async uploadStickerFile(user_id, sticker, sticker_format, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for upload_sticker_file()

Return type:

File

async upload_sticker_file(user_id, sticker, sticker_format, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Changed in version 20.5: Removed deprecated parameter png_sticker.

Parameters:
Returns:

On success, the uploaded File is returned.

Returns:

File

Raises:

telegram.error.TelegramError

property username: str

Bot’s username. Shortcut for the corresponding attribute of bot.

Type:

str

async verifyChat(chat_id, custom_description=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for verify_chat()

Return type:

bool

async verifyUser(user_id, custom_description=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for verify_user()

Return type:

bool

async verify_chat(chat_id, custom_description=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Verifies a chat |org-verify| which is represented by the bot.

Added in version 21.10.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • custom_description (str | None, default: None) – Custom description for the verification; 0- telegram.constants.VerifyLimit.MAX_TEXT_LENGTH characters. Must be empty if the organization isn’t allowed to provide a custom verification description.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async verify_user(user_id, custom_description=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Verifies a user |org-verify| which is represented by the bot.

Added in version 21.10.

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

  • custom_description (str | None, default: None) – Custom description for the verification; 0- telegram.constants.VerifyLimit.MAX_TEXT_LENGTH characters. Must be empty if the organization isn’t allowed to provide a custom verification description.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

class spotted.utils.info_util.CallbackContext(application, chat_id=None, user_id=None)[source]

Bases: Generic[BT, UD, CD, BD]

This is a context object passed to the callback called by telegram.ext.BaseHandler or by the telegram.ext.Application in an error handler added by telegram.ext.Application.add_error_handler or to the callback of a telegram.ext.Job.

Note

telegram.ext.Application will create a single context for an entire update. This means that if you got 2 handlers in different groups and they both get called, they will receive the same CallbackContext object (of course with proper attributes like matches differing). This allows you to add custom attributes in a lower handler group callback, and then subsequently access those attributes in a higher handler group callback. Note that the attributes on CallbackContext might change in the future, so make sure to use a fairly unique name for the attributes.

Warning

Do not combine custom attributes with telegram.ext.BaseHandler.block set to False or telegram.ext.Application.concurrent_updates set to True. Due to how those work, it will almost certainly execute the callbacks for an update out of order, and the attributes that you think you added will not be present.

This class is a Generic class and accepts four type variables:

  1. The type of bot. Must be telegram.Bot or a subclass of that class.

  2. The type of user_data (if user_data is not None).

  3. The type of chat_data (if chat_data is not None).

  4. The type of bot_data (if bot_data is not None).

Examples

  • Context Types Bot

  • Custom Webhook Bot

See also

telegram.ext.ContextTypes.DEFAULT_TYPE, Job Queue <Extensions---JobQueue>

Parameters:
  • application (Application[TypeVar(BT, bound= Bot), TypeVar(ST, bound= CallbackContext[Any, Any, Any, Any]), TypeVar(UD), TypeVar(CD), TypeVar(BD), Any]) – The application associated with this context.

  • chat_id (int | None, default: None) –

    The ID of the chat associated with this object. Used to provide chat_data.

    Added in version 20.0.

  • user_id (int | None, default: None) –

    The ID of the user associated with this object. Used to provide user_data.

    Added in version 20.0.

coroutine

Optional. Only present in error handlers if the error was caused by an awaitable run with Application.create_task() or a handler callback with block=False.

Type:

awaitable

matches

Optional. If the associated update originated from a filters.Regex, this will contain a list of match objects for every pattern where re.search(pattern, string) returned a match. Note that filters short circuit, so combined regex filters will not always be evaluated.

Type:

list[re.Match]

args

Optional. Arguments passed to a command if the associated update is handled by telegram.ext.CommandHandler, telegram.ext.PrefixHandler or telegram.ext.StringCommandHandler. It contains a list of the words in the text after the command, using any whitespace string as a delimiter.

Type:

list[str]

error

Optional. The error that was raised. Only present when passed to an error handler registered with telegram.ext.Application.add_error_handler.

Type:

Exception

job

Optional. The job which originated this callback. Only present when passed to the callback of telegram.ext.Job or in error handlers if the error is caused by a job.

Changed in version 20.0: job is now also present in error handlers if the error is caused by a job.

Type:

telegram.ext.Job

property application: Application[BT, ST, UD, CD, BD, Any]

The application associated with this context.

Type:

telegram.ext.Application

args: list[str] | None
property bot: BT

The bot associated with this context.

Type:

telegram.Bot

property bot_data: BD

Optional. An object that can be used to keep any data in. For each update it will be the same ContextTypes.bot_data. Defaults to dict.

See also

Storing Bot, User and Chat Related Data            <Storing-bot%2C-user-and-chat-related-data>

Type:

ContextTypes.bot_data

property chat_data: CD | None

Optional. An object that can be used to keep any data in. For each update from the same chat id it will be the same ContextTypes.chat_data. Defaults to dict.

Warning

When a group chat migrates to a supergroup, its chat id will change and the chat_data needs to be transferred. For details see our wiki page <Storing-bot,-user-and-chat-related-data#chat-migration>.

See also

Storing Bot, User and Chat Related Data            <Storing-bot%2C-user-and-chat-related-data>

Changed in version 20.0: The chat data is now also present in error handlers if the error is caused by a job.

Type:

ContextTypes.chat_data

coroutine: Generator[Future[object] | None, None, Any] | Awaitable[Any] | None
drop_callback_data(callback_query)[source]

Deletes the cached data for the specified callback query.

Added in version 13.6.

Note

Will not raise exceptions in case the data is not found in the cache. Will raise KeyError in case the callback query can not be found in the cache.

See also

Arbitrary callback_data <Arbitrary-callback_data>

Parameters:

callback_query (CallbackQuery) – The callback query.

Raises:

KeyError | RuntimeErrorKeyError, if the callback query can not be found in the cache and RuntimeError, if the bot doesn’t allow for arbitrary callback data.

Return type:

None

error: Exception | None
classmethod from_error(update, error, application, job=None, coroutine=None)[source]

Constructs an instance of telegram.ext.CallbackContext to be passed to the error handlers.

Changed in version 20.0: Removed arguments async_args and async_kwargs.

Parameters:
  • update (object) – The update associated with the error. May be None, e.g. for errors in job callbacks.

  • error (Exception) – The error.

  • application (Application[TypeVar(BT, bound= Bot), TypeVar(CCT, bound= CallbackContext[Any, Any, Any, Any]), TypeVar(UD), TypeVar(CD), TypeVar(BD), Any]) – The application associated with this context.

  • job (Job[Any] | None, default: None) –

    The job associated with the error.

    Added in version 20.0.

  • coroutine (Generator[Future[object] | None, None, Any] | Awaitable[Any] | None, default: None) –

    The awaitable associated with this error if the error was caused by a coroutine run with Application.create_task() or a handler callback with block=False.

    Added in version 20.0.

    Changed in version 20.2: Accepts asyncio.Future and generator-based coroutine functions.

Returns:

TypeVar(CCT, bound= CallbackContext[Any, Any, Any, Any])telegram.ext.CallbackContext

classmethod from_job(job, application)[source]

Constructs an instance of telegram.ext.CallbackContext to be passed to a job callback.

See also

telegram.ext.JobQueue()

Parameters:
  • job (Job[TypeVar(CCT, bound= CallbackContext[Any, Any, Any, Any])]) – The job.

  • application (Application[Any, TypeVar(CCT, bound= CallbackContext[Any, Any, Any, Any]), Any, Any, Any, Any]) – The application associated with this context.

Returns:

TypeVar(CCT, bound= CallbackContext[Any, Any, Any, Any])telegram.ext.CallbackContext

classmethod from_update(update, application)[source]

Constructs an instance of telegram.ext.CallbackContext to be passed to the handlers.

Parameters:
Returns:

TypeVar(CCT, bound= CallbackContext[Any, Any, Any, Any])telegram.ext.CallbackContext

job: Job[Any] | None
property job_queue: JobQueue[ST] | None

The JobQueue used by the telegram.ext.Application.

See also

Job Queue <Extensions---JobQueue>

Type:

telegram.ext.JobQueue

property match: Match[str] | None

The first match from matches. Useful if you are only filtering using a single regex filter. Returns None if matches is empty.

Type:

re.Match

matches: list[Match[str]] | None
async refresh_data()[source]

If application uses persistence, calls telegram.ext.BasePersistence.refresh_bot_data() on bot_data, telegram.ext.BasePersistence.refresh_chat_data() on chat_data and telegram.ext.BasePersistence.refresh_user_data() on user_data, if appropriate.

Will be called by telegram.ext.Application.process_update() and telegram.ext.Job.run().

Added in version 13.6.

Return type:

None

update(data)[source]

Updates self.__slots__ with the passed data.

Parameters:

data (dict[str, object]) – The data.

Return type:

None

property update_queue: Queue[object]

The asyncio.Queue instance used by the telegram.ext.Application and (usually) the telegram.ext.Updater associated with this context.

Type:

asyncio.Queue

property user_data: UD | None

Optional. An object that can be used to keep any data in. For each update from the same user it will be the same ContextTypes.user_data. Defaults to dict.

See also

Storing Bot, User and Chat Related Data            <Storing-bot%2C-user-and-chat-related-data>

Changed in version 20.0: The user data is now also present in error handlers if the error is caused by a job.

Type:

ContextTypes.user_data

class spotted.utils.info_util.CallbackQuery(id, from_user, chat_instance, message=None, data=None, inline_message_id=None, game_short_name=None, *, api_kwargs=None)[source]

Bases: TelegramObject

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

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

Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their id is equal.

Note

Parameters:
  • id (str) – Unique identifier for this query.

  • from_user (User) – Sender.

  • chat_instance (str) – Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. Useful for high scores in games.

  • message (MaybeInaccessibleMessage | None, default: None) –

    Message sent by the bot with the callback button that originated the query.

    Changed in version 20.8: Accept objects of type telegram.MaybeInaccessibleMessage since Bot API 7.0.

  • data (str | None, default: None) – Data associated with the callback button. Be aware that the message, which originated the query, can contain no callback buttons with this data.

  • inline_message_id (str | None, default: None) – Identifier of the message sent via the bot in inline mode, that originated the query.

  • game_short_name (str | None, default: None) – Short name of a Game to be returned, serves as the unique identifier for the game.

id

Unique identifier for this query.

Type:

str

from_user

Sender.

Type:

telegram.User

chat_instance

Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. Useful for high scores in games.

Type:

str

message

Optional. Message sent by the bot with the callback button that originated the query.

Changed in version 20.8: Objects may be of type telegram.MaybeInaccessibleMessage since Bot API 7.0.

Type:

telegram.MaybeInaccessibleMessage

data

Optional. Data associated with the callback button. Be aware that the message, which originated the query, can contain no callback buttons with this data.

Tip

The value here is the same as the value passed in telegram.InlineKeyboardButton.callback_data.

Type:

str | object

inline_message_id

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

Type:

str

game_short_name

Optional. Short name of a Game to be returned, serves as the unique identifier for the game.

Type:

str

MAX_ANSWER_TEXT_LENGTH: Final[int] = 200

telegram.constants.CallbackQueryLimit.ANSWER_CALLBACK_QUERY_TEXT_LENGTH

Added in version 13.2.

async answer(text=None, show_alert=None, url=None, cache_time=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.answer_callback_query(update.callback_query.id, *args, **kwargs)

For the documentation of the arguments, please see telegram.Bot.answer_callback_query().

Returns:

On success, True is returned.

Returns:

bool

chat_instance: str
async copy_message(chat_id, caption=None, parse_mode=None, caption_entities=None, disable_notification=None, reply_markup=None, protect_content=None, message_thread_id=None, reply_parameters=None, show_caption_above_media=None, allow_paid_broadcast=None, video_start_timestamp=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await update.callback_query.message.copy(
    from_chat_id=update.message.chat_id,
    message_id=update.message.message_id,
    direct_messages_topic_id=update.message.direct_messages_topic.topic_id,
    *args,
    **kwargs
)

For the documentation of the arguments, please see telegram.Message.copy().

Changed in version 20.8: Raises TypeError if message is not accessible.

Returns:

On success, returns the MessageId of the sent message.

Returns:

MessageId

Raises:

TypeError

data: str | None
classmethod de_json(data, bot=None)[source]

See telegram.TelegramObject.de_json().

Return type:

CallbackQuery

async delete_message(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await update.callback_query.message.delete(*args, **kwargs)

For the documentation of the arguments, please see telegram.Message.delete().

Changed in version 20.8: Raises TypeError if message is not accessible.

Returns:

On success, True is returned.

Returns:

bool

Raises:

TypeError

async edit_message_caption(caption=None, reply_markup=None, parse_mode=None, caption_entities=None, show_caption_above_media=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for either:

await update.callback_query.message.edit_caption(*args, **kwargs)

or:

await bot.edit_message_caption(
    inline_message_id=update.callback_query.inline_message_id, *args, **kwargs,
)

For the documentation of the arguments, please see telegram.Bot.edit_message_caption() and telegram.Message.edit_caption().

Changed in version 20.8: Raises TypeError if message is not accessible.

Returns:

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

Returns:

Message | bool

Raises:

TypeError

async edit_message_checklist(checklist, reply_markup=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await update.callback_query.message.edit_checklist(*args, **kwargs)

For the documentation of the arguments, please see telegram.Message.edit_checklist().

Added in version 22.3.

Returns:

On success, the edited Message is returned.

Returns:

Message | bool

Raises:

TypeError

async edit_message_live_location(latitude=None, longitude=None, reply_markup=None, horizontal_accuracy=None, heading=None, proximity_alert_radius=None, live_period=None, *, location=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for either:

await update.callback_query.message.edit_live_location(*args, **kwargs)

or:

await bot.edit_message_live_location(
    inline_message_id=update.callback_query.inline_message_id, *args, **kwargs
)

For the documentation of the arguments, please see telegram.Bot.edit_message_live_location() and telegram.Message.edit_live_location().

Changed in version 20.8: Raises TypeError if message is not accessible.

Returns:

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

Returns:

Message | bool

Raises:

TypeError

async edit_message_media(media, reply_markup=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for either:

await update.callback_query.message.edit_media(*args, **kwargs)

or:

await bot.edit_message_media(
    inline_message_id=update.callback_query.inline_message_id, *args, **kwargs
)

For the documentation of the arguments, please see telegram.Bot.edit_message_media() and telegram.Message.edit_media().

Changed in version 20.8: Raises TypeError if message is not accessible.

Returns:

On success, if edited message is not an inline message, the edited Message is returned, otherwise True is returned.

Returns:

Message | bool

Raises:

TypeError

async edit_message_reply_markup(reply_markup=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for either:

await update.callback_query.message.edit_reply_markup(*args, **kwargs)

or:

await bot.edit_message_reply_markup(
    inline_message_id=update.callback_query.inline_message_id, *args, **kwargs
)

For the documentation of the arguments, please see telegram.Bot.edit_message_reply_markup() and telegram.Message.edit_reply_markup().

Changed in version 20.8: Raises TypeError if message is not accessible.

Returns:

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

Returns:

Message | bool

Raises:

TypeError

async edit_message_text(text, parse_mode=None, reply_markup=None, entities=None, link_preview_options=None, *, disable_web_page_preview=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for either:

await update.callback_query.message.edit_text(*args, **kwargs)

or:

await bot.edit_message_text(
    inline_message_id=update.callback_query.inline_message_id, *args, **kwargs,
)

For the documentation of the arguments, please see telegram.Bot.edit_message_text() and telegram.Message.edit_text().

Changed in version 20.8: Raises TypeError if message is not accessible.

Returns:

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

Returns:

Message | bool

Raises:

TypeError

from_user: User
game_short_name: str | None
async get_game_high_scores(user_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for either:

await update.callback_query.message.get_game_high_score(*args, **kwargs)

or:

await bot.get_game_high_scores(
    inline_message_id=update.callback_query.inline_message_id, *args, **kwargs
)

For the documentation of the arguments, please see telegram.Bot.get_game_high_scores() and telegram.Message.get_game_high_scores().

Changed in version 20.8: Raises TypeError if message is not accessible.

Returns:

tuple[GameHighScore, ...] – tuple[telegram.GameHighScore]

Raises:

TypeError

id: str
inline_message_id: str | None
message: MaybeInaccessibleMessage | None
async pin_message(disable_notification=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await update.callback_query.message.pin(*args, **kwargs)

For the documentation of the arguments, please see telegram.Message.pin().

Changed in version 20.8: Raises TypeError if message is not accessible.

Returns:

On success, True is returned.

Returns:

bool

Raises:

TypeError

async set_game_score(user_id, score, force=None, disable_edit_message=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for either:

await update.callback_query.message.set_game_score(*args, **kwargs)

or:

await bot.set_game_score(
    inline_message_id=update.callback_query.inline_message_id, *args, **kwargs
)

For the documentation of the arguments, please see telegram.Bot.set_game_score() and telegram.Message.set_game_score().

Changed in version 20.8: Raises TypeError if message is not accessible.

Returns:

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

Returns:

Message | bool

Raises:

TypeError

async stop_message_live_location(reply_markup=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for either:

await update.callback_query.message.stop_live_location(*args, **kwargs)

or:

await bot.stop_message_live_location(
    inline_message_id=update.callback_query.inline_message_id, *args, **kwargs
)

For the documentation of the arguments, please see telegram.Bot.stop_message_live_location() and telegram.Message.stop_live_location().

Changed in version 20.8: Raises TypeError if message is not accessible.

Returns:

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

Returns:

Message | bool

Raises:

TypeError

async unpin_message(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await update.callback_query.message.unpin(*args, **kwargs)

For the documentation of the arguments, please see telegram.Message.unpin().

Changed in version 20.8: Raises TypeError if message is not accessible.

Returns:

On success, True is returned.

Returns:

bool

Raises:

TypeError

class spotted.utils.info_util.Chat(id, type, title=None, username=None, first_name=None, last_name=None, is_forum=None, is_direct_messages=None, *, api_kwargs=None)[source]

Bases: _ChatBase

This object represents a chat.

Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their id is equal.

Changed in version 20.0:

  • Removed the deprecated methods kick_member and get_members_count.

  • The following are now keyword-only arguments in Bot methods: location, filename, contact, {read, write, connect, pool}_timeout, api_kwargs. Use a named argument for those, and notice that some positional arguments changed position as a result.

Changed in version 20.0: Removed the attribute all_members_are_administrators. As long as Telegram provides this field for backwards compatibility, it is available through api_kwargs.

Changed in version 21.3: As per Bot API 7.3, most of the arguments and attributes of this class have now moved to telegram.ChatFullInfo.

Parameters:
  • id (int) – Unique identifier for this chat.

  • type (str) – Type of chat, can be either PRIVATE, GROUP, SUPERGROUP or CHANNEL.

  • title (str | None, default: None) – Title, for supergroups, channels and group chats.

  • username (str | None, default: None) – Username, for private chats, supergroups and channels if available.

  • first_name (str | None, default: None) – First name of the other party in a private chat.

  • last_name (str | None, default: None) – Last name of the other party in a private chat.

  • is_forum (bool | None, default: None) –

    True, if the supergroup chat is a forum (has topics enabled).

    Added in version 20.0.

  • is_direct_messages (bool | None, default: None) –

    True, if the chat is the direct messages chat of a channel.

    Added in version 22.4.

id

Unique identifier for this chat.

Type:

int

type

Type of chat, can be either PRIVATE, GROUP, SUPERGROUP or CHANNEL.

Type:

str

title

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

Type:

str

username

Optional. Username, for private chats, supergroups and channels if available.

Type:

str

first_name

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

Type:

str

last_name

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

Type:

str

is_forum

Optional. True, if the supergroup chat is a forum (has topics enabled).

Added in version 20.0.

Type:

bool

is_direct_messages

Optional. True, if the chat is the direct messages chat of a channel.

Added in version 22.4.

Type:

bool

class spotted.utils.info_util.Config[source]

Bases: object

Configurations

AUTOREPLIES_PATH = 'autoreplies.yaml'
DEFAULT_AUTOREPLIES_PATH = '/opt/hostedtoolcache/Python/3.14.3/x64/lib/python3.14/site-packages/spotted/config/yaml/autoreplies.yaml'
DEFAULT_SETTINGS_PATH = '/opt/hostedtoolcache/Python/3.14.3/x64/lib/python3.14/site-packages/spotted/config/yaml/settings.yaml'
SETTINGS_PATH = 'settings.yaml'
classmethod autoreplies_get(*keys, default=None)[source]

Get the value of the specified key in the autoreplies configuration dictionary. If the key is a tuple, it will return the value of the nested key. If the key is not present, it will return the default value.

Parameters:
  • key – key to get

  • default (Any, default: None) – default value to return if the key is not present

Returns:

dict – value of the key or default value

classmethod debug_get(key, default=None)[source]

Get the value of the specified key in the configuration under the ‘debug’ section. If the key is not present, it will return the default value.

Parameters:
  • key (Literal['local_log', 'reset_on_load', 'log_file', 'log_error_file', 'db_file', 'backup_chat_id', 'backup_keep_pending', 'crypto_key', 'zip_backup']) – key to get

  • default (Any, default: None) – default value to return if the key is not present

Returns:

Any – value of the key or default value

classmethod override_settings(config)[source]

Overrides the settings with the configuration provided in the config dict.

Parameters:

config (dict) – configuration dict used to override the current settings

classmethod post_get(key, default=None)[source]

Get the value of the specified key in the configuration under the ‘post’ section. If the key is not present, it will return the default value.

Parameters:
  • key (Literal['community_group_id', 'channel_id', 'channel_tag', 'comments', 'admin_group_id', 'n_votes', 'remove_after_h', 'report', 'report_wait_mins', 'replace_anonymous_comments', 'delete_anonymous_comments', 'blacklist_messages', 'max_n_warns', 'warn_expiration_days', 'mute_default_duration_days', 'autoreplies_per_page', 'reject_after_autoreply']) – key to get

  • default (Any, default: None) – default value to return if the key is not present

Returns:

Any – value of the key or default value

classmethod reload(force_reload=False)[source]

Reset the configuration. The next time a setting parameter is required, the whole configuration will be reloaded. If force_reload is True, the configuration will be reloaded immediately.

Parameters:

force_reload (bool, default: False) – if True, the configuration will be reloaded immediately

classmethod settings_get(*keys, default=None)[source]

Get the value of the specified key in the configuration. If the key is a tuple, it will return the value of the nested key. If the key is not present, it will return the default value.

Parameters:
  • key – key to get

  • default (Any, default: None) – default value to return if the key is not present

Returns:

Any – value of the key or default value

class spotted.utils.info_util.EventInfo(bot, ctx, update=None, message=None, query=None)[source]

Bases: object

Class that contains all the relevant information related to an event

async answer_callback_query(text=None)[source]

Calls the answer_callback_query method of the bot class, while also handling the exception

Parameters:

text (str | None, default: None) – Text to show to the user

property args: list[str]

Return the args of the message that caused the update. If the update was caused by a callback, the callback data is splitted by ‘,’ and returned

property bot: Bot

Instance of the telegram bot

property bot_data: dict

Data related to the bot. Is not persistent between restarts

property callback_key: str

Return the args of the message that caused the update. If the update was caused by a callback, the callback data is splitted by ‘,’ and returned

property chat_id: int | None

Id of the chat where the event happened

property chat_type: str | None

Type of the chat where the event happened

property context: CallbackContext

Context generated by some event

async edit_inline_keyboard(chat_id=None, message_id=None, new_keyboard=None)[source]

Generic wrapper used to edit the inline keyboard of a message with the telegram bot, while also handling the exception

Parameters:
  • chat_id (int | None, default: None) – id of the chat the message to edit belongs to or the current chat if None

  • message_id (int | None, default: None) – id of the message to edit. It is the current message if left None

  • new_keyboard (InlineKeyboardMarkup | None, default: None) – new inline keyboard to assign to the message

property forward_from_chat_id: int | None

Id of the original chat the message has been forwarded from

property forward_from_id: int | None

Id of the original message that has been forwarded

classmethod from_callback(update, ctx)[source]

Instance of EventInfo created by a callback update

Parameters:
  • update (Update) – update event

  • context – context passed by the handler

Returns:

EventInfo – instance of the class

classmethod from_job(ctx)[source]

Instance of EventInfo created by a job update

Parameters:

context – context passed by the handler

Returns:

EventInfo – instance of the class

classmethod from_message(update, ctx)[source]

Instance of EventInfo created by a message update

Parameters:
  • update (Update) – update event

  • context – context passed by the handler

Returns:

EventInfo – instance of the class

property inline_keyboard: InlineKeyboardMarkup | None

InlineKeyboard attached to the message

property is_forward_from_channel: bool

Whether the message has been forwarded from a channel

property is_forward_from_chat: bool

Whether the message has been forwarded from a chat

property is_forward_from_user: bool

Whether the message has been forwarded from a user

property is_forwarded_post: bool

Whether the message is in fact a forwarded post from the channel to the group

property is_private_chat: bool | None

Whether the chat is private or not

property is_valid_message_type: bool

Whether or not the type of the message is supported

property message: Message | None

Message that caused the update

property message_id: int | None

Id of the message that caused the update

property query_data: str | None

Data associated with the query that caused the update

property query_id: str | None

Id of the query that caused the update

property reply_markup: InlineKeyboardMarkup | None

Reply_markup of the message that caused the update

async send_post_to_admins()[source]

Sends the post to the admin group, so it can be approved

Returns:

bool – whether or not the operation was successful

async send_post_to_channel(user_id)[source]

Sends the post to the channel, so it can be enjoyed by the users (and voted, if comments are disabled)

async send_post_to_channel_group()[source]

If comments are enabled, sends the post to the group associated to the channel, allowing the author to be credited and other users to report the spot or follow it.

async show_admins_votes(pending_post, reason=None)[source]

After a post is been approved or rejected, shows the admins that approved or rejected it and edit the message to show the admin’s votes

Parameters:
  • pending_post (PendingPost) – post to show the admin’s votes for

  • reason (str | None, default: None) – reason for the rejection, currently used on autoreply

property text: str | None

Text of the message that caused the update

property update: Update | None

Update generated by some event

property user_data: dict | None

Data related to the user. Is not persistent between restarts

property user_id: int | None

Id of the user that caused the update

property user_name: str | None

Name of the user that caused the update

property user_username: str | None

Username of the user that caused the update

class spotted.utils.info_util.InlineKeyboardMarkup(inline_keyboard, *, api_kwargs=None)[source]

Bases: TelegramObject

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

Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their size of inline_keyboard and all the buttons are equal.

https://core.telegram.org/file/464001863/110f3/I47qTXAD9Z4.120010/e0ea04f66357b640ec

An inline keyboard on a message

See also

Another kind of keyboard would be the telegram.ReplyKeyboardMarkup.

Examples

  • Inline Keyboard 1

  • Inline Keyboard 2

Parameters:

inline_keyboard (Sequence[Sequence[InlineKeyboardButton]]) –

Sequence of button rows, each represented by a sequence of InlineKeyboardButton objects.

Changed in version 20.0: |sequenceclassargs|

inline_keyboard

Tuple of button rows, each represented by a tuple of InlineKeyboardButton objects.

Changed in version 20.0: |tupleclassattrs|

Type:

tuple[tuple[telegram.InlineKeyboardButton]]

classmethod de_json(data, bot=None)[source]

See telegram.TelegramObject.de_json().

Return type:

InlineKeyboardMarkup

classmethod from_button(button, **kwargs)[source]

Shortcut for:

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

Return an InlineKeyboardMarkup from a single InlineKeyboardButton

Parameters:

button (InlineKeyboardButton) – The button to use in the markup

Return type:

InlineKeyboardMarkup

classmethod from_column(button_column, **kwargs)[source]

Shortcut for:

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

Return an InlineKeyboardMarkup from a single column of InlineKeyboardButtons

Parameters:

button_column (Sequence[InlineKeyboardButton]) –

The button to use in the markup

Changed in version 20.0: |sequenceargs|

Return type:

InlineKeyboardMarkup

classmethod from_row(button_row, **kwargs)[source]

Shortcut for:

InlineKeyboardMarkup([button_row], **kwargs)

Return an InlineKeyboardMarkup from a single row of InlineKeyboardButtons

Parameters:

button_row (Sequence[InlineKeyboardButton]) –

The button to use in the markup

Changed in version 20.0: |sequenceargs|

Return type:

InlineKeyboardMarkup

inline_keyboard: tuple[tuple[InlineKeyboardButton, ...], ...]
class spotted.utils.info_util.LinkPreviewOptions(is_disabled=None, url=None, prefer_small_media=None, prefer_large_media=None, show_above_text=None, *, api_kwargs=None)[source]

Bases: TelegramObject

Describes the options used for link preview generation.

Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their is_disabled, url, prefer_small_media, prefer_large_media, and show_above_text are equal.

Added in version 20.8.

Parameters:
  • is_disabled (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – True, if the link preview is disabled.

  • url (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – The URL to use for the link preview. If empty, then the first URL found in the message text will be used.

  • prefer_small_media (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – True, if the media in the link preview is supposed to be shrunk; ignored if the URL isn’t explicitly specified or media size change isn’t supported for the preview.

  • prefer_large_media (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – True, if the media in the link preview is supposed to be enlarged; ignored if the URL isn’t explicitly specified or media size change isn’t supported for the preview.

  • show_above_text (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – True, if the link preview must be shown above the message text; otherwise, the link preview will be shown below the message text.

is_disabled

Optional. True, if the link preview is disabled.

Type:

bool

url

Optional. The URL to use for the link preview. If empty, then the first URL found in the message text will be used.

Type:

str

prefer_small_media

Optional. True, if the media in the link preview is supposed to be shrunk; ignored if the URL isn’t explicitly specified or media size change isn’t supported for the preview.

Type:

bool

prefer_large_media

Optional. True, if the media in the link preview is supposed to be enlarged; ignored if the URL isn’t explicitly specified or media size change isn’t supported for the preview.

Type:

bool

show_above_text

Optional. True, if the link preview must be shown above the message text; otherwise, the link preview will be shown below the message text.

Type:

bool

is_disabled: ODVInput[bool]
prefer_large_media: ODVInput[bool]
prefer_small_media: ODVInput[bool]
show_above_text: ODVInput[bool]
url: ODVInput[str]
class spotted.utils.info_util.Message(message_id, date, chat, from_user=None, reply_to_message=None, edit_date=None, text=None, entities=None, caption_entities=None, audio=None, document=None, game=None, photo=None, sticker=None, video=None, voice=None, video_note=None, new_chat_members=None, caption=None, contact=None, location=None, venue=None, left_chat_member=None, new_chat_title=None, new_chat_photo=None, delete_chat_photo=None, group_chat_created=None, supergroup_chat_created=None, channel_chat_created=None, migrate_to_chat_id=None, migrate_from_chat_id=None, pinned_message=None, invoice=None, successful_payment=None, author_signature=None, media_group_id=None, connected_website=None, animation=None, passport_data=None, poll=None, reply_markup=None, dice=None, via_bot=None, proximity_alert_triggered=None, sender_chat=None, video_chat_started=None, video_chat_ended=None, video_chat_participants_invited=None, message_auto_delete_timer_changed=None, video_chat_scheduled=None, is_automatic_forward=None, has_protected_content=None, web_app_data=None, is_topic_message=None, message_thread_id=None, forum_topic_created=None, forum_topic_closed=None, forum_topic_reopened=None, forum_topic_edited=None, general_forum_topic_hidden=None, general_forum_topic_unhidden=None, write_access_allowed=None, has_media_spoiler=None, chat_shared=None, story=None, giveaway=None, giveaway_completed=None, giveaway_created=None, giveaway_winners=None, users_shared=None, link_preview_options=None, external_reply=None, quote=None, forward_origin=None, reply_to_story=None, boost_added=None, sender_boost_count=None, business_connection_id=None, sender_business_bot=None, is_from_offline=None, chat_background_set=None, effect_id=None, show_caption_above_media=None, paid_media=None, refunded_payment=None, gift=None, unique_gift=None, paid_message_price_changed=None, paid_star_count=None, direct_message_price_changed=None, checklist=None, checklist_tasks_done=None, checklist_tasks_added=None, is_paid_post=None, direct_messages_topic=None, reply_to_checklist_task_id=None, suggested_post_declined=None, suggested_post_paid=None, suggested_post_refunded=None, suggested_post_info=None, suggested_post_approved=None, suggested_post_approval_failed=None, *, api_kwargs=None)[source]

Bases: MaybeInaccessibleMessage

This object represents a message.

Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their message_id and chat are equal.

Note

In Python from is a reserved word. Use from_user instead.

Changed in version 21.0: Removed deprecated arguments and attributes user_shared, forward_from, forward_from_chat, forward_from_message_id, forward_signature, forward_sender_name and forward_date.

Changed in version 20.8: * This class is now a subclass of telegram.MaybeInaccessibleMessage. * The pinned_message now can be either telegram.Message or telegram.InaccessibleMessage.

Changed in version 20.0:

  • The arguments and attributes voice_chat_scheduled, voice_chat_started and voice_chat_ended, voice_chat_participants_invited were renamed to video_chat_scheduled/video_chat_scheduled, video_chat_started/video_chat_started, video_chat_ended/video_chat_ended and video_chat_participants_invited/video_chat_participants_invited, respectively, in accordance to Bot API 6.0.

  • The following are now keyword-only arguments in Bot methods: {read, write, connect, pool}_timeout, api_kwargs, contact, quote, filename, loaction, venue. Use a named argument for those, and notice that some positional arguments changed position as a result.

Parameters:
  • message_id (int) – Unique message identifier inside this chat. In specific instances (e.g., message containing a video sent to a big chat), the server might automatically schedule a message instead of sending it immediately. In such cases, this field will be 0 and the relevant message will be unusable until it is actually sent.

  • from_user (User | None, default: None) – Sender of the message; may be empty for messages sent to channels. For backward compatibility, if the message was sent on behalf of a chat, the field contains a fake sender user in non-channel chats.

  • sender_chat (Chat | None, default: None) – Sender of the message when sent on behalf of a chat. For example, the supergroup itself for messages sent by its anonymous administrators or a linked channel for messages automatically forwarded to the channel’s discussion group. For backward compatibility, if the message was sent on behalf of a chat, the field from contains a fake sender user in non-channel chats.

  • date (datetime) –

    Date the message was sent in Unix time. Converted to datetime.datetime.

    Changed in version 20.3: |datetime_localization|

  • chat (Chat) – Conversation the message belongs to.

  • is_automatic_forward (bool | None, default: None) –

    True, if the message is a channel post that was automatically forwarded to the connected discussion group.

    Added in version 13.9.

  • reply_to_message (Message | None, default: None) – For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.

  • edit_date (datetime | None, default: None) –

    Date the message was last edited in Unix time. Converted to datetime.datetime.

    Changed in version 20.3: |datetime_localization|

  • has_protected_content (bool | None, default: None) –

    True, if the message can’t be forwarded.

    Added in version 13.9.

  • is_from_offline (bool | None, default: None) –

    True, if the message was sent by an implicit action, for example, as an away or a greeting business message, or as a scheduled message.

    Added in version 21.1.

  • media_group_id (str | None, default: None) – The unique identifier of a media message group this message belongs to.

  • text (str | None, default: None) – For text messages, the actual UTF-8 text of the message, 0-telegram.constants.MessageLimit.MAX_TEXT_LENGTH characters.

  • entities (Sequence[MessageEntity] | None, default: None) –

    For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text. See parse_entity and parse_entities methods for how to use properly. This list is empty if the message does not contain entities.

    Changed in version 20.0: |sequenceclassargs|

  • link_preview_options (LinkPreviewOptions | None, default: None) –

    Options used for link preview generation for the message, if it is a text message and link preview options were changed.

    Added in version 20.8.

  • suggested_post_info (SuggestedPostInfo | None, default: None) –

    Information about suggested post parameters if the message is a suggested post in a channel direct messages chat. If the message is an approved or declined suggested post, then it can’t be edited.

    Added in version 22.4.

  • effect_id (str | None, default: None) –

    Unique identifier of the message effect added to the message.

    Added in version 21.3.

  • caption_entities (Sequence[MessageEntity] | None, default: None) –

    For messages with a Caption. Special entities like usernames, URLs, bot commands, etc. that appear in the caption. See Message.parse_caption_entity and parse_caption_entities methods for how to use properly. This list is empty if the message does not contain caption entities.

    Changed in version 20.0: |sequenceclassargs|

  • show_caption_above_media (bool | None, default: None) –

    |show_cap_above_med|

    Added in version 21.3.

  • audio (Audio | None, default: None) – Message is an audio file, information about the file.

  • document (Document | None, default: None) – Message is a general file, information about the file.

  • animation (Animation | None, default: None) – Message is an animation, information about the animation. For backward compatibility, when this field is set, the document field will also be set.

  • game (Game | None, default: None) – Message is a game, information about the game. More about games >>.

  • photo (Sequence[PhotoSize] | None, default: None) –

    Message is a photo, available sizes of the photo. This list is empty if the message does not contain a photo.

    Changed in version 20.0: |sequenceclassargs|

  • sticker (Sticker | None, default: None) – Message is a sticker, information about the sticker.

  • story (Story | None, default: None) –

    Message is a forwarded story.

    Added in version 20.5.

  • video (Video | None, default: None) – Message is a video, information about the video.

  • voice (Voice | None, default: None) – Message is a voice message, information about the file.

  • video_note (VideoNote | None, default: None) – Message is a video note, information about the video message.

  • new_chat_members (Sequence[User] | None, default: None) –

    New members that were added to the group or supergroup and information about them (the bot itself may be one of these members). This list is empty if the message does not contain new chat members.

    Changed in version 20.0: |sequenceclassargs|

  • caption (str | None, default: None) – Caption for the animation, audio, document, paid media, photo, video or voice, 0-telegram.constants.MessageLimit.CAPTION_LENGTH characters.

  • contact (Contact | None, default: None) – Message is a shared contact, information about the contact.

  • location (Location | None, default: None) – Message is a shared location, information about the location.

  • venue (Venue | None, default: None) – Message is a venue, information about the venue. For backward compatibility, when this field is set, the location field will also be set.

  • left_chat_member (User | None, default: None) – A member was removed from the group, information about them (this member may be the bot itself).

  • new_chat_title (str | None, default: None) – A chat title was changed to this value.

  • new_chat_photo (Sequence[PhotoSize] | None, default: None) –

    A chat photo was changed to this value. This list is empty if the message does not contain a new chat photo.

    Changed in version 20.0: |sequenceclassargs|

  • delete_chat_photo (bool | None, default: None) – Service message: The chat photo was deleted.

  • group_chat_created (bool | None, default: None) – Service message: The group has been created.

  • supergroup_chat_created (bool | None, default: None) – Service message: The supergroup has been created. This field can’t be received in a message coming through updates, because bot can’t be a member of a supergroup when it is created. It can only be found in reply_to_message if someone replies to a very first message in a directly created supergroup.

  • channel_chat_created (bool | None, default: None) – Service message: The channel has been created. This field can’t be received in a message coming through updates, because bot can’t be a member of a channel when it is created. It can only be found in reply_to_message if someone replies to a very first message in a channel.

  • message_auto_delete_timer_changed (MessageAutoDeleteTimerChanged | None, default: None) –

    Service message: auto-delete timer settings changed in the chat.

    Added in version 13.4.

  • migrate_to_chat_id (int | None, default: None) – The group has been migrated to a supergroup with the specified identifier.

  • migrate_from_chat_id (int | None, default: None) – The supergroup has been migrated from a group with the specified identifier.

  • pinned_message (MaybeInaccessibleMessage | None, default: None) –

    Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply.

    Changed in version 20.8: This attribute now is either telegram.Message or telegram.InaccessibleMessage.

  • invoice (Invoice | None, default: None) – Message is an invoice for a payment, information about the invoice. More about payments >>.

  • successful_payment (SuccessfulPayment | None, default: None) – Message is a service message about a successful payment, information about the payment. More about payments >>.

  • connected_website (str | None, default: None) – The domain name of the website on which the user has logged in. More about Telegram Login >>.

  • author_signature (str | None, default: None) – Signature of the post author for messages in channels, or the custom title of an anonymous group administrator.

  • paid_star_count (int | None, default: None) –

    The number of Telegram Stars that were paid by the sender of the message to send it

    Added in version 22.1.

  • passport_data (PassportData | None, default: None) – Telegram Passport data.

  • poll (Poll | None, default: None) – Message is a native poll, information about the poll.

  • dice (Dice | None, default: None) – Message is a dice with random value.

  • via_bot (User | None, default: None) – Bot through which message was sent.

  • proximity_alert_triggered (ProximityAlertTriggered | None, default: None) – Service message. A user in the chat triggered another user’s proximity alert while sharing Live Location.

  • video_chat_scheduled (VideoChatScheduled | None, default: None) –

    Service message: video chat scheduled.

    Added in version 20.0.

  • video_chat_started (VideoChatStarted | None, default: None) –

    Service message: video chat started.

    Added in version 20.0.

  • video_chat_ended (VideoChatEnded | None, default: None) –

    Service message: video chat ended.

    Added in version 20.0.

  • video_chat_participants_invited (VideoChatParticipantsInvited | None, default: None) –

    Service message: new participants invited to a video chat.

    Added in version 20.0.

  • web_app_data (WebAppData | None, default: None) –

    Service message: data sent by a Web App.

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | None, default: None) – Inline keyboard attached to the message. ~telegram.InlineKeyboardButton.login_url buttons are represented as ordinary url buttons.

  • is_topic_message (bool | None, default: None) –

    True, if the message is sent to a forum topic.

    Added in version 20.0.

  • message_thread_id (int | None, default: None) –

    Unique identifier of a message thread to which the message belongs; for supergroups only.

    Added in version 20.0.

  • forum_topic_created (ForumTopicCreated | None, default: None) –

    Service message: forum topic created.

    Added in version 20.0.

  • forum_topic_closed (ForumTopicClosed | None, default: None) –

    Service message: forum topic closed.

    Added in version 20.0.

  • forum_topic_reopened (ForumTopicReopened | None, default: None) –

    Service message: forum topic reopened.

    Added in version 20.0.

  • forum_topic_edited (ForumTopicEdited | None, default: None) –

    Service message: forum topic edited.

    Added in version 20.0.

  • general_forum_topic_hidden (GeneralForumTopicHidden | None, default: None) –

    Service message: General forum topic hidden.

    Added in version 20.0.

  • general_forum_topic_unhidden (GeneralForumTopicUnhidden | None, default: None) –

    Service message: General forum topic unhidden.

    Added in version 20.0.

  • write_access_allowed (WriteAccessAllowed | None, default: None) –

    Service message: the user allowed the bot to write messages after adding it to the attachment or side menu, launching a Web App from a link, or accepting an explicit request from a Web App sent by the method requestWriteAccess.

    Added in version 20.0.

  • has_media_spoiler (bool | None, default: None) –

    True, if the message media is covered by a spoiler animation.

    Added in version 20.0.

  • checklist (Checklist | None, default: None) –

    Message is a checklist

    Added in version 22.3.

  • users_shared (UsersShared | None, default: None) –

    Service message: users were shared with the bot

    Added in version 20.8.

  • chat_shared (ChatShared | None, default: None) –

    Service message: a chat was shared with the bot.

    Added in version 20.1.

  • gift (GiftInfo | None, default: None) –

    Service message: a regular gift was sent or received.

    Added in version 22.1.

  • unique_gift (UniqueGiftInfo | None, default: None) –

    Service message: a unique gift was sent or received

    Added in version 22.1.

  • giveaway_created (GiveawayCreated | None, default: None) –

    Service message: a scheduled giveaway was created

    Added in version 20.8.

  • giveaway (Giveaway | None, default: None) –

    The message is a scheduled giveaway message

    Added in version 20.8.

  • giveaway_winners (GiveawayWinners | None, default: None) –

    A giveaway with public winners was completed

    Added in version 20.8.

  • giveaway_completed (GiveawayCompleted | None, default: None) –

    Service message: a giveaway without public winners was completed

    Added in version 20.8.

  • paid_message_price_changed (PaidMessagePriceChanged | None, default: None) –

    Service message: the price for paid messages has changed in the chat

    Added in version 22.1.

  • suggested_post_approved (SuggestedPostApproved | None, default: None) –

    Service message: a suggested post was approved.

    Added in version 22.4.

  • suggested_post_approval_failed (SuggestedPostApprovalFailed | None, default: None) –

    Service message: approval of a suggested post has failed.

    Added in version 22.4.

  • suggested_post_declined (SuggestedPostDeclined | None, default: None) –

    Service message: a suggested post was declined.

    Added in version 22.4.

  • suggested_post_paid (SuggestedPostPaid | None, default: None) –

    Service message: payment for a suggested post was received.

    Added in version 22.4.

  • suggested_post_refunded (SuggestedPostRefunded | None, default: None) –

    Service message: payment for a suggested post was refunded.

    Added in version 22.4.

  • external_reply (ExternalReplyInfo | None, default: None) –

    Information about the message that is being replied to, which may come from another chat or forum topic.

    Added in version 20.8.

  • quote (TextQuote | None, default: None) –

    For replies that quote part of the original message, the quoted part of the message.

    Added in version 20.8.

  • forward_origin (MessageOrigin | None, default: None) –

    Information about the original message for forwarded messages

    Added in version 20.8.

  • reply_to_story (Story | None, default: None) –

    For replies to a story, the original story.

    Added in version 21.0.

  • boost_added (ChatBoostAdded | None, default: None) –

    Service message: user boosted the chat.

    Added in version 21.0.

  • sender_boost_count (int | None, default: None) –

    If the sender of the message boosted the chat, the number of boosts added by the user.

    Added in version 21.0.

  • business_connection_id (str | None, default: None) –

    Unique identifier of the business connection from which the message was received. If non-empty, the message belongs to a chat of the corresponding business account that is independent from any potential bot chat which might share the same identifier.

    Added in version 21.1.

  • sender_business_bot (User | None, default: None) –

    The bot that actually sent the message on behalf of the business account. Available only for outgoing messages sent on behalf of the connected business account.

    Added in version 21.1.

  • chat_background_set (ChatBackground | None, default: None) –

    Service message: chat background set.

    Added in version 21.2.

  • checklist_tasks_done (ChecklistTasksDone | None, default: None) –

    Service message: some tasks in a checklist were marked as done or not done

    Added in version 22.3.

  • checklist_tasks_added (ChecklistTasksAdded | None, default: None) –

    Service message: tasks were added to a checklist

    Added in version 22.3.

  • paid_media (PaidMediaInfo | None, default: None) –

    Message contains paid media; information about the paid media.

    Added in version 21.4.

  • refunded_payment (RefundedPayment | None, default: None) –

    Message is a service message about a refunded payment, information about the payment.

    Added in version 21.4.

  • direct_message_price_changed (DirectMessagePriceChanged | None, default: None) –

    Service message: the price for paid messages in the corresponding direct messages chat of a channel has changed.

    Added in version 22.3.

  • is_paid_post (bool | None, default: None) –

    True, if the message is a paid post. Note that such posts must not be deleted for 24 hours to receive the payment and can’t be edited.

    Added in version 22.4.

  • direct_messages_topic (DirectMessagesTopic | None, default: None) –

    Information about the direct messages chat topic that contains the message.

    Added in version 22.4.

  • reply_to_checklist_task_id (int | None, default: None) –

    Identifier of the specific checklist task that is being replied to.

    Added in version 22.4.

message_id

Unique message identifier inside this chat. In specific instances (e.g., message containing a video sent to a big chat), the server might automatically schedule a message instead of sending it immediately. In such cases, this field will be 0 and the relevant message will be unusable until it is actually sent.

Type:

int

from_user

Optional. Sender of the message; may be empty for messages sent to channels. For backward compatibility, if the message was sent on behalf of a chat, the field contains a fake sender user in non-channel chats.

Type:

telegram.User

sender_chat

Optional. Sender of the message when sent on behalf of a chat. For example, the supergroup itself for messages sent by its anonymous administrators or a linked channel for messages automatically forwarded to the channel’s discussion group. For backward compatibility, if the message was sent on behalf of a chat, the field from contains a fake sender user in non-channel chats.

Type:

telegram.Chat

date

Date the message was sent in Unix time. Converted to datetime.datetime.

Changed in version 20.3: |datetime_localization|

Type:

datetime.datetime

chat

Conversation the message belongs to.

Type:

telegram.Chat

is_automatic_forward

Optional. True, if the message is a channel post that was automatically forwarded to the connected discussion group.

Added in version 13.9.

Type:

bool

reply_to_message

Optional. For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.

Type:

telegram.Message

edit_date

Optional. Date the message was last edited in Unix time. Converted to datetime.datetime.

Changed in version 20.3: |datetime_localization|

Type:

datetime.datetime

has_protected_content

Optional. True, if the message can’t be forwarded.

Added in version 13.9.

Type:

bool

is_from_offline

Optional. True, if the message was sent by an implicit action, for example, as an away or a greeting business message, or as a scheduled message.

Added in version 21.1.

Type:

bool

media_group_id

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

Type:

str

text

Optional. For text messages, the actual UTF-8 text of the message, 0-telegram.constants.MessageLimit.MAX_TEXT_LENGTH characters.

Type:

str

entities

Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text. See parse_entity and parse_entities methods for how to use properly. This list is empty if the message does not contain entities.

Changed in version 20.0: |tupleclassattrs|

Type:

tuple[telegram.MessageEntity]

Optional. Options used for link preview generation for the message, if it is a text message and link preview options were changed.

Added in version 20.8.

Type:

telegram.LinkPreviewOptions

suggested_post_info

Optional. Information about suggested post parameters if the message is a suggested post in a channel direct messages chat. If the message is an approved or declined suggested post, then it can’t be edited.

Added in version 22.4.

Type:

telegram.SuggestedPostInfo

effect_id

Optional. Unique identifier of the message effect added to the message.

Added in version 21.3.

Type:

str

caption_entities

Optional. For messages with a Caption. Special entities like usernames, URLs, bot commands, etc. that appear in the caption. See Message.parse_caption_entity and parse_caption_entities methods for how to use properly. This list is empty if the message does not contain caption entities.

Changed in version 20.0: |tupleclassattrs|

Type:

tuple[telegram.MessageEntity]

show_caption_above_media

Optional. |show_cap_above_med|

Added in version 21.3.

Type:

bool

audio

Optional. Message is an audio file, information about the file.

See also

Working with Files and Media <Working-with-Files-and-Media>

Type:

telegram.Audio

document

Optional. Message is a general file, information about the file.

See also

Working with Files and Media <Working-with-Files-and-Media>

Type:

telegram.Document

animation

Optional. Message is an animation, information about the animation. For backward compatibility, when this field is set, the document field will also be set.

See also

Working with Files and Media <Working-with-Files-and-Media>

Type:

telegram.Animation

game

Optional. Message is a game, information about the game. More about games >>.

Type:

telegram.Game

photo

Optional. Message is a photo, available sizes of the photo. This list is empty if the message does not contain a photo.

See also

Working with Files and Media <Working-with-Files-and-Media>

Changed in version 20.0: |tupleclassattrs|

Type:

tuple[telegram.PhotoSize]

sticker

Optional. Message is a sticker, information about the sticker.

See also

Working with Files and Media <Working-with-Files-and-Media>

Type:

telegram.Sticker

story

Optional. Message is a forwarded story.

Added in version 20.5.

Type:

telegram.Story

video

Optional. Message is a video, information about the video.

See also

Working with Files and Media <Working-with-Files-and-Media>

Type:

telegram.Video

voice

Optional. Message is a voice message, information about the file.

See also

Working with Files and Media <Working-with-Files-and-Media>

Type:

telegram.Voice

video_note

Optional. Message is a video note, information about the video message.

See also

Working with Files and Media <Working-with-Files-and-Media>

Type:

telegram.VideoNote

new_chat_members

Optional. New members that were added to the group or supergroup and information about them (the bot itself may be one of these members). This list is empty if the message does not contain new chat members.

Changed in version 20.0: |tupleclassattrs|

Type:

tuple[telegram.User]

caption

Optional. Caption for the animation, audio, document, paid media, photo, video or voice, 0-telegram.constants.MessageLimit.CAPTION_LENGTH characters.

Type:

str

contact

Optional. Message is a shared contact, information about the contact.

Type:

telegram.Contact

location

Optional. Message is a shared location, information about the location.

Type:

telegram.Location

venue

Optional. Message is a venue, information about the venue. For backward compatibility, when this field is set, the location field will also be set.

Type:

telegram.Venue

left_chat_member

Optional. A member was removed from the group, information about them (this member may be the bot itself).

Type:

telegram.User

new_chat_title

Optional. A chat title was changed to this value.

Type:

str

new_chat_photo

A chat photo was changed to this value. This list is empty if the message does not contain a new chat photo.

Changed in version 20.0: |tupleclassattrs|

Type:

tuple[telegram.PhotoSize]

delete_chat_photo

Optional. Service message: The chat photo was deleted.

Type:

bool

group_chat_created

Optional. Service message: The group has been created.

Type:

bool

supergroup_chat_created

Optional. Service message: The supergroup has been created. This field can’t be received in a message coming through updates, because bot can’t be a member of a supergroup when it is created. It can only be found in reply_to_message if someone replies to a very first message in a directly created supergroup.

Type:

bool

channel_chat_created

Optional. Service message: The channel has been created. This field can’t be received in a message coming through updates, because bot can’t be a member of a channel when it is created. It can only be found in reply_to_message if someone replies to a very first message in a channel.

Type:

bool

message_auto_delete_timer_changed

Optional. Service message: auto-delete timer settings changed in the chat.

Added in version 13.4.

Type:

telegram.MessageAutoDeleteTimerChanged

migrate_to_chat_id

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

Type:

int

migrate_from_chat_id

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

Type:

int

pinned_message

Optional. Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply.

Changed in version 20.8: This attribute now is either telegram.Message or telegram.InaccessibleMessage.

Type:

telegram.MaybeInaccessibleMessage

invoice

Optional. Message is an invoice for a payment, information about the invoice. More about payments >>.

Type:

telegram.Invoice

successful_payment

Optional. Message is a service message about a successful payment, information about the payment. More about payments >>.

Type:

telegram.SuccessfulPayment

connected_website

Optional. The domain name of the website on which the user has logged in. More about Telegram Login >>.

Type:

str

author_signature

Optional. Signature of the post author for messages in channels, or the custom title of an anonymous group administrator.

Type:

str

paid_star_count

Optional. The number of Telegram Stars that were paid by the sender of the message to send it

Added in version 22.1.

Type:

int

passport_data

Optional. Telegram Passport data.

Examples

Passport Bot

Type:

telegram.PassportData

poll

Optional. Message is a native poll, information about the poll.

Type:

telegram.Poll

dice

Optional. Message is a dice with random value.

Type:

telegram.Dice

via_bot

Optional. Bot through which message was sent.

Type:

telegram.User

proximity_alert_triggered

Optional. Service message. A user in the chat triggered another user’s proximity alert while sharing Live Location.

Type:

telegram.ProximityAlertTriggered

video_chat_scheduled

Optional. Service message: video chat scheduled.

Added in version 20.0.

Type:

telegram.VideoChatScheduled

video_chat_started

Optional. Service message: video chat started.

Added in version 20.0.

Type:

telegram.VideoChatStarted

video_chat_ended

Optional. Service message: video chat ended.

Added in version 20.0.

Type:

telegram.VideoChatEnded

video_chat_participants_invited

Optional. Service message: new participants invited to a video chat.

Added in version 20.0.

Type:

telegram.VideoChatParticipantsInvited

web_app_data

Optional. Service message: data sent by a Web App.

Added in version 20.0.

Type:

telegram.WebAppData

reply_markup

Optional. Inline keyboard attached to the message. ~telegram.InlineKeyboardButton.login_url buttons are represented as ordinary url buttons.

Type:

telegram.InlineKeyboardMarkup

is_topic_message

Optional. True, if the message is sent to a forum topic.

Added in version 20.0.

Type:

bool

message_thread_id

Optional. Unique identifier of a message thread to which the message belongs; for supergroups only.

Added in version 20.0.

Type:

int

forum_topic_created

Optional. Service message: forum topic created.

Added in version 20.0.

Type:

telegram.ForumTopicCreated

forum_topic_closed

Optional. Service message: forum topic closed.

Added in version 20.0.

Type:

telegram.ForumTopicClosed

forum_topic_reopened

Optional. Service message: forum topic reopened.

Added in version 20.0.

Type:

telegram.ForumTopicReopened

forum_topic_edited

Optional. Service message: forum topic edited.

Added in version 20.0.

Type:

telegram.ForumTopicEdited

general_forum_topic_hidden

Optional. Service message: General forum topic hidden.

Added in version 20.0.

Type:

telegram.GeneralForumTopicHidden

general_forum_topic_unhidden

Optional. Service message: General forum topic unhidden.

Added in version 20.0.

Type:

telegram.GeneralForumTopicUnhidden

write_access_allowed

Optional. Service message: the user allowed the bot added to the attachment menu to write messages.

Added in version 20.0.

Type:

telegram.WriteAccessAllowed

has_media_spoiler

Optional. True, if the message media is covered by a spoiler animation.

Added in version 20.0.

Type:

bool

checklist

Optional. Message is a checklist

Added in version 22.3.

Type:

telegram.Checklist

users_shared

Optional. Service message: users were shared with the bot

Added in version 20.8.

Type:

telegram.UsersShared

chat_shared

Optional. Service message: a chat was shared with the bot.

Added in version 20.1.

Type:

telegram.ChatShared

gift

Optional. Service message: a regular gift was sent or received.

Added in version 22.1.

Type:

telegram.GiftInfo

unique_gift

Optional. Service message: a unique gift was sent or received

Added in version 22.1.

Type:

telegram.UniqueGiftInfo

giveaway_created

Optional. Service message: a scheduled giveaway was created

Added in version 20.8.

Type:

telegram.GiveawayCreated

giveaway

Optional. The message is a scheduled giveaway message

Added in version 20.8.

Type:

telegram.Giveaway

giveaway_winners

Optional. A giveaway with public winners was completed

Added in version 20.8.

Type:

telegram.GiveawayWinners

giveaway_completed

Optional. Service message: a giveaway without public winners was completed

Added in version 20.8.

Type:

telegram.GiveawayCompleted

paid_message_price_changed

Optional. Service message: the price for paid messages has changed in the chat

Added in version 22.1.

Type:

telegram.PaidMessagePriceChanged

suggested_post_approved

Optional. Service message: a suggested post was approved.

Added in version 22.4.

Type:

telegram.SuggestedPostApproved

suggested_post_approval_failed

Optional. Service message: approval of a suggested post has failed.

Added in version 22.4.

Type:

telegram.SuggestedPostApproved

suggested_post_declined

Optional. Service message: a suggested post was declined.

Added in version 22.4.

Type:

telegram.SuggestedPostDeclined

suggested_post_paid

Optional. Service message: payment for a suggested post was received.

Added in version 22.4.

Type:

telegram.SuggestedPostPaid

suggested_post_refunded

Optional. Service message: payment for a suggested post was refunded.

Added in version 22.4.

Type:

telegram.SuggestedPostRefunded

external_reply

Optional. Information about the message that is being replied to, which may come from another chat or forum topic.

Added in version 20.8.

Type:

telegram.ExternalReplyInfo

quote

Optional. For replies that quote part of the original message, the quoted part of the message.

Added in version 20.8.

Type:

telegram.TextQuote

forward_origin

Optional. Information about the original message for forwarded messages

Added in version 20.8.

Type:

telegram.MessageOrigin

reply_to_story

Optional. For replies to a story, the original story.

Added in version 21.0.

Type:

telegram.Story

boost_added

Optional. Service message: user boosted the chat.

Added in version 21.0.

Type:

telegram.ChatBoostAdded

sender_boost_count

Optional. If the sender of the message boosted the chat, the number of boosts added by the user.

Added in version 21.0.

Type:

int

business_connection_id

Optional. Unique identifier of the business connection from which the message was received. If non-empty, the message belongs to a chat of the corresponding business account that is independent from any potential bot chat which might share the same identifier.

Added in version 21.1.

Type:

str

sender_business_bot

Optional. The bot that actually sent the message on behalf of the business account. Available only for outgoing messages sent on behalf of the connected business account.

Added in version 21.1.

Type:

telegram.User

chat_background_set

Optional. Service message: chat background set

Added in version 21.2.

Type:

telegram.ChatBackground

checklist_tasks_done

Optional. Service message: some tasks in a checklist were marked as done or not done

Added in version 22.3.

Type:

telegram.ChecklistTasksDone

checklist_tasks_added

Optional. Service message: tasks were added to a checklist

Added in version 22.3.

Type:

telegram.ChecklistTasksAdded

paid_media

Optional. Message contains paid media; information about the paid media.

Added in version 21.4.

Type:

telegram.PaidMediaInfo

refunded_payment

Optional. Message is a service message about a refunded payment, information about the payment.

Added in version 21.4.

Type:

telegram.RefundedPayment

direct_message_price_changed

Optional. Service message: the price for paid messages in the corresponding direct messages chat of a channel has changed.

Added in version 22.3.

Type:

telegram.DirectMessagePriceChanged

is_paid_post

Optional. True, if the message is a paid post. Note that such posts must not be deleted for 24 hours to receive the payment and can’t be edited.

Added in version 22.4.

Type:

bool

direct_messages_topic

Optional. Information about the direct messages chat topic that contains the message.

Added in version 22.4.

Type:

telegram.DirectMessagesTopic

reply_to_checklist_task_id

Optional. Identifier of the specific checklist task that is being replied to.

Added in version 22.4.

Type:

int

animation: Animation | None
async approve_suggested_post(send_date=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

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

For the documentation of the arguments, please see telegram.Bot.approve_suggested_post().

Added in version 22.4.

Returns:

boolbool On success, True is returned.

audio: Audio | None
author_signature: str | None
boost_added: ChatBoostAdded | None
build_reply_arguments(quote=None, quote_index=None, target_chat_id=None, allow_sending_without_reply=None, message_thread_id=None)[source]

Builds a dictionary with the keys chat_id and reply_parameters. This dictionary can be used to reply to a message with the given quote and target chat.

Examples

Usage with telegram.Bot.send_message():

await bot.send_message(
    text="This is a reply",
    **message.build_reply_arguments(quote="Quoted Text")
)

Usage with reply_text(), replying in the same chat:

await message.reply_text(
    "This is a reply",
    do_quote=message.build_reply_arguments(quote="Quoted Text")
)

Usage with reply_text(), replying in a different chat:

await message.reply_text(
    "This is a reply",
    do_quote=message.build_reply_arguments(
        quote="Quoted Text",
        target_chat_id=-100123456789
    )
)

Added in version 20.8.

Parameters:
Returns:

_ReplyKwargs

business_connection_id: str | None
caption: str | None
caption_entities: tuple[MessageEntity, ...]
property caption_html: str

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

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

Warning

|text_html|

Changed in version 13.10: Spoiler entities are now formatted as HTML.

Changed in version 20.3: Custom emoji entities are now supported.

Changed in version 20.8: Blockquote entities are now supported.

Returns:

Message caption with caption entities formatted as HTML.

Return type:

str

property caption_html_urled: str

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

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

Warning

|text_html|

Changed in version 13.10: Spoiler entities are now formatted as HTML.

Changed in version 20.3: Custom emoji entities are now supported.

Changed in version 20.8: Blockquote entities are now supported.

Returns:

Message caption with caption entities formatted as HTML.

Return type:

str

property caption_markdown: str

Creates an Markdown-formatted string from the markup entities found in the message’s caption using telegram.constants.ParseMode.MARKDOWN.

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

Warning

|text_markdown|

Note

telegram.constants.ParseMode.MARKDOWN is a legacy mode, retained by Telegram for backward compatibility. You should use caption_markdown_v2()

Changed in version 20.5: Since custom emoji entities are not supported by MARKDOWN, this method now raises a ValueError when encountering a custom emoji.

Changed in version 20.8: Since block quotation entities are not supported by MARKDOWN, this method now raises a ValueError when encountering a block quotation.

Returns:

Message caption with caption entities formatted as Markdown.

Return type:

str

Raises:

ValueError – If the message contains underline, strikethrough, spoiler, blockquote or nested entities.

property caption_markdown_urled: str

Creates an Markdown-formatted string from the markup entities found in the message’s caption using telegram.constants.ParseMode.MARKDOWN.

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

Warning

|text_markdown|

Note

telegram.constants.ParseMode.MARKDOWN is a legacy mode, retained by Telegram for backward compatibility. You should use caption_markdown_v2_urled() instead.

Changed in version 20.5: Since custom emoji entities are not supported by MARKDOWN, this method now raises a ValueError when encountering a custom emoji.

Changed in version 20.8: Since block quotation entities are not supported by MARKDOWN, this method now raises a ValueError when encountering a block quotation.

Returns:

Message caption with caption entities formatted as Markdown.

Return type:

str

Raises:

ValueError – If the message contains underline, strikethrough, spoiler, blockquote or nested entities.

property caption_markdown_v2: str

Creates an Markdown-formatted string from the markup entities found in the message’s caption using telegram.constants.ParseMode.MARKDOWN_V2.

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

Warning

|text_markdown|

Changed in version 13.10: Spoiler entities are now formatted as Markdown V2.

Changed in version 20.3: Custom emoji entities are now supported.

Changed in version 20.8: Blockquote entities are now supported.

Returns:

Message caption with caption entities formatted as Markdown.

Return type:

str

property caption_markdown_v2_urled: str

Creates an Markdown-formatted string from the markup entities found in the message’s caption using telegram.constants.ParseMode.MARKDOWN_V2.

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

Warning

|text_markdown|

Changed in version 13.10: Spoiler entities are now formatted as Markdown V2.

Changed in version 20.3: Custom emoji entities are now supported.

Changed in version 20.8: Blockquote entities are now supported.

Returns:

Message caption with caption entities formatted as Markdown.

Return type:

str

channel_chat_created: bool | None
chat_background_set: ChatBackground | None
property chat_id: int

Shortcut for telegram.Chat.id for chat.

Type:

int

chat_shared: ChatShared | None
checklist: Checklist | None
checklist_tasks_added: ChecklistTasksAdded | None
checklist_tasks_done: ChecklistTasksDone | None
async close_forum_topic(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.close_forum_topic(
   chat_id=message.chat_id, message_thread_id=message.message_thread_id, *args,
   **kwargs
)

For the documentation of the arguments, please see telegram.Bot.close_forum_topic().

Added in version 20.0.

Returns:

On success, True is returned.

Returns:

bool

compute_quote_position_and_entities(quote, index=None)[source]

Use this function to compute position and entities of a quote in the message text or caption. Useful for filling the parameters ~telegram.ReplyParameters.quote_position and ~telegram.ReplyParameters.quote_entities of telegram.ReplyParameters when replying to a message.

Example

Given a message with the text "Hello, world! Hello, world!", the following code will return the position and entities of the second occurrence of "Hello, world!".

message.compute_quote_position_and_entities("Hello, world!", 1)

Added in version 20.8.

Parameters:
  • quote (str) – Part of the message which is to be quoted. This is expected to have plain text without formatting entities.

  • index (int | None, default: None) – 0-based index of the occurrence of the quote in the message. If not specified, the first occurrence is used.

Returns:

On success, a tuple containing information about quote position and entities is returned.

Returns:

tuple[int, tuple[MessageEntity, ...] | None]

Raises:
connected_website: str | None
contact: Contact | None
async copy(chat_id, caption=None, parse_mode=None, caption_entities=None, disable_notification=None, reply_markup=None, protect_content=None, message_thread_id=None, reply_parameters=None, show_caption_above_media=None, allow_paid_broadcast=None, video_start_timestamp=None, suggested_post_parameters=None, *, reply_to_message_id=None, allow_sending_without_reply=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.copy_message(
    chat_id=chat_id,
    from_chat_id=update.effective_message.chat_id,
    message_id=update.effective_message.message_id,
    direct_messages_topic_id=self.direct_messages_topic.topic_id,
    *args,
    **kwargs
)

For the documentation of the arguments, please see telegram.Bot.copy_message().

Returns:

On success, returns the MessageId of the sent message.

Returns:

MessageId

classmethod de_json(data, bot=None)[source]

See telegram.TelegramObject.de_json().

Return type:

Message

async decline_suggested_post(comment=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

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

For the documentation of the arguments, please see telegram.Bot.decline_suggested_post().

Added in version 22.4.

Returns:

boolbool On success, True is returned.

async delete(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for either:

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

or:

await bot.delete_business_messages(
    business_connection_id=self.business_connection_id,
    message_ids=[self.message_id],
    *args,
    **kwargs,
)

For the documentation of the arguments, please see telegram.Bot.delete_message() and telegram.Bot.delete_business_messages().

Returns:

On success, True is returned.

Returns:

bool

delete_chat_photo: bool | None
async delete_forum_topic(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.delete_forum_topic(
   chat_id=message.chat_id, message_thread_id=message.message_thread_id, *args,
   **kwargs
)

For the documentation of the arguments, please see telegram.Bot.delete_forum_topic().

Added in version 20.0.

Returns:

On success, True is returned.

Returns:

bool

dice: Dice | None
direct_message_price_changed: DirectMessagePriceChanged | None
direct_messages_topic: DirectMessagesTopic | None
document: Document | None
async edit_caption(caption=None, reply_markup=None, parse_mode=None, caption_entities=None, show_caption_above_media=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

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

For the documentation of the arguments, please see telegram.Bot.edit_message_caption().

Note

You can only edit messages that the bot sent itself (i.e. of the bot.send_* family of methods) or channel posts, if the bot is an admin in that channel. However, this behaviour is undocumented and might be changed by Telegram.

Changed in version 21.4: Now also passes business_connection_id.

Returns:

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

Returns:

Message | bool

async edit_checklist(checklist, reply_markup=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.edit_message_checklist(
    business_connection_id=message.business_connection_id,
    chat_id=message.chat_id,
    message_id=message.message_id,
    *args, **kwargs
)

For the documentation of the arguments, please see telegram.Bot.edit_message_checklist().

Added in version 22.3.

Note

You can only edit messages that the bot sent itself (i.e. of the bot.send_* family of methods) or channel posts, if the bot is an admin in that channel. However, this behaviour is undocumented and might be changed by Telegram.

Returns:

On success, the edited Message is returned.

Returns:

Message

edit_date: dtm.datetime | None
async edit_forum_topic(name=None, icon_custom_emoji_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.edit_forum_topic(
   chat_id=message.chat_id, message_thread_id=message.message_thread_id, *args,
   **kwargs
)

For the documentation of the arguments, please see telegram.Bot.edit_forum_topic().

Added in version 20.0.

Returns:

On success, True is returned.

Returns:

bool

async edit_live_location(latitude=None, longitude=None, reply_markup=None, horizontal_accuracy=None, heading=None, proximity_alert_radius=None, live_period=None, *, location=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.edit_message_live_location(
    chat_id=message.chat_id,
    message_id=message.message_id,
    business_connection_id=message.business_connection_id,
    *args, **kwargs
)

For the documentation of the arguments, please see telegram.Bot.edit_message_live_location().

Note

You can only edit messages that the bot sent itself (i.e. of the bot.send_* family of methods) or channel posts, if the bot is an admin in that channel. However, this behaviour is undocumented and might be changed by Telegram.

Changed in version 21.4: Now also passes business_connection_id.

Returns:

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

Returns:

Message | bool

async edit_media(media, reply_markup=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

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

For the documentation of the arguments, please see telegram.Bot.edit_message_media().

Note

You can only edit messages that the bot sent itself(i.e. of the bot.send_* family of methods) or channel posts, if the bot is an admin in that channel. However, this behaviour is undocumented and might be changed by Telegram.

Changed in version 21.4: Now also passes business_connection_id.

Returns:

On success, if edited message is not an inline message, the edited Message is returned, otherwise True is returned.

Returns:

Message | bool

async edit_reply_markup(reply_markup=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

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

For the documentation of the arguments, please see telegram.Bot.edit_message_reply_markup().

Note

You can only edit messages that the bot sent itself (i.e. of the bot.send_* family of methods) or channel posts, if the bot is an admin in that channel. However, this behaviour is undocumented and might be changed by Telegram.

Changed in version 21.4: Now also passes business_connection_id.

Returns:

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

Returns:

Message | bool

async edit_text(text, parse_mode=None, reply_markup=None, entities=None, link_preview_options=None, *, disable_web_page_preview=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

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

For the documentation of the arguments, please see telegram.Bot.edit_message_text().

Note

You can only edit messages that the bot sent itself (i.e. of the bot.send_* family of methods) or channel posts, if the bot is an admin in that channel. However, this behaviour is undocumented and might be changed by Telegram.

Changed in version 21.4: Now also passes business_connection_id.

Returns:

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

Returns:

Message | bool

effect_id: str | None
property effective_attachment: Animation | Audio | Contact | Dice | Document | Game | Invoice | Location | PassportData | Sequence[PhotoSize] | PaidMediaInfo | Poll | Sticker | Story | SuccessfulPayment | Venue | Video | VideoNote | Voice | None

If the message is a user generated content which is not a plain text message, this property is set to this content. It may be one of

Otherwise None is returned.

See also

Working with Files and Media <Working-with-Files-and-Media>

Changed in version 20.0: dice, passport_data and poll are now also considered to be an attachment.

Changed in version 21.4: paid_media is now also considered to be an attachment.

Deprecated since version 21.4: successful_payment will be removed in future major versions.

entities: tuple[MessageEntity, ...]
external_reply: ExternalReplyInfo | None
forum_topic_closed: ForumTopicClosed | None
forum_topic_created: ForumTopicCreated | None
forum_topic_edited: ForumTopicEdited | None
forum_topic_reopened: ForumTopicReopened | None
async forward(chat_id, disable_notification=None, protect_content=None, message_thread_id=None, video_start_timestamp=None, suggested_post_parameters=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.forward_message(
    from_chat_id=update.effective_message.chat_id,
    message_id=update.effective_message.message_id,
    direct_messages_topic_id=self.direct_messages_topic.topic_id,
    *args,
    **kwargs
)

For the documentation of the arguments, please see telegram.Bot.forward_message().

Note

Since the release of Bot API 5.5 it can be impossible to forward messages from some chats. Use the attributes telegram.Message.has_protected_content and telegram.ChatFullInfo.has_protected_content to check this.

As a workaround, it is still possible to use copy(). However, this behaviour is undocumented and might be changed by Telegram.

Returns:

On success, instance representing the message forwarded.

Returns:

Message

forward_origin: MessageOrigin | None
from_user: User | None
game: Game | None
general_forum_topic_hidden: GeneralForumTopicHidden | None
general_forum_topic_unhidden: GeneralForumTopicUnhidden | None
async get_game_high_scores(user_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

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

For the documentation of the arguments, please see telegram.Bot.get_game_high_scores().

Note

You can only edit messages that the bot sent itself (i.e. of the bot.send_* family of methods) or channel posts, if the bot is an admin in that channel. However, this behaviour is undocumented and might be changed by Telegram.

Returns:

tuple[GameHighScore, ...] – tuple[telegram.GameHighScore]

gift: GiftInfo | None
giveaway: Giveaway | None
giveaway_completed: GiveawayCompleted | None
giveaway_created: GiveawayCreated | None
giveaway_winners: GiveawayWinners | None
group_chat_created: bool | None
has_media_spoiler: bool | None
has_protected_content: bool | None
property id: int

Shortcut for message_id.

Added in version 20.0.

Type:

int

invoice: Invoice | None
is_automatic_forward: bool | None
is_from_offline: bool | None
is_paid_post: bool | None
is_topic_message: bool | None
left_chat_member: User | None

Convenience property. If the chat of the message is not a private chat or normal group, returns a t.me link of the message.

Changed in version 20.3: For messages that are replies or part of a forum topic, the link now points to the corresponding thread view.

Type:

str

link_preview_options: LinkPreviewOptions | None
location: Location | None
media_group_id: str | None
message_auto_delete_timer_changed: MessageAutoDeleteTimerChanged | None
message_thread_id: int | None
migrate_from_chat_id: int | None
migrate_to_chat_id: int | None
new_chat_members: tuple[User, ...]
new_chat_photo: tuple[PhotoSize, ...]
new_chat_title: str | None
paid_media: PaidMediaInfo | None
paid_message_price_changed: PaidMessagePriceChanged | None
paid_star_count: int | None
parse_caption_entities(types=None)[source]

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

Note

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

Parameters:

types (list[str] | None, default: None) – List of telegram.MessageEntity types as strings. If the type attribute of an entity is contained in this list, it will be returned. Defaults to a list of all types. All types can be found as constants in telegram.MessageEntity.

Returns:

A dictionary of entities mapped to the text that belongs to them, calculated based on UTF-16 codepoints.

Returns:

dict[MessageEntity, str]

parse_caption_entity(entity)[source]

Returns the text from a given telegram.MessageEntity.

Note

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

Parameters:

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

Returns:

The text of the given entity.

Returns:

str

Raises:

RuntimeError – If the message has no caption.

parse_entities(types=None)[source]

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

Note

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

Parameters:

types (list[str] | None, default: None) – List of telegram.MessageEntity types as strings. If the type attribute of an entity is contained in this list, it will be returned. Defaults to a list of all types. All types can be found as constants in telegram.MessageEntity.

Returns:

A dictionary of entities mapped to the text that belongs to them, calculated based on UTF-16 codepoints.

Returns:

dict[MessageEntity, str]

parse_entity(entity)[source]

Returns the text from a given telegram.MessageEntity.

Note

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

Parameters:

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

Returns:

The text of the given entity.

Returns:

str

Raises:

RuntimeError – If the message has no text.

passport_data: PassportData | None
photo: tuple[PhotoSize, ...]
async pin(disable_notification=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.pin_chat_message(
    chat_id=message.chat_id,
    message_id=message.message_id,
    business_connection_id=message.business_connection_id,
    *args, **kwargs
)

For the documentation of the arguments, please see telegram.Bot.pin_chat_message().

Changed in version 21.5: Now also passes business_connection_id to telegram.Bot.pin_chat_message().

Returns:

On success, True is returned.

Returns:

bool

pinned_message: MaybeInaccessibleMessage | None
poll: Poll | None
proximity_alert_triggered: ProximityAlertTriggered | None
quote: TextQuote | None
async read_business_message(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

 await bot.read_business_message(
    chat_id=message.chat_id,
    message_id=message.message_id,
    business_connection_id=message.business_connection_id,
    *args, **kwargs
)

For the documentation of the arguments, please see telegram.Bot.read_business_message().

Added in version 22.1.

Returns:

boolbool On success, True is returned.

refunded_payment: RefundedPayment | None
async reopen_forum_topic(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.reopen_forum_topic(
    chat_id=message.chat_id, message_thread_id=message.message_thread_id, *args,
    **kwargs
 )

For the documentation of the arguments, please see telegram.Bot.reopen_forum_topic().

Added in version 20.0.

Returns:

On success, True is returned.

Returns:

bool

async reply_animation(animation, duration=None, width=None, height=None, caption=None, parse_mode=None, disable_notification=None, reply_markup=None, caption_entities=None, protect_content=None, message_thread_id=None, has_spoiler=None, thumbnail=None, reply_parameters=None, message_effect_id=None, allow_paid_broadcast=None, show_caption_above_media=None, suggested_post_parameters=None, *, reply_to_message_id=None, allow_sending_without_reply=None, filename=None, do_quote=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.send_animation(
    update.effective_message.chat_id,
    message_thread_id=update.effective_message.message_thread_id,
    business_connection_id=self.business_connection_id,
    direct_messages_topic_id=self.direct_messages_topic.topic_id,
    *args,
    **kwargs,
)

For the documentation of the arguments, please see telegram.Bot.send_animation().

Changed in version 21.1: If message_thread_id is not provided, this will reply to the same thread (topic) of the original message.

Changed in version 22.0: Removed deprecated parameter quote. Use do_quote instead.

Keyword Arguments:

do_quote (bool | dict, optional) –

|do_quote|

Added in version 20.8.

Returns:

On success, instance representing the message posted.

Returns:

Message

async reply_audio(audio, duration=None, performer=None, title=None, caption=None, disable_notification=None, reply_markup=None, parse_mode=None, caption_entities=None, protect_content=None, message_thread_id=None, thumbnail=None, reply_parameters=None, message_effect_id=None, allow_paid_broadcast=None, suggested_post_parameters=None, *, reply_to_message_id=None, allow_sending_without_reply=None, filename=None, do_quote=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.send_audio(
    update.effective_message.chat_id,
    message_thread_id=update.effective_message.message_thread_id,
    business_connection_id=self.business_connection_id,
    direct_messages_topic_id=self.direct_messages_topic.topic_id,
    *args,
    **kwargs,
)

For the documentation of the arguments, please see telegram.Bot.send_audio().

Changed in version 21.1: If message_thread_id is not provided, this will reply to the same thread (topic) of the original message.

Changed in version 22.0: Removed deprecated parameter quote. Use do_quote instead.

Keyword Arguments:

do_quote (bool | dict, optional) –

|do_quote|

Added in version 20.8.

Returns:

On success, instance representing the message posted.

Returns:

Message

async reply_chat_action(action, message_thread_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.send_chat_action(
    update.effective_message.chat_id,
    message_thread_id=update.effective_message.message_thread_id,
    business_connection_id=self.business_connection_id,
    *args,
    **kwargs,
)

For the documentation of the arguments, please see telegram.Bot.send_chat_action().

Changed in version 21.1: If message_thread_id is not provided, this will reply to the same thread (topic) of the original message.

Added in version 13.2.

Returns:

On success, True is returned.

Returns:

bool

async reply_checklist(checklist, disable_notification=None, protect_content=None, message_effect_id=None, reply_parameters=None, reply_markup=None, *, reply_to_message_id=None, allow_sending_without_reply=None, do_quote=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.send_checklist(
    business_connection_id=self.business_connection_id,
    chat_id=update.effective_message.chat_id,
    *args,
    **kwargs,
)

For the documentation of the arguments, please see telegram.Bot.send_checklist().

Added in version 22.3.

Keyword Arguments:

do_quote (bool | dict, optional) – |do_quote|

Returns:

On success, instance representing the message posted.

Returns:

Message

async reply_contact(phone_number=None, first_name=None, last_name=None, disable_notification=None, reply_markup=None, vcard=None, protect_content=None, message_thread_id=None, reply_parameters=None, message_effect_id=None, allow_paid_broadcast=None, suggested_post_parameters=None, *, reply_to_message_id=None, allow_sending_without_reply=None, contact=None, do_quote=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.send_contact(
    update.effective_message.chat_id,
    message_thread_id=update.effective_message.message_thread_id,
    business_connection_id=self.business_connection_id,
    direct_messages_topic_id=self.direct_messages_topic.topic_id,
    *args,
    **kwargs,
)

For the documentation of the arguments, please see telegram.Bot.send_contact().

Changed in version 21.1: If message_thread_id is not provided, this will reply to the same thread (topic) of the original message.

Changed in version 22.0: Removed deprecated parameter quote. Use do_quote instead.

Keyword Arguments:

do_quote (bool | dict, optional) –

|do_quote|

Added in version 20.8.

Returns:

On success, instance representing the message posted.

Returns:

Message

async reply_copy(from_chat_id, message_id, caption=None, parse_mode=None, caption_entities=None, disable_notification=None, reply_markup=None, protect_content=None, message_thread_id=None, reply_parameters=None, show_caption_above_media=None, allow_paid_broadcast=None, video_start_timestamp=None, suggested_post_parameters=None, *, reply_to_message_id=None, allow_sending_without_reply=None, do_quote=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.copy_message(
    chat_id=message.chat.id,
    message_thread_id=update.effective_message.message_thread_id,
    message_id=message_id,
    direct_messages_topic_id=self.direct_messages_topic.topic_id,
    *args,
    **kwargs
)

For the documentation of the arguments, please see telegram.Bot.copy_message().

Changed in version 21.1: If message_thread_id is not provided, this will reply to the same thread (topic) of the original message.

Changed in version 22.0: Removed deprecated parameter quote. Use do_quote instead.

Keyword Arguments:

do_quote (bool | dict, optional) –

|do_quote|

Added in version 20.8.

Returns:

On success, returns the MessageId of the sent message.

Returns:

MessageId

async reply_dice(disable_notification=None, reply_markup=None, emoji=None, protect_content=None, message_thread_id=None, reply_parameters=None, message_effect_id=None, allow_paid_broadcast=None, suggested_post_parameters=None, *, reply_to_message_id=None, allow_sending_without_reply=None, do_quote=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.send_dice(
    update.effective_message.chat_id,
    message_thread_id=update.effective_message.message_thread_id,
    business_connection_id=self.business_connection_id,
    direct_messages_topic_id=self.direct_messages_topic.topic_id,
    *args,
    **kwargs,
)

For the documentation of the arguments, please see telegram.Bot.send_dice().

Changed in version 21.1: If message_thread_id is not provided, this will reply to the same thread (topic) of the original message.

Changed in version 22.0: Removed deprecated parameter quote. Use do_quote instead.

Keyword Arguments:

do_quote (bool | dict, optional) –

|do_quote|

Added in version 20.8.

Returns:

On success, instance representing the message posted.

Returns:

Message

async reply_document(document, caption=None, disable_notification=None, reply_markup=None, parse_mode=None, disable_content_type_detection=None, caption_entities=None, protect_content=None, message_thread_id=None, thumbnail=None, reply_parameters=None, message_effect_id=None, allow_paid_broadcast=None, suggested_post_parameters=None, *, reply_to_message_id=None, allow_sending_without_reply=None, filename=None, do_quote=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.send_document(
    update.effective_message.chat_id,
    message_thread_id=update.effective_message.message_thread_id,
    business_connection_id=self.business_connection_id,
    direct_messages_topic_id=self.direct_messages_topic.topic_id,
    *args,
    **kwargs,
)

For the documentation of the arguments, please see telegram.Bot.send_document().

Changed in version 21.1: If message_thread_id is not provided, this will reply to the same thread (topic) of the original message.

Changed in version 22.0: Removed deprecated parameter quote. Use do_quote instead.

Keyword Arguments:

do_quote (bool | dict, optional) –

|do_quote|

Added in version 20.8.

Returns:

On success, instance representing the message posted.

Returns:

Message

async reply_game(game_short_name, disable_notification=None, reply_markup=None, protect_content=None, message_thread_id=None, reply_parameters=None, message_effect_id=None, allow_paid_broadcast=None, *, reply_to_message_id=None, allow_sending_without_reply=None, do_quote=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.send_game(
    update.effective_message.chat_id,
    message_thread_id=update.effective_message.message_thread_id,
    business_connection_id=self.business_connection_id,
    *args,
    **kwargs,
)

For the documentation of the arguments, please see telegram.Bot.send_game().

Changed in version 21.1: If message_thread_id is not provided, this will reply to the same thread (topic) of the original message.

Changed in version 22.0: Removed deprecated parameter quote. Use do_quote instead.

Keyword Arguments:

do_quote (bool | dict, optional) –

|do_quote|

Added in version 20.8.

Added in version 13.2.

Returns:

On success, instance representing the message posted.

Returns:

Message

async reply_html(text, disable_notification=None, reply_markup=None, entities=None, protect_content=None, message_thread_id=None, link_preview_options=None, reply_parameters=None, message_effect_id=None, allow_paid_broadcast=None, suggested_post_parameters=None, *, reply_to_message_id=None, allow_sending_without_reply=None, disable_web_page_preview=None, do_quote=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.send_message(
    update.effective_message.chat_id,
    message_thread_id=update.effective_message.message_thread_id,
    parse_mode=ParseMode.HTML,
    direct_messages_topic_id=self.direct_messages_topic.topic_id,
    business_connection_id=self.business_connection_id,
    *args,
    **kwargs,
)

Sends a message with HTML formatting.

For the documentation of the arguments, please see telegram.Bot.send_message().

Changed in version 21.1: If message_thread_id is not provided, this will reply to the same thread (topic) of the original message.

Changed in version 22.0: Removed deprecated parameter quote. Use do_quote instead.

Keyword Arguments:

do_quote (bool | dict, optional) –

|do_quote|

Added in version 20.8.

Returns:

On success, instance representing the message posted.

Returns:

Message

async reply_invoice(title, description, payload, currency, prices, provider_token=None, start_parameter=None, photo_url=None, photo_size=None, photo_width=None, photo_height=None, need_name=None, need_phone_number=None, need_email=None, need_shipping_address=None, is_flexible=None, disable_notification=None, reply_markup=None, provider_data=None, send_phone_number_to_provider=None, send_email_to_provider=None, max_tip_amount=None, suggested_tip_amounts=None, protect_content=None, message_thread_id=None, reply_parameters=None, message_effect_id=None, allow_paid_broadcast=None, suggested_post_parameters=None, *, reply_to_message_id=None, allow_sending_without_reply=None, do_quote=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.send_invoice(
    update.effective_message.chat_id,
    message_thread_id=update.effective_message.message_thread_id,
    direct_messages_topic_id=self.direct_messages_topic.topic_id,
    *args,
    **kwargs,
)

For the documentation of the arguments, please see telegram.Bot.send_invoice().

Changed in version 21.1: If message_thread_id is not provided, this will reply to the same thread (topic) of the original message.

Changed in version 22.0: Removed deprecated parameter quote. Use do_quote instead.

Warning

As of API 5.2 start_parameter <telegram.Bot.send_invoice.start_parameter> is an optional argument and therefore the order of the arguments had to be changed. Use keyword arguments to make sure that the arguments are passed correctly.

Added in version 13.2.

Changed in version 13.5: As of Bot API 5.2, the parameter start_parameter <telegram.Bot.send_invoice.start_parameter> is optional.

Keyword Arguments:

do_quote (bool | dict, optional) –

|do_quote|

Added in version 20.8.

Returns:

On success, instance representing the message posted.

Returns:

Message

async reply_location(latitude=None, longitude=None, disable_notification=None, reply_markup=None, live_period=None, horizontal_accuracy=None, heading=None, proximity_alert_radius=None, protect_content=None, message_thread_id=None, reply_parameters=None, message_effect_id=None, allow_paid_broadcast=None, suggested_post_parameters=None, *, reply_to_message_id=None, allow_sending_without_reply=None, location=None, do_quote=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.send_location(
    update.effective_message.chat_id,
    message_thread_id=update.effective_message.message_thread_id,
    business_connection_id=self.business_connection_id,
    direct_messages_topic_id=self.direct_messages_topic.topic_id,
    *args,
    **kwargs,
)

For the documentation of the arguments, please see telegram.Bot.send_location().

Changed in version 21.1: If message_thread_id is not provided, this will reply to the same thread (topic) of the original message.

Changed in version 22.0: Removed deprecated parameter quote. Use do_quote instead.

Keyword Arguments:

do_quote (bool | dict, optional) –

|do_quote|

Added in version 20.8.

Returns:

On success, instance representing the message posted.

Returns:

Message

async reply_markdown(text, disable_notification=None, reply_markup=None, entities=None, protect_content=None, message_thread_id=None, link_preview_options=None, reply_parameters=None, message_effect_id=None, allow_paid_broadcast=None, suggested_post_parameters=None, *, reply_to_message_id=None, allow_sending_without_reply=None, disable_web_page_preview=None, do_quote=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.send_message(
    update.effective_message.chat_id,
    message_thread_id=update.effective_message.message_thread_id,
    parse_mode=ParseMode.MARKDOWN,
    business_connection_id=self.business_connection_id,
    direct_messages_topic_id=self.direct_messages_topic.topic_id,
    *args,
    **kwargs,
)

Sends a message with Markdown version 1 formatting.

For the documentation of the arguments, please see telegram.Bot.send_message().

Changed in version 21.1: If message_thread_id is not provided, this will reply to the same thread (topic) of the original message.

Changed in version 22.0: Removed deprecated parameter quote. Use do_quote instead.

Note

telegram.constants.ParseMode.MARKDOWN is a legacy mode, retained by Telegram for backward compatibility. You should use reply_markdown_v2() instead.

Keyword Arguments:

do_quote (bool | dict, optional) –

|do_quote|

Added in version 20.8.

Returns:

On success, instance representing the message posted.

Returns:

Message

async reply_markdown_v2(text, disable_notification=None, reply_markup=None, entities=None, protect_content=None, message_thread_id=None, link_preview_options=None, reply_parameters=None, message_effect_id=None, allow_paid_broadcast=None, suggested_post_parameters=None, *, reply_to_message_id=None, allow_sending_without_reply=None, disable_web_page_preview=None, do_quote=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.send_message(
    update.effective_message.chat_id,
    message_thread_id=update.effective_message.message_thread_id,
    parse_mode=ParseMode.MARKDOWN_V2,
    direct_messages_topic_id=self.direct_messages_topic.topic_id,
    business_connection_id=self.business_connection_id,
    *args,
    **kwargs,
)

Sends a message with markdown version 2 formatting.

For the documentation of the arguments, please see telegram.Bot.send_message().

Changed in version 21.1: If message_thread_id is not provided, this will reply to the same thread (topic) of the original message.

Changed in version 22.0: Removed deprecated parameter quote. Use do_quote instead.

Keyword Arguments:

do_quote (bool | dict, optional) –

|do_quote|

Added in version 20.8.

Returns:

On success, instance representing the message posted.

Returns:

Message

reply_markup: InlineKeyboardMarkup | None
async reply_media_group(media, disable_notification=None, protect_content=None, message_thread_id=None, reply_parameters=None, message_effect_id=None, allow_paid_broadcast=None, *, reply_to_message_id=None, allow_sending_without_reply=None, do_quote=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None, caption=None, parse_mode=None, caption_entities=None)[source]

Shortcut for:

await bot.send_media_group(
    update.effective_message.chat_id,
    message_thread_id=update.effective_message.message_thread_id,
    business_connection_id=self.business_connection_id,
    direct_messages_topic_id=self.direct_messages_topic.topic_id,
    *args,
    **kwargs,
)

For the documentation of the arguments, please see telegram.Bot.send_media_group().

Changed in version 21.1: If message_thread_id is not provided, this will reply to the same thread (topic) of the original message.

Changed in version 22.0: Removed deprecated parameter quote. Use do_quote instead.

Keyword Arguments:

do_quote (bool | dict, optional) –

|do_quote|

Added in version 20.8.

Returns:

An array of the sent Messages.

Returns:

tuple[Message, ...]

Raises:

telegram.error.TelegramError

async reply_paid_media(star_count, media, caption=None, parse_mode=None, caption_entities=None, show_caption_above_media=None, disable_notification=None, protect_content=None, reply_parameters=None, reply_markup=None, payload=None, allow_paid_broadcast=None, suggested_post_parameters=None, message_thread_id=None, *, reply_to_message_id=None, allow_sending_without_reply=None, do_quote=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.send_paid_media(
    chat_id=message.chat.id,
    message_thread_id=update.effective_message.message_thread_id,
    business_connection_id=message.business_connection_id,
    direct_messages_topic_id=self.direct_messages_topic.topic_id,
    *args,
    **kwargs
)

For the documentation of the arguments, please see telegram.Bot.send_paid_media().

Added in version 21.7.

Keyword Arguments:

do_quote (bool | dict, optional) – |do_quote|

Returns:

On success, the sent message is returned.

Returns:

Message

async reply_photo(photo, caption=None, disable_notification=None, reply_markup=None, parse_mode=None, caption_entities=None, protect_content=None, message_thread_id=None, has_spoiler=None, reply_parameters=None, message_effect_id=None, allow_paid_broadcast=None, show_caption_above_media=None, suggested_post_parameters=None, *, reply_to_message_id=None, allow_sending_without_reply=None, filename=None, do_quote=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.send_photo(
    update.effective_message.chat_id,
    message_thread_id=update.effective_message.message_thread_id,
    business_connection_id=self.business_connection_id,
    direct_messages_topic_id=self.direct_messages_topic.topic_id,
    *args,
    **kwargs,
)

For the documentation of the arguments, please see telegram.Bot.send_photo().

Changed in version 21.1: If message_thread_id is not provided, this will reply to the same thread (topic) of the original message.

Changed in version 22.0: Removed deprecated parameter quote. Use do_quote instead.

Keyword Arguments:

do_quote (bool | dict, optional) –

|do_quote|

Added in version 20.8.

Returns:

On success, instance representing the message posted.

Returns:

Message

async reply_poll(question, options, is_anonymous=None, type=None, allows_multiple_answers=None, correct_option_id=None, is_closed=None, disable_notification=None, reply_markup=None, explanation=None, explanation_parse_mode=None, open_period=None, close_date=None, explanation_entities=None, protect_content=None, message_thread_id=None, reply_parameters=None, question_parse_mode=None, question_entities=None, message_effect_id=None, allow_paid_broadcast=None, *, reply_to_message_id=None, allow_sending_without_reply=None, do_quote=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.send_poll(
    update.effective_message.chat_id,
    message_thread_id=update.effective_message.message_thread_id,
    business_connection_id=self.business_connection_id,
    *args,
    **kwargs,
)

For the documentation of the arguments, please see telegram.Bot.send_poll().

Changed in version 21.1: If message_thread_id is not provided, this will reply to the same thread (topic) of the original message.

Changed in version 22.0: Removed deprecated parameter quote. Use do_quote instead.

Keyword Arguments:

do_quote (bool | dict, optional) –

|do_quote|

Added in version 20.8.

Returns:

On success, instance representing the message posted.

Returns:

Message

async reply_sticker(sticker, disable_notification=None, reply_markup=None, protect_content=None, message_thread_id=None, emoji=None, reply_parameters=None, message_effect_id=None, allow_paid_broadcast=None, suggested_post_parameters=None, *, reply_to_message_id=None, allow_sending_without_reply=None, do_quote=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.send_sticker(
    update.effective_message.chat_id,
    message_thread_id=update.effective_message.message_thread_id,
    business_connection_id=self.business_connection_id,
    direct_messages_topic_id=self.direct_messages_topic.topic_id,
    *args,
    **kwargs,
)

For the documentation of the arguments, please see telegram.Bot.send_sticker().

Changed in version 21.1: If message_thread_id is not provided, this will reply to the same thread (topic) of the original message.

Changed in version 22.0: Removed deprecated parameter quote. Use do_quote instead.

Keyword Arguments:

do_quote (bool | dict, optional) –

|do_quote|

Added in version 20.8.

Returns:

On success, instance representing the message posted.

Returns:

Message

async reply_text(text, parse_mode=None, disable_notification=None, reply_markup=None, entities=None, protect_content=None, message_thread_id=None, link_preview_options=None, reply_parameters=None, message_effect_id=None, allow_paid_broadcast=None, suggested_post_parameters=None, *, reply_to_message_id=None, allow_sending_without_reply=None, disable_web_page_preview=None, do_quote=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.send_message(
    update.effective_message.chat_id,
    message_thread_id=update.effective_message.message_thread_id,
    business_connection_id=self.business_connection_id,
    direct_messages_topic_id=self.direct_messages_topic.topic_id,
    *args,
    **kwargs,
)

For the documentation of the arguments, please see telegram.Bot.send_message().

Changed in version 21.1: If message_thread_id is not provided, this will reply to the same thread (topic) of the original message.

Changed in version 22.0: Removed deprecated parameter quote. Use do_quote instead.

Keyword Arguments:

do_quote (bool | dict, optional) –

|do_quote|

Added in version 20.8.

Returns:

On success, instance representing the message posted.

Returns:

Message

reply_to_checklist_task_id: int | None
reply_to_message: Message | None
reply_to_story: Story | None
async reply_venue(latitude=None, longitude=None, title=None, address=None, foursquare_id=None, disable_notification=None, reply_markup=None, foursquare_type=None, google_place_id=None, google_place_type=None, protect_content=None, message_thread_id=None, reply_parameters=None, message_effect_id=None, allow_paid_broadcast=None, suggested_post_parameters=None, *, reply_to_message_id=None, allow_sending_without_reply=None, venue=None, do_quote=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.send_venue(
    update.effective_message.chat_id,
    message_thread_id=update.effective_message.message_thread_id,
    business_connection_id=self.business_connection_id,
    direct_messages_topic_id=self.direct_messages_topic.topic_id,
    *args,
    **kwargs,
)

For the documentation of the arguments, please see telegram.Bot.send_venue().

Changed in version 21.1: If message_thread_id is not provided, this will reply to the same thread (topic) of the original message.

Changed in version 22.0: Removed deprecated parameter quote. Use do_quote instead.

Keyword Arguments:

do_quote (bool | dict, optional) –

|do_quote|

Added in version 20.8.

Returns:

On success, instance representing the message posted.

Returns:

Message

async reply_video(video, duration=None, caption=None, disable_notification=None, reply_markup=None, width=None, height=None, parse_mode=None, supports_streaming=None, caption_entities=None, protect_content=None, message_thread_id=None, has_spoiler=None, thumbnail=None, reply_parameters=None, message_effect_id=None, allow_paid_broadcast=None, show_caption_above_media=None, cover=None, start_timestamp=None, suggested_post_parameters=None, *, reply_to_message_id=None, allow_sending_without_reply=None, filename=None, do_quote=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.send_video(
    update.effective_message.chat_id,
    message_thread_id=update.effective_message.message_thread_id,
    business_connection_id=self.business_connection_id,
    direct_messages_topic_id=self.direct_messages_topic.topic_id,
    *args,
    **kwargs,
)

For the documentation of the arguments, please see telegram.Bot.send_video().

Changed in version 21.1: If message_thread_id is not provided, this will reply to the same thread (topic) of the original message.

Changed in version 22.0: Removed deprecated parameter quote. Use do_quote instead.

Keyword Arguments:

do_quote (bool | dict, optional) –

|do_quote|

Added in version 20.8.

Returns:

On success, instance representing the message posted.

Returns:

Message

async reply_video_note(video_note, duration=None, length=None, disable_notification=None, reply_markup=None, protect_content=None, message_thread_id=None, thumbnail=None, reply_parameters=None, message_effect_id=None, allow_paid_broadcast=None, suggested_post_parameters=None, *, reply_to_message_id=None, allow_sending_without_reply=None, filename=None, do_quote=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.send_video_note(
    update.effective_message.chat_id,
    message_thread_id=update.effective_message.message_thread_id,
    business_connection_id=self.business_connection_id,
    direct_messages_topic_id=self.direct_messages_topic.topic_id,
    *args,
    **kwargs,
)

For the documentation of the arguments, please see telegram.Bot.send_video_note().

Changed in version 21.1: If message_thread_id is not provided, this will reply to the same thread (topic) of the original message.

Changed in version 22.0: Removed deprecated parameter quote. Use do_quote instead.

Keyword Arguments:

do_quote (bool | dict, optional) –

|do_quote|

Added in version 20.8.

Returns:

On success, instance representing the message posted.

Returns:

Message

async reply_voice(voice, duration=None, caption=None, disable_notification=None, reply_markup=None, parse_mode=None, caption_entities=None, protect_content=None, message_thread_id=None, reply_parameters=None, message_effect_id=None, allow_paid_broadcast=None, suggested_post_parameters=None, *, reply_to_message_id=None, allow_sending_without_reply=None, filename=None, do_quote=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.send_voice(
    update.effective_message.chat_id,
    message_thread_id=update.effective_message.message_thread_id,
    business_connection_id=self.business_connection_id,
    direct_messages_topic_id=self.direct_messages_topic.topic_id,
    *args,
    **kwargs,
)

For the documentation of the arguments, please see telegram.Bot.send_voice().

Changed in version 21.1: If message_thread_id is not provided, this will reply to the same thread (topic) of the original message.

Changed in version 22.0: Removed deprecated parameter quote. Use do_quote instead.

Keyword Arguments:

do_quote (bool | dict, optional) –

|do_quote|

Added in version 20.8.

Returns:

On success, instance representing the message posted.

Returns:

Message

sender_boost_count: int | None
sender_business_bot: User | None
sender_chat: Chat | None
async set_game_score(user_id, score, force=None, disable_edit_message=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

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

For the documentation of the arguments, please see telegram.Bot.set_game_score().

Note

You can only edit messages that the bot sent itself (i.e. of the bot.send_* family of methods) or channel posts, if the bot is an admin in that channel. However, this behaviour is undocumented and might be changed by Telegram.

Returns:

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

Returns:

Message | bool

async set_reaction(reaction=None, is_big=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

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

For the documentation of the arguments, please see telegram.Bot.set_message_reaction().

Added in version 20.8.

Returns:

boolbool On success, True is returned.

show_caption_above_media: bool | None
sticker: Sticker | None
async stop_live_location(reply_markup=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.stop_message_live_location(
    chat_id=message.chat_id,
    message_id=message.message_id,
    business_connection_id=message.business_connection_id,
    *args, **kwargs
)

For the documentation of the arguments, please see telegram.Bot.stop_message_live_location().

Note

You can only edit messages that the bot sent itself (i.e. of the bot.send_* family of methods) or channel posts, if the bot is an admin in that channel. However, this behaviour is undocumented and might be changed by Telegram.

Changed in version 21.4: Now also passes business_connection_id.

Returns:

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

Returns:

Message | bool

async stop_poll(reply_markup=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.stop_poll(
    chat_id=message.chat_id,
    message_id=message.message_id,
    business_connection_id=message.business_connection_id,
    *args, **kwargs
)

For the documentation of the arguments, please see telegram.Bot.stop_poll().

Changed in version 21.4: Now also passes business_connection_id.

Returns:

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

Returns:

Poll

story: Story | None
successful_payment: SuccessfulPayment | None
suggested_post_approval_failed: SuggestedPostApprovalFailed | None
suggested_post_approved: SuggestedPostApproved | None
suggested_post_declined: SuggestedPostDeclined | None
suggested_post_info: SuggestedPostInfo | None
suggested_post_paid: SuggestedPostPaid | None
suggested_post_refunded: SuggestedPostRefunded | None
supergroup_chat_created: bool | None
text: str | None
property text_html: str

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

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

Warning

|text_html|

Changed in version 13.10: Spoiler entities are now formatted as HTML.

Changed in version 20.3: Custom emoji entities are now supported.

Changed in version 20.8: Blockquote entities are now supported.

Returns:

Message text with entities formatted as HTML.

Return type:

str

property text_html_urled: str

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

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

Warning

|text_html|

Changed in version 13.10: Spoiler entities are now formatted as HTML.

Changed in version 20.3: Custom emoji entities are now supported.

Changed in version 20.8: Blockquote entities are now supported.

Returns:

Message text with entities formatted as HTML.

Return type:

str

property text_markdown: str

Creates an Markdown-formatted string from the markup entities found in the message using telegram.constants.ParseMode.MARKDOWN.

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

Warning

|text_markdown|

Note

telegram.constants.ParseMode.MARKDOWN is a legacy mode, retained by Telegram for backward compatibility. You should use text_markdown_v2() instead.

Changed in version 20.5: Since custom emoji entities are not supported by MARKDOWN, this method now raises a ValueError when encountering a custom emoji.

Changed in version 20.8: Since block quotation entities are not supported by MARKDOWN, this method now raises a ValueError when encountering a block quotation.

Returns:

Message text with entities formatted as Markdown.

Return type:

str

Raises:

ValueError – If the message contains underline, strikethrough, spoiler, blockquote or nested entities.

property text_markdown_urled: str

Creates an Markdown-formatted string from the markup entities found in the message using telegram.constants.ParseMode.MARKDOWN.

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

Warning

|text_markdown|

Note

telegram.constants.ParseMode.MARKDOWN is a legacy mode, retained by Telegram for backward compatibility. You should use text_markdown_v2_urled() instead.

Changed in version 20.5: Since custom emoji entities are not supported by MARKDOWN, this method now raises a ValueError when encountering a custom emoji.

Changed in version 20.8: Since block quotation entities are not supported by MARKDOWN, this method now raises a ValueError when encountering a block quotation.

Returns:

Message text with entities formatted as Markdown.

Return type:

str

Raises:

ValueError – If the message contains underline, strikethrough, spoiler, blockquote or nested entities.

property text_markdown_v2: str

Creates an Markdown-formatted string from the markup entities found in the message using telegram.constants.ParseMode.MARKDOWN_V2.

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

Warning

|text_markdown|

Changed in version 13.10: Spoiler entities are now formatted as Markdown V2.

Changed in version 20.3: Custom emoji entities are now supported.

Changed in version 20.8: Blockquote entities are now supported.

Returns:

Message text with entities formatted as Markdown.

Return type:

str

property text_markdown_v2_urled: str

Creates an Markdown-formatted string from the markup entities found in the message using telegram.constants.ParseMode.MARKDOWN_V2.

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

Warning

|text_markdown|

Changed in version 13.10: Spoiler entities are now formatted as Markdown V2.

Changed in version 20.3: Custom emoji entities are now supported.

Changed in version 20.8: Blockquote entities are now supported.

Returns:

Message text with entities formatted as Markdown.

Return type:

str

unique_gift: UniqueGiftInfo | None
async unpin(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.unpin_chat_message(
    chat_id=message.chat_id,
    message_id=message.message_id,
    business_connection_id=message.business_connection_id,
    *args, **kwargs
)

For the documentation of the arguments, please see telegram.Bot.unpin_chat_message().

Changed in version 21.5: Now also passes business_connection_id to telegram.Bot.pin_chat_message().

Returns:

On success, True is returned.

Returns:

bool

async unpin_all_forum_topic_messages(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Shortcut for:

await bot.unpin_all_forum_topic_messages(
   chat_id=message.chat_id, message_thread_id=message.message_thread_id, *args,
   **kwargs
)

For the documentation of the arguments, please see telegram.Bot.unpin_all_forum_topic_messages().

Added in version 20.0.

Returns:

On success, True is returned.

Returns:

bool

users_shared: UsersShared | None
venue: Venue | None
via_bot: User | None
video: Video | None
video_chat_ended: VideoChatEnded | None
video_chat_participants_invited: VideoChatParticipantsInvited | None
video_chat_scheduled: VideoChatScheduled | None
video_chat_started: VideoChatStarted | None
video_note: VideoNote | None
voice: Voice | None
web_app_data: WebAppData | None
write_access_allowed: WriteAccessAllowed | None
class spotted.utils.info_util.MessageId(message_id, *, api_kwargs=None)[source]

Bases: TelegramObject

This object represents a unique message identifier.

Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their message_id is equal.

Parameters:

message_id (int) – Unique message identifier. In specific instances (e.g., message containing a video sent to a big chat), the server might automatically schedule a message instead of sending it immediately. In such cases, this field will be 0 and the relevant message will be unusable until it is actually sent.

message_id

Unique message identifier. In specific instances (e.g., message containing a video sent to a big chat), the server might automatically schedule a message instead of sending it immediately. In such cases, this field will be 0 and the relevant message will be unusable until it is actually sent.

Type:

int

message_id: int
class spotted.utils.info_util.MessageOriginChannel(date, chat, message_id, author_signature=None, *, api_kwargs=None)[source]

Bases: MessageOrigin

The message was originally sent to a channel chat.

Added in version 20.8.

Parameters:
  • date (datetime) – Date the message was sent originally. |datetime_localization|

  • chat (Chat) – Channel chat to which the message was originally sent.

  • message_id (int) – Unique message identifier inside the chat.

  • author_signature (str | None, default: None) – Signature of the original post author.

type

Type of the message origin. Always ~telegram.MessageOrigin.CHANNEL.

Type:

str

date

Date the message was sent originally. |datetime_localization|

Type:

datetime.datetime

chat

Channel chat to which the message was originally sent.

Type:

telegram.Chat

message_id

Unique message identifier inside the chat.

Type:

int

author_signature

Optional. Signature of the original post author.

Type:

str

author_signature: str | None
chat: Chat
message_id: int
class spotted.utils.info_util.MessageOriginChat(date, sender_chat, author_signature=None, *, api_kwargs=None)[source]

Bases: MessageOrigin

The message was originally sent on behalf of a chat to a group chat.

Added in version 20.8.

Parameters:
  • date (datetime) – Date the message was sent originally. |datetime_localization|

  • sender_chat (Chat) – Chat that sent the message originally.

  • author_signature (str | None, default: None) – For messages originally sent by an anonymous chat administrator, original message author signature

type

Type of the message origin. Always ~telegram.MessageOrigin.CHAT.

Type:

str

date

Date the message was sent originally. |datetime_localization|

Type:

datetime.datetime

sender_chat

Chat that sent the message originally.

Type:

telegram.Chat

author_signature

Optional. For messages originally sent by an anonymous chat administrator, original message author signature

Type:

str

author_signature: str | None
sender_chat: Chat
class spotted.utils.info_util.MessageOriginUser(date, sender_user, *, api_kwargs=None)[source]

Bases: MessageOrigin

The message was originally sent by a known user.

Added in version 20.8.

Parameters:
type

Type of the message origin. Always ~telegram.MessageOrigin.USER.

Type:

str

date

Date the message was sent originally. |datetime_localization|

Type:

datetime.datetime

sender_user

User that sent the message originally.

Type:

telegram.User

sender_user: User
class spotted.utils.info_util.PendingPost(user_id, u_message_id, g_message_id, admin_group_id, date, credit_username=None)[source]

Bases: object

Class that represents a pending post

Parameters:
  • user_id (int) – id of the user that sent the post

  • u_message_id (int) – id of the original message of the post

  • g_message_id (int) – id of the post in the group

  • admin_group_id (int) – id of the admin group

  • credit_username (str | None, default: None) – username of the user that sent the post if it’s a credit post

  • date (datetime) – when the post was sent

admin_group_id: int
classmethod create(user_message, g_message_id, admin_group_id, credit_username=None)[source]

Creates a new post and inserts it in the table of pending posts

Parameters:
  • user_message (Message) – message sent by the user that contains the post

  • g_message_id (int) – id of the post in the group

  • admin_group_id (int) – id of the admin group

  • credit_username (str | None, default: None) – username of the user that sent the post if it’s a credit post

Returns:

PendingPost – instance of the class

credit_username: str | None = None
date: datetime
delete_post()[source]

Removes all entries on a post that is no longer pending

classmethod from_group(g_message_id, admin_group_id)[source]

Retrieves a pending post from the info related to the admin group

Parameters:
  • g_message_id (int) – id of the post in the group

  • admin_group_id (int) – id of the admin group

Returns:

PendingPost | None – instance of the class

classmethod from_user(user_id)[source]

Retrieves a pending post from the user_id

Parameters:

user_id (int) – id of the author of the post

Returns:

PendingPost | None – instance of the class

g_message_id: int
static get_all(admin_group_id, before=None)[source]

Gets the list of pending posts in the specified admin group. If before is specified, returns only the one sent before that timestamp

Parameters:
  • admin_group_id (int) – id of the admin group

  • before (datetime | None, default: None) – timestamp before which messages will be considered

Returns:

list[PendingPost] – list of ids of pending posts

get_credit_username()[source]

Gets the username of the user that credited the post

Returns:

str | None – username of the user that credited the post, or None if the post is not credited

get_list_admin_votes(vote=None)[source]

Gets the list of admins that approved or rejected the post

Parameters:

vote (bool | None, default: None) – whether you look for the approve or reject votes, or None if you want all the votes

Returns:

list[int] | list[tuple[int, bool]] – list of admins that approved or rejected a pending post

get_votes(vote)[source]

Gets all the votes of a specific kind (approve or reject)

Parameters:

vote (bool) – whether you look for the approve or reject votes

Returns:

int – number of votes

save_post()[source]

Saves the pending_post in the database

Return type:

PendingPost

set_admin_vote(admin_id, approval)[source]

Adds the vote of the admin on a specific post, or update the existing vote, if needed

Parameters:
  • admin_id (int) – id of the admin that voted

  • approval (bool) – whether the vote is approval or reject

Returns:

int – number of similar votes (all the approve or the reject), or -1 if the vote wasn’t updated

u_message_id: int
user_id: int
class spotted.utils.info_util.PublishedPost(channel_id, c_message_id, date)[source]

Bases: object

Class that represents a published post

Parameters:
  • channel_id (int) – id of the channel

  • c_message_id (int) – id of the post in the channel

c_message_id: int
channel_id: int
classmethod create(channel_id, c_message_id)[source]

Inserts a new post in the table of published posts

Parameters:
  • channel_id (int) – id of the channel

  • c_message_id (int) – id of the post in the channel

Returns:

PublishedPost – instance of the class

date: datetime
classmethod from_channel(channel_id, c_message_id)[source]

Retrieves a published post from the info related to the channel

Parameters:
  • channel_id (int) – id of the channel

  • c_message_id (int) – id of the post in the channel

Returns:

PublishedPost | None – instance of the class

save_post()[source]

Saves the published_post in the database

Return type:

PublishedPost

class spotted.utils.info_util.Update(update_id, message=None, edited_message=None, channel_post=None, edited_channel_post=None, inline_query=None, chosen_inline_result=None, callback_query=None, shipping_query=None, pre_checkout_query=None, poll=None, poll_answer=None, my_chat_member=None, chat_member=None, chat_join_request=None, chat_boost=None, removed_chat_boost=None, message_reaction=None, message_reaction_count=None, business_connection=None, business_message=None, edited_business_message=None, deleted_business_messages=None, purchased_paid_media=None, *, api_kwargs=None)[source]

Bases: TelegramObject

This object represents an incoming update.

Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their update_id is equal.

Note

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

See also

Your First Bot <Extensions---Your-first-Bot>

Parameters:
  • update_id (int) – The update’s unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order. If there are no new updates for at least a week, then identifier of the next update will be chosen randomly instead of sequentially.

  • message (Message | None, default: None) – New incoming message of any kind - text, photo, sticker, etc.

  • edited_message (Message | None, default: None) – New version of a message that is known to the bot and was edited. This update may at times be triggered by changes to message fields that are either unavailable or not actively used by your bot.

  • channel_post (Message | None, default: None) – New incoming channel post of any kind - text, photo, sticker, etc.

  • edited_channel_post (Message | None, default: None) – New version of a channel post that is known to the bot and was edited. This update may at times be triggered by changes to message fields that are either unavailable or not actively used by your bot.

  • inline_query (InlineQuery | None, default: None) – New incoming inline query.

  • chosen_inline_result (ChosenInlineResult | None, default: None) – The result of an inline query that was chosen by a user and sent to their chat partner.

  • callback_query (CallbackQuery | None, default: None) – New incoming callback query.

  • shipping_query (ShippingQuery | None, default: None) – New incoming shipping query. Only for invoices with flexible price.

  • pre_checkout_query (PreCheckoutQuery | None, default: None) – New incoming pre-checkout query. Contains full information about checkout.

  • poll (Poll | None, default: None) – New poll state. Bots receive only updates about manually stopped polls and polls, which are sent by the bot.

  • poll_answer (PollAnswer | None, default: None) – A user changed their answer in a non-anonymous poll. Bots receive new votes only in polls that were sent by the bot itself.

  • my_chat_member (ChatMemberUpdated | None, default: None) –

    The bot’s chat member status was updated in a chat. For private chats, this update is received only when the bot is blocked or unblocked by the user.

    Added in version 13.4.

  • chat_member (ChatMemberUpdated | None, default: None) –

    A chat member’s status was updated in a chat. The bot must be an administrator in the chat and must explicitly specify CHAT_MEMBER in the list of telegram.ext.Application.run_polling.allowed_updates to receive these updates (see telegram.Bot.get_updates(), telegram.Bot.set_webhook(), telegram.ext.Application.run_polling() and telegram.ext.Application.run_webhook()).

    Added in version 13.4.

  • chat_join_request (ChatJoinRequest | None, default: None) –

    A request to join the chat has been sent. The bot must have the telegram.ChatPermissions.can_invite_users administrator right in the chat to receive these updates.

    Added in version 13.8.

  • chat_boost (ChatBoostUpdated | None, default: None) –

    A chat boost was added or changed. The bot must be an administrator in the chat to receive these updates.

    Added in version 20.8.

  • removed_chat_boost (ChatBoostRemoved | None, default: None) –

    A boost was removed from a chat. The bot must be an administrator in the chat to receive these updates.

    Added in version 20.8.

  • message_reaction (MessageReactionUpdated | None, default: None) –

    A reaction to a message was changed by a user. The bot must be an administrator in the chat and must explicitly specify MESSAGE_REACTION in the list of telegram.ext.Application.run_polling.allowed_updates to receive these updates (see telegram.Bot.get_updates(), telegram.Bot.set_webhook(), telegram.ext.Application.run_polling() and telegram.ext.Application.run_webhook()). The update isn’t received for reactions set by bots.

    Added in version 20.8.

  • message_reaction_count (MessageReactionCountUpdated | None, default: None) –

    Reactions to a message with anonymous reactions were changed. The bot must be an administrator in the chat and must explicitly specify MESSAGE_REACTION_COUNT in the list of telegram.ext.Application.run_polling.allowed_updates to receive these updates (see telegram.Bot.get_updates(), telegram.Bot.set_webhook(), telegram.ext.Application.run_polling() and telegram.ext.Application.run_webhook()). The updates are grouped and can be sent with delay up to a few minutes.

    Added in version 20.8.

  • business_connection (BusinessConnection | None, default: None) –

    The bot was connected to or disconnected from a business account, or a user edited an existing connection with the bot.

    Added in version 21.1.

  • business_message (Message | None, default: None) –

    New message from a connected business account.

    Added in version 21.1.

  • edited_business_message (Message | None, default: None) –

    New version of a message from a connected business account.

    Added in version 21.1.

  • deleted_business_messages (BusinessMessagesDeleted | None, default: None) –

    Messages were deleted from a connected business account.

    Added in version 21.1.

  • purchased_paid_media (PaidMediaPurchased | None, default: None) –

    A user purchased paid media with a non-empty payload sent by the bot in a non-channel chat.

    Added in version 21.6.

update_id

The update’s unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you’re using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order. If there are no new updates for at least a week, then identifier of the next update will be chosen randomly instead of sequentially.

Type:

int

message

Optional. New incoming message of any kind - text, photo, sticker, etc.

Type:

telegram.Message

edited_message

Optional. New version of a message that is known to the bot and was edited. This update may at times be triggered by changes to message fields that are either unavailable or not actively used by your bot.

Type:

telegram.Message

channel_post

Optional. New incoming channel post of any kind - text, photo, sticker, etc.

Type:

telegram.Message

edited_channel_post

Optional. New version of a channel post that is known to the bot and was edited. This update may at times be triggered by changes to message fields that are either unavailable or not actively used by your bot.

Type:

telegram.Message

inline_query

Optional. New incoming inline query.

Type:

telegram.InlineQuery

chosen_inline_result

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

Type:

telegram.ChosenInlineResult

callback_query

Optional. New incoming callback query.

Examples

Arbitrary Callback Data Bot

Type:

telegram.CallbackQuery

shipping_query

Optional. New incoming shipping query. Only for invoices with flexible price.

Type:

telegram.ShippingQuery

pre_checkout_query

Optional. New incoming pre-checkout query. Contains full information about checkout.

Type:

telegram.PreCheckoutQuery

poll

Optional. New poll state. Bots receive only updates about manually stopped polls and polls, which are sent by the bot.

Type:

telegram.Poll

poll_answer

Optional. A user changed their answer in a non-anonymous poll. Bots receive new votes only in polls that were sent by the bot itself.

Type:

telegram.PollAnswer

my_chat_member

Optional. The bot’s chat member status was updated in a chat. For private chats, this update is received only when the bot is blocked or unblocked by the user.

Added in version 13.4.

Type:

telegram.ChatMemberUpdated

chat_member

Optional. A chat member’s status was updated in a chat. The bot must be an administrator in the chat and must explicitly specify CHAT_MEMBER in the list of telegram.ext.Application.run_polling.allowed_updates to receive these updates (see telegram.Bot.get_updates(), telegram.Bot.set_webhook(), telegram.ext.Application.run_polling() and telegram.ext.Application.run_webhook()).

Added in version 13.4.

Type:

telegram.ChatMemberUpdated

chat_join_request

Optional. A request to join the chat has been sent. The bot must have the telegram.ChatPermissions.can_invite_users administrator right in the chat to receive these updates.

Added in version 13.8.

Type:

telegram.ChatJoinRequest

chat_boost

Optional. A chat boost was added or changed. The bot must be an administrator in the chat to receive these updates.

Added in version 20.8.

Type:

telegram.ChatBoostUpdated

removed_chat_boost

Optional. A boost was removed from a chat. The bot must be an administrator in the chat to receive these updates.

Added in version 20.8.

Type:

telegram.ChatBoostRemoved

message_reaction

Optional. A reaction to a message was changed by a user. The bot must be an administrator in the chat and must explicitly specify MESSAGE_REACTION in the list of telegram.ext.Application.run_polling.allowed_updates to receive these updates (see telegram.Bot.get_updates(), telegram.Bot.set_webhook(), telegram.ext.Application.run_polling() and telegram.ext.Application.run_webhook()). The update isn’t received for reactions set by bots.

Added in version 20.8.

Type:

telegram.MessageReactionUpdated

message_reaction_count

Optional. Reactions to a message with anonymous reactions were changed. The bot must be an administrator in the chat and must explicitly specify MESSAGE_REACTION_COUNT in the list of telegram.ext.Application.run_polling.allowed_updates to receive these updates (see telegram.Bot.get_updates(), telegram.Bot.set_webhook(), telegram.ext.Application.run_polling() and telegram.ext.Application.run_webhook()). The updates are grouped and can be sent with delay up to a few minutes.

Added in version 20.8.

Type:

telegram.MessageReactionCountUpdated

business_connection

Optional. The bot was connected to or disconnected from a business account, or a user edited an existing connection with the bot.

Added in version 21.1.

Type:

telegram.BusinessConnection

business_message

Optional. New message from a connected business account.

Added in version 21.1.

Type:

telegram.Message

edited_business_message

Optional. New version of a message from a connected business account.

Added in version 21.1.

Type:

telegram.Message

deleted_business_messages

Optional. Messages were deleted from a connected business account.

Added in version 21.1.

Type:

telegram.BusinessMessagesDeleted

purchased_paid_media

Optional. A user purchased paid media with a non-empty payload sent by the bot in a non-channel chat.

Added in version 21.6.

Type:

telegram.PaidMediaPurchased

ALL_TYPES: Final[list[str]] = [<UpdateType.MESSAGE>, <UpdateType.EDITED_MESSAGE>, <UpdateType.CHANNEL_POST>, <UpdateType.EDITED_CHANNEL_POST>, <UpdateType.INLINE_QUERY>, <UpdateType.CHOSEN_INLINE_RESULT>, <UpdateType.CALLBACK_QUERY>, <UpdateType.SHIPPING_QUERY>, <UpdateType.PRE_CHECKOUT_QUERY>, <UpdateType.POLL>, <UpdateType.POLL_ANSWER>, <UpdateType.MY_CHAT_MEMBER>, <UpdateType.CHAT_MEMBER>, <UpdateType.CHAT_JOIN_REQUEST>, <UpdateType.CHAT_BOOST>, <UpdateType.REMOVED_CHAT_BOOST>, <UpdateType.MESSAGE_REACTION>, <UpdateType.MESSAGE_REACTION_COUNT>, <UpdateType.BUSINESS_CONNECTION>, <UpdateType.BUSINESS_MESSAGE>, <UpdateType.EDITED_BUSINESS_MESSAGE>, <UpdateType.DELETED_BUSINESS_MESSAGES>, <UpdateType.PURCHASED_PAID_MEDIA>]

A list of all available update types.

Added in version 13.5.

Type:

list[str]

BUSINESS_CONNECTION: Final[str] = 'business_connection'

telegram.constants.UpdateType.BUSINESS_CONNECTION

Added in version 21.1.

BUSINESS_MESSAGE: Final[str] = 'business_message'

telegram.constants.UpdateType.BUSINESS_MESSAGE

Added in version 21.1.

CALLBACK_QUERY: Final[str] = 'callback_query'

telegram.constants.UpdateType.CALLBACK_QUERY

Added in version 13.5.

CHANNEL_POST: Final[str] = 'channel_post'

telegram.constants.UpdateType.CHANNEL_POST

Added in version 13.5.

CHAT_BOOST: Final[str] = 'chat_boost'

telegram.constants.UpdateType.CHAT_BOOST

Added in version 20.8.

CHAT_JOIN_REQUEST: Final[str] = 'chat_join_request'

telegram.constants.UpdateType.CHAT_JOIN_REQUEST

Added in version 13.8.

CHAT_MEMBER: Final[str] = 'chat_member'

telegram.constants.UpdateType.CHAT_MEMBER

Added in version 13.5.

CHOSEN_INLINE_RESULT: Final[str] = 'chosen_inline_result'

telegram.constants.UpdateType.CHOSEN_INLINE_RESULT

Added in version 13.5.

DELETED_BUSINESS_MESSAGES: Final[str] = 'deleted_business_messages'

telegram.constants.UpdateType.DELETED_BUSINESS_MESSAGES

Added in version 21.1.

EDITED_BUSINESS_MESSAGE: Final[str] = 'edited_business_message'

telegram.constants.UpdateType.EDITED_BUSINESS_MESSAGE

Added in version 21.1.

EDITED_CHANNEL_POST: Final[str] = 'edited_channel_post'

telegram.constants.UpdateType.EDITED_CHANNEL_POST

Added in version 13.5.

EDITED_MESSAGE: Final[str] = 'edited_message'

telegram.constants.UpdateType.EDITED_MESSAGE

Added in version 13.5.

INLINE_QUERY: Final[str] = 'inline_query'

telegram.constants.UpdateType.INLINE_QUERY

Added in version 13.5.

MESSAGE: Final[str] = 'message'

telegram.constants.UpdateType.MESSAGE

Added in version 13.5.

MESSAGE_REACTION: Final[str] = 'message_reaction'

telegram.constants.UpdateType.MESSAGE_REACTION

Added in version 20.8.

MESSAGE_REACTION_COUNT: Final[str] = 'message_reaction_count'

telegram.constants.UpdateType.MESSAGE_REACTION_COUNT

Added in version 20.8.

MY_CHAT_MEMBER: Final[str] = 'my_chat_member'

telegram.constants.UpdateType.MY_CHAT_MEMBER

Added in version 13.5.

POLL: Final[str] = 'poll'

telegram.constants.UpdateType.POLL

Added in version 13.5.

POLL_ANSWER: Final[str] = 'poll_answer'

telegram.constants.UpdateType.POLL_ANSWER

Added in version 13.5.

PRE_CHECKOUT_QUERY: Final[str] = 'pre_checkout_query'

telegram.constants.UpdateType.PRE_CHECKOUT_QUERY

Added in version 13.5.

PURCHASED_PAID_MEDIA: Final[str] = 'purchased_paid_media'

telegram.constants.UpdateType.PURCHASED_PAID_MEDIA

Added in version 21.6.

REMOVED_CHAT_BOOST: Final[str] = 'removed_chat_boost'

telegram.constants.UpdateType.REMOVED_CHAT_BOOST

Added in version 20.8.

SHIPPING_QUERY: Final[str] = 'shipping_query'

telegram.constants.UpdateType.SHIPPING_QUERY

Added in version 13.5.

business_connection: BusinessConnection | None
business_message: Message | None
callback_query: CallbackQuery | None
channel_post: Message | None
chat_boost: ChatBoostUpdated | None
chat_join_request: ChatJoinRequest | None
chat_member: ChatMemberUpdated | None
chosen_inline_result: ChosenInlineResult | None
classmethod de_json(data, bot=None)[source]

See telegram.TelegramObject.de_json().

Return type:

Update

deleted_business_messages: BusinessMessagesDeleted | None
edited_business_message: Message | None
edited_channel_post: Message | None
edited_message: Message | None
property effective_chat: Chat | None

The chat that this update was sent in, no matter what kind of update this is. If no chat is associated with this update, this gives None. This is the case, if inline_query, chosen_inline_result, callback_query from inline messages, shipping_query, pre_checkout_query, poll, poll_answer, business_connection, or purchased_paid_media is present.

Changed in version 21.1: This property now also considers business_message, edited_business_message, and deleted_business_messages.

Example

If message is present, this will give telegram.Message.chat.

Type:

telegram.Chat

property effective_message: Message | None
The message included in this update, no matter what kind of

update this is. More precisely, this will be the message contained in message, edited_message, channel_post, edited_channel_post or callback_query (i.e. telegram.CallbackQuery.message) or None, if none of those are present.

Changed in version 21.1: This property now also considers business_message, and edited_business_message.

Tip

This property will only ever return objects of type telegram.Message or None, never telegram.MaybeInaccessibleMessage or telegram.InaccessibleMessage. Currently, this is only relevant for callback_query, as telegram.CallbackQuery.message is the only attribute considered by this property that can be an object of these types.

Type:

telegram.Message

property effective_sender: User | Chat | None

The user or chat that sent this update, no matter what kind of update this is.

Note

If no user whatsoever is associated with this update, this gives None. This is the case if any of

is present.

Example

Added in version 21.1.

Type:

telegram.User or telegram.Chat

property effective_user: User | None

The user that sent this update, no matter what kind of update this is. If no user is associated with this update, this gives None. This is the case if any of

is present.

Changed in version 21.1: This property now also considers business_connection, business_message and edited_business_message.

Changed in version 21.6: This property now also considers purchased_paid_media.

Example

Type:

telegram.User

inline_query: InlineQuery | None
message: Message | None
message_reaction: MessageReactionUpdated | None
message_reaction_count: MessageReactionCountUpdated | None
my_chat_member: ChatMemberUpdated | None
poll: Poll | None
poll_answer: PollAnswer | None
pre_checkout_query: PreCheckoutQuery | None
purchased_paid_media: PaidMediaPurchased | None
removed_chat_boost: ChatBoostRemoved | None
shipping_query: ShippingQuery | None
update_id: int
class spotted.utils.info_util.User(user_id, private_message_id=None, ban_date=None, mute_date=None, mute_expire_date=None, follow_date=None)[source]

Bases: object

Class that represents a user

Parameters:
  • user_id (int) – id of the user

  • private_message_id (int | None, default: None) – id of the private message sent by the user to the bot. Only used for following

  • ban_date (datetime | None, default: None) – datetime of when the user was banned. Only used for banned users

  • follow_date (datetime | None, default: None) – datetime of when the user started following a post. Only used for following users

ban()[source]

Adds the user to the banned list

ban_date: datetime | None = None
classmethod banned_users()[source]

Returns a list of all the banned users

Return type:

list[User]

become_anonym()[source]

Removes the user from the credited list, if he was present

Returns:

bool – whether the user was already anonym

become_credited()[source]

Adds the user to the credited list, if he wasn’t already credited

Returns:

bool – whether the user was already credited

classmethod credited_users()[source]

Returns a list of all the credited users

Return type:

list[User]

follow_date: datetime | None = None
classmethod following_users(message_id)[source]

Returns a list of all the users following the post with the associated private message id used by the bot to send updates about the post by replying to it

Parameters:

message_id (int) – id of the post the users are following

Returns:

list[User] – list of users with private_message_id set to the id of the private message in the user’s conversation with the bot

get_follow_private_message_id(message_id)[source]

Verifies if the user is following a post

Parameters:

message_id (int) – id of the post

Returns:

int | None – whether the user is following the post or not

get_n_warns()[source]

Returns the count of consecutive warns of the user

Return type:

int

async get_user_sign(bot)[source]

Generates a sign for the user. It will be a random name for an anonym user

Parameters:

bot (Bot) – telegram bot

Returns:

str – the sign of the user

property is_banned: bool

If the user is banned or not

property is_credited: bool

If the user is in the credited list

is_following(message_id)[source]

Verifies if the user is following a post

Parameters:

message_id (int) – id of the post

Returns:

bool – whether the user is following the post or not

property is_muted: bool

If the user is muted or not

property is_pending: bool

If the user has a post already pending or not

property is_warn_bannable: bool

If the user is bannable due to warns

async mute(bot, days)[source]

Mute a user restricting its actions inside the community group

Parameters:
  • bot (Bot | None) – the telegram bot

  • days (int) – The number of days the user should be muted for.

mute_date: datetime | None = None
mute_expire_date: datetime | None = None
classmethod muted_users()[source]

Returns a list of all the muted users

Return type:

list[User]

private_message_id: int | None = None
sban()[source]

Removes the user from the banned list

Returns:

bool – whether the user was present in the banned list before the sban or not

set_follow(message_id, private_message_id)[source]

Sets the follow status of the user. If the private_message_id is None, the user is not following the post anymore, and the record is deleted from the database. Otherwise, the user is following the post and a new record is created.

Parameters:
  • message_id (int) – id of the post

  • private_message_id (int | None) – id of the private message. If None, the record is deleted

async unmute(bot)[source]

Unmute a user taking back all restrictions

Parameters:

bot (Bot | None) – the telegram bot

Returns:

bool – whether the user was muted before the unmute or not

user_id: int
warn()[source]

Increase the number of warns of a user If the number of warns is greater than the maximum allowed, the user is banned

Parameters:

bot – the telegram bot

spotted.utils.info_util.cast(typ, val)[source]

Cast a value to a type.

This returns the value unchanged. To the type checker this signals that the return value has the designated type, but at runtime we intentionally don’t check anything (we want this to be as fast as possible).

spotted.utils.info_util.get_approve_kb(pending_post=None, approve=-1, reject=-1, credited_username=None)[source]

Generates the InlineKeyboard for the pending post. If the pending post is None, the keyboard will be generated with 0 votes. Otherwise, the keyboard will be generated with the correct number of votes. To avoid unnecessary queries, the number of votes can be passed as an argument and will be assumed to be correct.

Parameters:
  • pending_post (PendingPost | None, default: None) – existing pending post to which the keyboard is attached

  • approve (int, default: -1) – number of approve votes known in advance

  • reject (int, default: -1) – number of reject votes known in advance

  • credited_username (str | None, default: None) – username of the user who credited the post if it was credited

Returns:

InlineKeyboardMarkup – new inline keyboard

async spotted.utils.info_util.get_post_outcome_kb(bot, votes, reason=None)[source]

Generates the InlineKeyboard for the outcome of a post

Parameters:
  • bot (Bot) – bot instance

  • votes (list[tuple[int, bool]]) – list of votes

  • reason (str | None, default: None) – reason for the rejection, currently used on autoreplies

Returns:

InlineKeyboardMarkup – new inline keyboard

spotted.utils.info_util.get_published_post_kb()[source]

Generates the InlineKeyboard for the published post adding the report button if needed

Returns:

InlineKeyboardMarkup | None – new inline keyboard

spotted.utils.keyboard_util module

Creates the inlinekeyboard sent by the bot in its messages. Callback_data format: <callback_family>_<callback_name>,[arg]

class spotted.utils.keyboard_util.Bot(token, base_url='https://api.telegram.org/bot', base_file_url='https://api.telegram.org/file/bot', request=None, get_updates_request=None, private_key=None, private_key_password=None, local_mode=False)[source]

Bases: TelegramObject, AbstractAsyncContextManager[Bot]

This object represents a Telegram Bot.

Instances of this class can be used as asyncio context managers, where

async with bot:
    # code

is roughly equivalent to

try:
    await bot.initialize()
    # code
finally:
    await bot.shutdown()

See also

__aenter__() and __aexit__().

Note

  • Most bot methods have the argument api_kwargs which allows passing arbitrary keywords to the Telegram API. This can be used to access new features of the API before they are incorporated into PTB. The limitations to this argument are the same as the ones described in do_api_request().

  • Bots should not be serialized since if you for e.g. change the bots token, then your serialized instance will not reflect that change. Trying to pickle a bot instance will raise pickle.PicklingError. Trying to deepcopy a bot instance will raise TypeError.

Examples

Raw API Bot

See also

Your First Bot <Extensions---Your-first-Bot>, Builder Pattern <Builder-Pattern>

Added in version 13.2: Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their bot is equal.

Changed in version 20.0:

  • Removed the deprecated methods kick_chat_member, kickChatMember, get_chat_members_count and getChatMembersCount.

  • Removed the deprecated property commands.

  • Removed the deprecated defaults parameter. If you want to use telegram.ext.Defaults, please use the subclass telegram.ext.ExtBot instead.

  • Attempting to pickle a bot instance will now raise pickle.PicklingError.

  • Attempting to deepcopy a bot instance will now raise TypeError.

  • The following are now keyword-only arguments in Bot methods: location, filename, venue, contact, {read, write, connect, pool}_timeout, api_kwargs. Use a named argument for those, and notice that some positional arguments changed position as a result.

  • For uploading files, file paths are now always accepted. If local_mode is False, the file contents will be read in binary mode and uploaded. Otherwise, the file path will be passed in the file URI scheme.

Changed in version 20.5: Removed deprecated methods set_sticker_set_thumb and setStickerSetThumb. Use set_sticker_set_thumbnail() and setStickerSetThumbnail() instead.

Parameters:
  • token (str) – Bot’s unique authentication token.

  • base_url (str | Callable[[str], str], default: 'https://api.telegram.org/bot') –

    Telegram Bot API service URL. If the string contains {token}, it will be replaced with the bot’s token. If a callable is passed, it will be called with the bot’s token as the only argument and must return the base URL. Otherwise, the token will be appended to the string. Defaults to "https://api.telegram.org/bot".

    Tip

    Customizing the base URL can be used to run a bot against Local Bot API Server <Local-Bot-API-Server> or using Telegrams test environment.

    Example:

    "https://api.telegram.org/bot{token}/test"

    Changed in version 21.11: Supports callable input and string formatting.

  • base_file_url (str | Callable[[str], str], default: 'https://api.telegram.org/file/bot') –

    Telegram Bot API file URL. If the string contains {token}, it will be replaced with the bot’s token. If a callable is passed, it will be called with the bot’s token as the only argument and must return the base URL. Otherwise, the token will be appended to the string. Defaults to "https://api.telegram.org/bot".

    Tip

    Customizing the base URL can be used to run a bot against Local Bot API Server <Local-Bot-API-Server> or using Telegrams test environment.

    Example:

    "https://api.telegram.org/file/bot{token}/test"

    Changed in version 21.11: Supports callable input and string formatting.

  • request (BaseRequest | None, default: None) – Pre initialized telegram.request.BaseRequest instances. Will be used for all bot methods except for get_updates(). If not passed, an instance of telegram.request.HTTPXRequest will be used.

  • get_updates_request (BaseRequest | None, default: None) – Pre initialized telegram.request.BaseRequest instances. Will be used exclusively for get_updates(). If not passed, an instance of telegram.request.HTTPXRequest will be used.

  • private_key (bytes | None, default: None) – Private key for decryption of telegram passport data.

  • private_key_password (bytes | None, default: None) – Password for above private key.

  • local_mode (bool, default: False) –

    Set to True, if the base_url is the URI of a Local Bot API Server that runs with the --local flag. Currently, the only effect of this is that files are uploaded using their local path in the file URI scheme. Defaults to False.

    Added in version 20.0..

Note

For complete information on Bot methods and their usage, see the python-telegram-bot Bot API documentation.

async addStickerToSet(user_id, name, sticker, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for add_sticker_to_set()

Return type:

bool

async add_sticker_to_set(user_id, name, sticker, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 telegram.constants.StickerSetLimit.MAX_EMOJI_STICKERS stickers. Other sticker sets can have up to telegram.constants.StickerSetLimit.MAX_STATIC_STICKERS stickers.

Changed in version 20.2: Since Bot API 6.6, the parameter sticker replace the parameters png_sticker, tgs_sticker, webm_sticker, emojis, and mask_position.

Changed in version 20.5: Removed deprecated parameters png_sticker, tgs_sticker, webm_sticker, emojis, and mask_position.

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

  • name (str) – Sticker set name.

  • sticker (InputSticker) –

    An object with information about the added sticker. If exactly the same sticker had already been added to the set, then the set isn’t changed.

    Added in version 20.2.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async answerCallbackQuery(callback_query_id, text=None, show_alert=None, url=None, cache_time=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for answer_callback_query()

Return type:

bool

async answerInlineQuery(inline_query_id, results, cache_time=None, is_personal=None, next_offset=None, button=None, *, current_offset=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for answer_inline_query()

Return type:

bool

async answerPreCheckoutQuery(pre_checkout_query_id, ok, error_message=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for answer_pre_checkout_query()

Return type:

bool

async answerShippingQuery(shipping_query_id, ok, shipping_options=None, error_message=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for answer_shipping_query()

Return type:

bool

async answerWebAppQuery(web_app_query_id, result, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for answer_web_app_query()

Return type:

SentWebAppMessage

async answer_callback_query(callback_query_id, text=None, show_alert=None, url=None, cache_time=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. Alternatively, the user can be redirected to the specified Game URL. For this option to work, you must first create a game for your bot via @BotFather and accept the terms. Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.

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

  • text (str | None, default: None) – Text of the notification. If not specified, nothing will be shown to the user, 0-telegram.CallbackQuery.MAX_ANSWER_TEXT_LENGTH characters.

  • show_alert (bool | None, default: None) – 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 | None, default: None) –

    URL that will be opened by the user’s client. If you have created a Game and accepted the conditions via @BotFather, specify the URL that opens your game - note that this will only work if the query comes from a callback game button. Otherwise, you may use links like t.me/your_bot?start=XXXX that open your bot with a parameter.

  • cache_time (int | timedelta | None, default: None) –

    The maximum amount of time in seconds that the result of the callback query may be cached client-side. Defaults to 0.

    Changed in version 21.11: |time-period-input|

Returns:

boolbool On success, True is returned.

Raises:

telegram.error.TelegramError

async answer_inline_query(inline_query_id, results, cache_time=None, is_personal=None, next_offset=None, button=None, *, current_offset=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Warning

In most use cases current_offset should not be passed manually. Instead of calling this method directly, use the shortcut telegram.InlineQuery.answer() with telegram.InlineQuery.answer.auto_pagination set to True, which will take care of passing the correct value.

See also

Working with Files and Media <Working-with-Files-and-Media>

Changed in version 20.5: Removed deprecated arguments switch_pm_text and switch_pm_parameter.

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

  • results (Sequence[InlineQueryResult] | Callable[[int], Sequence[InlineQueryResult] | None]) – A list of results for the inline query. In case current_offset is passed, results may also be a callable that accepts the current page index starting from 0. It must return either a list of telegram.InlineQueryResult instances or None if there are no more results.

  • cache_time (int | timedelta | None, default: None) –

    The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300.

    Changed in version 21.11: |time-period-input|

  • is_personal (bool | None, default: None) – Pass True, if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query.

  • next_offset (str | None, default: None) – Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you don’t support pagination. Offset length can’t exceed telegram.InlineQuery.MAX_OFFSET_LENGTH bytes.

  • button (InlineQueryResultsButton | None, default: None) –

    A button to be shown above the inline query results.

    Added in version 20.3.

Keyword Arguments:

current_offset (str, optional) – The telegram.InlineQuery.offset of the inline query to answer. If passed, PTB will automatically take care of the pagination for you, i.e. pass the correct next_offset and truncate the results list/get the results from the callable you passed.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async answer_pre_checkout_query(pre_checkout_query_id, ok, error_message=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Note

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

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

  • ok (bool) – Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems.

  • error_message (str | None, default: None) – 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

Returns:

bool

Raises:

telegram.error.TelegramError

async answer_shipping_query(shipping_query_id, ok, shipping_options=None, error_message=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

If you sent an invoice requesting a shipping address and the parameter send_invoice.is_flexible was specified, the Bot API will send an telegram.Update with a telegram.Update.shipping_query field to the bot. Use this method to reply to shipping queries.

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

  • ok (bool) – Specify True if delivery to the specified address is possible and False if there are any problems (for example, if delivery to the specified address is not possible).

  • shipping_options (Sequence[ShippingOption] | None, default: None) –

    Required if ok is True. A sequence of available shipping options.

    Changed in version 20.0: |sequenceargs|

  • error_message (str | None, default: None) – 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.

Returns:

bool

Raises:

telegram.error.TelegramError

async answer_web_app_query(web_app_query_id, result, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Added in version 20.0.

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

  • result (InlineQueryResult) – An object describing the message to be sent.

Returns:

On success, a sent telegram.SentWebAppMessage is returned.

Returns:

SentWebAppMessage

Raises:

telegram.error.TelegramError

async approveChatJoinRequest(chat_id, user_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for approve_chat_join_request()

Return type:

bool

async approveSuggestedPost(chat_id, message_id, send_date=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for approve_suggested_post()

Return type:

bool

async approve_chat_join_request(chat_id, user_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 telegram.ChatPermissions.can_invite_users administrator right.

Added in version 13.8.

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async approve_suggested_post(chat_id, message_id, send_date=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to approve a suggested post in a direct messages chat. The bot must have the can_post_messages administrator right in the corresponding channel chat.

Added in version 22.4.

Parameters:
  • chat_id (int) – Unique identifier of the target direct messages chat.

  • message_id (int) – Identifier of a suggested post message to approve.

  • send_date (int | datetime | None, default: None) –

    Date when the post is expected to be published; omit if the date has already been specified when the suggested post was created. If specified, then the date must be not more than telegram.constants.SuggestedPost.MAX_SEND_DATE seconds (30 days) in the future.

    |tz-naive-dtms|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async banChatMember(chat_id, user_id, until_date=None, revoke_messages=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for ban_chat_member()

Return type:

bool

async banChatSenderChat(chat_id, sender_chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for ban_chat_sender_chat()

Return type:

bool

async ban_chat_member(chat_id, user_id, until_date=None, revoke_messages=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 13.7.

Parameters:
  • chat_id (str | int) – 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 | datetime | None, default: None) – Date when the user will be unbanned, unix time. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever. Applied for supergroups and channels only. |tz-naive-dtms|

  • revoke_messages (bool | None, default: None) –

    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.

    Added in version 13.4.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async ban_chat_sender_chat(chat_id, sender_chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 13.9.

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

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

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

property base_file_url: str

Telegram Bot API file URL, built from Bot.base_file_url and Bot.token.

Added in version 20.0.

Type:

str

property base_url: str

Telegram Bot API service URL, built from Bot.base_url and Bot.token.

Added in version 20.0.

Type:

str

property bot: User

User instance for the bot as returned by get_me().

Warning

This value is the cached return value of get_me(). If the bots profile is changed during runtime, this value won’t reflect the changes until get_me() is called again.

See also

initialize()

Type:

telegram.User

property can_join_groups: bool

Bot’s telegram.User.can_join_groups attribute. Shortcut for the corresponding attribute of bot.

Type:

bool

property can_read_all_group_messages: bool

Bot’s telegram.User.can_read_all_group_messages attribute. Shortcut for the corresponding attribute of bot.

Type:

bool

async close(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async closeForumTopic(chat_id, message_thread_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for close_forum_topic()

Return type:

bool

async closeGeneralForumTopic(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for close_general_forum_topic()

Return type:

bool

async close_forum_topic(chat_id, message_thread_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 ~telegram.ChatAdministratorRights.can_manage_topics administrator rights, unless it is the creator of the topic.

Added in version 20.0.

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async close_general_forum_topic(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 20.0.

Parameters:

chat_id (str | int) – |chat_id_group|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async convertGiftToStars(business_connection_id, owned_gift_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for convert_gift_to_stars()

Return type:

bool

async convert_gift_to_stars(business_connection_id, owned_gift_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Converts a given regular gift to Telegram Stars. Requires the can_convert_gifts_to_stars business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection

  • owned_gift_id (str) – Unique identifier of the regular gift that should be converted to Telegram Stars.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async copyMessage(chat_id, from_chat_id, message_id, caption=None, parse_mode=None, caption_entities=None, disable_notification=None, reply_markup=None, protect_content=None, message_thread_id=None, reply_parameters=None, show_caption_above_media=None, allow_paid_broadcast=None, video_start_timestamp=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for copy_message()

Return type:

MessageId

async copyMessages(chat_id, from_chat_id, message_ids, disable_notification=None, protect_content=None, message_thread_id=None, remove_caption=None, direct_messages_topic_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for copy_messages()

Return type:

tuple[MessageId, ...]

async copy_message(chat_id, from_chat_id, message_id, caption=None, parse_mode=None, caption_entities=None, disable_notification=None, reply_markup=None, protect_content=None, message_thread_id=None, reply_parameters=None, show_caption_above_media=None, allow_paid_broadcast=None, video_start_timestamp=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to copy messages of any kind. Service messages, paid media messages, giveaway messages, giveaway winners messages, and invoice messages can’t be copied. The method is analogous to the method forward_message(), but the copied message doesn’t have a link to the original message.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

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

  • video_start_timestamp (int | None, default: None) –

    New start timestamp for the copied video in the message

    Added in version 21.11.

  • caption (str | None, default: None) – New caption for media, 0-telegram.constants.MessageLimit.CAPTION_LENGTH characters after entities parsing. If not specified, the original caption is kept.

  • parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – Mode for parsing entities in the new caption. See the constants in telegram.constants.ParseMode for the available modes.

  • caption_entities (Sequence[MessageEntity] | None, default: None) –

    |caption_entities|

    Changed in version 20.0: |sequenceargs|

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • show_caption_above_media (bool | None, default: None) –

    Pass |show_cap_above_med|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
Returns:

On success, the telegram.MessageId of the sent

message is returned.

Returns:

MessageId

Raises:

telegram.error.TelegramError

async copy_messages(chat_id, from_chat_id, message_ids, disable_notification=None, protect_content=None, message_thread_id=None, remove_caption=None, direct_messages_topic_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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, paid media 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 telegram.Poll.correct_option_id is known to the bot. The method is analogous to the method forward_messages(), but the copied messages don’t have a link to the original message. Album grouping is kept for copied messages.

Added in version 20.8.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

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

  • message_ids (Sequence[int]) – A list of telegram.constants.BulkRequestLimit.MIN_LIMIT - telegram.constants.BulkRequestLimit.MAX_LIMIT identifiers of messages in the chat from_chat_id to copy. The identifiers must be specified in a strictly increasing order.

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |protect_content|

  • message_thread_id (int | None, default: None) – |message_thread_id_arg|

  • remove_caption (bool | None, default: None) – Pass True to copy the messages without their captions.

  • direct_messages_topic_id (int | None, default: None) –

    Identifier of the direct messages topic to which the message will be sent; required if the message is sent to a direct messages chat.

    Added in version 22.4.

Returns:

On success, a tuple of MessageId of the sent messages is returned.

Returns:

tuple[MessageId, ...]

Raises:

telegram.error.TelegramError

Alias for create_chat_invite_link()

Return type:

ChatInviteLink

Alias for create_chat_subscription_invite_link()

Return type:

ChatInviteLink

async createForumTopic(chat_id, name, icon_color=None, icon_custom_emoji_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for create_forum_topic()

Return type:

ForumTopic

Alias for create_invoice_link()

Return type:

str

async createNewStickerSet(user_id, name, title, stickers, sticker_type=None, needs_repainting=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for create_new_sticker_set()

Return type:

bool

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

Note

When joining public groups via an invite link, Telegram clients may display the usual “Join” button, effectively ignoring the invite link. In particular, the parameter creates_join_request has no effect in this case. However, this behavior is undocument and may be subject to change. See this GitHub thread for some discussion.

Added in version 13.4.

Parameters:
  • chat_id (str | int) – |chat_id_channel|

  • expire_date (int | datetime | None, default: None) – Date when the link will expire. Integer input will be interpreted as Unix timestamp. |tz-naive-dtms|

  • member_limit (int | None, default: None) – Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; telegram.constants.ChatInviteLinkLimit.MIN_MEMBER_LIMIT- telegram.constants.ChatInviteLinkLimit.MAX_MEMBER_LIMIT.

  • name (str | None, default: None) –

    Invite link name; 0-telegram.constants.ChatInviteLinkLimit.NAME_LENGTH characters.

    Added in version 13.8.

  • creates_join_request (bool | None, default: None) –

    True, if users joining the chat via the link need to be approved by chat administrators. If True, member_limit can’t be specified.

    Added in version 13.8.

Returns:

ChatInviteLinktelegram.ChatInviteLink

Raises:

telegram.error.TelegramError

Use this method to create a subscription invite link for a channel chat. The bot must have the can_invite_users administrator right. The link can be edited using the edit_chat_subscription_invite_link() or revoked using the revoke_chat_invite_link().

Added in version 21.5.

Parameters:
  • chat_id (str | int) – |chat_id_channel|

  • subscription_period (int | timedelta) –

    The number of seconds the subscription will be active for before the next payment. Currently, it must always be telegram.constants.ChatSubscriptionLimit.SUBSCRIPTION_PERIOD (30 days).

    Changed in version 21.11: |time-period-input|

  • subscription_price (int) – The number of Telegram Stars a user must pay initially and after each subsequent subscription period to be a member of the chat; telegram.constants.ChatSubscriptionLimit.MIN_PRICE- telegram.constants.ChatSubscriptionLimit.MAX_PRICE.

  • name (str | None, default: None) – Invite link name; 0-telegram.constants.ChatInviteLinkLimit.NAME_LENGTH characters.

Returns:

ChatInviteLinktelegram.ChatInviteLink

Raises:

telegram.error.TelegramError

async create_forum_topic(chat_id, name, icon_color=None, icon_custom_emoji_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 ~telegram.ChatAdministratorRights.can_manage_topics administrator rights.

Added in version 20.0.

Parameters:
Returns:

ForumTopictelegram.ForumTopic

Raises:

telegram.error.TelegramError

Use this method to create a link for an invoice.

Added in version 20.0.

Parameters:
  • business_connection_id (str | None, default: None) –

    |business_id_str| For payments in |tg_stars| only.

    Added in version 21.8.

  • title (str) – Product name. telegram.Invoice.MIN_TITLE_LENGTH- telegram.Invoice.MAX_TITLE_LENGTH characters.

  • description (str) – Product description. telegram.Invoice.MIN_DESCRIPTION_LENGTH- telegram.Invoice.MAX_DESCRIPTION_LENGTH characters.

  • payload (str) – Bot-defined invoice payload. telegram.Invoice.MIN_PAYLOAD_LENGTH- telegram.Invoice.MAX_PAYLOAD_LENGTH bytes. This will not be displayed to the user, use it for your internal processes.

  • provider_token (str | None, default: None) –

    Payments provider token, obtained via @BotFather. Pass an empty string for payments in |tg_stars|.

    Changed in version 21.11: Bot API 7.4 made this parameter is optional and this is now reflected in the function signature.

  • currency (str) –

    Three-letter ISO 4217 currency code, see more on currencies. Pass XTR for payments in |tg_stars|.

  • prices (Sequence[LabeledPrice]) –

    Price breakdown, a sequence of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.). Must contain exactly one item for payments in |tg_stars|.

    Changed in version 20.0: |sequenceargs|

  • subscription_period (int | timedelta | None, default: None) –

    The time the subscription will be active for before the next payment, either as number of seconds or as datetime.timedelta object. The currency must be set to “XTR” (Telegram Stars) if the parameter is used. Currently, it must always be telegram.constants.InvoiceLimit.SUBSCRIPTION_PERIOD if specified. Any number of subscriptions can be active for a given bot at the same time, including multiple concurrent subscriptions from the same user. Subscription price must not exceed telegram.constants.InvoiceLimit.SUBSCRIPTION_MAX_PRICE Telegram Stars.

    Added in version 21.8.

  • max_tip_amount (int | None, default: None) –

    The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0. Not supported for payments in |tg_stars|.

  • suggested_tip_amounts (Sequence[int] | None, default: None) –

    An array of suggested amounts of tips in the smallest units of the currency (integer, not float/double). At most telegram.Invoice.MAX_TIP_AMOUNTS 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.

    Changed in version 20.0: |sequenceargs|

  • provider_data (str | object | None, default: None) – Data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider. When an object is passed, it will be encoded as JSON.

  • photo_url (str | None, default: None) – URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service.

  • photo_size (int | None, default: None) – Photo size in bytes.

  • photo_width (int | None, default: None) – Photo width.

  • photo_height (int | None, default: None) – Photo height.

  • need_name (bool | None, default: None) – Pass True, if you require the user’s full name to complete the order. Ignored for payments in |tg_stars|.

  • need_phone_number (bool | None, default: None) – Pass True, if you require the user’s phone number to complete the order. Ignored for payments in |tg_stars|.

  • need_email (bool | None, default: None) – Pass True, if you require the user’s email address to complete the order. Ignored for payments in |tg_stars|.

  • need_shipping_address (bool | None, default: None) – Pass True, if you require the user’s shipping address to complete the order. Ignored for payments in |tg_stars|.

  • send_phone_number_to_provider (bool | None, default: None) – Pass True, if user’s phone number should be sent to provider. Ignored for payments in |tg_stars|.

  • send_email_to_provider (bool | None, default: None) – Pass True, if user’s email address should be sent to provider. Ignored for payments in |tg_stars|.

  • is_flexible (bool | None, default: None) – Pass True, if the final price depends on the shipping method. Ignored for payments in |tg_stars|.

Returns:

On success, the created invoice link is returned.

Returns:

str

async create_new_sticker_set(user_id, name, title, stickers, sticker_type=None, needs_repainting=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Changed in version 20.0: The parameter contains_masks has been removed. Use sticker_type instead.

Changed in version 20.2: Since Bot API 6.6, the parameters stickers and sticker_format replace the parameters png_sticker, tgs_sticker,``webm_sticker``, emojis, and mask_position.

Changed in version 20.5: Removed the deprecated parameters mentioned above and adjusted the order of the parameters.

Removed in version 21.2: Removed the deprecated parameter sticker_format.

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. telegram.constants.StickerLimit.MIN_NAME_AND_TITLE- telegram.constants.StickerLimit.MAX_NAME_AND_TITLE characters.

  • title (str) – Sticker set title, telegram.constants.StickerLimit.MIN_NAME_AND_TITLE- telegram.constants.StickerLimit.MAX_NAME_AND_TITLE characters.

  • stickers (Sequence[InputSticker]) –

    A sequence of telegram.constants.StickerSetLimit.MIN_INITIAL_STICKERS- telegram.constants.StickerSetLimit.MAX_INITIAL_STICKERS initial stickers to be added to the sticker set.

    Added in version 20.2.

  • sticker_type (str | None, default: None) –

    Type of stickers in the set, pass telegram.Sticker.REGULAR or telegram.Sticker.MASK, or telegram.Sticker.CUSTOM_EMOJI. By default, a regular sticker set is created

    Added in version 20.0.

  • needs_repainting (bool | None, default: None) –

    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.

    Added in version 20.2.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async declineChatJoinRequest(chat_id, user_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for decline_chat_join_request()

Return type:

bool

async declineSuggestedPost(chat_id, message_id, comment=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for decline_suggested_post()

Return type:

bool

async decline_chat_join_request(chat_id, user_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 telegram.ChatPermissions.can_invite_users administrator right.

Added in version 13.8.

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async decline_suggested_post(chat_id, message_id, comment=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to decline a suggested post in a direct messages chat. The bot must have the can_manage_direct_messages administrator right in the corresponding channel chat.

Added in version 22.4.

Parameters:
  • chat_id (int) – Unique identifier of the target direct messages chat.

  • message_id (int) – Identifier of a suggested post message to decline.

  • comment (str | None, default: None) – Comment for the creator of the suggested post. 0-telegram.constants.SuggestedPost.MAX_COMMENT_LENGTH characters.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async deleteBusinessMessages(business_connection_id, message_ids, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for delete_business_messages()

Return type:

bool

async deleteChatPhoto(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for delete_chat_photo()

Return type:

bool

async deleteChatStickerSet(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for delete_chat_sticker_set()

Return type:

bool

async deleteForumTopic(chat_id, message_thread_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for delete_forum_topic()

Return type:

bool

async deleteMessage(chat_id, message_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for delete_message()

Return type:

bool

async deleteMessages(chat_id, message_ids, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for delete_messages()

Return type:

bool

async deleteMyCommands(scope=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for delete_my_commands()

Return type:

bool

async deleteStickerFromSet(sticker, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for delete_sticker_from_set()

Return type:

bool

async deleteStickerSet(name, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for delete_sticker_set()

Return type:

bool

async deleteStory(business_connection_id, story_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for delete_story()

Return type:

bool

async deleteWebhook(drop_pending_updates=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for delete_webhook()

Return type:

bool

async delete_business_messages(business_connection_id, message_ids, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Delete messages on behalf of a business account. Requires the can_delete_sent_messages business bot right to delete messages sent by the bot itself, or the can_delete_all_messages business bot right to delete any message.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection on behalf of which to delete the messages

  • message_ids (Sequence[int]) – A list of telegram.constants.BulkRequestLimit.MIN_LIMIT- telegram.constants.BulkRequestLimit.MAX_LIMIT identifiers of messages to delete. See delete_message() for limitations on which messages can be deleted.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async delete_chat_photo(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Parameters:

chat_id (str | int) – |chat_id_channel|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async delete_chat_sticker_set(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 telegram.ChatFullInfo.can_set_sticker_set optionally returned in get_chat() requests to check if the bot can use this method.

Parameters:

chat_id (str | int) – |chat_id_group|

Returns:

On success, True is returned.

Returns:

bool

async delete_forum_topic(chat_id, message_thread_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to delete a forum topic along with all its messages in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have ~telegram.ChatAdministratorRights.can_delete_messages administrator rights.

Added in version 20.0.

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async delete_message(chat_id, message_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

  • Service messages about a supergroup, channel, or forum topic creation can’t be deleted.

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

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async delete_messages(chat_id, message_ids, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 20.8.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • message_ids (Sequence[int]) – A list of telegram.constants.BulkRequestLimit.MIN_LIMIT- telegram.constants.BulkRequestLimit.MAX_LIMIT identifiers of messages to delete. See delete_message() for limitations on which messages can be deleted.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async delete_my_commands(scope=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Added in version 13.7.

Parameters:
  • scope (BotCommandScope | None, default: None) – An object, describing scope of users for which the commands are relevant. Defaults to telegram.BotCommandScopeDefault.

  • language_code (str | None, default: None) – 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:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async delete_sticker_from_set(sticker, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Parameters:

sticker (str | Sticker) –

File identifier of the sticker or the sticker object.

Changed in version 21.10: Accepts also telegram.Sticker instances.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async delete_sticker_set(name, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 20.2.

Parameters:

name (str) – Sticker set name.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async delete_story(business_connection_id, story_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Deletes a story previously posted by the bot on behalf of a managed business account. Requires the can_manage_stories business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection.

  • story_id (int) – Unique identifier of the story to delete.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async delete_webhook(drop_pending_updates=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to remove webhook integration if you decide to switch back to get_updates().

Parameters:

drop_pending_updates (bool | None, default: None) – Pass True to drop all pending updates.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async do_api_request(endpoint, api_kwargs=None, return_type=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None)[source]

Do a request to the Telegram API.

This method is here to make it easier to use new API methods that are not yet supported by this library.

Hint

Since PTB does not know which arguments are passed to this method, some caution is necessary in terms of PTBs utility functionalities. In particular

  • passing objects of any class defined in the telegram module is supported

  • when uploading files, a telegram.InputFile must be passed as the value for the corresponding argument. Passing a file path or file-like object will not work. File paths will work only in combination with ~Bot.local_mode.

  • when uploading files, PTB can still correctly determine that a special write timeout value should be used instead of the default telegram.request.HTTPXRequest.write_timeout.

  • insertion of default values specified via telegram.ext.Defaults will not work (only relevant for telegram.ext.ExtBot).

  • The only exception is telegram.ext.Defaults.tzinfo, which will be correctly applied to datetime.datetime objects.

Added in version 20.8.

Parameters:
  • endpoint (str) – The API endpoint to use, e.g. getMe or get_me.

  • api_kwargs (dict[str, Any] | None, default: None) – The keyword arguments to pass to the API call. If not specified, no arguments are passed.

  • return_type (type[TelegramObject] | None, default: None) – If specified, the result of the API call will be deserialized into an instance of this class or tuple of instances of this class. If not specified, the raw result of the API call will be returned.

Returns:

Any – The result of the API call. If return_type is not specified, this is a dict or bool, otherwise an instance of return_type or a tuple of return_type.

Raises:

telegram.error.TelegramError

Alias for edit_chat_invite_link()

Return type:

ChatInviteLink

Alias for edit_chat_subscription_invite_link()

Return type:

ChatInviteLink

async editForumTopic(chat_id, message_thread_id, name=None, icon_custom_emoji_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for edit_forum_topic()

Return type:

bool

async editGeneralForumTopic(chat_id, name, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for edit_general_forum_topic()

Return type:

bool

async editMessageCaption(chat_id=None, message_id=None, inline_message_id=None, caption=None, reply_markup=None, parse_mode=None, caption_entities=None, show_caption_above_media=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for edit_message_caption()

Return type:

Message | bool

async editMessageChecklist(business_connection_id, chat_id, message_id, checklist, reply_markup=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for edit_message_checklist()

Return type:

Message

async editMessageLiveLocation(chat_id=None, message_id=None, inline_message_id=None, latitude=None, longitude=None, reply_markup=None, horizontal_accuracy=None, heading=None, proximity_alert_radius=None, live_period=None, business_connection_id=None, *, location=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for edit_message_live_location()

Return type:

Message | bool

async editMessageMedia(media, chat_id=None, message_id=None, inline_message_id=None, reply_markup=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for edit_message_media()

Return type:

Message | bool

async editMessageReplyMarkup(chat_id=None, message_id=None, inline_message_id=None, reply_markup=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for edit_message_reply_markup()

Return type:

Message | bool

async editMessageText(text, chat_id=None, message_id=None, inline_message_id=None, parse_mode=None, reply_markup=None, entities=None, link_preview_options=None, business_connection_id=None, *, disable_web_page_preview=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for edit_message_text()

Return type:

Message | bool

async editStory(business_connection_id, story_id, content, caption=None, parse_mode=None, caption_entities=None, areas=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for edit_story()

Return type:

Story

async editUserStarSubscription(user_id, telegram_payment_charge_id, is_canceled, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for edit_user_star_subscription()

Return type:

bool

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.

Note

Though not stated explicitly in the official docs, Telegram changes not only the optional parameters that are explicitly passed, but also replaces all other optional parameters to the default values. However, since not documented, this behaviour may change unbeknown to PTB.

Added in version 13.4.

Parameters:
  • chat_id (str | int) – |chat_id_channel|

  • invite_link (str | ChatInviteLink) –

    The invite link to edit.

    Changed in version 20.0: Now also accepts telegram.ChatInviteLink instances.

  • expire_date (int | datetime | None, default: None) – Date when the link will expire. |tz-naive-dtms|

  • member_limit (int | None, default: None) – Maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; telegram.constants.ChatInviteLinkLimit.MIN_MEMBER_LIMIT- telegram.constants.ChatInviteLinkLimit.MAX_MEMBER_LIMIT.

  • name (str | None, default: None) –

    Invite link name; 0-telegram.constants.ChatInviteLinkLimit.NAME_LENGTH characters.

    Added in version 13.8.

  • creates_join_request (bool | None, default: None) –

    True, if users joining the chat via the link need to be approved by chat administrators. If True, member_limit can’t be specified.

    Added in version 13.8.

Returns:

ChatInviteLinktelegram.ChatInviteLink

Raises:

telegram.error.TelegramError

Use this method to edit a subscription invite link created by the bot. The bot must have telegram.ChatPermissions.can_invite_users administrator right.

Added in version 21.5.

Parameters:
  • chat_id (str | int) – |chat_id_channel|

  • invite_link (str | ChatInviteLink) – The invite link to edit.

  • name (str | None, default: None) –

    Invite link name; 0-telegram.constants.ChatInviteLinkLimit.NAME_LENGTH characters.

    Tip

    Omitting this argument removes the name of the invite link.

Returns:

ChatInviteLinktelegram.ChatInviteLink

Raises:

telegram.error.TelegramError

async edit_forum_topic(chat_id, message_thread_id, name=None, icon_custom_emoji_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 the ~telegram.ChatAdministratorRights.can_manage_topics administrator rights, unless it is the creator of the topic.

Added in version 20.0.

Parameters:
  • chat_id (str | int) – |chat_id_group|

  • message_thread_id (int) – |message_thread_id|

  • name (str | None, default: None) – New topic name, telegram.constants.ForumTopicLimit.MIN_NAME_LENGTH- telegram.constants.ForumTopicLimit.MAX_NAME_LENGTH characters. If not specified or empty, the current name of the topic will be kept.

  • icon_custom_emoji_id (str | None, default: None) – New unique identifier of the custom emoji shown as the topic icon. Use get_forum_topic_icon_stickers() 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.

Returns:

bool

Raises:

telegram.error.TelegramError

async edit_general_forum_topic(chat_id, name, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 the can_manage_topics administrator rights.

Added in version 20.0.

Parameters:
  • chat_id (str | int) – |chat_id_group|

  • name (str) – New topic name, telegram.constants.ForumTopicLimit.MIN_NAME_LENGTH- telegram.constants.ForumTopicLimit.MAX_NAME_LENGTH characters.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async edit_message_caption(chat_id=None, message_id=None, inline_message_id=None, caption=None, reply_markup=None, parse_mode=None, caption_entities=None, show_caption_above_media=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to edit captions of messages.

Parameters:
  • chat_id (int | str | None, default: None) – Required if inline_message_id is not specified. |chat_id_channel|

  • message_id (int | None, default: None) – Required if inline_message_id is not specified. Identifier of the message to edit.

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

  • caption (str | None, default: None) – New caption of the message, 0-telegram.constants.MessageLimit.CAPTION_LENGTH characters after entities parsing.

  • parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – |parse_mode|

  • caption_entities (Sequence[MessageEntity] | None, default: None) –

    |caption_entities|

    Changed in version 20.0: |sequenceargs|

  • reply_markup (InlineKeyboardMarkup | None, default: None) – An object for an inline keyboard.

  • show_caption_above_media (bool | None, default: None) –

    Pass |show_cap_above_med|

    Added in version 21.3.

  • business_connection_id (str | None, default: None) –

    |business_id_str_edit|

    Added in version 21.4.

Returns:

On success, if edited message is not an inline message, the edited message is returned, otherwise True is returned.

Returns:

Message | bool

Raises:

telegram.error.TelegramError

async edit_message_checklist(business_connection_id, chat_id, message_id, checklist, reply_markup=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to edit a checklist on behalf of a connected business account.

Added in version 22.3.

Parameters:
  • business_connection_id (str) – |business_id_str|

  • chat_id (int) – Unique identifier for the target chat.

  • message_id (int) – Unique identifier for the target message.

  • checklist (InputChecklist) – The new checklist.

  • reply_markup (InlineKeyboardMarkup | None, default: None) – An object for the new inline keyboard for the message.

Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async edit_message_live_location(chat_id=None, message_id=None, inline_message_id=None, latitude=None, longitude=None, reply_markup=None, horizontal_accuracy=None, heading=None, proximity_alert_radius=None, live_period=None, business_connection_id=None, *, location=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Note

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

Parameters:
  • chat_id (int | str | None, default: None) – Required if inline_message_id is not specified. |chat_id_channel|

  • message_id (int | None, default: None) – Required if inline_message_id is not specified. Identifier of the message to edit.

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

  • latitude (float | None, default: None) – Latitude of location.

  • longitude (float | None, default: None) – Longitude of location.

  • horizontal_accuracy (float | None, default: None) – The radius of uncertainty for the location, measured in meters; 0-telegram.constants.LocationLimit.HORIZONTAL_ACCURACY.

  • heading (int | None, default: None) – Direction in which the user is moving, in degrees. Must be between telegram.constants.LocationLimit.MIN_HEADING and telegram.constants.LocationLimit.MAX_HEADING if specified.

  • proximity_alert_radius (int | None, default: None) – Maximum distance for proximity alerts about approaching another chat member, in meters. Must be between telegram.constants.LocationLimit.MIN_PROXIMITY_ALERT_RADIUS and telegram.constants.LocationLimit.MAX_PROXIMITY_ALERT_RADIUS if specified.

  • reply_markup (InlineKeyboardMarkup | None, default: None) – An object for a new inline keyboard.

  • live_period (int | timedelta | None, default: None) –

    New period in seconds during which the location can be updated, starting from the message send date. If telegram.constants.LocationLimit.LIVE_PERIOD_FOREVER is specified, then the location can be updated forever. Otherwise, the new value must not exceed the current live_period by more than a day, and the live location expiration date must remain within the next 90 days. If not specified, then live_period remains unchanged

    Added in version 21.2..

    Changed in version 21.11: |time-period-input|

  • business_connection_id (str | None, default: None) –

    |business_id_str_edit|

    Added in version 21.4.

Keyword Arguments:

location (telegram.Location, optional) – The location to send.

Returns:

On success, if edited message is not an inline message, the edited message is returned, otherwise True is returned.

Returns:

Message | bool

async edit_message_media(media, chat_id=None, message_id=None, inline_message_id=None, reply_markup=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to edit animation, audio, document, photo, or video messages, or to add media to text messages. If a message is part of a message album, then it can be edited only to an audio for audio albums, only to a document for document albums and to a photo or a video otherwise. When an inline message is edited, a new file can’t be uploaded; use a previously uploaded file via its file_id or specify a URL.

See also

Working with Files and Media <Working-with-Files-and-Media>

Parameters:
  • media (InputMedia) – An object for a new media content of the message.

  • chat_id (int | str | None, default: None) – Required if inline_message_id is not specified. |chat_id_channel|

  • message_id (int | None, default: None) – Required if inline_message_id is not specified. Identifier of the message to edit.

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

  • reply_markup (InlineKeyboardMarkup | None, default: None) – An object for an inline keyboard.

  • business_connection_id (str | None, default: None) –

    |business_id_str_edit|

    Added in version 21.4.

Returns:

On success, if edited message is not an inline message, the edited Message is returned, otherwise True is returned.

Returns:

Message | bool

Raises:

telegram.error.TelegramError

async edit_message_reply_markup(chat_id=None, message_id=None, inline_message_id=None, reply_markup=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Parameters:
  • chat_id (int | str | None, default: None) – Required if inline_message_id is not specified. |chat_id_channel|

  • message_id (int | None, default: None) – Required if inline_message_id is not specified. Identifier of the message to edit.

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

  • reply_markup (InlineKeyboardMarkup | None, default: None) – An object for an inline keyboard.

  • business_connection_id (str | None, default: None) –

    |business_id_str_edit|

    Added in version 21.4.

Returns:

On success, if edited message is not an inline message, the edited message is returned, otherwise True is returned.

Returns:

Message | bool

Raises:

telegram.error.TelegramError

async edit_message_text(text, chat_id=None, message_id=None, inline_message_id=None, parse_mode=None, reply_markup=None, entities=None, link_preview_options=None, business_connection_id=None, *, disable_web_page_preview=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to edit text and game messages.

Parameters:
  • chat_id (int | str | None, default: None) – Required if inline_message_id is not specified. |chat_id_channel|

  • message_id (int | None, default: None) – Required if inline_message_id is not specified. Identifier of the message to edit.

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

  • text (str) – New text of the message, telegram.constants.MessageLimit.MIN_TEXT_LENGTH- telegram.constants.MessageLimit.MAX_TEXT_LENGTH characters after entities parsing.

  • parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – |parse_mode|

  • entities (Sequence[MessageEntity] | None, default: None) –

    Sequence of special entities that appear in message text, which can be specified instead of parse_mode.

    Changed in version 20.0: |sequenceargs|

  • link_preview_options (DefaultValue[DVValueType] | LinkPreviewOptions | DefaultValue[None] | None, default: None) –

    Link preview generation options for the message. Mutually exclusive with disable_web_page_preview.

    Added in version 20.8.

  • reply_markup (InlineKeyboardMarkup | None, default: None) – An object for an inline keyboard.

  • business_connection_id (str | None, default: None) –

    |business_id_str_edit|

    Added in version 21.4.

Keyword Arguments:

disable_web_page_preview (bool, optional) –

Disables link previews for links in this message. Convenience parameter for setting link_preview_options. Mutually exclusive with link_preview_options.

Changed in version 20.8: Bot API 7.0 introduced link_preview_options replacing this argument. PTB will automatically convert this argument to that one, but for advanced options, please use link_preview_options directly.

Changed in version 21.0: |keyword_only_arg|

Returns:

On success, if edited message is not an inline message, the edited message is returned, otherwise True is returned.

Returns:

Message | bool

Raises:
async edit_story(business_connection_id, story_id, content, caption=None, parse_mode=None, caption_entities=None, areas=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Edits a story previously posted by the bot on behalf of a managed business account. Requires the can_manage_stories business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection.

  • story_id (int) – Unique identifier of the story to edit.

  • content (InputStoryContent) – Content of the story.

  • caption (str | None, default: None) – Caption of the story, 0-~telegram.constants.StoryLimit.CAPTION_LENGTH characters after entities parsing.

  • parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – Mode for parsing entities in the story caption. See the constants in telegram.constants.ParseMode for the available modes.

  • caption_entities (Sequence[MessageEntity] | None, default: None) – |caption_entities|

  • areas (Sequence[StoryArea] | None, default: None) –

    Sequence of clickable areas to be shown on the story.

    Note

    Each type of clickable area in areas has its own maximum limit:

Returns:

StoryStory

Raises:

telegram.error.TelegramError

async edit_user_star_subscription(user_id, telegram_payment_charge_id, is_canceled, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Allows the bot to cancel or re-enable extension of a subscription paid in Telegram Stars.

Added in version 21.8.

Parameters:
  • user_id (int) – Identifier of the user whose subscription will be edited.

  • telegram_payment_charge_id (str) – Telegram payment identifier for the subscription.

  • is_canceled (bool) – Pass True to cancel extension of the user subscription; the subscription must be active up to the end of the current subscription period. Pass False to allow the user to re-enable a subscription that was previously canceled by the bot.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

Alias for export_chat_invite_link()

Return type:

str

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

Note

Each administrator in a chat generates their own invite links. Bots can’t use invite links generated by other administrators. If you want your bot to work with invite links, it will need to generate its own link using export_chat_invite_link() or by calling the get_chat() method. If your bot needs to generate a new primary invite link replacing its previous one, use export_chat_invite_link() again.

Parameters:

chat_id (str | int) – |chat_id_channel|

Returns:

New invite link on success.

Returns:

str

Raises:

telegram.error.TelegramError

property first_name: str

Bot’s first name. Shortcut for the corresponding attribute of bot.

Type:

str

async forwardMessage(chat_id, from_chat_id, message_id, disable_notification=None, protect_content=None, message_thread_id=None, video_start_timestamp=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for forward_message()

Return type:

Message

async forwardMessages(chat_id, from_chat_id, message_ids, disable_notification=None, protect_content=None, message_thread_id=None, direct_messages_topic_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for forward_messages()

Return type:

tuple[MessageId, ...]

async forward_message(chat_id, from_chat_id, message_id, disable_notification=None, protect_content=None, message_thread_id=None, video_start_timestamp=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to forward messages of any kind. Service messages can’t be forwarded.

Note

Since the release of Bot API 5.5 it can be impossible to forward messages from some chats. Use the attributes telegram.Message.has_protected_content and telegram.ChatFullInfo.has_protected_content to check this.

As a workaround, it is still possible to use copy_message(). However, this behaviour is undocumented and might be changed by Telegram.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

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

  • video_start_timestamp (int | None, default: None) –

    New start timestamp for the forwarded video in the message

    Added in version 21.11.

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    An object containing the parameters of the suggested post to send; for direct messages chats only.

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    Identifier of the direct messages topic to which the message will be forwarded; required if the message is forwarded to a direct messages chat.

    Added in version 22.4.

Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async forward_messages(chat_id, from_chat_id, message_ids, disable_notification=None, protect_content=None, message_thread_id=None, direct_messages_topic_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to forward 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.

Added in version 20.8.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

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

  • message_ids (Sequence[int]) – A list of telegram.constants.BulkRequestLimit.MIN_LIMIT- telegram.constants.BulkRequestLimit.MAX_LIMIT identifiers of messages in the chat from_chat_id to forward. The identifiers must be specified in a strictly increasing order.

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |protect_content|

  • message_thread_id (int | None, default: None) – |message_thread_id_arg|

  • direct_messages_topic_id (int | None, default: None) –

    Identifier of the direct messages topic to which the messages will be forwarded; required if the messages are forwarded to a direct messages chat.

    Added in version 22.4.

Returns:

On success, a tuple of MessageId of sent messages is returned.

Returns:

tuple[MessageId, ...]

Raises:

telegram.error.TelegramError

async getAvailableGifts(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_available_gifts()

Return type:

Gifts

async getBusinessAccountGifts(business_connection_id, exclude_unsaved=None, exclude_saved=None, exclude_unlimited=None, exclude_limited=None, exclude_unique=None, sort_by_price=None, offset=None, limit=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_business_account_gifts()

Return type:

OwnedGifts

async getBusinessAccountStarBalance(business_connection_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_business_account_star_balance()

Return type:

StarAmount

async getBusinessConnection(business_connection_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_business_connection()

Return type:

BusinessConnection

async getChat(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_chat()

Return type:

ChatFullInfo

async getChatAdministrators(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_chat_administrators()

Return type:

tuple[ChatMember, ...]

async getChatMember(chat_id, user_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_chat_member()

Return type:

ChatMember

async getChatMemberCount(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_chat_member_count()

Return type:

int

async getChatMenuButton(chat_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_chat_menu_button()

Return type:

MenuButton

async getCustomEmojiStickers(custom_emoji_ids, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_custom_emoji_stickers()

Return type:

tuple[Sticker, ...]

async getFile(file_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_file()

Return type:

File

async getForumTopicIconStickers(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_forum_topic_icon_stickers()

Return type:

tuple[Sticker, ...]

async getGameHighScores(user_id, chat_id=None, message_id=None, inline_message_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_game_high_scores()

Return type:

tuple[GameHighScore, ...]

async getMe(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_me()

Return type:

User

async getMyCommands(scope=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_my_commands()

Return type:

tuple[BotCommand, ...]

async getMyDefaultAdministratorRights(for_channels=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_my_default_administrator_rights()

Return type:

ChatAdministratorRights

async getMyDescription(language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_my_description()

Return type:

BotDescription

async getMyName(language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_my_name()

Return type:

BotName

async getMyShortDescription(language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_my_short_description()

Return type:

BotShortDescription

async getMyStarBalance(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_my_star_balance()

Return type:

StarAmount

async getStarTransactions(offset=None, limit=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_star_transactions()

Return type:

StarTransactions

async getStickerSet(name, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_sticker_set()

Return type:

StickerSet

async getUpdates(offset=None, limit=None, timeout=None, allowed_updates=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_updates()

Return type:

tuple[Update, ...]

async getUserChatBoosts(chat_id, user_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_user_chat_boosts()

Return type:

UserChatBoosts

async getUserProfilePhotos(user_id, offset=None, limit=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_user_profile_photos()

Return type:

UserProfilePhotos

async getWebhookInfo(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for get_webhook_info()

Return type:

WebhookInfo

async get_available_gifts(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Returns the list of gifts that can be sent by the bot to users and channel chats. Requires no parameters.

Added in version 21.8.

Returns:

Giftstelegram.Gifts

Raises:

telegram.error.TelegramError

async get_business_account_gifts(business_connection_id, exclude_unsaved=None, exclude_saved=None, exclude_unlimited=None, exclude_limited=None, exclude_unique=None, sort_by_price=None, offset=None, limit=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Returns the gifts received and owned by a managed business account. Requires the can_view_gifts_and_stars business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection.

  • exclude_unsaved (bool | None, default: None) – Pass True to exclude gifts that aren’t saved to the account’s profile page.

  • exclude_saved (bool | None, default: None) – Pass True to exclude gifts that are saved to the account’s profile page.

  • exclude_unlimited (bool | None, default: None) – Pass True to exclude gifts that can be purchased an unlimited number of times.

  • exclude_limited (bool | None, default: None) – Pass True to exclude gifts that can be purchased a limited number of times.

  • exclude_unique (bool | None, default: None) – Pass True to exclude unique gifts.

  • sort_by_price (bool | None, default: None) – Pass True to sort results by gift price instead of send date. Sorting is applied before pagination.

  • offset (str | None, default: None) – Offset of the first entry to return as received from the previous request; use empty string to get the first chunk of results.

  • limit (int | None, default: None) – The maximum number of gifts to be returned; telegram.constants.BusinessLimit.MIN_GIFT_RESULTS- telegram.constants.BusinessLimit.MAX_GIFT_RESULTS. Defaults to telegram.constants.BusinessLimit.MAX_GIFT_RESULTS.

Returns:

OwnedGiftstelegram.OwnedGifts

Raises:

telegram.error.TelegramError

async get_business_account_star_balance(business_connection_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Returns the amount of Telegram Stars owned by a managed business account. Requires the can_view_gifts_and_stars business bot right.

Added in version 22.1.

Parameters:

business_connection_id (str) – Unique identifier of the business connection.

Returns:

StarAmounttelegram.StarAmount

Raises:

telegram.error.TelegramError

async get_business_connection(business_connection_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to get information about the connection of the bot with a business account.

Added in version 21.1.

Parameters:

business_connection_id (str) – Unique identifier of the business connection.

Returns:

On success, the object containing the business

connection information is returned.

Returns:

BusinessConnection

Raises:

telegram.error.TelegramError

async get_chat(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.).

Changed in version 21.2: In accordance to Bot API 7.3, this method now returns a telegram.ChatFullInfo.

Parameters:

chat_id (str | int) – |chat_id_channel|

Returns:

ChatFullInfotelegram.ChatFullInfo

Raises:

telegram.error.TelegramError

async get_chat_administrators(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Changed in version 20.0: Returns a tuple instead of a list.

Parameters:

chat_id (str | int) – |chat_id_channel|

Returns:

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

Returns:

tuple[ChatMember, ...]

Raises:

telegram.error.TelegramError

async get_chat_member(chat_id, user_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to get information about a member of a chat. The method is only guaranteed to work for other users if the bot is an administrator in the chat.

Parameters:
Returns:

ChatMembertelegram.ChatMember

Raises:

telegram.error.TelegramError

async get_chat_member_count(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 13.7.

Parameters:

chat_id (str | int) – |chat_id_channel|

Returns:

Number of members in the chat.

Returns:

int

Raises:

telegram.error.TelegramError

async get_chat_menu_button(chat_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 20.0.

Parameters:

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

Returns:

On success, the current menu button is returned.

Returns:

MenuButton

async get_custom_emoji_stickers(custom_emoji_ids, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Changed in version 20.0: Returns a tuple instead of a list.

Parameters:

custom_emoji_ids (Sequence[str]) –

Sequence of custom emoji identifiers. At most telegram.constants.CustomEmojiStickerLimit.CUSTOM_EMOJI_IDENTIFIER_LIMIT custom emoji identifiers can be specified.

Changed in version 20.0: |sequenceargs|

Returns:

tuple[Sticker, ...] – tuple[telegram.Sticker]

Raises:

telegram.error.TelegramError

async get_file(file_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 telegram.constants.FileSizeLimit.FILESIZE_DOWNLOAD in size. The file can then be e.g. downloaded with telegram.File.download_to_drive(). 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.

Note

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

See also

Working with Files and Media <Working-with-Files-and-Media>

Parameters:

file_id (str | Animation | Audio | ChatPhoto | Document | PhotoSize | Sticker | Video | VideoNote | Voice) – Either the file identifier or an object that has a file_id attribute to get file information about.

Returns:

Filetelegram.File

Raises:

telegram.error.TelegramError

async get_forum_topic_icon_stickers(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 20.0.

Returns:

tuple[Sticker, ...] – tuple[telegram.Sticker]

Raises:

telegram.error.TelegramError

async get_game_high_scores(user_id, chat_id=None, message_id=None, inline_message_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Note

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 his neighbors are not among them. Please note that this behavior is subject to change.

Changed in version 20.0: Returns a tuple instead of a list.

Parameters:
  • user_id (int) – Target user id.

  • chat_id (int | None, default: None) – Required if inline_message_id is not specified. Unique identifier for the target chat.

  • message_id (int | None, default: None) – Required if inline_message_id is not specified. Identifier of the sent message.

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

Returns:

tuple[GameHighScore, ...] – tuple[telegram.GameHighScore]

Raises:

telegram.error.TelegramError

async get_me(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Returns:

A telegram.User instance representing that bot if the credentials are valid, None otherwise.

Returns:

User

Raises:

telegram.error.TelegramError

async get_my_commands(scope=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to get the current list of the bot’s commands for the given scope and user language.

Changed in version 20.0: Returns a tuple instead of a list.

Parameters:
Returns:

On success, the commands set for the bot. An empty tuple is returned if commands are not set.

Returns:

tuple[BotCommand, ...]

Raises:

telegram.error.TelegramError

async get_my_default_administrator_rights(for_channels=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to get the current default administrator rights of the bot.

Added in version 20.0.

Parameters:

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

Returns:

On success.

Returns:

ChatAdministratorRights

Raises:

telegram.error.TelegramError

async get_my_description(language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to get the current bot description for the given user language.

Parameters:

language_code (str | None, default: None) – A two-letter ISO 639-1 language code or an empty string.

Returns:

On success, the bot description is returned.

Returns:

BotDescription

Raises:

telegram.error.TelegramError

async get_my_name(language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to get the current bot name for the given user language.

Parameters:

language_code (str | None, default: None) – A two-letter ISO 639-1 language code or an empty string.

Returns:

On success, the bot name is returned.

Returns:

BotName

Raises:

telegram.error.TelegramError

async get_my_short_description(language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to get the current bot short description for the given user language.

Parameters:

language_code (str | None, default: None) – A two-letter ISO 639-1 language code or an empty string.

Returns:

On success, the bot short description is

returned.

Returns:

BotShortDescription

Raises:

telegram.error.TelegramError

async get_my_star_balance(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

A method to get the current Telegram Stars balance of the bot. Requires no parameters.

Added in version 22.3.

Returns:

StarAmounttelegram.StarAmount

Raises:

telegram.error.TelegramError

async get_star_transactions(offset=None, limit=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 21.4.

Parameters:
  • offset (int | None, default: None) – Number of transactions to skip in the response.

  • limit (int | None, default: None) – The maximum number of transactions to be retrieved. Values between telegram.constants.StarTransactionsLimit.MIN_LIMIT- telegram.constants.StarTransactionsLimit.MAX_LIMIT are accepted. Defaults to telegram.constants.StarTransactionsLimit.MAX_LIMIT.

Returns:

On success.

Returns:

StarTransactions

Raises:

telegram.error.TelegramError

async get_sticker_set(name, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to get a sticker set.

Parameters:

name (str) – Name of the sticker set.

Returns:

StickerSettelegram.StickerSet

Raises:

telegram.error.TelegramError

async get_updates(offset=None, limit=None, timeout=None, allowed_updates=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to receive incoming updates using long polling.

Note

  1. This method will not work if an outgoing webhook is set up.

  2. In order to avoid getting duplicate updates, recalculate offset after each server response.

  3. To take full advantage of this library take a look at telegram.ext.Updater

Changed in version 20.0: Returns a tuple instead of a list.

Parameters:
  • offset (int | None, default: None) – 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 this method is called with an offset higher than its telegram.Update.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 be forgotten.

  • limit (int | None, default: None) – Limits the number of updates to be retrieved. Values between telegram.constants.PollingLimit.MIN_LIMIT- telegram.constants.PollingLimit.MAX_LIMIT are accepted. Defaults to 100.

  • timeout (int | timedelta | None, default: None) –

    Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be positive, short polling should be used for testing purposes only.

    Changed in version v22.2: |time-period-input|

  • allowed_updates (Sequence[str] | None, default: None) –

    A sequence the types of updates you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See telegram.Update for a complete list of available update types. Specify an empty sequence to receive all updates except telegram.Update.chat_member, telegram.Update.message_reaction and telegram.Update.message_reaction_count (default). If not specified, the previous setting will be used. Please note that this parameter doesn’t affect updates created before the call to the get_updates, so unwanted updates may be received for a short period of time.

    Changed in version 20.0: |sequenceargs|

Returns:

tuple[Update, ...] – tuple[telegram.Update]

Raises:

telegram.error.TelegramError

async get_user_chat_boosts(chat_id, user_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 20.8.

Parameters:
Returns:

On success, the object containing the list of boosts

is returned.

Returns:

UserChatBoosts

Raises:

telegram.error.TelegramError

async get_user_profile_photos(user_id, offset=None, limit=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

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

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

  • limit (int | None, default: None) – Limits the number of photos to be retrieved. Values between telegram.constants.UserProfilePhotosLimit.MIN_LIMIT- telegram.constants.UserProfilePhotosLimit.MAX_LIMIT are accepted. Defaults to 100.

Returns:

UserProfilePhotostelegram.UserProfilePhotos

Raises:

telegram.error.TelegramError

async get_webhook_info(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

If the bot is using get_updates(), will return an object with the telegram.WebhookInfo.url field empty.

Returns:

WebhookInfotelegram.WebhookInfo

async giftPremiumSubscription(user_id, month_count, star_count, text=None, text_parse_mode=None, text_entities=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for gift_premium_subscription()

Return type:

bool

async gift_premium_subscription(user_id, month_count, star_count, text=None, text_parse_mode=None, text_entities=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Gifts a Telegram Premium subscription to the given user.

Added in version 22.1.

Parameters:
  • user_id (int) – Unique identifier of the target user who will receive a Telegram Premium subscription.

  • month_count (int) – Number of months the Telegram Premium subscription will be active for the user; must be one of telegram.constants.PremiumSubscription.MONTH_COUNT_THREE, telegram.constants.PremiumSubscription.MONTH_COUNT_SIX, or telegram.constants.PremiumSubscription.MONTH_COUNT_TWELVE.

  • star_count (int) – Number of Telegram Stars to pay for the Telegram Premium subscription; must be telegram.constants.PremiumSubscription.STARS_THREE_MONTHS for telegram.constants.PremiumSubscription.MONTH_COUNT_THREE months, telegram.constants.PremiumSubscription.STARS_SIX_MONTHS for telegram.constants.PremiumSubscription.MONTH_COUNT_SIX months, and telegram.constants.PremiumSubscription.STARS_TWELVE_MONTHS for telegram.constants.PremiumSubscription.MONTH_COUNT_TWELVE months.

  • text (str | None, default: None) – Text that will be shown along with the service message about the subscription; 0-telegram.constants.PremiumSubscription.MAX_TEXT_LENGTH characters.

  • text_parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – Mode for parsing entities. See telegram.constants.ParseMode and formatting options for more details. Entities other than BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, SPOILER, and CUSTOM_EMOJI are ignored.

  • text_entities (Sequence[MessageEntity] | None, default: None) – A list of special entities that appear in the gift text. It can be specified instead of text_parse_mode. Entities other than BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, SPOILER, and CUSTOM_EMOJI are ignored.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async hideGeneralForumTopic(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for hide_general_forum_topic()

Return type:

bool

async hide_general_forum_topic(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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. The topic will be automatically closed if it was open.

Added in version 20.0.

Parameters:

chat_id (str | int) – |chat_id_group|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

property id: int

Unique identifier for this bot. Shortcut for the corresponding attribute of bot.

Type:

int

async initialize()[source]

Initialize resources used by this class. Currently calls get_me() to cache bot and calls telegram.request.BaseRequest.initialize() for the request objects used by this bot.

See also

shutdown()

Added in version 20.0.

Return type:

None

property last_name: str

Optional. Bot’s last name. Shortcut for the corresponding attribute of bot.

Type:

str

async leaveChat(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for leave_chat()

Return type:

bool

async leave_chat(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Parameters:

chat_id (str | int) – |chat_id_channel|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

Convenience property. Returns the t.me link of the bot.

Type:

str

property local_mode: bool

Whether this bot is running in local mode.

Added in version 20.0.

Type:

bool

async logOut(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for log_out()

Return type:

bool

async log_out(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

property name: str

Bot’s @username. Shortcut for the corresponding attribute of bot.

Type:

str

async pinChatMessage(chat_id, message_id, disable_notification=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for pin_chat_message()

Return type:

bool

async pin_chat_message(chat_id, message_id, disable_notification=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Parameters:
  • chat_id (str | int) – |chat_id_channel|

  • message_id (int) – Identifier of a message to pin.

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – Pass True, if it is not necessary to send a notification to all chat members about the new pinned message. Notifications are always disabled in channels and private chats.

  • business_connection_id (str | None, default: None) –

    Unique identifier of the business connection on behalf of which the message will be pinned.

    Added in version 21.5.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async postStory(business_connection_id, content, active_period, caption=None, parse_mode=None, caption_entities=None, areas=None, post_to_chat_page=None, protect_content=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for post_story()

Return type:

Story

async post_story(business_connection_id, content, active_period, caption=None, parse_mode=None, caption_entities=None, areas=None, post_to_chat_page=None, protect_content=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Posts a story on behalf of a managed business account. Requires the can_manage_stories business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection.

  • content (InputStoryContent) – Content of the story.

  • active_period (int | timedelta) – Period after which the story is moved to the archive, in seconds; must be one of ~telegram.constants.StoryLimit.ACTIVITY_SIX_HOURS, ~telegram.constants.StoryLimit.ACTIVITY_TWELVE_HOURS, ~telegram.constants.StoryLimit.ACTIVITY_ONE_DAY, or ~telegram.constants.StoryLimit.ACTIVITY_TWO_DAYS.

  • caption (str | None, default: None) – Caption of the story, 0-~telegram.constants.StoryLimit.CAPTION_LENGTH characters after entities parsing.

  • parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – Mode for parsing entities in the story caption. See the constants in telegram.constants.ParseMode for the available modes.

  • caption_entities (Sequence[MessageEntity] | None, default: None) – |caption_entities|

  • areas (Sequence[StoryArea] | None, default: None) –

    Sequence of clickable areas to be shown on the story.

    Note

    Each type of clickable area in areas has its own maximum limit:

  • post_to_chat_page (bool | None, default: None) – Pass True to keep the story accessible after it expires.

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – Pass True if the content of the story must be protected from forwarding and screenshotting

Returns:

StoryStory

Raises:

telegram.error.TelegramError

property private_key: Any | None

Deserialized private key for decryption of telegram passport data.

Added in version 20.0.

async promoteChatMember(chat_id, user_id, can_change_info=None, can_post_messages=None, can_edit_messages=None, can_delete_messages=None, can_invite_users=None, can_restrict_members=None, can_pin_messages=None, can_promote_members=None, is_anonymous=None, can_manage_chat=None, can_manage_video_chats=None, can_manage_topics=None, can_post_stories=None, can_edit_stories=None, can_delete_stories=None, can_manage_direct_messages=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for promote_chat_member()

Return type:

bool

async promote_chat_member(chat_id, user_id, can_change_info=None, can_post_messages=None, can_edit_messages=None, can_delete_messages=None, can_invite_users=None, can_restrict_members=None, can_pin_messages=None, can_promote_members=None, is_anonymous=None, can_manage_chat=None, can_manage_video_chats=None, can_manage_topics=None, can_post_stories=None, can_edit_stories=None, can_delete_stories=None, can_manage_direct_messages=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Changed in version 20.0: The argument can_manage_voice_chats was renamed to can_manage_video_chats in accordance to Bot API 6.0.

Parameters:
  • chat_id (str | int) – |chat_id_channel|

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

  • is_anonymous (bool | None, default: None) – Pass True, if the administrator’s presence in the chat is hidden.

  • can_manage_chat (bool | None, default: None) –

    Pass True, if the administrator can access the chat event log, get boost list, see hidden supergroup and channel members, report spam messages and ignore slow mode. Implied by any other administrator privilege.

    Added in version 13.4.

  • can_manage_video_chats (bool | None, default: None) –

    Pass True, if the administrator can manage video chats.

    Added in version 20.0.

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

  • can_post_messages (bool | None, default: None) – Pass True, if the administrator can post messages in the channel, or access channel statistics; for channels only.

  • can_edit_messages (bool | None, default: None) – Pass True, if the administrator can edit messages of other users and can pin messages, for channels only.

  • can_delete_messages (bool | None, default: None) – Pass True, if the administrator can delete messages of other users.

  • can_invite_users (bool | None, default: None) – Pass True, if the administrator can invite new users to the chat.

  • can_restrict_members (bool | None, default: None) – Pass True, if the administrator can restrict, ban or unban chat members, or access supergroup statistics.

  • can_pin_messages (bool | None, default: None) – Pass True, if the administrator can pin messages, for supergroups only.

  • can_promote_members (bool | None, default: None) – Pass True, if the administrator can add new administrators with a subset of their own privileges or demote administrators that they have promoted, directly or indirectly (promoted by administrators that were appointed by the user).

  • can_manage_topics (bool | None, default: None) –

    Pass True, if the user is allowed to create, rename, close, and reopen forum topics; for supergroups only.

    Added in version 20.0.

  • can_post_stories (bool | None, default: None) –

    Pass True, if the administrator can post stories to the chat.

    Added in version 20.6.

  • can_edit_stories (bool | None, default: None) –

    Pass True, if the administrator can edit stories posted by other users, post stories to the chat page, pin chat stories, and access the chat’s story archive

    Added in version 20.6.

  • can_delete_stories (bool | None, default: None) –

    Pass True, if the administrator can delete stories posted by other users.

    Added in version 20.6.

  • can_manage_direct_messages (bool | None, default: None) –

    Pass True, if the administrator can manage direct messages within the channel and decline suggested posts; for channels only

    Added in version 22.4.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async readBusinessMessage(business_connection_id, chat_id, message_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for read_business_message()

Return type:

bool

async read_business_message(business_connection_id, chat_id, message_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Marks incoming message as read on behalf of a business account. Requires the can_read_messages business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection on behalf of which to read the message.

  • chat_id (int) – Unique identifier of the chat in which the message was received. The chat must have been active in the last ~telegram.constants.BusinessLimit.CHAT_ACTIVITY_TIMEOUT seconds.

  • message_id (int) – Unique identifier of the message to mark as read.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async refundStarPayment(user_id, telegram_payment_charge_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for refund_star_payment()

Return type:

bool

async refund_star_payment(user_id, telegram_payment_charge_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Refunds a successful payment in |tg_stars|.

Added in version 21.3.

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

  • telegram_payment_charge_id (str) – Telegram payment identifier.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async removeBusinessAccountProfilePhoto(business_connection_id, is_public=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for remove_business_account_profile_photo()

Return type:

bool

async removeChatVerification(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for remove_chat_verification()

Return type:

bool

async removeUserVerification(user_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for remove_user_verification()

Return type:

bool

async remove_business_account_profile_photo(business_connection_id, is_public=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Removes the current profile photo of a managed business account. Requires the can_edit_profile_photo business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection.

  • is_public (bool | None, default: None) – Pass True to remove the public photo, which will be visible even if the main photo is hidden by the business account’s privacy settings. After the main photo is removed, the previous profile photo (if present) becomes the main photo.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async remove_chat_verification(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Removes verification from a chat that is currently verified |org-verify| represented by the bot.

Added in version 21.10.

Parameters:

chat_id (int | str) – |chat_id_channel|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async remove_user_verification(user_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Removes verification from a user who is currently verified |org-verify| represented by the bot.

Added in version 21.10.

Parameters:

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

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async reopenForumTopic(chat_id, message_thread_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for reopen_forum_topic()

Return type:

bool

async reopenGeneralForumTopic(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for reopen_general_forum_topic()

Return type:

bool

async reopen_forum_topic(chat_id, message_thread_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 ~telegram.ChatAdministratorRights.can_manage_topics administrator rights, unless it is the creator of the topic.

Added in version 20.0.

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async reopen_general_forum_topic(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to reopen a closed ‘General’ topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights. The topic will be automatically unhidden if it was hidden.

Added in version 20.0.

Parameters:

chat_id (str | int) – |chat_id_group|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async replaceStickerInSet(user_id, name, old_sticker, sticker, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for replace_sticker_in_set()

Return type:

bool

async replace_sticker_in_set(user_id, name, old_sticker, sticker, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to replace an existing sticker in a sticker set with a new one. The method is equivalent to calling delete_sticker_from_set(), then add_sticker_to_set(), then set_sticker_position_in_set().

Added in version 21.1.

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

  • name (str) – Sticker set name.

  • old_sticker (str | Sticker) –

    File identifier of the replaced sticker or the sticker object itself.

    Changed in version 21.10: Accepts also telegram.Sticker instances.

  • sticker (InputSticker) – An 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:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

property request: BaseRequest

The BaseRequest object used by this bot.

Warning

Requests to the Bot API are made by the various methods of this class. This attribute should not be used manually.

async restrictChatMember(chat_id, user_id, permissions, until_date=None, use_independent_chat_permissions=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for restrict_chat_member()

Return type:

bool

async restrict_chat_member(chat_id, user_id, permissions, until_date=None, use_independent_chat_permissions=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

Alias for revoke_chat_invite_link()

Return type:

ChatInviteLink

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

Added in version 13.4.

Parameters:
Returns:

ChatInviteLinktelegram.ChatInviteLink

Raises:

telegram.error.TelegramError

async savePreparedInlineMessage(user_id, result, allow_user_chats=None, allow_bot_chats=None, allow_group_chats=None, allow_channel_chats=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for save_prepared_inline_message()

Return type:

PreparedInlineMessage

async save_prepared_inline_message(user_id, result, allow_user_chats=None, allow_bot_chats=None, allow_group_chats=None, allow_channel_chats=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Stores a message that can be sent by a user of a Mini App.

Added in version 21.8.

Parameters:
  • user_id (int) – Unique identifier of the target user that can use the prepared message.

  • result (InlineQueryResult) – The result to store.

  • allow_user_chats (bool | None, default: None) – Pass True if the message can be sent to private chats with users

  • allow_bot_chats (bool | None, default: None) – Pass True if the message can be sent to private chats with bots

  • allow_group_chats (bool | None, default: None) – Pass True if the message can be sent to group and supergroup chats

  • allow_channel_chats (bool | None, default: None) – Pass True if the message can be sent to channels

Returns:

On success, the prepared message is returned.

Returns:

PreparedInlineMessage

Raises:

telegram.error.TelegramError

async sendAnimation(chat_id, animation, duration=None, width=None, height=None, caption=None, parse_mode=None, disable_notification=None, reply_markup=None, caption_entities=None, protect_content=None, message_thread_id=None, has_spoiler=None, thumbnail=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, show_caption_above_media=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_animation()

Return type:

Message

async sendAudio(chat_id, audio, duration=None, performer=None, title=None, caption=None, disable_notification=None, reply_markup=None, parse_mode=None, caption_entities=None, protect_content=None, message_thread_id=None, thumbnail=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_audio()

Return type:

Message

async sendChatAction(chat_id, action, message_thread_id=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_chat_action()

Return type:

bool

async sendChecklist(business_connection_id, chat_id, checklist, disable_notification=None, protect_content=None, message_effect_id=None, reply_parameters=None, reply_markup=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_checklist()

Return type:

Message

async sendContact(chat_id, phone_number=None, first_name=None, last_name=None, disable_notification=None, reply_markup=None, vcard=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, contact=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_contact()

Return type:

Message

async sendDice(chat_id, disable_notification=None, reply_markup=None, emoji=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_dice()

Return type:

Message

async sendDocument(chat_id, document, caption=None, disable_notification=None, reply_markup=None, parse_mode=None, disable_content_type_detection=None, caption_entities=None, protect_content=None, message_thread_id=None, thumbnail=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_document()

Return type:

Message

async sendGame(chat_id, game_short_name, disable_notification=None, reply_markup=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_game()

Return type:

Message

async sendGift(gift_id, text=None, text_parse_mode=None, text_entities=None, pay_for_upgrade=None, chat_id=None, user_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_gift()

Return type:

bool

async sendInvoice(chat_id, title, description, payload, currency, prices, provider_token=None, start_parameter=None, photo_url=None, photo_size=None, photo_width=None, photo_height=None, need_name=None, need_phone_number=None, need_email=None, need_shipping_address=None, is_flexible=None, disable_notification=None, reply_markup=None, provider_data=None, send_phone_number_to_provider=None, send_email_to_provider=None, max_tip_amount=None, suggested_tip_amounts=None, protect_content=None, message_thread_id=None, reply_parameters=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_invoice()

Return type:

Message

async sendLocation(chat_id, latitude=None, longitude=None, disable_notification=None, reply_markup=None, live_period=None, horizontal_accuracy=None, heading=None, proximity_alert_radius=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, location=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_location()

Return type:

Message

async sendMediaGroup(chat_id, media, disable_notification=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None, caption=None, parse_mode=None, caption_entities=None)

Alias for send_media_group()

Return type:

tuple[Message, ...]

async sendMessage(chat_id, text, parse_mode=None, entities=None, disable_notification=None, protect_content=None, reply_markup=None, message_thread_id=None, link_preview_options=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, disable_web_page_preview=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_message()

Return type:

Message

async sendPaidMedia(chat_id, star_count, media, caption=None, parse_mode=None, caption_entities=None, show_caption_above_media=None, disable_notification=None, protect_content=None, reply_parameters=None, reply_markup=None, business_connection_id=None, payload=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, message_thread_id=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_paid_media()

Return type:

Message

async sendPhoto(chat_id, photo, caption=None, disable_notification=None, reply_markup=None, parse_mode=None, caption_entities=None, protect_content=None, message_thread_id=None, has_spoiler=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, show_caption_above_media=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_photo()

Return type:

Message

async sendPoll(chat_id, question, options, is_anonymous=None, type=None, allows_multiple_answers=None, correct_option_id=None, is_closed=None, disable_notification=None, reply_markup=None, explanation=None, explanation_parse_mode=None, open_period=None, close_date=None, explanation_entities=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, question_parse_mode=None, question_entities=None, message_effect_id=None, allow_paid_broadcast=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_poll()

Return type:

Message

async sendSticker(chat_id, sticker, disable_notification=None, reply_markup=None, protect_content=None, message_thread_id=None, emoji=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_sticker()

Return type:

Message

async sendVenue(chat_id, latitude=None, longitude=None, title=None, address=None, foursquare_id=None, disable_notification=None, reply_markup=None, foursquare_type=None, google_place_id=None, google_place_type=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, venue=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_venue()

Return type:

Message

async sendVideo(chat_id, video, duration=None, caption=None, disable_notification=None, reply_markup=None, width=None, height=None, parse_mode=None, supports_streaming=None, caption_entities=None, protect_content=None, message_thread_id=None, has_spoiler=None, thumbnail=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, show_caption_above_media=None, cover=None, start_timestamp=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_video()

Return type:

Message

async sendVideoNote(chat_id, video_note, duration=None, length=None, disable_notification=None, reply_markup=None, protect_content=None, message_thread_id=None, thumbnail=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_video_note()

Return type:

Message

async sendVoice(chat_id, voice, duration=None, caption=None, disable_notification=None, reply_markup=None, parse_mode=None, caption_entities=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for send_voice()

Return type:

Message

async send_animation(chat_id, animation, duration=None, width=None, height=None, caption=None, parse_mode=None, disable_notification=None, reply_markup=None, caption_entities=None, protect_content=None, message_thread_id=None, has_spoiler=None, thumbnail=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, show_caption_above_media=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). Bots can currently send animation files of up to telegram.constants.FileSizeLimit.FILESIZE_UPLOAD in size, this limit may be changed in the future.

Note

thumbnail will be ignored for small files, for which Telegram can easily generate thumbnails. However, this behaviour is undocumented and might be changed by Telegram.

See also

Working with Files and Media <Working-with-Files-and-Media>

Changed in version 20.5: Removed deprecated argument thumb. Use thumbnail instead.

Parameters:
Keyword Arguments:
  • allow_sending_without_reply (bool, optional) –

    |allow_sending_without_reply| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • reply_to_message_id (int, optional) –

    |reply_to_msg_id| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • filename (str, optional) –

    Custom file name for the animation, when uploading a new file. Convenience parameter, useful e.g. when sending files generated by the tempfile module.

    Added in version 13.1.

Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_audio(chat_id, audio, duration=None, performer=None, title=None, caption=None, disable_notification=None, reply_markup=None, parse_mode=None, caption_entities=None, protect_content=None, message_thread_id=None, thumbnail=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Bots can currently send audio files of up to telegram.constants.FileSizeLimit.FILESIZE_UPLOAD in size, this limit may be changed in the future.

For sending voice messages, use the send_voice() method instead.

See also

Working with Files and Media <Working-with-Files-and-Media>

Changed in version 20.5: Removed deprecated argument thumb. Use thumbnail instead.

Parameters:
Keyword Arguments:
  • allow_sending_without_reply (bool, optional) –

    |allow_sending_without_reply| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • reply_to_message_id (int, optional) –

    |reply_to_msg_id| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • filename (str, optional) –

    Custom file name for the audio, when uploading a new file. Convenience parameter, useful e.g. when sending files generated by the tempfile module.

    Added in version 13.1.

Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_chat_action(chat_id, action, message_thread_id=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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). Telegram only recommends using this method when a response from the bot will take a noticeable amount of time to arrive.

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async send_checklist(business_connection_id, chat_id, checklist, disable_notification=None, protect_content=None, message_effect_id=None, reply_parameters=None, reply_markup=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send a checklist on behalf of a connected business account.

Added in version 22.3.

Parameters:
Keyword Arguments:
  • allow_sending_without_reply (bool, optional) – |allow_sending_without_reply| Mutually exclusive with reply_parameters, which this is a convenience parameter for

  • reply_to_message_id (int, optional) – |reply_to_msg_id| Mutually exclusive with reply_parameters, which this is a convenience parameter for

Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_contact(chat_id, phone_number=None, first_name=None, last_name=None, disable_notification=None, reply_markup=None, vcard=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, contact=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send phone contacts.

Note

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

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • phone_number (str | None, default: None) – Contact’s phone number.

  • first_name (str | None, default: None) – Contact’s first name.

  • last_name (str | None, default: None) – Contact’s last name.

  • vcard (str | None, default: None) – Additional data about the contact in the form of a vCard, 0-telegram.constants.ContactLimit.VCARD bytes.

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_dice(chat_id, disable_notification=None, reply_markup=None, emoji=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send an animated emoji that will display a random value.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user

  • emoji (str | None, default: None) –

    Emoji on which the dice throw animation is based. Currently, must be one of telegram.constants.DiceEmoji. Dice can have values telegram.Dice.MIN_VALUE-telegram.Dice.MAX_VALUE_BOWLING for telegram.Dice.DICE, telegram.Dice.DARTS and telegram.Dice.BOWLING, values telegram.Dice.MIN_VALUE-telegram.Dice.MAX_VALUE_BASKETBALL for telegram.Dice.BASKETBALL and telegram.Dice.FOOTBALL, and values telegram.Dice.MIN_VALUE- telegram.Dice.MAX_VALUE_SLOT_MACHINE for telegram.Dice.SLOT_MACHINE. Defaults to telegram.Dice.DICE.

    Changed in version 13.4: Added the telegram.Dice.BOWLING emoji.

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_document(chat_id, document, caption=None, disable_notification=None, reply_markup=None, parse_mode=None, disable_content_type_detection=None, caption_entities=None, protect_content=None, message_thread_id=None, thumbnail=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send general files.

Bots can currently send files of any type of up to telegram.constants.FileSizeLimit.FILESIZE_UPLOAD in size, this limit may be changed in the future.

See also

Working with Files and Media <Working-with-Files-and-Media>

Changed in version 20.5: Removed deprecated argument thumb. Use thumbnail instead.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • document (str | Path | IO[bytes] | InputFile | bytes | Document) –

    File to send. |fileinput| Lastly you can pass an existing telegram.Document object to send.

    Note

    Sending by URL will currently only work GIF, PDF & ZIP files.

    Changed in version 13.2: Accept bytes as input.

    Changed in version 20.0: File paths as input is also accepted for bots not running in ~telegram.Bot.local_mode.

  • caption (str | None, default: None) – Document caption (may also be used when resending documents by file_id), 0-telegram.constants.MessageLimit.CAPTION_LENGTH characters after entities parsing.

  • disable_content_type_detection (bool | None, default: None) – Disables automatic server-side content type detection for files uploaded using multipart/form-data.

  • parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – |parse_mode|

  • caption_entities (Sequence[MessageEntity] | None, default: None) –

    |caption_entities|

    Changed in version 20.0: |sequenceargs|

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • thumbnail (str | Path | IO[bytes] | InputFile | bytes | None, default: None) –

    |thumbdocstring|

    Added in version 20.2.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
  • allow_sending_without_reply (bool, optional) –

    |allow_sending_without_reply| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • reply_to_message_id (int, optional) –

    |reply_to_msg_id| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • filename (str, optional) – Custom file name for the document, when uploading a new file. Convenience parameter, useful e.g. when sending files generated by the tempfile module.

Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_game(chat_id, game_short_name, disable_notification=None, reply_markup=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send a game.

Parameters:
  • chat_id (int) – Unique identifier for the target chat.

  • 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 (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | None, default: None) – An object for a new inline keyboard. If empty, one “Play game_title” button will be shown. If not empty, the first button must launch the game.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

Keyword Arguments:
Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_gift(gift_id, text=None, text_parse_mode=None, text_entities=None, pay_for_upgrade=None, chat_id=None, user_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Sends a gift to the given user or channel chat. The gift can’t be converted to Telegram Stars by the receiver.

Added in version 21.8.

Changed in version 22.1: Bot API 8.3 made user_id optional. In version 22.1, the methods signature was changed accordingly.

Parameters:
  • gift_id (str | Gift) – Identifier of the gift or a Gift object

  • user_id (int | None, default: None) –

    Required if chat_id is not specified. Unique identifier of the target user that will receive the gift.

    Changed in version 21.11: Now optional.

  • chat_id (int | str | None, default: None) –

    Required if user_id is not specified. |chat_id_channel| It will receive the gift.

    Added in version 21.11.

  • text (str | None, default: None) – Text that will be shown along with the gift; 0- telegram.constants.GiftLimit.MAX_TEXT_LENGTH characters

  • text_parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – Mode for parsing entities. See telegram.constants.ParseMode and formatting options for more details. Entities other than BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, SPOILER, and CUSTOM_EMOJI are ignored.

  • text_entities (Sequence[MessageEntity] | None, default: None) – A list of special entities that appear in the gift text. It can be specified instead of text_parse_mode. Entities other than BOLD, ITALIC, UNDERLINE, STRIKETHROUGH, SPOILER, and CUSTOM_EMOJI are ignored.

  • pay_for_upgrade (bool | None, default: None) –

    Pass True to pay for the gift upgrade from the bot’s balance, thereby making the upgrade free for the receiver.

    Added in version 21.10.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async send_invoice(chat_id, title, description, payload, currency, prices, provider_token=None, start_parameter=None, photo_url=None, photo_size=None, photo_width=None, photo_height=None, need_name=None, need_phone_number=None, need_email=None, need_shipping_address=None, is_flexible=None, disable_notification=None, reply_markup=None, provider_data=None, send_phone_number_to_provider=None, send_email_to_provider=None, max_tip_amount=None, suggested_tip_amounts=None, protect_content=None, message_thread_id=None, reply_parameters=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send invoices.

Warning

As of API 5.2 start_parameter is an optional argument and therefore the order of the arguments had to be changed. Use keyword arguments to make sure that the arguments are passed correctly.

Changed in version 13.5: As of Bot API 5.2, the parameter start_parameter is optional.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • title (str) – Product name. telegram.Invoice.MIN_TITLE_LENGTH- telegram.Invoice.MAX_TITLE_LENGTH characters.

  • description (str) – Product description. telegram.Invoice.MIN_DESCRIPTION_LENGTH- telegram.Invoice.MAX_DESCRIPTION_LENGTH characters.

  • payload (str) – Bot-defined invoice payload. telegram.Invoice.MIN_PAYLOAD_LENGTH- telegram.Invoice.MAX_PAYLOAD_LENGTH bytes. This will not be displayed to the user, use it for your internal processes.

  • provider_token (str | None, default: None) –

    Payments provider token, obtained via @BotFather. Pass an empty string for payments in |tg_stars|.

    Changed in version 21.11: Bot API 7.4 made this parameter is optional and this is now reflected in the function signature.

  • currency (str) –

    Three-letter ISO 4217 currency code, see more on currencies. Pass XTR for payment in |tg_stars|.

  • prices (Sequence[LabeledPrice]) –

    Price breakdown, a sequence of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.). Must contain exactly one item for payment in |tg_stars|.

    Changed in version 20.0: |sequenceargs|

  • max_tip_amount (int | None, default: None) –

    The maximum accepted amount for tips in the smallest units of the currency (integer, not float/double). For example, for a maximum tip of US$ 1.45 pass max_tip_amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to 0. Not supported for payment in |tg_stars|.

    Added in version 13.5.

  • suggested_tip_amounts (Sequence[int] | None, default: None) –

    An array of suggested amounts of tips in the smallest units of the currency (integer, not float/double). At most telegram.Invoice.MAX_TIP_AMOUNTS 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.

    Added in version 13.5.

    Changed in version 20.0: |sequenceargs|

  • start_parameter (str | None, default: None) –

    Unique deep-linking parameter. If left empty, forwarded copies of the sent message will have a Pay button, allowing multiple users to pay directly from the forwarded message, using the same invoice. If non-empty, forwarded copies of the sent message will have a URL button with a deep link to the bot (instead of a Pay button), with the value used as the start parameter.

    Changed in version 13.5: As of Bot API 5.2, this parameter is optional.

  • provider_data (str | object | None, default: None) – data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider. When an object is passed, it will be encoded as JSON.

  • photo_url (str | None, default: None) – 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 | None, default: None) – Photo size.

  • photo_width (int | None, default: None) – Photo width.

  • photo_height (int | None, default: None) – Photo height.

  • need_name (bool | None, default: None) – Pass True, if you require the user’s full name to complete the order. Ignored for payments in |tg_stars|.

  • need_phone_number (bool | None, default: None) – Pass True, if you require the user’s phone number to complete the order. Ignored for payments in |tg_stars|.

  • need_email (bool | None, default: None) – Pass True, if you require the user’s email to complete the order. Ignored for payments in |tg_stars|.

  • need_shipping_address (bool | None, default: None) – Pass True, if you require the user’s shipping address to complete the order. Ignored for payments in |tg_stars|.

  • send_phone_number_to_provider (bool | None, default: None) – Pass True, if user’s phone number should be sent to provider. Ignored for payments in |tg_stars|.

  • send_email_to_provider (bool | None, default: None) – Pass True, if user’s email address should be sent to provider. Ignored for payments in |tg_stars|.

  • is_flexible (bool | None, default: None) – Pass True, if the final price depends on the shipping method. Ignored for payments in |tg_stars|.

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | None, default: None) – An 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.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_location(chat_id, latitude=None, longitude=None, disable_notification=None, reply_markup=None, live_period=None, horizontal_accuracy=None, heading=None, proximity_alert_radius=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, location=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send point on the map.

Note

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

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • latitude (float | None, default: None) – Latitude of location.

  • longitude (float | None, default: None) – Longitude of location.

  • horizontal_accuracy (float | None, default: None) – The radius of uncertainty for the location, measured in meters; 0-telegram.constants.LocationLimit.HORIZONTAL_ACCURACY.

  • live_period (int | timedelta | None, default: None) –

    Period in seconds for which the location will be updated, should be between telegram.constants.LocationLimit.MIN_LIVE_PERIOD and telegram.constants.LocationLimit.MAX_LIVE_PERIOD, or telegram.constants.LocationLimit.LIVE_PERIOD_FOREVER for live locations that can be edited indefinitely.

    Changed in version 21.11: |time-period-input|

  • heading (int | None, default: None) – For live locations, a direction in which the user is moving, in degrees. Must be between telegram.constants.LocationLimit.MIN_HEADING and telegram.constants.LocationLimit.MAX_HEADING if specified.

  • proximity_alert_radius (int | None, default: None) – For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. Must be between telegram.constants.LocationLimit.MIN_PROXIMITY_ALERT_RADIUS and telegram.constants.LocationLimit.MAX_PROXIMITY_ALERT_RADIUS if specified.

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_media_group(chat_id, media, disable_notification=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None, caption=None, parse_mode=None, caption_entities=None)[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.

Note

If you supply a caption (along with either parse_mode or caption_entities), then items in media must have no captions, and vice versa.

See also

Working with Files and Media <Working-with-Files-and-Media>

Changed in version 20.0: Returns a tuple instead of a list.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • media (Sequence[InputMediaAudio | InputMediaDocument | InputMediaPhoto | InputMediaVideo]) –

    An array describing messages to be sent, must include telegram.constants.MediaGroupLimit.MIN_MEDIA_LENGTH- telegram.constants.MediaGroupLimit.MAX_MEDIA_LENGTH items.

    Changed in version 20.0: |sequenceargs|

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • direct_messages_topic_id (int | None, default: None) –

    Identifier of the direct messages topic to which the messages will be sent; required if the messages are sent to a direct messages chat.

    Added in version 22.4.

Keyword Arguments:
  • allow_sending_without_reply (bool, optional) –

    |allow_sending_without_reply| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • reply_to_message_id (int, optional) –

    |reply_to_msg_id| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • caption (str, optional) –

    Caption that will be added to the first element of media, so that it will be used as caption for the whole media group. Defaults to None.

    Added in version 20.0.

  • parse_mode (str | None, optional) –

    Parse mode for caption. See the constants in telegram.constants.ParseMode for the available modes.

    Added in version 20.0.

  • caption_entities (Sequence[telegram.MessageEntity], optional) –

    List of special entities for caption, which can be specified instead of parse_mode. Defaults to None.

    Added in version 20.0.

Returns:

An array of the sent Messages.

Returns:

tuple[Message, ...]

Raises:

telegram.error.TelegramError

async send_message(chat_id, text, parse_mode=None, entities=None, disable_notification=None, protect_content=None, reply_markup=None, message_thread_id=None, link_preview_options=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, disable_web_page_preview=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send text messages.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • text (str) – Text of the message to be sent. Max telegram.constants.MessageLimit.MAX_TEXT_LENGTH characters after entities parsing.

  • parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – |parse_mode|

  • entities (Sequence[MessageEntity] | None, default: None) –

    Sequence of special entities that appear in message text, which can be specified instead of parse_mode.

    Changed in version 20.0: |sequenceargs|

  • link_preview_options (DefaultValue[DVValueType] | LinkPreviewOptions | DefaultValue[None] | None, default: None) –

    Link preview generation options for the message. Mutually exclusive with disable_web_page_preview.

    Added in version 20.8.

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
  • allow_sending_without_reply (bool, optional) –

    |allow_sending_without_reply| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • reply_to_message_id (int, optional) –

    |reply_to_msg_id| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • disable_web_page_preview (bool, optional) –

    Disables link previews for links in this message. Convenience parameter for setting link_preview_options. Mutually exclusive with link_preview_options.

    Changed in version 20.8: Bot API 7.0 introduced link_preview_options replacing this argument. PTB will automatically convert this argument to that one, but for advanced options, please use link_preview_options directly.

    Changed in version 21.0: |keyword_only_arg|

Returns:

On success, the sent message is returned.

Returns:

Message

Raises:
async send_paid_media(chat_id, star_count, media, caption=None, parse_mode=None, caption_entities=None, show_caption_above_media=None, disable_notification=None, protect_content=None, reply_parameters=None, reply_markup=None, business_connection_id=None, payload=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, message_thread_id=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send paid media.

Added in version 21.4.

Parameters:
  • chat_id (str | int) – |chat_id_channel| If the chat is a channel, all Telegram Star proceeds from this media will be credited to the chat’s balance. Otherwise, they will be credited to the bot’s balance.

  • star_count (int) – The number of Telegram Stars that must be paid to buy access to the media; telegram.constants.InvoiceLimit.MIN_STAR_COUNT - telegram.constants.InvoiceLimit.MAX_STAR_COUNT.

  • media (Sequence[InputPaidMedia]) – A list describing the media to be sent; up to telegram.constants.MediaGroupLimit.MAX_MEDIA_LENGTH items.

  • payload (str | None, default: None) –

    Bot-defined paid media payload, 0-telegram.constants.InvoiceLimit.MAX_PAYLOAD_LENGTH bytes. This will not be displayed to the user, use it for your internal processes.

    Added in version 21.6.

  • caption (str | None, default: None) – Caption of the media to be sent, 0-telegram.constants.MessageLimit.CAPTION_LENGTH characters.

  • parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – |parse_mode|

  • caption_entities (Sequence[MessageEntity] | None, default: None) – |caption_entities|

  • show_caption_above_media (bool | None, default: None) – Pass |show_cap_above_med|

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |protect_content|

  • reply_parameters (ReplyParameters | None, default: None) – |reply_parameters|

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.5.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 22.4.

Keyword Arguments:
  • allow_sending_without_reply (bool, optional) – |allow_sending_without_reply| Mutually exclusive with reply_parameters, which this is a convenience parameter for

  • reply_to_message_id (int, optional) – |reply_to_msg_id| Mutually exclusive with reply_parameters, which this is a convenience parameter for

Returns:

On success, the sent message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_photo(chat_id, photo, caption=None, disable_notification=None, reply_markup=None, parse_mode=None, caption_entities=None, protect_content=None, message_thread_id=None, has_spoiler=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, show_caption_above_media=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send photos.

See also

Working with Files and Media <Working-with-Files-and-Media>

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • photo (str | Path | IO[bytes] | InputFile | bytes | PhotoSize) –

    Photo to send. |fileinput| Lastly you can pass an existing telegram.PhotoSize object to send.

    Caution

    • The photo must be at most 10MB in size.

    • The photo’s width and height must not exceed 10000 in total.

    • Width and height ratio must be at most 20.

    Changed in version 13.2: Accept bytes as input.

    Changed in version 20.0: File paths as input is also accepted for bots not running in ~telegram.Bot.local_mode.

  • caption (str | None, default: None) – Photo caption (may also be used when resending photos by file_id), 0-telegram.constants.MessageLimit.CAPTION_LENGTH characters after entities parsing.

  • parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – |parse_mode|

  • caption_entities (Sequence[MessageEntity] | None, default: None) –

    |caption_entities|

    Changed in version 20.0: |sequenceargs|

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • has_spoiler (bool | None, default: None) –

    Pass True if the photo needs to be covered with a spoiler animation.

    Added in version 20.0.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • show_caption_above_media (bool | None, default: None) –

    Pass |show_cap_above_med|

    Added in version 21.3.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
  • allow_sending_without_reply (bool, optional) –

    |allow_sending_without_reply| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • reply_to_message_id (int, optional) –

    |reply_to_msg_id| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • filename (str, optional) –

    Custom file name for the photo, when uploading a new file. Convenience parameter, useful e.g. when sending files generated by the tempfile module.

    Added in version 13.1.

Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_poll(chat_id, question, options, is_anonymous=None, type=None, allows_multiple_answers=None, correct_option_id=None, is_closed=None, disable_notification=None, reply_markup=None, explanation=None, explanation_parse_mode=None, open_period=None, close_date=None, explanation_entities=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, question_parse_mode=None, question_entities=None, message_effect_id=None, allow_paid_broadcast=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send a native poll.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • question (str) – Poll question, telegram.Poll.MIN_QUESTION_LENGTH- telegram.Poll.MAX_QUESTION_LENGTH characters.

  • options (Sequence[str | InputPollOption]) –

    Sequence of telegram.Poll.MIN_OPTION_NUMBER- telegram.Poll.MAX_OPTION_NUMBER answer options. Each option may either be a string with telegram.Poll.MIN_OPTION_LENGTH- telegram.Poll.MAX_OPTION_LENGTH characters or an InputPollOption object. Strings are converted to InputPollOption objects automatically.

    Changed in version 20.0: |sequenceargs|

    Changed in version 21.2: Bot API 7.3 adds support for InputPollOption objects.

  • is_anonymous (bool | None, default: None) – True, if the poll needs to be anonymous, defaults to True.

  • type (str | None, default: None) – Poll type, telegram.Poll.QUIZ or telegram.Poll.REGULAR, defaults to telegram.Poll.REGULAR.

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

  • correct_option_id (Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | None, default: None) – 0-based identifier of the correct answer option, required for polls in quiz mode.

  • explanation (str | None, default: None) – Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-telegram.Poll.MAX_EXPLANATION_LENGTH characters with at most telegram.Poll.MAX_EXPLANATION_LINE_FEEDS line feeds after entities parsing.

  • explanation_parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – Mode for parsing entities in the explanation. See the constants in telegram.constants.ParseMode for the available modes.

  • explanation_entities (Sequence[MessageEntity] | None, default: None) –

    Sequence of special entities that appear in message text, which can be specified instead of explanation_parse_mode.

    Changed in version 20.0: |sequenceargs|

  • open_period (int | timedelta | None, default: None) –

    Amount of time in seconds the poll will be active after creation, telegram.Poll.MIN_OPEN_PERIOD- telegram.Poll.MAX_OPEN_PERIOD. Can’t be used together with close_date.

    Changed in version 21.11: |time-period-input|

  • close_date (int | datetime | None, default: None) – Point in time (Unix timestamp) when the poll will be automatically closed. Must be at least telegram.Poll.MIN_OPEN_PERIOD and no more than telegram.Poll.MAX_OPEN_PERIOD seconds in the future. Can’t be used together with open_period. |tz-naive-dtms|

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

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • question_parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) –

    Mode for parsing entities in the question. See the constants in telegram.constants.ParseMode for the available modes. Currently, only custom emoji entities are allowed.

    Added in version 21.2.

  • question_entities (Sequence[MessageEntity] | None, default: None) –

    Special entities that appear in the poll question. It can be specified instead of question_parse_mode.

    Added in version 21.2.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

Keyword Arguments:
Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_sticker(chat_id, sticker, disable_notification=None, reply_markup=None, protect_content=None, message_thread_id=None, emoji=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send static .WEBP, animated .TGS, or video .WEBM stickers.

See also

Working with Files and Media <Working-with-Files-and-Media>

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • sticker (str | Path | IO[bytes] | InputFile | bytes | Sticker) –

    Sticker to send. |fileinput| Video stickers can only be sent by a file_id. Video and animated stickers can’t be sent via an HTTP URL.

    Lastly you can pass an existing telegram.Sticker object to send.

    Changed in version 13.2: Accept bytes as input.

    Changed in version 20.0: File paths as input is also accepted for bots not running in ~telegram.Bot.local_mode.

  • emoji (str | None, default: None) –

    Emoji associated with the sticker; only for just uploaded stickers

    Added in version 20.2.

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_venue(chat_id, latitude=None, longitude=None, title=None, address=None, foursquare_id=None, disable_notification=None, reply_markup=None, foursquare_type=None, google_place_id=None, google_place_type=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, venue=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to send information about a venue.

Note

  • You can either supply venue, or latitude, longitude, title and address and optionally foursquare_id and foursquare_type or optionally google_place_id and google_place_type.

  • Foursquare details and Google Place details are mutually exclusive. However, this behaviour is undocumented and might be changed by Telegram.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • latitude (float | None, default: None) – Latitude of venue.

  • longitude (float | None, default: None) – Longitude of venue.

  • title (str | None, default: None) – Name of the venue.

  • address (str | None, default: None) – Address of the venue.

  • foursquare_id (str | None, default: None) – Foursquare identifier of the venue.

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

  • google_place_id (str | None, default: None) – Google Places identifier of the venue.

  • google_place_type (str | None, default: None) –

    Google Places type of the venue. (See supported types.)

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_video(chat_id, video, duration=None, caption=None, disable_notification=None, reply_markup=None, width=None, height=None, parse_mode=None, supports_streaming=None, caption_entities=None, protect_content=None, message_thread_id=None, has_spoiler=None, thumbnail=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, show_caption_above_media=None, cover=None, start_timestamp=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Bots can currently send video files of up to telegram.constants.FileSizeLimit.FILESIZE_UPLOAD in size, this limit may be changed in the future.

Note

thumbnail will be ignored for small video files, for which Telegram can easily generate thumbnails. However, this behaviour is undocumented and might be changed by Telegram.

See also

Working with Files and Media <Working-with-Files-and-Media>

Changed in version 20.5: Removed deprecated argument thumb. Use thumbnail instead.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • video (str | Path | IO[bytes] | InputFile | bytes | Video) –

    Video file to send. |fileinput| Lastly you can pass an existing telegram.Video object to send.

    Changed in version 13.2: Accept bytes as input.

    Changed in version 20.0: File paths as input is also accepted for bots not running in ~telegram.Bot.local_mode.

  • duration (int | timedelta | None, default: None) –

    Duration of sent video in seconds.

    Changed in version 21.11: |time-period-input|

  • width (int | None, default: None) – Video width.

  • height (int | None, default: None) – Video height.

  • cover (str | Path | IO[bytes] | InputFile | bytes | None, default: None) –

    Cover for the video in the message. |fileinputnopath|

    Added in version 21.11.

  • start_timestamp (int | None, default: None) –

    Start timestamp for the video in the message.

    Added in version 21.11.

  • caption (str | None, default: None) – Video caption (may also be used when resending videos by file_id), 0-telegram.constants.MessageLimit.CAPTION_LENGTH characters after entities parsing.

  • parse_mode (DefaultValue[DVValueType] | str | DefaultValue[None] | None, default: None) – |parse_mode|

  • caption_entities (Sequence[MessageEntity] | None, default: None) –

    |caption_entities|

    Changed in version 20.0: |sequenceargs|

  • supports_streaming (bool | None, default: None) – Pass True, if the uploaded video is suitable for streaming.

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • has_spoiler (bool | None, default: None) –

    Pass True if the video needs to be covered with a spoiler animation.

    Added in version 20.0.

  • thumbnail (str | Path | IO[bytes] | InputFile | bytes | None, default: None) –

    |thumbdocstring|

    Added in version 20.2.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • show_caption_above_media (bool | None, default: None) –

    Pass |show_cap_above_med|

    Added in version 21.3.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
  • allow_sending_without_reply (bool, optional) –

    |allow_sending_without_reply| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • reply_to_message_id (int, optional) –

    |reply_to_msg_id| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • filename (str, optional) –

    Custom file name for the video, when uploading a new file. Convenience parameter, useful e.g. when sending files generated by the tempfile module.

    Added in version 13.1.

Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_video_note(chat_id, video_note, duration=None, length=None, disable_notification=None, reply_markup=None, protect_content=None, message_thread_id=None, thumbnail=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Note

thumbnail will be ignored for small video files, for which Telegram can easily generate thumbnails. However, this behaviour is undocumented and might be changed by Telegram.

See also

Working with Files and Media <Working-with-Files-and-Media>

Changed in version 20.5: Removed deprecated argument thumb. Use thumbnail instead.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • video_note (str | Path | IO[bytes] | InputFile | bytes | VideoNote) –

    Video note to send. Pass a file_id as String to send a video note that exists on the Telegram servers (recommended) or upload a new video using multipart/form-data. |uploadinput| Lastly you can pass an existing telegram.VideoNote object to send. Sending video notes by a URL is currently unsupported.

    Changed in version 13.2: Accept bytes as input.

    Changed in version 20.0: File paths as input is also accepted for bots not running in ~telegram.Bot.local_mode.

  • duration (int | timedelta | None, default: None) –

    Duration of sent video in seconds.

    Changed in version 21.11: |time-period-input|

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

  • disable_notification (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) – |disable_notification|

  • protect_content (DefaultValue[DVValueType] | bool | DefaultValue[None] | None, default: None) –

    |protect_content|

    Added in version 13.10.

  • message_thread_id (int | None, default: None) –

    |message_thread_id_arg|

    Added in version 20.0.

  • reply_markup (InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply | None, default: None) – Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.

  • thumbnail (str | Path | IO[bytes] | InputFile | bytes | None, default: None) –

    |thumbdocstring|

    Added in version 20.2.

  • reply_parameters (ReplyParameters | None, default: None) –

    |reply_parameters|

    Added in version 20.8.

  • business_connection_id (str | None, default: None) –

    |business_id_str|

    Added in version 21.1.

  • message_effect_id (str | None, default: None) –

    |message_effect_id|

    Added in version 21.3.

  • allow_paid_broadcast (bool | None, default: None) –

    |allow_paid_broadcast|

    Added in version 21.7.

  • suggested_post_parameters (SuggestedPostParameters | None, default: None) –

    |suggested_post_parameters|

    Added in version 22.4.

  • direct_messages_topic_id (int | None, default: None) –

    |direct_messages_topic_id|

    Added in version 22.4.

Keyword Arguments:
  • allow_sending_without_reply (bool, optional) –

    |allow_sending_without_reply| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • reply_to_message_id (int, optional) –

    |reply_to_msg_id| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • filename (str, optional) –

    Custom file name for the video note, when uploading a new file. Convenience parameter, useful e.g. when sending files generated by the tempfile module.

    Added in version 13.1.

Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async send_voice(chat_id, voice, duration=None, caption=None, disable_notification=None, reply_markup=None, parse_mode=None, caption_entities=None, protect_content=None, message_thread_id=None, reply_parameters=None, business_connection_id=None, message_effect_id=None, allow_paid_broadcast=None, direct_messages_topic_id=None, suggested_post_parameters=None, *, allow_sending_without_reply=None, reply_to_message_id=None, filename=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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). Bots can currently send voice messages of up to telegram.constants.FileSizeLimit.FILESIZE_UPLOAD in size, this limit may be changed in the future.

Note

To use this method, the file must have the type audio/ogg and be no more than telegram.constants.FileSizeLimit.VOICE_NOTE_FILE_SIZE in size. telegram.constants.FileSizeLimit.VOICE_NOTE_FILE_SIZE- telegram.constants.FileSizeLimit.FILESIZE_DOWNLOAD voice notes will be sent as files.

See also

Working with Files and Media <Working-with-Files-and-Media>

Parameters:
Keyword Arguments:
  • allow_sending_without_reply (bool, optional) –

    |allow_sending_without_reply| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • reply_to_message_id (int, optional) –

    |reply_to_msg_id| Mutually exclusive with reply_parameters, which this is a convenience parameter for

    Changed in version 20.8: Bot API 7.0 introduced reply_parameters |rtm_aswr_deprecated|

    Changed in version 21.0: |keyword_only_arg|

  • filename (str, optional) –

    Custom file name for the voice, when uploading a new file. Convenience parameter, useful e.g. when sending files generated by the tempfile module.

    Added in version 13.1.

Returns:

On success, the sent Message is returned.

Returns:

Message

Raises:

telegram.error.TelegramError

async setBusinessAccountBio(business_connection_id, bio=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_business_account_bio()

Return type:

bool

async setBusinessAccountGiftSettings(business_connection_id, show_gift_button, accepted_gift_types, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_business_account_gift_settings()

Return type:

bool

async setBusinessAccountName(business_connection_id, first_name, last_name=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_business_account_name()

Return type:

bool

async setBusinessAccountProfilePhoto(business_connection_id, photo, is_public=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_business_account_profile_photo()

Return type:

bool

async setBusinessAccountUsername(business_connection_id, username=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_business_account_username()

Return type:

bool

async setChatAdministratorCustomTitle(chat_id, user_id, custom_title, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_chat_administrator_custom_title()

Return type:

bool

async setChatDescription(chat_id, description=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_chat_description()

Return type:

bool

async setChatMenuButton(chat_id=None, menu_button=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_chat_menu_button()

Return type:

bool

async setChatPermissions(chat_id, permissions, use_independent_chat_permissions=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_chat_permissions()

Return type:

bool

async setChatPhoto(chat_id, photo, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_chat_photo()

Return type:

bool

async setChatStickerSet(chat_id, sticker_set_name, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_chat_sticker_set()

Return type:

bool

async setChatTitle(chat_id, title, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_chat_title()

Return type:

bool

async setCustomEmojiStickerSetThumbnail(name, custom_emoji_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_custom_emoji_sticker_set_thumbnail()

Return type:

bool

async setGameScore(user_id, score, chat_id=None, message_id=None, inline_message_id=None, force=None, disable_edit_message=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_game_score()

Return type:

Message | bool

async setMessageReaction(chat_id, message_id, reaction=None, is_big=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_message_reaction()

Return type:

bool

async setMyCommands(commands, scope=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_my_commands()

Return type:

bool

async setMyDefaultAdministratorRights(rights=None, for_channels=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_my_default_administrator_rights()

Return type:

bool

async setMyDescription(description=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_my_description()

Return type:

bool

async setMyName(name=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_my_name()

Return type:

bool

async setMyShortDescription(short_description=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_my_short_description()

Return type:

bool

async setPassportDataErrors(user_id, errors, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_passport_data_errors()

Return type:

bool

async setStickerEmojiList(sticker, emoji_list, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_sticker_emoji_list()

Return type:

bool

async setStickerKeywords(sticker, keywords=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_sticker_keywords()

Return type:

bool

async setStickerMaskPosition(sticker, mask_position=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_sticker_mask_position()

Return type:

bool

async setStickerPositionInSet(sticker, position, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_sticker_position_in_set()

Return type:

bool

async setStickerSetThumbnail(name, user_id, format, thumbnail=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_sticker_set_thumbnail()

Return type:

bool

async setStickerSetTitle(name, title, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_sticker_set_title()

Return type:

bool

async setUserEmojiStatus(user_id, emoji_status_custom_emoji_id=None, emoji_status_expiration_date=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_user_emoji_status()

Return type:

bool

async setWebhook(url, certificate=None, max_connections=None, allowed_updates=None, ip_address=None, drop_pending_updates=None, secret_token=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for set_webhook()

Return type:

bool

async set_business_account_bio(business_connection_id, bio=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Changes the bio of a managed business account. Requires the can_edit_bio business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection.

  • bio (str | None, default: None) – The new value of the bio for the business account; 0-telegram.constants.BusinessLimit.MAX_BIO_LENGTH characters.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_business_account_gift_settings(business_connection_id, show_gift_button, accepted_gift_types, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Changes the privacy settings pertaining to incoming gifts in a managed business account. Requires the can_change_gift_settings business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection

  • show_gift_button (bool) – Pass True, if a button for sending a gift to the user or by the business account must always be shown in the input field.

  • accepted_gift_types (AcceptedGiftTypes) – Types of gifts accepted by the business account.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_business_account_name(business_connection_id, first_name, last_name=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Changes the first and last name of a managed business account. Requires the can_edit_name business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection

  • first_name (str) – New first name of the business account; telegram.constants.BusinessLimit.MIN_NAME_LENGTH- telegram.constants.BusinessLimit.MAX_NAME_LENGTH characters.

  • last_name (str | None, default: None) – New last name of the business account; 0-telegram.constants.BusinessLimit.MAX_NAME_LENGTH characters.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_business_account_profile_photo(business_connection_id, photo, is_public=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Changes the profile photo of a managed business account. Requires the can_edit_profile_photo business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection.

  • photo (InputProfilePhoto) – The new profile photo to set.

  • is_public (bool | None, default: None) – Pass True to set the public photo, which will be visible even if the main photo is hidden by the business account’s privacy settings. An account can have only one public photo.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_business_account_username(business_connection_id, username=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Changes the username of a managed business account. Requires the can_edit_username business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection.

  • username (str | None, default: None) – New business account username; 0-telegram.constants.BusinessLimit.MAX_USERNAME_LENGTH characters.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_chat_administrator_custom_title(chat_id, user_id, custom_title, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to set a custom title for administrators promoted by the bot in a supergroup. The bot must be an administrator for this to work.

Parameters:
  • chat_id (int | str) – |chat_id_group|

  • user_id (int) – Unique identifier of the target administrator.

  • custom_title (str) – New custom title for the administrator; 0-telegram.constants.ChatLimit.CHAT_ADMINISTRATOR_CUSTOM_TITLE_LENGTH characters, emoji are not allowed.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_chat_description(chat_id, description=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Parameters:
  • chat_id (str | int) – |chat_id_channel|

  • description (str | None, default: None) – New chat description, 0-telegram.constants.ChatLimit.CHAT_DESCRIPTION_LENGTH characters.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_chat_menu_button(chat_id=None, menu_button=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 20.0.

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

  • menu_button (MenuButton | None, default: None) – An object for the new bot’s menu button. Defaults to telegram.MenuButtonDefault.

Returns:

On success, True is returned.

Returns:

bool

async set_chat_permissions(chat_id, permissions, use_independent_chat_permissions=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 telegram.ChatMemberAdministrator.can_restrict_members admin rights.

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_chat_photo(chat_id, photo, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_chat_sticker_set(chat_id, sticker_set_name, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to set a new group sticker set for a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Use the field telegram.ChatFullInfo.can_set_sticker_set optionally returned in get_chat() requests to check if the bot can use this method.

Parameters:
  • chat_id (str | int) – |chat_id_group|

  • sticker_set_name (str) – Name of the sticker set to be set as the group sticker set.

Returns:

On success, True is returned.

Returns:

bool

async set_chat_title(chat_id, title, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Parameters:
  • chat_id (str | int) – |chat_id_channel|

  • title (str) – New chat title, telegram.constants.ChatLimit.MIN_CHAT_TITLE_LENGTH- telegram.constants.ChatLimit.MAX_CHAT_TITLE_LENGTH characters.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_custom_emoji_sticker_set_thumbnail(name, custom_emoji_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to set the thumbnail of a custom emoji sticker set.

Added in version 20.2.

Parameters:
  • name (str) – Sticker set name.

  • custom_emoji_id (str | None, default: None) – 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:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_game_score(user_id, score, chat_id=None, message_id=None, inline_message_id=None, force=None, disable_edit_message=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Parameters:
  • user_id (int) – User identifier.

  • score (int) – New score, must be non-negative.

  • force (bool | None, default: None) – Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters.

  • disable_edit_message (bool | None, default: None) – Pass True, if the game message should not be automatically edited to include the current scoreboard.

  • chat_id (int | None, default: None) – Required if inline_message_id is not specified. Unique identifier for the target chat.

  • message_id (int | None, default: None) – Required if inline_message_id is not specified. Identifier of the sent message.

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

Returns:

The edited message. If the message is not an inline message , True.

Returns:

Message | bool

Raises:

telegram.error.TelegramError – If the new score is not greater than the user’s current score in the chat and force is False.

async set_message_reaction(chat_id, message_id, reaction=None, is_big=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to change the chosen reactions on a message. Service messages of some types 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. Bots can’t use paid reactions.

Added in version 20.8.

Parameters:
  • chat_id (str | int) – |chat_id_channel|

  • message_id (int) – Identifier of the target message. If the message belongs to a media group, the reaction is set to the first non-deleted message in the group instead.

  • reaction (Sequence[ReactionType | str] | ReactionType | str | None, default: None) –

    A 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. Paid reactions can’t be used by bots.

    Tip

    Passed str values will be converted to either telegram.ReactionTypeEmoji or telegram.ReactionTypeCustomEmoji depending on whether they are listed in ReactionEmoji.

  • is_big (bool | None, default: None) – Pass True to set the reaction with a big animation.

Returns:

boolbool On success, True is returned.

Raises:

telegram.error.TelegramError

async set_my_commands(commands, scope=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to change the list of the bot’s commands. See the Telegram docs for more details about bot commands.

Parameters:
  • commands (Sequence[BotCommand | tuple[str, str]]) –

    A sequence of bot commands to be set as the list of the bot’s commands. At most telegram.constants.BotCommandLimit.MAX_COMMAND_NUMBER commands can be specified.

    Note

    If you pass in a sequence of tuple, the order of elements in each tuple must correspond to the order of positional arguments to create a BotCommand instance.

    Changed in version 20.0: |sequenceargs|

  • scope (BotCommandScope | None, default: None) –

    An object, describing scope of users for which the commands are relevant. Defaults to telegram.BotCommandScopeDefault.

    Added in version 13.7.

  • language_code (str | None, default: None) –

    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.

    Added in version 13.7.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_my_default_administrator_rights(rights=None, for_channels=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 free to modify the list before adding the bot.

Added in version 20.0.

Parameters:
  • rights (ChatAdministratorRights | None, default: None) – A telegram.ChatAdministratorRights object describing new default administrator rights. If not specified, the default administrator rights will be cleared.

  • for_channels (bool | None, default: None) – 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:

Returns True on success.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_my_description(description=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Added in version 20.2.

Parameters:
  • description (str | None, default: None) – New bot description; 0-telegram.constants.BotDescriptionLimit.MAX_DESCRIPTION_LENGTH characters. Pass an empty string to remove the dedicated description for the given language.

  • language_code (str | None, default: None) – 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:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_my_name(name=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to change the bot’s name.

Added in version 20.3.

Parameters:
  • name (str | None, default: None) –

    New bot name; 0-telegram.constants.BotNameLimit.MAX_NAME_LENGTH characters. Pass an empty string to remove the dedicated name for the given language.

    Caution

    If language_code is not specified, a name must be specified.

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

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_my_short_description(short_description=None, language_code=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Added in version 20.2.

Parameters:
  • short_description (str | None, default: None) – New short description for the bot; 0-telegram.constants.BotDescriptionLimit.MAX_SHORT_DESCRIPTION_LENGTH characters. Pass an empty string to remove the dedicated description for the given language.

  • language_code (str | None, default: None) – 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:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_passport_data_errors(user_id, errors, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

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

Parameters:
  • user_id (int) – User identifier

  • errors (Sequence[PassportElementError]) –

    A Sequence describing the errors.

    Changed in version 20.0: |sequenceargs|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_sticker_emoji_list(sticker, emoji_list, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to change the list of emoji assigned to a regular or custom emoji sticker. The sticker must belong to a sticker set created by the bot.

Added in version 20.2.

Parameters:
  • sticker (str | Sticker) –

    File identifier of the sticker or the sticker object.

    Changed in version 21.10: Accepts also telegram.Sticker instances.

  • emoji_list (Sequence[str]) – A sequence of telegram.constants.StickerLimit.MIN_STICKER_EMOJI- telegram.constants.StickerLimit.MAX_STICKER_EMOJI emoji associated with the sticker.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_sticker_keywords(sticker, keywords=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Added in version 20.2.

Parameters:
  • sticker (str | Sticker) –

    File identifier of the sticker or the sticker object.

    Changed in version 21.10: Accepts also telegram.Sticker instances.

  • keywords (Sequence[str] | None, default: None) – A sequence of 0-telegram.constants.StickerLimit.MAX_SEARCH_KEYWORDS search keywords for the sticker with total length up to telegram.constants.StickerLimit.MAX_KEYWORD_LENGTH characters.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_sticker_mask_position(sticker, mask_position=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Added in version 20.2.

Parameters:
  • sticker (str | Sticker) –

    File identifier of the sticker or the sticker object.

    Changed in version 21.10: Accepts also telegram.Sticker instances.

  • mask_position (MaskPosition | None, default: None) – A object with the position where the mask should be placed on faces. Omit the parameter to remove the mask position.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_sticker_position_in_set(sticker, position, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Parameters:
  • sticker (str | Sticker) –

    File identifier of the sticker or the sticker object.

    Changed in version 21.10: Accepts also telegram.Sticker instances.

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

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_sticker_set_thumbnail(name, user_id, format, thumbnail=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to set the thumbnail of a regular or mask sticker set. The format of the thumbnail file must match the format of the stickers in the set.

Added in version 20.2.

Changed in version 21.1: As per Bot API 7.2, the new argument format will be required, and thus the order of the arguments had to be changed.

Parameters:
  • name (str) – Sticker set name

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

  • format (str) –

    Format of the added sticker, must be one of telegram.constants.StickerFormat.STATIC for a .WEBP or .PNG image, telegram.constants.StickerFormat.ANIMATED for a .TGS animation, telegram.constants.StickerFormat.VIDEO for a .WEBM video.

    Added in version 21.1.

  • thumbnail (str | Path | IO[bytes] | InputFile | bytes | None, default: None) –

    A .WEBP or .PNG image with the thumbnail, must be up to telegram.constants.StickerSetLimit.MAX_STATIC_THUMBNAIL_SIZE kilobytes in size and have width and height of exactly telegram.constants.StickerSetLimit.STATIC_THUMB_DIMENSIONS px, or a .TGS animation with the thumbnail up to telegram.constants.StickerSetLimit.MAX_ANIMATED_THUMBNAIL_SIZE kilobytes in size; see the docs for animated sticker technical requirements, or a .WEBM video with the thumbnail up to telegram.constants.StickerSetLimit.MAX_ANIMATED_THUMBNAIL_SIZE kilobytes in size; see this for video sticker technical requirements.

    |fileinput|

    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.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_sticker_set_title(name, title, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to set the title of a created sticker set.

Added in version 20.2.

Parameters:
  • name (str) – Sticker set name.

  • title (str) – Sticker set title, telegram.constants.StickerLimit.MIN_NAME_AND_TITLE- telegram.constants.StickerLimit.MAX_NAME_AND_TITLE characters.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_user_emoji_status(user_id, emoji_status_custom_emoji_id=None, emoji_status_expiration_date=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Changes the emoji status for a given user that previously allowed the bot to manage their emoji status via the Mini App method requestEmojiStatusAccess .

Added in version 21.8.

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

  • emoji_status_custom_emoji_id (str | None, default: None) – Custom emoji identifier of the emoji status to set. Pass an empty string to remove the status.

  • emoji_status_expiration_date (int | datetime | None, default: None) – Expiration date of the emoji status, if any, as unix timestamp or datetime.datetime object. |tz-naive-dtms|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async set_webhook(url, certificate=None, max_connections=None, allowed_updates=None, ip_address=None, drop_pending_updates=None, secret_token=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, Telegram will send an HTTPS POST request to the specified url, containing An Update. In case of an unsuccessful request (a request with response HTTP status code <https://en.wikipedia.org/wiki/List_of_HTTP_status_codes>`_different from ``2XY`), Telegram will repeat the request and give up after a reasonable amount of attempts.

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.

Note

  1. You will not be able to receive updates using get_updates() for long as an outgoing webhook is set up.

  2. To use a self-signed certificate, you need to upload your public key certificate using certificate parameter. Please upload as InputFile, sending a String will not work.

  3. Ports currently supported for Webhooks: telegram.constants.SUPPORTED_WEBHOOK_PORTS.

If you’re having any trouble setting up webhooks, please check out this guide to Webhooks.

Examples

Custom Webhook Bot

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

  • certificate (str | Path | IO[bytes] | InputFile | bytes | None, default: None) – Upload your public key certificate so that the root certificate in use can be checked. See our self-signed guide                <Webhooks#creating-a-self-signed-certificate-using-openssl> for details. |uploadinputnopath|

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

  • max_connections (int | None, default: None) – Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, telegram.constants.WebhookLimit.MIN_CONNECTIONS_LIMIT- telegram.constants.WebhookLimit.MAX_CONNECTIONS_LIMIT. Defaults to 40. Use lower values to limit the load on your bot’s server, and higher values to increase your bot’s throughput.

  • allowed_updates (Sequence[str] | None, default: None) –

    A sequence of the types of updates you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See telegram.Update for a complete list of available update types. Specify an empty sequence to receive all updates except telegram.Update.chat_member, telegram.Update.message_reaction and telegram.Update.message_reaction_count (default). If not specified, the previous setting will be used. Please note that this parameter doesn’t affect updates created before the call to the set_webhook, so unwanted update may be received for a short period of time.

    Changed in version 20.0: |sequenceargs|

  • drop_pending_updates (bool | None, default: None) – Pass True to drop all pending updates.

  • secret_token (str | None, default: None) –

    A secret token to be sent in a header X-Telegram-Bot-Api-Secret-Token in every webhook request, telegram.constants.WebhookLimit.MIN_SECRET_TOKEN_LENGTH- telegram.constants.WebhookLimit.MAX_SECRET_TOKEN_LENGTH 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.

    Added in version 20.0.

Returns:

boolbool On success, True is returned.

Raises:

telegram.error.TelegramError

async shutdown()[source]

Stop & clear resources used by this class. Currently just calls telegram.request.BaseRequest.shutdown() for the request objects used by this bot.

See also

initialize()

Added in version 20.0.

Return type:

None

async stopMessageLiveLocation(chat_id=None, message_id=None, inline_message_id=None, reply_markup=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for stop_message_live_location()

Return type:

Message | bool

async stopPoll(chat_id, message_id, reply_markup=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for stop_poll()

Return type:

Poll

async stop_message_live_location(chat_id=None, message_id=None, inline_message_id=None, reply_markup=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Parameters:
  • chat_id (int | str | None, default: None) – Required if inline_message_id is not specified. |chat_id_channel|

  • message_id (int | None, default: None) – Required if inline_message_id is not specified. Identifier of the sent message with live location to stop.

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

  • reply_markup (InlineKeyboardMarkup | None, default: None) – An object for a new inline keyboard.

  • business_connection_id (str | None, default: None) –

    |business_id_str_edit|

    Added in version 21.4.

Returns:

On success, if edited message is not an inline message, the edited message is returned, otherwise True is returned.

Returns:

Message | bool

async stop_poll(chat_id, message_id, reply_markup=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to stop a poll which was sent by the bot.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

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

  • reply_markup (InlineKeyboardMarkup | None, default: None) – An object for a new message inline keyboard.

  • business_connection_id (str | None, default: None) –

    |business_id_str_edit|

    Added in version 21.4.

Returns:

On success, the stopped Poll is returned.

Returns:

Poll

Raises:

telegram.error.TelegramError

property supports_inline_queries: bool

Bot’s telegram.User.supports_inline_queries attribute. Shortcut for the corresponding attribute of bot.

Type:

bool

to_dict(recursive=True)[source]

See telegram.TelegramObject.to_dict().

Return type:

dict[str, Any]

property token: str

Bot’s unique authentication token.

Added in version 20.0.

Type:

str

async transferBusinessAccountStars(business_connection_id, star_count, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for transfer_business_account_stars()

Return type:

bool

async transferGift(business_connection_id, owned_gift_id, new_owner_chat_id, star_count=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for transfer_gift()

Return type:

bool

async transfer_business_account_stars(business_connection_id, star_count, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Transfers Telegram Stars from the business account balance to the bot’s balance. Requires the can_transfer_stars business bot right.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection

  • star_count (int) – Number of Telegram Stars to transfer; ~telegram.constants.BusinessLimit.MIN_STAR_COUNT-~telegram.constants.BusinessLimit.MAX_STAR_COUNT

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async transfer_gift(business_connection_id, owned_gift_id, new_owner_chat_id, star_count=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Transfers an owned unique gift to another user. Requires the can_transfer_and_upgrade_gifts business bot right. Requires can_transfer_stars business bot right if the transfer is paid.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection

  • owned_gift_id (str) – Unique identifier of the regular gift that should be transferred.

  • new_owner_chat_id (int) – Unique identifier of the chat which will own the gift. The chat must be active in the last ~telegram.constants.BusinessLimit.CHAT_ACTIVITY_TIMEOUT seconds.

  • star_count (int | None, default: None) – The amount of Telegram Stars that will be paid for the transfer from the business account balance. If positive, then the can_transfer_stars business bot right is required.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async unbanChatMember(chat_id, user_id, only_if_banned=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for unban_chat_member()

Return type:

bool

async unbanChatSenderChat(chat_id, sender_chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for unban_chat_sender_chat()

Return type:

bool

async unban_chat_member(chat_id, user_id, only_if_banned=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Parameters:
  • chat_id (str | int) – |chat_id_channel|

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

  • only_if_banned (bool | None, default: None) – Do nothing if the user is not banned.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async unban_chat_sender_chat(chat_id, sender_chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to unban a previously banned channel in a supergroup or channel. The bot must be an administrator for this to work and must have the appropriate administrator rights.

Added in version 13.9.

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async unhideGeneralForumTopic(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for unhide_general_forum_topic()

Return type:

bool

async unhide_general_forum_topic(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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.

Added in version 20.0.

Parameters:

chat_id (str | int) – |chat_id_group|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async unpinAllChatMessages(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for unpin_all_chat_messages()

Return type:

bool

async unpinAllForumTopicMessages(chat_id, message_thread_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for unpin_all_forum_topic_messages()

Return type:

bool

async unpinAllGeneralForumTopicMessages(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for unpin_all_general_forum_topic_messages()

Return type:

bool

async unpinChatMessage(chat_id, message_id=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for unpin_chat_message()

Return type:

bool

async unpin_all_chat_messages(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Use this method to clear the list of pinned messages in a chat. If the chat is not a private chat, the bot must be an administrator in the chat for this to work and must have the ~telegram.ChatAdministratorRights.can_pin_messages admin right in a supergroup or can_edit_messages admin right in a channel.

Parameters:

chat_id (str | int) – |chat_id_channel|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async unpin_all_forum_topic_messages(chat_id, message_thread_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 ~telegram.ChatAdministratorRights.can_pin_messages administrator rights in the supergroup.

Added in version 20.0.

Parameters:
Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async unpin_all_general_forum_topic_messages(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[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 ~telegram.ChatAdministratorRights.can_pin_messages administrator rights in the supergroup.

Added in version 20.5.

Parameters:

chat_id (str | int) – |chat_id_group|

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async unpin_chat_message(chat_id, message_id=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Parameters:
  • chat_id (str | int) – |chat_id_channel|

  • message_id (int | None, default: None) – Identifier of the message to unpin. Required if business_connection_id is specified. If not specified, the most recent pinned message (by sending date) will be unpinned.

  • business_connection_id (str | None, default: None) –

    Unique identifier of the business connection on behalf of which the message will be unpinned.

    Added in version 21.5.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async upgradeGift(business_connection_id, owned_gift_id, keep_original_details=None, star_count=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for upgrade_gift()

Return type:

bool

async upgrade_gift(business_connection_id, owned_gift_id, keep_original_details=None, star_count=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Upgrades a given regular gift to a unique gift. Requires the can_transfer_and_upgrade_gifts business bot right. Additionally requires the can_transfer_stars business bot right if the upgrade is paid.

Added in version 22.1.

Parameters:
  • business_connection_id (str) – Unique identifier of the business connection

  • owned_gift_id (str) – Unique identifier of the regular gift that should be upgraded to a unique one.

  • keep_original_details (bool | None, default: None) – Pass True to keep the original gift text, sender and receiver in the upgraded gift

  • star_count (int | None, default: None) – The amount of Telegram Stars that will be paid for the upgrade from the business account balance. If gift.prepaid_upgrade_star_count > 0, then pass 0, otherwise, the can_transfer_stars business bot right is required and telegram.Gift.upgrade_star_count must be passed.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async uploadStickerFile(user_id, sticker, sticker_format, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for upload_sticker_file()

Return type:

File

async upload_sticker_file(user_id, sticker, sticker_format, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

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

Changed in version 20.5: Removed deprecated parameter png_sticker.

Parameters:
Returns:

On success, the uploaded File is returned.

Returns:

File

Raises:

telegram.error.TelegramError

property username: str

Bot’s username. Shortcut for the corresponding attribute of bot.

Type:

str

async verifyChat(chat_id, custom_description=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for verify_chat()

Return type:

bool

async verifyUser(user_id, custom_description=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)

Alias for verify_user()

Return type:

bool

async verify_chat(chat_id, custom_description=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Verifies a chat |org-verify| which is represented by the bot.

Added in version 21.10.

Parameters:
  • chat_id (int | str) – |chat_id_channel|

  • custom_description (str | None, default: None) – Custom description for the verification; 0- telegram.constants.VerifyLimit.MAX_TEXT_LENGTH characters. Must be empty if the organization isn’t allowed to provide a custom verification description.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

async verify_user(user_id, custom_description=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]

Verifies a user |org-verify| which is represented by the bot.

Added in version 21.10.

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

  • custom_description (str | None, default: None) – Custom description for the verification; 0- telegram.constants.VerifyLimit.MAX_TEXT_LENGTH characters. Must be empty if the organization isn’t allowed to provide a custom verification description.

Returns:

On success, True is returned.

Returns:

bool

Raises:

telegram.error.TelegramError

class spotted.utils.keyboard_util.Config[source]

Bases: object

Configurations

AUTOREPLIES_PATH = 'autoreplies.yaml'
DEFAULT_AUTOREPLIES_PATH = '/opt/hostedtoolcache/Python/3.14.3/x64/lib/python3.14/site-packages/spotted/config/yaml/autoreplies.yaml'
DEFAULT_SETTINGS_PATH = '/opt/hostedtoolcache/Python/3.14.3/x64/lib/python3.14/site-packages/spotted/config/yaml/settings.yaml'
SETTINGS_PATH = 'settings.yaml'
classmethod autoreplies_get(*keys, default=None)[source]

Get the value of the specified key in the autoreplies configuration dictionary. If the key is a tuple, it will return the value of the nested key. If the key is not present, it will return the default value.

Parameters:
  • key – key to get

  • default (Any, default: None) – default value to return if the key is not present

Returns:

dict – value of the key or default value

classmethod debug_get(key, default=None)[source]

Get the value of the specified key in the configuration under the ‘debug’ section. If the key is not present, it will return the default value.

Parameters:
  • key (Literal['local_log', 'reset_on_load', 'log_file', 'log_error_file', 'db_file', 'backup_chat_id', 'backup_keep_pending', 'crypto_key', 'zip_backup']) – key to get

  • default (Any, default: None) – default value to return if the key is not present

Returns:

Any – value of the key or default value

classmethod override_settings(config)[source]

Overrides the settings with the configuration provided in the config dict.

Parameters:

config (dict) – configuration dict used to override the current settings

classmethod post_get(key, default=None)[source]

Get the value of the specified key in the configuration under the ‘post’ section. If the key is not present, it will return the default value.

Parameters:
  • key (Literal['community_group_id', 'channel_id', 'channel_tag', 'comments', 'admin_group_id', 'n_votes', 'remove_after_h', 'report', 'report_wait_mins', 'replace_anonymous_comments', 'delete_anonymous_comments', 'blacklist_messages', 'max_n_warns', 'warn_expiration_days', 'mute_default_duration_days', 'autoreplies_per_page', 'reject_after_autoreply']) – key to get

  • default (Any, default: None) – default value to return if the key is not present

Returns:

Any – value of the key or default value

classmethod reload(force_reload=False)[source]

Reset the configuration. The next time a setting parameter is required, the whole configuration will be reloaded. If force_reload is True, the configuration will be reloaded immediately.

Parameters:

force_reload (bool, default: False) – if True, the configuration will be reloaded immediately

classmethod settings_get(*keys, default=None)[source]

Get the value of the specified key in the configuration. If the key is a tuple, it will return the value of the nested key. If the key is not present, it will return the default value.

Parameters:
  • key – key to get

  • default (Any, default: None) – default value to return if the key is not present

Returns:

Any – value of the key or default value

class spotted.utils.keyboard_util.InlineKeyboardButton(text, url=None, callback_data=None, switch_inline_query=None, switch_inline_query_current_chat=None, callback_game=None, pay=None, login_url=None, web_app=None, switch_inline_query_chosen_chat=None, copy_text=None, *, api_kwargs=None)[source]

Bases: TelegramObject

This object represents one button of an inline keyboard.

Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their text, url, login_url, callback_data, switch_inline_query, switch_inline_query_current_chat, callback_game, web_app and pay are equal.

Note

  • Exactly one of the optional fields must be used to specify type of the button.

  • Mind that callback_game is not working as expected. Putting a game short name in it might, but is not guaranteed to work.

  • If your bot allows for arbitrary callback data, in keyboards returned in a response from telegram, callback_data may be an instance of telegram.ext.InvalidCallbackData. This will be the case, if the data associated with the button was already deleted.

    Added in version 13.6.

  • Since Bot API 5.5, it’s now allowed to mention users by their ID in inline keyboards. This will only work in Telegram versions released after December 7, 2021. Older clients will display unsupported message.

Warning

  • If your bot allows your arbitrary callback data, buttons whose callback data is a non-hashable object will become unhashable. Trying to evaluate hash(button) will result in a TypeError.

    Changed in version 13.6.

  • After Bot API 6.1, only HTTPS links will be allowed in login_url.

Examples

  • Inline Keyboard 1

  • Inline Keyboard 2

Changed in version 20.0: web_app is considered as well when comparing objects of this type in terms of equality.

Parameters:
  • text (str) – Label text on the button.

  • url (str | None, default: None) –

    HTTP or tg:// url to be opened when the button is pressed. Links tg://user?id=<user_id> can be used to mention a user by their ID without using a username, if this is allowed by their privacy settings.

    Changed in version 13.9: You can now mention a user using tg://user?id=<user_id>.

  • login_url (LoginUrl | None, default: None) –

    An HTTPS URL used to automatically authorize the user. Can be used as a replacement for the Telegram Login Widget.

    Caution

    Only HTTPS links are allowed after Bot API 6.1.

  • callback_data (str | object | None, default: None) –

    Data to be sent in a callback query to the bot when the button is pressed, UTF-8 telegram.InlineKeyboardButton.MIN_CALLBACK_DATA- telegram.InlineKeyboardButton.MAX_CALLBACK_DATA bytes. If the bot instance allows arbitrary callback data, anything can be passed.

    Tip

    The value entered here will be available in telegram.CallbackQuery.data.

    See also

    Arbitrary callback_data <Arbitrary-callback_data>

  • web_app (WebAppInfo | None, default: None) –

    Description of the Web App that will be launched when the user presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the method answer_web_app_query(). Available only in private chats between a user and the bot. Not supported for messages sent on behalf of a Telegram Business account.

    Added in version 20.0.

  • switch_inline_query (str | None, default: None) –

    If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot’s username and the specified inline query in the input field. May be empty, in which case just the bot’s username will be inserted. Not supported for messages sent on behalf of a Telegram Business account.

    Tip

    This is similar to the parameter switch_inline_query_chosen_chat, but gives no control over which chats can be selected.

  • switch_inline_query_current_chat (str | None, default: None) –

    If set, pressing the button will insert the bot’s username and the specified inline query in the current chat’s input field. May be empty, in which case only the bot’s username will be inserted.

    This offers a quick way for the user to open your bot in inline mode in the same chat - good for selecting something from multiple options. Not supported in channels and for messages sent on behalf of a Telegram Business account.

  • copy_text (CopyTextButton | None, default: None) –

    Description of the button that copies the specified text to the clipboard.

    Added in version 21.7.

  • callback_game (CallbackGame | None, default: None) –

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

    Note

    This type of button must always be the first button in the first row.

  • pay (bool | None, default: None) –

    Specify True, to send a Pay button. Substrings “⭐️” and “XTR” in the buttons’s text will be replaced with a Telegram Star icon.

    Note

    This type of button must always be the first button in the first row and can only be used in invoice messages.

  • switch_inline_query_chosen_chat (SwitchInlineQueryChosenChat | None, default: None) –

    If set, pressing the button will prompt the user to select one of their chats of the specified type, open that chat and insert the bot’s username and the specified inline query in the input field. Not supported for messages sent on behalf of a Telegram Business account.

    Added in version 20.3.

    Tip

    This is similar to switch_inline_query, but gives more control on which chats can be selected.

    Caution

    The PTB team has discovered that this field works correctly only if your Telegram client is released after April 20th 2023.

text

Label text on the button.

Type:

str

url

Optional. HTTP or tg:// url to be opened when the button is pressed. Links tg://user?id=<user_id> can be used to mention a user by their ID without using a username, if this is allowed by their privacy settings.

Changed in version 13.9: You can now mention a user using tg://user?id=<user_id>.

Type:

str

login_url

Optional. An HTTPS URL used to automatically authorize the user. Can be used as a replacement for the Telegram Login Widget.

Caution

Only HTTPS links are allowed after Bot API 6.1.

Type:

telegram.LoginUrl

callback_data

Optional. Data to be sent in a callback query to the bot when the button is pressed, UTF-8 telegram.InlineKeyboardButton.MIN_CALLBACK_DATA- telegram.InlineKeyboardButton.MAX_CALLBACK_DATA bytes.

Type:

str | object

web_app

Optional. Description of the Web App that will be launched when the user presses the button. The Web App will be able to send an arbitrary message on behalf of the user using the method answer_web_app_query(). Available only in private chats between a user and the bot. Not supported for messages sent on behalf of a Telegram Business account.

Added in version 20.0.

Type:

telegram.WebAppInfo

switch_inline_query

Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot’s username and the specified inline query in the input field. May be empty, in which case just the bot’s username will be inserted. Not supported for messages sent on behalf of a Telegram Business account.

Tip

This is similar to the parameter switch_inline_query_chosen_chat, but gives no control over which chats can be selected.

Type:

str

switch_inline_query_current_chat

Optional. If set, pressing the button will insert the bot’s username and the specified inline query in the current chat’s input field. May be empty, in which case only the bot’s username will be inserted.

This offers a quick way for the user to open your bot in inline mode in the same chat - good for selecting something from multiple options. Not supported in channels and for messages sent on behalf of a Telegram Business account.

Type:

str

copy_text

Optional. Description of the button that copies the specified text to the clipboard.

Added in version 21.7.

Type:

telegram.CopyTextButton

callback_game

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

Note

This type of button must always be the first button in the first row.

Type:

telegram.CallbackGame

pay

Optional. Specify True, to send a Pay button. Substrings “⭐️” and “XTR” in the buttons’s text will be replaced with a Telegram Star icon.

Note

This type of button must always be the first button in the first row and can only be used in invoice messages.

Type:

bool

switch_inline_query_chosen_chat

Optional. If set, pressing the button will prompt the user to select one of their chats of the specified type, open that chat and insert the bot’s username and the specified inline query in the input field. Not supported for messages sent on behalf of a Telegram Business account.

Added in version 20.3.

Tip

This is similar to switch_inline_query, but gives more control on which chats can be selected.

Caution

The PTB team has discovered that this field works correctly only if your Telegram client is released after April 20th 2023.

Type:

telegram.SwitchInlineQueryChosenChat

MAX_CALLBACK_DATA: Final[int] = 64

telegram.constants.InlineKeyboardButtonLimit.MAX_CALLBACK_DATA

Added in version 20.0.

MIN_CALLBACK_DATA: Final[int] = 1

telegram.constants.InlineKeyboardButtonLimit.MIN_CALLBACK_DATA

Added in version 20.0.

callback_data: str | object | None
callback_game: CallbackGame | None
copy_text: CopyTextButton | None
classmethod de_json(data, bot=None)[source]

See telegram.TelegramObject.de_json().

Return type:

InlineKeyboardButton

login_url: LoginUrl | None
pay: bool | None
switch_inline_query: str | None
switch_inline_query_chosen_chat: SwitchInlineQueryChosenChat | None
switch_inline_query_current_chat: str | None
text: str
update_callback_data(callback_data)[source]

Sets callback_data to the passed object. Intended to be used by telegram.ext.CallbackDataCache.

Added in version 13.6.

Parameters:

callback_data (str | object) – The new callback data.

Return type:

None

url: str | None
web_app: WebAppInfo | None
class spotted.utils.keyboard_util.InlineKeyboardMarkup(inline_keyboard, *, api_kwargs=None)[source]

Bases: TelegramObject

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

Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their size of inline_keyboard and all the buttons are equal.

https://core.telegram.org/file/464001863/110f3/I47qTXAD9Z4.120010/e0ea04f66357b640ec

An inline keyboard on a message

See also

Another kind of keyboard would be the telegram.ReplyKeyboardMarkup.

Examples

  • Inline Keyboard 1

  • Inline Keyboard 2

Parameters:

inline_keyboard (Sequence[Sequence[InlineKeyboardButton]]) –

Sequence of button rows, each represented by a sequence of InlineKeyboardButton objects.

Changed in version 20.0: |sequenceclassargs|

inline_keyboard

Tuple of button rows, each represented by a tuple of InlineKeyboardButton objects.

Changed in version 20.0: |tupleclassattrs|

Type:

tuple[tuple[telegram.InlineKeyboardButton]]

classmethod de_json(data, bot=None)[source]

See telegram.TelegramObject.de_json().

Return type:

InlineKeyboardMarkup

classmethod from_button(button, **kwargs)[source]

Shortcut for:

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

Return an InlineKeyboardMarkup from a single InlineKeyboardButton

Parameters:

button (InlineKeyboardButton) – The button to use in the markup

Return type:

InlineKeyboardMarkup

classmethod from_column(button_column, **kwargs)[source]

Shortcut for:

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

Return an InlineKeyboardMarkup from a single column of InlineKeyboardButtons

Parameters:

button_column (Sequence[InlineKeyboardButton]) –

The button to use in the markup

Changed in version 20.0: |sequenceargs|

Return type:

InlineKeyboardMarkup

classmethod from_row(button_row, **kwargs)[source]

Shortcut for:

InlineKeyboardMarkup([button_row], **kwargs)

Return an InlineKeyboardMarkup from a single row of InlineKeyboardButtons

Parameters:

button_row (Sequence[InlineKeyboardButton]) –

The button to use in the markup

Changed in version 20.0: |sequenceargs|

Return type:

InlineKeyboardMarkup

inline_keyboard: tuple[tuple[InlineKeyboardButton, ...], ...]
class spotted.utils.keyboard_util.PendingPost(user_id, u_message_id, g_message_id, admin_group_id, date, credit_username=None)[source]

Bases: object

Class that represents a pending post

Parameters:
  • user_id (int) – id of the user that sent the post

  • u_message_id (int) – id of the original message of the post

  • g_message_id (int) – id of the post in the group

  • admin_group_id (int) – id of the admin group

  • credit_username (str | None, default: None) – username of the user that sent the post if it’s a credit post

  • date (datetime) – when the post was sent

admin_group_id: int
classmethod create(user_message, g_message_id, admin_group_id, credit_username=None)[source]

Creates a new post and inserts it in the table of pending posts

Parameters:
  • user_message (Message) – message sent by the user that contains the post

  • g_message_id (int) – id of the post in the group

  • admin_group_id (int) – id of the admin group

  • credit_username (str | None, default: None) – username of the user that sent the post if it’s a credit post

Returns:

PendingPost – instance of the class

credit_username: str | None = None
date: datetime
delete_post()[source]

Removes all entries on a post that is no longer pending

classmethod from_group(g_message_id, admin_group_id)[source]

Retrieves a pending post from the info related to the admin group

Parameters:
  • g_message_id (int) – id of the post in the group

  • admin_group_id (int) – id of the admin group

Returns:

PendingPost | None – instance of the class

classmethod from_user(user_id)[source]

Retrieves a pending post from the user_id

Parameters:

user_id (int) – id of the author of the post

Returns:

PendingPost | None – instance of the class

g_message_id: int
static get_all(admin_group_id, before=None)[source]

Gets the list of pending posts in the specified admin group. If before is specified, returns only the one sent before that timestamp

Parameters:
  • admin_group_id (int) – id of the admin group

  • before (datetime | None, default: None) – timestamp before which messages will be considered

Returns:

list[PendingPost] – list of ids of pending posts

get_credit_username()[source]

Gets the username of the user that credited the post

Returns:

str | None – username of the user that credited the post, or None if the post is not credited

get_list_admin_votes(vote=None)[source]

Gets the list of admins that approved or rejected the post

Parameters:

vote (bool | None, default: None) – whether you look for the approve or reject votes, or None if you want all the votes

Returns:

list[int] | list[tuple[int, bool]] – list of admins that approved or rejected a pending post

get_votes(vote)[source]

Gets all the votes of a specific kind (approve or reject)

Parameters:

vote (bool) – whether you look for the approve or reject votes

Returns:

int – number of votes

save_post()[source]

Saves the pending_post in the database

Return type:

PendingPost

set_admin_vote(admin_id, approval)[source]

Adds the vote of the admin on a specific post, or update the existing vote, if needed

Parameters:
  • admin_id (int) – id of the admin that voted

  • approval (bool) – whether the vote is approval or reject

Returns:

int – number of similar votes (all the approve or the reject), or -1 if the vote wasn’t updated

u_message_id: int
user_id: int
spotted.utils.keyboard_util.get_approve_kb(pending_post=None, approve=-1, reject=-1, credited_username=None)[source]

Generates the InlineKeyboard for the pending post. If the pending post is None, the keyboard will be generated with 0 votes. Otherwise, the keyboard will be generated with the correct number of votes. To avoid unnecessary queries, the number of votes can be passed as an argument and will be assumed to be correct.

Parameters:
  • pending_post (PendingPost | None, default: None) – existing pending post to which the keyboard is attached

  • approve (int, default: -1) – number of approve votes known in advance

  • reject (int, default: -1) – number of reject votes known in advance

  • credited_username (str | None, default: None) – username of the user who credited the post if it was credited

Returns:

InlineKeyboardMarkup – new inline keyboard

spotted.utils.keyboard_util.get_autoreply_kb(page, items_per_page)[source]

Generates the keyboard for the autoreplies

Parameters:
  • page (int) – page of the autoreplies

  • items_per_page (int) – number of items per page

Returns:

list[list[InlineKeyboardButton]] – new part of keyboard

spotted.utils.keyboard_util.get_confirm_kb()[source]

Generates the InlineKeyboard to confirm the creation of the post

Returns:

InlineKeyboardMarkup – new inline keyboard

spotted.utils.keyboard_util.get_paused_kb(page, items_per_page)[source]

Generates the InlineKeyboard for the paused post

Parameters:

page (int) – page of the autoreplies

Returns:

InlineKeyboardMarkup – autoreplies keyboard append with resume button

async spotted.utils.keyboard_util.get_post_outcome_kb(bot, votes, reason=None)[source]

Generates the InlineKeyboard for the outcome of a post

Parameters:
  • bot (Bot) – bot instance

  • votes (list[tuple[int, bool]]) – list of votes

  • reason (str | None, default: None) – reason for the rejection, currently used on autoreplies

Returns:

InlineKeyboardMarkup – new inline keyboard

spotted.utils.keyboard_util.get_preview_kb()[source]

Generates the InlineKeyboard to choose if the post should be previewed or not

Returns:

InlineKeyboardMarkup – new inline keyboard

spotted.utils.keyboard_util.get_published_post_kb()[source]

Generates the InlineKeyboard for the published post adding the report button if needed

Returns:

InlineKeyboardMarkup | None – new inline keyboard

spotted.utils.keyboard_util.get_settings_kb()[source]

Generates the InlineKeyboard to edit the settings

Returns:

InlineKeyboardMarkup – new inline keyboard

class spotted.utils.keyboard_util.islice

Bases: object

islice(iterable, stop) –> islice object islice(iterable, start, stop[, step]) –> islice object

Return an iterator whose next() method returns selected values from an iterable. If start is specified, will skip all preceding elements; otherwise, start defaults to zero. Step defaults to one. If specified as another value, step determines how many values are skipped between successive calls. Works like a slice() on a list but returns an iterator.

class spotted.utils.keyboard_util.zip_longest(*iterables, fillvalue=None)

Bases: object

Return a zip_longest object whose .__next__() method returns a tuple where the i-th element comes from the i-th iterable argument. The .__next__() method continues until the longest iterable in the argument sequence is exhausted and then it raises StopIteration. When the shorter iterables are exhausted, the fillvalue is substituted in their place. The fillvalue defaults to None or can be specified by a keyword argument.

spotted.utils.utils module

class spotted.utils.utils.User(user_id, private_message_id=None, ban_date=None, mute_date=None, mute_expire_date=None, follow_date=None)[source]

Bases: object

Class that represents a user

Parameters:
  • user_id (int) – id of the user

  • private_message_id (int | None, default: None) – id of the private message sent by the user to the bot. Only used for following

  • ban_date (datetime | None, default: None) – datetime of when the user was banned. Only used for banned users

  • follow_date (datetime | None, default: None) – datetime of when the user started following a post. Only used for following users

ban()[source]

Adds the user to the banned list

ban_date: datetime | None = None
classmethod banned_users()[source]

Returns a list of all the banned users

Return type:

list[User]

become_anonym()[source]

Removes the user from the credited list, if he was present

Returns:

bool – whether the user was already anonym

become_credited()[source]

Adds the user to the credited list, if he wasn’t already credited

Returns:

bool – whether the user was already credited

classmethod credited_users()[source]

Returns a list of all the credited users

Return type:

list[User]

follow_date: datetime | None = None
classmethod following_users(message_id)[source]

Returns a list of all the users following the post with the associated private message id used by the bot to send updates about the post by replying to it

Parameters:

message_id (int) – id of the post the users are following

Returns:

list[User] – list of users with private_message_id set to the id of the private message in the user’s conversation with the bot

get_follow_private_message_id(message_id)[source]

Verifies if the user is following a post

Parameters:

message_id (int) – id of the post

Returns:

int | None – whether the user is following the post or not

get_n_warns()[source]

Returns the count of consecutive warns of the user

Return type:

int

async get_user_sign(bot)[source]

Generates a sign for the user. It will be a random name for an anonym user

Parameters:

bot (Bot) – telegram bot

Returns:

str – the sign of the user

property is_banned: bool

If the user is banned or not

property is_credited: bool

If the user is in the credited list

is_following(message_id)[source]

Verifies if the user is following a post

Parameters:

message_id (int) – id of the post

Returns:

bool – whether the user is following the post or not

property is_muted: bool

If the user is muted or not

property is_pending: bool

If the user has a post already pending or not

property is_warn_bannable: bool

If the user is bannable due to warns

async mute(bot, days)[source]

Mute a user restricting its actions inside the community group

Parameters:
  • bot (Bot | None) – the telegram bot

  • days (int) – The number of days the user should be muted for.

mute_date: datetime | None = None
mute_expire_date: datetime | None = None
classmethod muted_users()[source]

Returns a list of all the muted users

Return type:

list[User]

private_message_id: int | None = None
sban()[source]

Removes the user from the banned list

Returns:

bool – whether the user was present in the banned list before the sban or not

set_follow(message_id, private_message_id)[source]

Sets the follow status of the user. If the private_message_id is None, the user is not following the post anymore, and the record is deleted from the database. Otherwise, the user is following the post and a new record is created.

Parameters:
  • message_id (int) – id of the post

  • private_message_id (int | None) – id of the private message. If None, the record is deleted

async unmute(bot)[source]

Unmute a user taking back all restrictions

Parameters:

bot (Bot | None) – the telegram bot

Returns:

bool – whether the user was muted before the unmute or not

user_id: int
warn()[source]

Increase the number of warns of a user If the number of warns is greater than the maximum allowed, the user is banned

Parameters:

bot – the telegram bot

spotted.utils.utils.get_user_by_id_or_index(user_id_or_idx, users_list)[source]

Get a user either by their user_id or by their index in a given list of users. The index is specified by prefixing the number with a ‘#’ character. For example, ‘#0’ would refer to the first user in the list. On the other hand, if the input is a number without the ‘#’ prefix, it will be treated as a user_id.

Parameters:
  • user_id_or_idx (str) – The user_id or index to look for. If it starts with ‘#’, it will be treated as an index.

  • users_list (list[User]) – The list of users to search through when looking for an index.

Returns:

User | None – The User object corresponding to the given user_id or index, or None if no such user exists.