Module contents
Modules that provide various util
- class spotted.utils.EventInfo(bot, ctx, update=None, message=None, query=None)[source]
Bases:
objectClass 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
- 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 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 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 Nonemessage_id (
int|None, default:None) – id of the message to edit. It is the current message if left Nonenew_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
- 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
- property inline_keyboard: InlineKeyboardMarkup | None
InlineKeyboard attached to the message
- property is_forwarded_post: bool
Whether the message is in fact a forwarded post from the channel to the group
- 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 forreason (
str|None, default:None) – reason for the rejection, currently used on autoreply
- 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
- spotted.utils.conv_fail(family)[source]
Creates a function used to handle any error in the conversation
- 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 attachedapprove (
int, default:-1) – number of approve votes known in advancereject (
int, default:-1) – number of reject votes known in advancecredited_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.
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:
objectSpecial 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.BaseHandleror by thetelegram.ext.Applicationin an error handler added bytelegram.ext.Application.add_error_handleror to the callback of atelegram.ext.Job.Note
telegram.ext.Applicationwill 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 sameCallbackContextobject (of course with proper attributes likematchesdiffering). 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 onCallbackContextmight 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.blockset toFalseortelegram.ext.Application.concurrent_updatesset toTrue. 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
Genericclass and accepts four type variables:The type of
bot. Must betelegram.Botor a subclass of that class.
Examples
Context Types BotCustom 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 withblock=False.- Type:
- matches
Optional. If the associated update originated from a
filters.Regex, this will contain a list of match objects for every pattern wherere.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.PrefixHandlerortelegram.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:
- job
Optional. The job which originated this callback. Only present when passed to the callback of
telegram.ext.Jobor in error handlers if the error is caused by a job.Changed in version 20.0:
jobis now also present in error handlers if the error is caused by a job.- Type:
- property application: Application[BT, ST, UD, CD, BD, Any]
The application associated with this context.
- Type:
- property bot: BT
The bot associated with this context.
- Type:
- 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 todict.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 todict.Warning
When a group chat migrates to a supergroup, its chat id will change and the
chat_dataneeds to be transferred. For details see ourwiki 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
- 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
KeyErrorin 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 | RuntimeError –
KeyError, if the callback query can not be found in the cache andRuntimeError, if the bot doesn’t allow for arbitrary callback data.- Return type:
- classmethod from_error(update, error, application, job=None, coroutine=None)[source]
Constructs an instance of
telegram.ext.CallbackContextto be passed to the error handlers.Changed in version 20.0: Removed arguments
async_argsandasync_kwargs.- Parameters:
update (
object) – The update associated with the error. May beNone, 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 withblock=False.Added in version 20.0.
Changed in version 20.2: Accepts
asyncio.Futureand 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.CallbackContextto be passed to a job callback.See also
telegram.ext.JobQueue()- Parameters:
- Returns:
TypeVar(CCT, bound= CallbackContext[Any, Any, Any, Any]) –telegram.ext.CallbackContext
- classmethod from_update(update, application)[source]
Constructs an instance of
telegram.ext.CallbackContextto be passed to the handlers.- Parameters:
- Returns:
TypeVar(CCT, bound= CallbackContext[Any, Any, Any, Any]) –telegram.ext.CallbackContext
- property job_queue: JobQueue[ST] | None
The
JobQueueused by thetelegram.ext.Application.See also
Job Queue <Extensions---JobQueue>- Type:
- property match: Match[str] | None
The first match from
matches. Useful if you are only filtering using a single regex filter. ReturnsNoneifmatchesis empty.- Type:
- async refresh_data()[source]
If
applicationuses persistence, callstelegram.ext.BasePersistence.refresh_bot_data()onbot_data,telegram.ext.BasePersistence.refresh_chat_data()onchat_dataandtelegram.ext.BasePersistence.refresh_user_data()onuser_data, if appropriate.Will be called by
telegram.ext.Application.process_update()andtelegram.ext.Job.run().Added in version 13.6.
- Return type:
- property update_queue: Queue[object]
The
asyncio.Queueinstance used by thetelegram.ext.Applicationand (usually) thetelegram.ext.Updaterassociated with this context.- Type:
- 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 todict.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
- class spotted.utils.conversation_util.EventInfo(bot, ctx, update=None, message=None, query=None)[source]
Bases:
objectClass 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
- 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 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 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 Nonemessage_id (
int|None, default:None) – id of the message to edit. It is the current message if left Nonenew_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
- 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
- property inline_keyboard: InlineKeyboardMarkup | None
InlineKeyboard attached to the message
- property is_forwarded_post: bool
Whether the message is in fact a forwarded post from the channel to the group
- 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 forreason (
str|None, default:None) – reason for the rejection, currently used on autoreply
- class spotted.utils.conversation_util.ParseMode(*values)[source]
Bases:
StringEnumThis enum contains the available parse modes. The enum members of this enumeration are instances of
strand can be treated as such.Added in version 20.0.
- MARKDOWN = 'Markdown'
Markdown parse mode.
Note
MARKDOWNis a legacy mode, retained by Telegram for backward compatibility. You should useMARKDOWN_V2instead.- Type:
- 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:
TelegramObjectThis 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_idis 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_MEMBERin the list oftelegram.ext.Application.run_polling.allowed_updatesto receive these updates (seetelegram.Bot.get_updates(),telegram.Bot.set_webhook(),telegram.ext.Application.run_polling()andtelegram.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_usersadministrator 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_REACTIONin the list oftelegram.ext.Application.run_polling.allowed_updatesto receive these updates (seetelegram.Bot.get_updates(),telegram.Bot.set_webhook(),telegram.ext.Application.run_polling()andtelegram.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_COUNTin the list oftelegram.ext.Application.run_polling.allowed_updatesto receive these updates (seetelegram.Bot.get_updates(),telegram.Bot.set_webhook(),telegram.ext.Application.run_polling()andtelegram.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:
- message
Optional. New incoming message of any kind - text, photo, sticker, etc.
- Type:
- 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:
- channel_post
Optional. New incoming channel post of any kind - text, photo, sticker, etc.
- Type:
- 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:
- inline_query
Optional. New incoming inline query.
- Type:
- chosen_inline_result
Optional. The result of an inline query that was chosen by a user and sent to their chat partner.
- callback_query
Optional. New incoming callback query.
Examples
Arbitrary Callback Data Bot- Type:
- shipping_query
Optional. New incoming shipping query. Only for invoices with flexible price.
- Type:
- pre_checkout_query
Optional. New incoming pre-checkout query. Contains full information about checkout.
- poll
Optional. New poll state. Bots receive only updates about manually stopped polls and polls, which are sent by the bot.
- Type:
- 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:
- 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.
- 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_MEMBERin the list oftelegram.ext.Application.run_polling.allowed_updatesto receive these updates (seetelegram.Bot.get_updates(),telegram.Bot.set_webhook(),telegram.ext.Application.run_polling()andtelegram.ext.Application.run_webhook()).Added in version 13.4.
- chat_join_request
Optional. A request to join the chat has been sent. The bot must have the
telegram.ChatPermissions.can_invite_usersadministrator right in the chat to receive these updates.Added in version 13.8.
- Type:
- 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.
- 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.
- 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_REACTIONin the list oftelegram.ext.Application.run_polling.allowed_updatesto receive these updates (seetelegram.Bot.get_updates(),telegram.Bot.set_webhook(),telegram.ext.Application.run_polling()andtelegram.ext.Application.run_webhook()). The update isn’t received for reactions set by bots.Added in version 20.8.
- 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_COUNTin the list oftelegram.ext.Application.run_polling.allowed_updatesto receive these updates (seetelegram.Bot.get_updates(),telegram.Bot.set_webhook(),telegram.ext.Application.run_polling()andtelegram.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
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.
- business_message
Optional. New message from a connected business account.
Added in version 21.1.
- Type:
- edited_business_message
Optional. New version of a message from a connected business account.
Added in version 21.1.
- Type:
- deleted_business_messages
Optional. Messages were deleted from a connected business account.
Added in version 21.1.
- 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.
- 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_CONNECTIONAdded in version 21.1.
- BUSINESS_MESSAGE: Final[str] = 'business_message'
telegram.constants.UpdateType.BUSINESS_MESSAGEAdded in version 21.1.
- CALLBACK_QUERY: Final[str] = 'callback_query'
telegram.constants.UpdateType.CALLBACK_QUERYAdded in version 13.5.
- CHANNEL_POST: Final[str] = 'channel_post'
telegram.constants.UpdateType.CHANNEL_POSTAdded in version 13.5.
- CHAT_BOOST: Final[str] = 'chat_boost'
telegram.constants.UpdateType.CHAT_BOOSTAdded in version 20.8.
- CHAT_JOIN_REQUEST: Final[str] = 'chat_join_request'
telegram.constants.UpdateType.CHAT_JOIN_REQUESTAdded in version 13.8.
- CHAT_MEMBER: Final[str] = 'chat_member'
telegram.constants.UpdateType.CHAT_MEMBERAdded in version 13.5.
- CHOSEN_INLINE_RESULT: Final[str] = 'chosen_inline_result'
telegram.constants.UpdateType.CHOSEN_INLINE_RESULTAdded in version 13.5.
- DELETED_BUSINESS_MESSAGES: Final[str] = 'deleted_business_messages'
telegram.constants.UpdateType.DELETED_BUSINESS_MESSAGESAdded in version 21.1.
- EDITED_BUSINESS_MESSAGE: Final[str] = 'edited_business_message'
telegram.constants.UpdateType.EDITED_BUSINESS_MESSAGEAdded in version 21.1.
- EDITED_CHANNEL_POST: Final[str] = 'edited_channel_post'
telegram.constants.UpdateType.EDITED_CHANNEL_POSTAdded in version 13.5.
- EDITED_MESSAGE: Final[str] = 'edited_message'
telegram.constants.UpdateType.EDITED_MESSAGEAdded in version 13.5.
- INLINE_QUERY: Final[str] = 'inline_query'
telegram.constants.UpdateType.INLINE_QUERYAdded in version 13.5.
- MESSAGE_REACTION: Final[str] = 'message_reaction'
telegram.constants.UpdateType.MESSAGE_REACTIONAdded in version 20.8.
- MESSAGE_REACTION_COUNT: Final[str] = 'message_reaction_count'
telegram.constants.UpdateType.MESSAGE_REACTION_COUNTAdded in version 20.8.
- MY_CHAT_MEMBER: Final[str] = 'my_chat_member'
telegram.constants.UpdateType.MY_CHAT_MEMBERAdded in version 13.5.
- POLL_ANSWER: Final[str] = 'poll_answer'
telegram.constants.UpdateType.POLL_ANSWERAdded in version 13.5.
- PRE_CHECKOUT_QUERY: Final[str] = 'pre_checkout_query'
telegram.constants.UpdateType.PRE_CHECKOUT_QUERYAdded in version 13.5.
- PURCHASED_PAID_MEDIA: Final[str] = 'purchased_paid_media'
telegram.constants.UpdateType.PURCHASED_PAID_MEDIAAdded in version 21.6.
- REMOVED_CHAT_BOOST: Final[str] = 'removed_chat_boost'
telegram.constants.UpdateType.REMOVED_CHAT_BOOSTAdded in version 20.8.
- SHIPPING_QUERY: Final[str] = 'shipping_query'
telegram.constants.UpdateType.SHIPPING_QUERYAdded in version 13.5.
- callback_query: CallbackQuery | None
- classmethod de_json(data, bot=None)[source]
See
telegram.TelegramObject.de_json().- Return type:
- 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, ifinline_query,chosen_inline_result,callback_queryfrom inline messages,shipping_query,pre_checkout_query,poll,poll_answer,business_connection, orpurchased_paid_mediais present.Changed in version 21.1: This property now also considers
business_message,edited_business_message, anddeleted_business_messages.Example
If
messageis present, this will givetelegram.Message.chat.- Type:
- 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_postorcallback_query(i.e.telegram.CallbackQuery.message) orNone, if none of those are present.
Changed in version 21.1: This property now also considers
business_message, andedited_business_message.Tip
This property will only ever return objects of type
telegram.MessageorNone, nevertelegram.MaybeInaccessibleMessageortelegram.InaccessibleMessage. Currently, this is only relevant forcallback_query, astelegram.CallbackQuery.messageis the only attribute considered by this property that can be an object of these types.- Type:
- property effective_sender: User | Chat | None
The user or chat that sent this update, no matter what kind of update this is.
Note
Depending on the type of update and the user’s ‘Remain anonymous’ setting, this could either be
telegram.User,telegram.ChatorNone.
If no user whatsoever is associated with this update, this gives
None. This is the case if any ofis present.
Example
If
messageis present, this will give eithertelegram.Message.from_userortelegram.Message.sender_chat.If
poll_answeris present, this will give eithertelegram.PollAnswer.userortelegram.PollAnswer.voter_chat.If
channel_postis present, this will givetelegram.Message.sender_chat.
Added in version 21.1.
- Type:
- 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 ofis present.
Changed in version 21.1: This property now also considers
business_connection,business_messageandedited_business_message.Changed in version 21.6: This property now also considers
purchased_paid_media.Example
If
messageis present, this will givetelegram.Message.from_user.If
poll_answeris present, this will givetelegram.PollAnswer.user.
- Type:
- 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
- spotted.utils.conversation_util.conv_fail(family)[source]
Creates a function used to handle any error in the conversation
spotted.utils.info_util module
Common info needed in both command and callback handlers
- exception spotted.utils.info_util.BadRequest(message)[source]
Bases:
NetworkErrorRaised 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_kwargswhich 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 indo_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 raiseTypeError.
Examples
Raw API BotSee 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
botis equal.Changed in version 20.0:
Removed the deprecated methods
kick_chat_member,kickChatMember,get_chat_members_countandgetChatMembersCount.Removed the deprecated property
commands.Removed the deprecated
defaultsparameter. If you want to usetelegram.ext.Defaults, please use the subclasstelegram.ext.ExtBotinstead.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_modeisFalse, 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_thumbandsetStickerSetThumb. Useset_sticker_set_thumbnail()andsetStickerSetThumbnail()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 initializedtelegram.request.BaseRequestinstances. Will be used for all bot methods except forget_updates(). If not passed, an instance oftelegram.request.HTTPXRequestwill be used.get_updates_request (
BaseRequest|None, default:None) – Pre initializedtelegram.request.BaseRequestinstances. Will be used exclusively forget_updates(). If not passed, an instance oftelegram.request.HTTPXRequestwill 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 thebase_urlis the URI of a Local Bot API Server that runs with the--localflag. Currently, the only effect of this is that files are uploaded using their local path in the file URI scheme. Defaults toFalse.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:
- 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_STICKERSstickers. Other sticker sets can have up totelegram.constants.StickerSetLimit.MAX_STATIC_STICKERSstickers.Changed in version 20.2: Since Bot API 6.6, the parameter
stickerreplace the parameterspng_sticker,tgs_sticker,webm_sticker,emojis, andmask_position.Changed in version 20.5: Removed deprecated parameters
png_sticker,tgs_sticker,webm_sticker,emojis, andmask_position.
- 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:
- 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:
- 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:
- 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:
- 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:
- 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_LENGTHcharacters.show_alert (
bool|None, default:None) – IfTrue, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults toFalse.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:
- Raises:
- 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_RESULTSresults per query are allowed.Warning
In most use cases
current_offsetshould not be passed manually. Instead of calling this method directly, use the shortcuttelegram.InlineQuery.answer()withtelegram.InlineQuery.answer.auto_paginationset toTrue, 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_textandswitch_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 casecurrent_offsetis passed,resultsmay also be a callable that accepts the current page index starting from 0. It must return either a list oftelegram.InlineQueryResultinstances orNoneif 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) – PassTrue, 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 exceedtelegram.InlineQuery.MAX_OFFSET_LENGTHbytes.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) – Thetelegram.InlineQuery.offsetof the inline query to answer. If passed, PTB will automatically take care of the pagination for you, i.e. pass the correctnext_offsetand truncate the results list/get the results from the callable you passed.- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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.Updatewith the fieldtelegram.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) – SpecifyTrueif everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. UseFalseif there are any problems.error_message (
str|None, default:None) – Required ifokisFalse. 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,
Trueis returned- Returns:
bool–- Raises:
- 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_flexiblewas specified, the Bot API will send antelegram.Updatewith atelegram.Update.shipping_queryfield 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) – SpecifyTrueif delivery to the specified address is possible andFalseif there are any problems (for example, if delivery to the specified address is not possible).shipping_options (
Sequence[ShippingOption] |None, default:None) –Required if
okisTrue. A sequence of available shipping options.Changed in version 20.0: |sequenceargs|
error_message (
str|None, default:None) – Required ifokisFalse. 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,
Trueis returned.- Returns:
bool–- Raises:
- 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.SentWebAppMessageis returned.- Returns:
- Raises:
- 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:
- 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:
- 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_usersadministrator right.Added in version 13.8.
- 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_messagesadministrator 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_DATEseconds (30 days) in the future.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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:
- 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
Trueto delete all messages from the chat for the user that is being removed. IfFalse, the user will be able to see messages in the group that were sent before the user was removed. AlwaysTruefor supergroups and channels.Added in version 13.4.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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.
- property base_file_url: str
Telegram Bot API file URL, built from
Bot.base_file_urlandBot.token.Added in version 20.0.
- Type:
- property base_url: str
Telegram Bot API service URL, built from
Bot.base_urlandBot.token.Added in version 20.0.
- Type:
- 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 untilget_me()is called again.See also
- Type:
- property can_join_groups: bool
Bot’s
telegram.User.can_join_groupsattribute. Shortcut for the corresponding attribute ofbot.- Type:
- property can_read_all_group_messages: bool
Bot’s
telegram.User.can_read_all_group_messagesattribute. Shortcut for the corresponding attribute ofbot.- Type:
- 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.
- 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:
- 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:
- 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_topicsadministrator 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|
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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_topicsadministrator rights.Added in version 20.0.
- Parameters:
chat_id (
str|int) – |chat_id_group|- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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_starsbusiness bot right.Added in version 22.1.
- 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:
- 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()
- 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_LENGTHcharacters 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 intelegram.constants.ParseModefor the available modes.caption_entities (
Sequence[MessageEntity] |None, default:None) –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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –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) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged in version 20.8: Bot API 7.0 introduced
reply_parameters|rtm_aswr_deprecated|Changed in version 21.0: |keyword_only_arg|
- Returns:
- On success, the
telegram.MessageIdof the sent message is returned.
- On success, the
- Returns:
- Raises:
- 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_idis known to the bot. The method is analogous to the methodforward_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 oftelegram.constants.BulkRequestLimit.MIN_LIMIT-telegram.constants.BulkRequestLimit.MAX_LIMITidentifiers of messages in the chatfrom_chat_idto 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) – PassTrueto 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
MessageIdof the sent messages is returned.- Returns:
- Raises:
- async createChatInviteLink(chat_id, expire_date=None, member_limit=None, name=None, creates_join_request=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
create_chat_invite_link()- Return type:
- async createChatSubscriptionInviteLink(chat_id, subscription_period, subscription_price, name=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
create_chat_subscription_invite_link()- Return type:
- 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:
- async createInvoiceLink(title, description, payload, currency, prices, provider_token=None, max_tip_amount=None, suggested_tip_amounts=None, provider_data=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, send_phone_number_to_provider=None, send_email_to_provider=None, is_flexible=None, subscription_period=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
create_invoice_link()- Return type:
- 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:
- async create_chat_invite_link(chat_id, expire_date=None, member_limit=None, name=None, creates_join_request=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]
Use this method to create an additional invite link for a chat. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. The link can be revoked using the method
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_requesthas 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_LENGTHcharacters.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. IfTrue,member_limitcan’t be specified.Added in version 13.8.
- Returns:
- Raises:
- async create_chat_subscription_invite_link(chat_id, subscription_period, subscription_price, name=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]
Use this method to create a subscription invite link for a channel chat. The bot must have the
can_invite_usersadministrator right. The link can be edited using theedit_chat_subscription_invite_link()or revoked using therevoke_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_LENGTHcharacters.
- Returns:
- Raises:
- 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_topicsadministrator 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_LENGTHcharacters.icon_color (
int|None, default:None) – Color of the topic icon in RGB format. Currently, must be one oftelegram.constants.ForumIconColor.BLUE,telegram.constants.ForumIconColor.YELLOW,telegram.constants.ForumIconColor.PURPLE,telegram.constants.ForumIconColor.GREEN,telegram.constants.ForumIconColor.PINK, ortelegram.constants.ForumIconColor.RED.icon_custom_emoji_id (
str|None, default:None) – New unique identifier of the custom emoji shown as the topic icon. Useget_forum_topic_icon_stickers()to get all allowed custom emoji identifiers.
- Returns:
- Raises:
- async create_invoice_link(title, description, payload, currency, prices, provider_token=None, max_tip_amount=None, suggested_tip_amounts=None, provider_data=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, send_phone_number_to_provider=None, send_email_to_provider=None, is_flexible=None, subscription_period=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 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_LENGTHcharacters.description (
str) – Product description.telegram.Invoice.MIN_DESCRIPTION_LENGTH-telegram.Invoice.MAX_DESCRIPTION_LENGTHcharacters.payload (
str) – Bot-defined invoice payload.telegram.Invoice.MIN_PAYLOAD_LENGTH-telegram.Invoice.MAX_PAYLOAD_LENGTHbytes. 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. PassXTRfor 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.timedeltaobject. The currency must be set to“XTR”(Telegram Stars) if the parameter is used. Currently, it must always betelegram.constants.InvoiceLimit.SUBSCRIPTION_PERIODif 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 exceedtelegram.constants.InvoiceLimit.SUBSCRIPTION_MAX_PRICETelegram 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 ofUS$ 1.45passmax_tip_amount = 145. See theexpparameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to0. 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_AMOUNTSsuggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceedmax_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.need_name (
bool|None, default:None) – PassTrue, 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) – PassTrue, if you require the user’s phone number to complete the order. Ignored for payments in |tg_stars|.need_email (
bool|None, default:None) – PassTrue, 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) – PassTrue, 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) – PassTrue, if user’s phone number should be sent to provider. Ignored for payments in |tg_stars|.send_email_to_provider (
bool|None, default:None) – PassTrue, if user’s email address should be sent to provider. Ignored for payments in |tg_stars|.is_flexible (
bool|None, default:None) – PassTrue, 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_maskshas been removed. Usesticker_typeinstead.Changed in version 20.2: Since Bot API 6.6, the parameters
stickersandsticker_formatreplace the parameterspng_sticker,tgs_sticker,``webm_sticker``,emojis, andmask_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_TITLEcharacters.title (
str) – Sticker set title,telegram.constants.StickerLimit.MIN_NAME_AND_TITLE-telegram.constants.StickerLimit.MAX_NAME_AND_TITLEcharacters.stickers (
Sequence[InputSticker]) –A sequence of
telegram.constants.StickerSetLimit.MIN_INITIAL_STICKERS-telegram.constants.StickerSetLimit.MAX_INITIAL_STICKERSinitial 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.REGULARortelegram.Sticker.MASK, ortelegram.Sticker.CUSTOM_EMOJI. By default, a regular sticker set is createdAdded in version 20.0.
needs_repainting (
bool|None, default:None) –Pass
Trueif 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,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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:
- 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_usersadministrator right.Added in version 13.8.
- 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_messagesadministrator right in the corresponding channel chat.Added in version 22.4.
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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_messagesbusiness bot right to delete messages sent by the bot itself, or thecan_delete_all_messagesbusiness 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 messagesmessage_ids (
Sequence[int]) – A list oftelegram.constants.BulkRequestLimit.MIN_LIMIT-telegram.constants.BulkRequestLimit.MAX_LIMITidentifiers of messages to delete. Seedelete_message()for limitations on which messages can be deleted.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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,
Trueis returned.- Returns:
bool–- Raises:
- 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_setoptionally returned inget_chat()requests to check if the bot can use this method.- Parameters:
chat_id (
str|int) – |chat_id_group|- Returns:
On success,
Trueis 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_messagesadministrator rights.Added in version 20.0.
- Parameters:
chat_id (
str|int) – |chat_id_group|message_thread_id (
int) – |message_thread_id|
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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_messagespermissions 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_messagespermission in a supergroup or a channel, it can delete any message there.
See also
telegram.CallbackQuery.delete_message()(callsdelete_message()indirectly, viatelegram.Message.delete())
- 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 oftelegram.constants.BulkRequestLimit.MIN_LIMIT-telegram.constants.BulkRequestLimit.MAX_LIMITidentifiers of messages to delete. Seedelete_message()for limitations on which messages can be deleted.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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.
See also
- Parameters:
scope (
BotCommandScope|None, default:None) – An object, describing scope of users for which the commands are relevant. Defaults totelegram.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,
Trueis returned.- Returns:
bool–- Raises:
- 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.Stickerinstances.- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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.
- 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_storiesbusiness bot right.Added in version 22.1.
- 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().
- 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
telegrammodule is supportedwhen uploading files, a
telegram.InputFilemust 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.Defaultswill not work (only relevant fortelegram.ext.ExtBot).The only exception is
telegram.ext.Defaults.tzinfo, which will be correctly applied todatetime.datetimeobjects.
Added in version 20.8.
- Parameters:
endpoint (
str) – The API endpoint to use, e.g.getMeorget_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. Ifreturn_typeis not specified, this is adictorbool, otherwise an instance ofreturn_typeor a tuple ofreturn_type.- Raises:
- async editChatInviteLink(chat_id, invite_link, expire_date=None, member_limit=None, name=None, creates_join_request=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
edit_chat_invite_link()- Return type:
- async editChatSubscriptionInviteLink(chat_id, invite_link, name=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
edit_chat_subscription_invite_link()- Return type:
- 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:
- 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:
- 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()
- 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:
- 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()
- 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()
- 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()
- 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()
- 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:
- 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:
- async edit_chat_invite_link(chat_id, invite_link, expire_date=None, member_limit=None, name=None, creates_join_request=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]
Use this method to edit a non-primary invite link created by the bot. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
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.ChatInviteLinkinstances.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_LENGTHcharacters.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. IfTrue,member_limitcan’t be specified.Added in version 13.8.
- Returns:
- Raises:
- async edit_chat_subscription_invite_link(chat_id, invite_link, name=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]
Use this method to edit a subscription invite link created by the bot. The bot must have
telegram.ChatPermissions.can_invite_usersadministrator right.Added in version 21.5.
- Parameters:
- Returns:
- Raises:
- 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_topicsadministrator 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_LENGTHcharacters. 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. Useget_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,
Trueis returned.- Returns:
bool–- Raises:
- 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_topicsadministrator rights.Added in version 20.0.
- 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_LENGTHcharacters after entities parsing.parse_mode (DefaultValue[DVValueType] |
str| DefaultValue[None] |None, default:None) – |parse_mode|caption_entities (
Sequence[MessageEntity] |None, default:None) –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) –Added in version 21.4.
- Returns:
On success, if edited message is not an inline message, the edited message is returned, otherwise
Trueis returned.- Returns:
- Raises:
- 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:
- 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_periodexpires or editing is explicitly disabled by a call tostop_message_live_location().Note
You can either supply a
latitudeandlongitudeor alocation.- Parameters:
chat_id (
int|str|None, default:None) – Required ifinline_message_idis not specified. |chat_id_channel|message_id (
int|None, default:None) – Required ifinline_message_idis not specified. Identifier of the message to edit.inline_message_id (
str|None, default:None) – Required ifchat_idandmessage_idare 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 betweentelegram.constants.LocationLimit.MIN_HEADINGandtelegram.constants.LocationLimit.MAX_HEADINGif specified.proximity_alert_radius (
int|None, default:None) – Maximum distance for proximity alerts about approaching another chat member, in meters. Must be betweentelegram.constants.LocationLimit.MIN_PROXIMITY_ALERT_RADIUSandtelegram.constants.LocationLimit.MAX_PROXIMITY_ALERT_RADIUSif 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_FOREVERis specified, then the location can be updated forever. Otherwise, the new value must not exceed the currentlive_periodby more than a day, and the live location expiration date must remain within the next 90 days. If not specified, thenlive_periodremains unchangedAdded in version 21.2..
Changed in version 21.11: |time-period-input|
business_connection_id (
str|None, default:None) –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
Trueis returned.- Returns:
- 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_idor 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) –Added in version 21.4.
- Returns:
On success, if edited message is not an inline message, the edited Message is returned, otherwise
Trueis returned.- Returns:
- Raises:
- 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) –Added in version 21.4.
- Returns:
On success, if edited message is not an inline message, the edited message is returned, otherwise
Trueis returned.- Returns:
- Raises:
- 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.
See also
- Parameters:
chat_id (
int|str|None, default:None) – Required ifinline_message_idis not specified. |chat_id_channel|message_id (
int|None, default:None) – Required ifinline_message_idis not specified. Identifier of the message to edit.inline_message_id (
str|None, default:None) – Required ifchat_idandmessage_idare 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_LENGTHcharacters 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) –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 withlink_preview_options.Changed in version 20.8: Bot API 7.0 introduced
link_preview_optionsreplacing this argument. PTB will automatically convert this argument to that one, but for advanced options, please uselink_preview_optionsdirectly.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
Trueis returned.- Returns:
- Raises:
ValueError – If both
disable_web_page_previewandlink_preview_optionsare passed.telegram.error.TelegramError – For other errors.
- 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_storiesbusiness 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_LENGTHcharacters after entities parsing.parse_mode (DefaultValue[DVValueType] |
str| DefaultValue[None] |None, default:None) – Mode for parsing entities in the story caption. See the constants intelegram.constants.ParseModefor 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
areashas its own maximum limit:Up to
~telegram.constants.StoryAreaTypeLimit.MAX_LOCATION_AREASoftelegram.StoryAreaTypeLocation.Up to
~telegram.constants.StoryAreaTypeLimit.MAX_SUGGESTED_REACTION_AREASoftelegram.StoryAreaTypeSuggestedReaction.Up to
~telegram.constants.StoryAreaTypeLimit.MAX_LINK_AREASoftelegram.StoryAreaTypeLink.Up to
~telegram.constants.StoryAreaTypeLimit.MAX_WEATHER_AREASoftelegram.StoryAreaTypeWeather.Up to
~telegram.constants.StoryAreaTypeLimit.MAX_UNIQUE_GIFT_AREASoftelegram.StoryAreaTypeUniqueGift.
- Returns:
Story–Story- Raises:
- 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) – PassTrueto cancel extension of the user subscription; the subscription must be active up to the end of the current subscription period. PassFalseto allow the user to re-enable a subscription that was previously canceled by the bot.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- async exportChatInviteLink(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
export_chat_invite_link()- Return type:
- async export_chat_invite_link(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]
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 theget_chat()method. If your bot needs to generate a new primary invite link replacing its previous one, useexport_chat_invite_link()again.- Parameters:
chat_id (
str|int) – |chat_id_channel|- Returns:
New invite link on success.
- Returns:
str–- Raises:
- 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:
- 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()
- 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_contentandtelegram.ChatFullInfo.has_protected_contentto 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 infrom_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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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:
- 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 oftelegram.constants.BulkRequestLimit.MIN_LIMIT-telegram.constants.BulkRequestLimit.MAX_LIMITidentifiers of messages in the chatfrom_chat_idto 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
MessageIdof sent messages is returned.- Returns:
- Raises:
- async getAvailableGifts(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
get_available_gifts()- Return type:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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()
- 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:
- async getForumTopicIconStickers(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
get_forum_topic_icon_stickers()
- 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:
- async getMe(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
get_me()- Return type:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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()
- 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:
- 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:
- async getWebhookInfo(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
get_webhook_info()- Return type:
- 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:
- Raises:
- 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_starsbusiness bot right.Added in version 22.1.
- Parameters:
business_connection_id (
str) – Unique identifier of the business connection.exclude_unsaved (
bool|None, default:None) – PassTrueto exclude gifts that aren’t saved to the account’s profile page.exclude_saved (
bool|None, default:None) – PassTrueto exclude gifts that are saved to the account’s profile page.exclude_unlimited (
bool|None, default:None) – PassTrueto exclude gifts that can be purchased an unlimited number of times.exclude_limited (
bool|None, default:None) – PassTrueto exclude gifts that can be purchased a limited number of times.exclude_unique (
bool|None, default:None) – PassTrueto exclude unique gifts.sort_by_price (
bool|None, default:None) – PassTrueto 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 totelegram.constants.BusinessLimit.MAX_GIFT_RESULTS.
- Returns:
- Raises:
- 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_starsbusiness bot right.Added in version 22.1.
- Parameters:
business_connection_id (
str) – Unique identifier of the business connection.- Returns:
- Raises:
- 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:
- Raises:
- 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:
- Raises:
- 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
ChatMemberobjects 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:
- 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:
chat_id (
str|int) – |chat_id_channel|user_id (
int) – Unique identifier of the target user.
- Returns:
- Raises:
- 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:
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.
- 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_LIMITcustom emoji identifiers can be specified.Changed in version 20.0: |sequenceargs|
- Returns:
tuple[Sticker,...] – tuple[telegram.Sticker]- Raises:
- 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_DOWNLOADin size. The file can then be e.g. downloaded withtelegram.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>
- 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:
- 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 ifinline_message_idis not specified. Unique identifier for the target chat.message_id (
int|None, default:None) – Required ifinline_message_idis not specified. Identifier of the sent message.inline_message_id (
str|None, default:None) – Required ifchat_idandmessage_idare not specified. Identifier of the inline message.
- Returns:
tuple[GameHighScore,...] – tuple[telegram.GameHighScore]- Raises:
- 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.Userinstance representing that bot if the credentials are valid,Noneotherwise.- Returns:
User–- Raises:
- 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.
See also
Changed in version 20.0: Returns a tuple instead of a list.
- Parameters:
scope (
BotCommandScope|None, default:None) –An object, describing scope of users. Defaults to
telegram.BotCommandScopeDefault.Added in version 13.7.
language_code (
str|None, default:None) –A two-letter ISO 639-1 language code or an empty string.
Added in version 13.7.
- Returns:
On success, the commands set for the bot. An empty tuple is returned if commands are not set.
- Returns:
tuple[BotCommand,...] –- Raises:
- 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.
- 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.
- 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.
- 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.
- 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:
- Raises:
- 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 betweentelegram.constants.StarTransactionsLimit.MIN_LIMIT-telegram.constants.StarTransactionsLimit.MAX_LIMITare accepted. Defaults totelegram.constants.StarTransactionsLimit.MAX_LIMIT.
- Returns:
On success.
- Returns:
- Raises:
- 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:
- Raises:
- 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
This method will not work if an outgoing webhook is set up.
In order to avoid getting duplicate updates, recalculate offset after each server response.
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 itstelegram.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 betweentelegram.constants.PollingLimit.MIN_LIMIT-telegram.constants.PollingLimit.MAX_LIMITare accepted. Defaults to100.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.Updatefor a complete list of available update types. Specify an empty sequence to receive all updates excepttelegram.Update.chat_member,telegram.Update.message_reactionandtelegram.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:
- 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:
chat_id (
str|int) – |chat_id_channel|user_id (
int) – Unique identifier of the target user.
- Returns:
- On success, the object containing the list of boosts
is returned.
- Returns:
- Raises:
- 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 betweentelegram.constants.UserProfilePhotosLimit.MIN_LIMIT-telegram.constants.UserProfilePhotosLimit.MAX_LIMITare accepted. Defaults to100.
- Returns:
- Raises:
- 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 thetelegram.WebhookInfo.urlfield empty.- Returns:
- 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:
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 oftelegram.constants.PremiumSubscription.MONTH_COUNT_THREE,telegram.constants.PremiumSubscription.MONTH_COUNT_SIX, ortelegram.constants.PremiumSubscription.MONTH_COUNT_TWELVE.star_count (
int) – Number of Telegram Stars to pay for the Telegram Premium subscription; must betelegram.constants.PremiumSubscription.STARS_THREE_MONTHSfortelegram.constants.PremiumSubscription.MONTH_COUNT_THREEmonths,telegram.constants.PremiumSubscription.STARS_SIX_MONTHSfortelegram.constants.PremiumSubscription.MONTH_COUNT_SIXmonths, andtelegram.constants.PremiumSubscription.STARS_TWELVE_MONTHSfortelegram.constants.PremiumSubscription.MONTH_COUNT_TWELVEmonths.text (
str|None, default:None) – Text that will be shown along with the service message about the subscription; 0-telegram.constants.PremiumSubscription.MAX_TEXT_LENGTHcharacters.text_parse_mode (DefaultValue[DVValueType] |
str| DefaultValue[None] |None, default:None) – Mode for parsing entities. Seetelegram.constants.ParseModeand formatting options for more details. Entities other thanBOLD,ITALIC,UNDERLINE,STRIKETHROUGH,SPOILER, andCUSTOM_EMOJIare ignored.text_entities (
Sequence[MessageEntity] |None, default:None) – A list of special entities that appear in the gift text. It can be specified instead oftext_parse_mode. Entities other thanBOLD,ITALIC,UNDERLINE,STRIKETHROUGH,SPOILER, andCUSTOM_EMOJIare ignored.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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_topicsadministrator 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,
Trueis returned.- Returns:
bool–- Raises:
- property id: int
Unique identifier for this bot. Shortcut for the corresponding attribute of
bot.- Type:
- async initialize()[source]
Initialize resources used by this class. Currently calls
get_me()to cachebotand callstelegram.request.BaseRequest.initialize()for the request objects used by this bot.See also
Added in version 20.0.
- Return type:
- property last_name: str
Optional. Bot’s last name. Shortcut for the corresponding attribute of
bot.- Type:
- 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:
- 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,
Trueis returned.- Returns:
bool–- Raises:
- async logOut(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
log_out()- Return type:
- 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.
- 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:
- 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_messagesadmin right in a supergroup orcan_edit_messagesadmin 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) – PassTrue, 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,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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_storiesbusiness 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_LENGTHcharacters after entities parsing.parse_mode (DefaultValue[DVValueType] |
str| DefaultValue[None] |None, default:None) – Mode for parsing entities in the story caption. See the constants intelegram.constants.ParseModefor 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
areashas its own maximum limit:Up to
~telegram.constants.StoryAreaTypeLimit.MAX_LOCATION_AREASoftelegram.StoryAreaTypeLocation.Up to
~telegram.constants.StoryAreaTypeLimit.MAX_SUGGESTED_REACTION_AREASoftelegram.StoryAreaTypeSuggestedReaction.Up to
~telegram.constants.StoryAreaTypeLimit.MAX_LINK_AREASoftelegram.StoryAreaTypeLink.Up to
~telegram.constants.StoryAreaTypeLimit.MAX_WEATHER_AREASoftelegram.StoryAreaTypeWeather.Up to
~telegram.constants.StoryAreaTypeLimit.MAX_UNIQUE_GIFT_AREASoftelegram.StoryAreaTypeUniqueGift.
post_to_chat_page (
bool|None, default:None) – PassTrueto keep the story accessible after it expires.protect_content (DefaultValue[DVValueType] |
bool| DefaultValue[None] |None, default:None) – PassTrueif the content of the story must be protected from forwarding and screenshotting
- Returns:
Story–Story- Raises:
- 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:
- 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
Falsefor all boolean parameters to demote a user.Changed in version 20.0: The argument
can_manage_voice_chatswas renamed tocan_manage_video_chatsin 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) – PassTrue, 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) – PassTrue, if the administrator can change chat title, photo and other settings.can_post_messages (
bool|None, default:None) – PassTrue, if the administrator can post messages in the channel, or access channel statistics; for channels only.can_edit_messages (
bool|None, default:None) – PassTrue, if the administrator can edit messages of other users and can pin messages, for channels only.can_delete_messages (
bool|None, default:None) – PassTrue, if the administrator can delete messages of other users.can_invite_users (
bool|None, default:None) – PassTrue, if the administrator can invite new users to the chat.can_restrict_members (
bool|None, default:None) – PassTrue, if the administrator can restrict, ban or unban chat members, or access supergroup statistics.can_pin_messages (
bool|None, default:None) – PassTrue, if the administrator can pin messages, for supergroups only.can_promote_members (
bool|None, default:None) – PassTrue, 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 archiveAdded 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 onlyAdded in version 22.4.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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_messagesbusiness 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_TIMEOUTseconds.message_id (
int) – Unique identifier of the message to mark as read.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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.
- 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:
- 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:
- 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:
- 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_photobusiness bot right.Added in version 22.1.
- Parameters:
business_connection_id (
str) – Unique identifier of the business connection.is_public (
bool|None, default:None) – PassTrueto 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,
Trueis returned.- Returns:
bool–- Raises:
- 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,
Trueis returned.- Returns:
bool–- Raises:
- 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.
- 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:
- 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:
- 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_topicsadministrator 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|
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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_topicsadministrator 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,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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(), thenadd_sticker_to_set(), thenset_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.Stickerinstances.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,
Trueis returned.- Returns:
bool–- Raises:
- property request: BaseRequest
The
BaseRequestobject 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:
- 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
Truefor all boolean parameters to lift restrictions from a user.- Parameters:
chat_id (
str|int) – |chat_id_group|user_id (
int) – Unique identifier of the target user.until_date (
int|datetime|None, default:None) – Date when restrictions will be lifted for the user, unix time. If user is restricted for more than 366 days or less than 30 seconds from the current time, they are considered to be restricted forever. |tz-naive-dtms|permissions (
ChatPermissions) – An object for new user permissions.use_independent_chat_permissions (
bool|None, default:None) –Pass
Trueif chat permissions are set independently. Otherwise, thecan_send_other_messagesandcan_add_web_page_previewspermissions will imply thecan_send_messages,can_send_audios,can_send_documents,can_send_photos,can_send_videos,can_send_video_notes, andcan_send_voice_notespermissions; thecan_send_pollspermission will imply thecan_send_messagespermission.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- async revokeChatInviteLink(chat_id, invite_link, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
revoke_chat_invite_link()- Return type:
- async revoke_chat_invite_link(chat_id, invite_link, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]
Use this method to revoke an invite link created by the bot. If the primary link is revoked, a new link is automatically generated. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
Added in version 13.4.
- Parameters:
chat_id (
str|int) – |chat_id_channel|invite_link (
str| ChatInviteLink) –The invite link to revoke.
Changed in version 20.0: Now also accepts
telegram.ChatInviteLinkinstances.
- Returns:
- Raises:
- 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:
- 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) – PassTrueif the message can be sent to private chats with usersallow_bot_chats (
bool|None, default:None) – PassTrueif the message can be sent to private chats with botsallow_group_chats (
bool|None, default:None) – PassTrueif the message can be sent to group and supergroup chatsallow_channel_chats (
bool|None, default:None) – PassTrueif the message can be sent to channels
- Returns:
On success, the prepared message is returned.
- Returns:
- Raises:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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()
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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_UPLOADin size, this limit may be changed in the future.Note
thumbnailwill 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. Usethumbnailinstead.- Parameters:
chat_id (
int|str) – |chat_id_channel|animation (
str|Path|IO[bytes] | InputFile |bytes| Animation) –Animation to send. |fileinput| Lastly you can pass an existing
telegram.Animationobject to send.Changed in version 13.2: Accept
bytesas input.duration (
int|timedelta|None, default:None) –Duration of sent animation in seconds.
Changed in version 21.11: |time-period-input|
caption (
str|None, default:None) – Animation caption (may also be used when resending animations by file_id), 0-telegram.constants.MessageLimit.CAPTION_LENGTHcharacters after entities parsing.parse_mode (DefaultValue[DVValueType] |
str| DefaultValue[None] |None, default:None) – |parse_mode|caption_entities (
Sequence[MessageEntity] |None, default:None) –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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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
Trueif the animation needs to be covered with a spoiler animation.Added in version 20.0.
thumbnail (
str|Path|IO[bytes] | InputFile |bytes|None, default:None) –Added in version 20.2.
reply_parameters (ReplyParameters |
None, default:None) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –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) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged 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
tempfilemodule.Added in version 13.1.
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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
.mp3or.m4aformat.Bots can currently send audio files of up to
telegram.constants.FileSizeLimit.FILESIZE_UPLOADin 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. Usethumbnailinstead.- Parameters:
chat_id (
int|str) – |chat_id_channel|audio (
str|Path|IO[bytes] | InputFile |bytes| Audio) –Audio file to send. |fileinput| Lastly you can pass an existing
telegram.Audioobject to send.Changed in version 13.2: Accept
bytesas 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) – Audio caption, 0-telegram.constants.MessageLimit.CAPTION_LENGTHcharacters after entities parsing.parse_mode (DefaultValue[DVValueType] |
str| DefaultValue[None] |None, default:None) – |parse_mode|caption_entities (
Sequence[MessageEntity] |None, default:None) –Changed in version 20.0: |sequenceargs|
duration (
int|timedelta|None, default:None) –Duration of sent audio in seconds.
Changed in version 21.11: |time-period-input|
disable_notification (DefaultValue[DVValueType] |
bool| DefaultValue[None] |None, default:None) – |disable_notification|protect_content (DefaultValue[DVValueType] |
bool| DefaultValue[None] |None, default:None) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –Added in version 20.2.
reply_parameters (ReplyParameters |
None, default:None) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged 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
tempfilemodule.Added in version 13.1.
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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:
chat_id (
str|int) – |chat_id_channel|action (
str) – Type of action to broadcast. Choose one, depending on what the user is about to receive. For convenience look at the constants intelegram.constants.ChatAction.message_thread_id (
int|None, default:None) –Added in version 20.0.
business_connection_id (
str|None, default:None) –Added in version 21.1.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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:
business_connection_id (
str) – |business_id_str|chat_id (
int) – Unique identifier for the target chat.checklist (
InputChecklist) – The checklist to send.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_effect_id (
str|None, default:None) – |message_effect_id|reply_parameters (ReplyParameters |
None, default:None) – |reply_parameters|reply_markup (InlineKeyboardMarkup |
None, default:None) – An object for an inline keyboard
- Keyword Arguments:
allow_sending_without_reply (
bool, optional) – |allow_sending_without_reply| Mutually exclusive withreply_parameters, which this is a convenience parameter forreply_to_message_id (
int, optional) – |reply_to_msg_id| Mutually exclusive withreply_parameters, which this is a convenience parameter for
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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
contactorphone_numberandfirst_namewith optionallylast_nameand optionallyvcard.- 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.VCARDbytes.disable_notification (DefaultValue[DVValueType] |
bool| DefaultValue[None] |None, default:None) – |disable_notification|protect_content (DefaultValue[DVValueType] |
bool| DefaultValue[None] |None, default:None) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged in version 20.8: Bot API 7.0 introduced
reply_parameters|rtm_aswr_deprecated|Changed in version 21.0: |keyword_only_arg|
contact (
telegram.Contact, optional) – The contact to send.
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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 useremoji (
str|None, default:None) –Emoji on which the dice throw animation is based. Currently, must be one of
telegram.constants.DiceEmoji. Dice can have valuestelegram.Dice.MIN_VALUE-telegram.Dice.MAX_VALUE_BOWLINGfortelegram.Dice.DICE,telegram.Dice.DARTSandtelegram.Dice.BOWLING, valuestelegram.Dice.MIN_VALUE-telegram.Dice.MAX_VALUE_BASKETBALLfortelegram.Dice.BASKETBALLandtelegram.Dice.FOOTBALL, and valuestelegram.Dice.MIN_VALUE-telegram.Dice.MAX_VALUE_SLOT_MACHINEfortelegram.Dice.SLOT_MACHINE. Defaults totelegram.Dice.DICE.Changed in version 13.4: Added the
telegram.Dice.BOWLINGemoji.protect_content (DefaultValue[DVValueType] |
bool| DefaultValue[None] |None, default:None) –Added in version 13.10.
message_thread_id (
int|None, default:None) –Added in version 20.0.
reply_parameters (ReplyParameters |
None, default:None) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged in version 20.8: Bot API 7.0 introduced
reply_parameters|rtm_aswr_deprecated|Changed in version 21.0: |keyword_only_arg|
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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_UPLOADin 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. Usethumbnailinstead.- 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.Documentobject to send.Note
Sending by URL will currently only work
GIF,PDF&ZIPfiles.Changed in version 13.2: Accept
bytesas 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_LENGTHcharacters 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) –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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –Added in version 20.2.
reply_parameters (ReplyParameters |
None, default:None) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged 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 thetempfilemodule.
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
- Keyword Arguments:
allow_sending_without_reply (
bool, optional) –|allow_sending_without_reply| Mutually exclusive with
reply_parameters, which this is a convenience parameter forChanged 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 forChanged in version 20.8: Bot API 7.0 introduced
reply_parameters|rtm_aswr_deprecated|Changed in version 21.0: |keyword_only_arg|
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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_idoptional. In version 22.1, the methods signature was changed accordingly.- Parameters:
gift_id (
str|Gift) – Identifier of the gift or aGiftobjectuser_id (
int|None, default:None) –Required if
chat_idis 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_idis 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_LENGTHcharacterstext_parse_mode (DefaultValue[DVValueType] |
str| DefaultValue[None] |None, default:None) – Mode for parsing entities. Seetelegram.constants.ParseModeand formatting options for more details. Entities other thanBOLD,ITALIC,UNDERLINE,STRIKETHROUGH,SPOILER, andCUSTOM_EMOJIare ignored.text_entities (
Sequence[MessageEntity] |None, default:None) – A list of special entities that appear in the gift text. It can be specified instead oftext_parse_mode. Entities other thanBOLD,ITALIC,UNDERLINE,STRIKETHROUGH,SPOILER, andCUSTOM_EMOJIare ignored.pay_for_upgrade (
bool|None, default:None) –Pass
Trueto 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,
Trueis returned.- Returns:
bool–- Raises:
- 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_parameteris 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_parameteris optional.- Parameters:
chat_id (
int|str) – |chat_id_channel|title (
str) – Product name.telegram.Invoice.MIN_TITLE_LENGTH-telegram.Invoice.MAX_TITLE_LENGTHcharacters.description (
str) – Product description.telegram.Invoice.MIN_DESCRIPTION_LENGTH-telegram.Invoice.MAX_DESCRIPTION_LENGTHcharacters.payload (
str) – Bot-defined invoice payload.telegram.Invoice.MIN_PAYLOAD_LENGTH-telegram.Invoice.MAX_PAYLOAD_LENGTHbytes. 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
XTRfor 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.45passmax_tip_amount = 145. See theexpparameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to0. 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_AMOUNTSsuggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceedmax_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.need_name (
bool|None, default:None) – PassTrue, 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) – PassTrue, if you require the user’s phone number to complete the order. Ignored for payments in |tg_stars|.need_email (
bool|None, default:None) – PassTrue, if you require the user’s email to complete the order. Ignored for payments in |tg_stars|.need_shipping_address (
bool|None, default:None) – PassTrue, 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) – PassTrue, if user’s phone number should be sent to provider. Ignored for payments in |tg_stars|.send_email_to_provider (
bool|None, default:None) – PassTrue, if user’s email address should be sent to provider. Ignored for payments in |tg_stars|.is_flexible (
bool|None, default:None) – PassTrue, 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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –Added in version 20.8.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged in version 20.8: Bot API 7.0 introduced
reply_parameters|rtm_aswr_deprecated|Changed in version 21.0: |keyword_only_arg|
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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
latitudeandlongitudeor alocation.- 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_PERIODandtelegram.constants.LocationLimit.MAX_LIVE_PERIOD, ortelegram.constants.LocationLimit.LIVE_PERIOD_FOREVERfor 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 betweentelegram.constants.LocationLimit.MIN_HEADINGandtelegram.constants.LocationLimit.MAX_HEADINGif 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 betweentelegram.constants.LocationLimit.MIN_PROXIMITY_ALERT_RADIUSandtelegram.constants.LocationLimit.MAX_PROXIMITY_ALERT_RADIUSif specified.disable_notification (DefaultValue[DVValueType] |
bool| DefaultValue[None] |None, default:None) – |disable_notification|protect_content (DefaultValue[DVValueType] |
bool| DefaultValue[None] |None, default:None) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged in version 20.8: Bot API 7.0 introduced
reply_parameters|rtm_aswr_deprecated|Changed in version 21.0: |keyword_only_arg|
location (
telegram.Location, optional) – The location to send.
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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 eitherparse_modeorcaption_entities), then items inmediamust 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_LENGTHitems.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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –Added in version 20.0.
reply_parameters (ReplyParameters |
None, default:None) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –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 forChanged 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 forChanged 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 toNone.Added in version 20.0.
parse_mode (
str|None, optional) –Parse mode for
caption. See the constants intelegram.constants.ParseModefor 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 ofparse_mode. Defaults toNone.Added in version 20.0.
- Returns:
An array of the sent Messages.
- Returns:
- Raises:
- 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. Maxtelegram.constants.MessageLimit.MAX_TEXT_LENGTHcharacters 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) –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) –Added in version 20.0.
reply_parameters (ReplyParameters |
None, default:None) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged 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 withlink_preview_options.Changed in version 20.8: Bot API 7.0 introduced
link_preview_optionsreplacing this argument. PTB will automatically convert this argument to that one, but for advanced options, please uselink_preview_optionsdirectly.Changed in version 21.0: |keyword_only_arg|
- Returns:
On success, the sent message is returned.
- Returns:
Message–- Raises:
ValueError – If both
disable_web_page_previewandlink_preview_optionsare passed.telegram.error.TelegramError – For other errors.
- 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 totelegram.constants.MediaGroupLimit.MAX_MEDIA_LENGTHitems.payload (
str|None, default:None) –Bot-defined paid media payload, 0-
telegram.constants.InvoiceLimit.MAX_PAYLOAD_LENGTHbytes. 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_LENGTHcharacters.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) –Added in version 21.5.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –Added in version 22.4.
message_thread_id (
int|None, default:None) –Added in version 22.4.
- Keyword Arguments:
allow_sending_without_reply (
bool, optional) – |allow_sending_without_reply| Mutually exclusive withreply_parameters, which this is a convenience parameter forreply_to_message_id (
int, optional) – |reply_to_msg_id| Mutually exclusive withreply_parameters, which this is a convenience parameter for
- Returns:
On success, the sent message is returned.
- Returns:
Message–- Raises:
- 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.PhotoSizeobject 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
bytesas 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_LENGTHcharacters after entities parsing.parse_mode (DefaultValue[DVValueType] |
str| DefaultValue[None] |None, default:None) – |parse_mode|caption_entities (
Sequence[MessageEntity] |None, default:None) –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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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
Trueif the photo needs to be covered with a spoiler animation.Added in version 20.0.
reply_parameters (ReplyParameters |
None, default:None) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –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) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged 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
tempfilemodule.Added in version 13.1.
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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_LENGTHcharacters.options (
Sequence[str| InputPollOption]) –Sequence of
telegram.Poll.MIN_OPTION_NUMBER-telegram.Poll.MAX_OPTION_NUMBERanswer options. Each option may either be a string withtelegram.Poll.MIN_OPTION_LENGTH-telegram.Poll.MAX_OPTION_LENGTHcharacters or anInputPollOptionobject. Strings are converted toInputPollOptionobjects automatically.Changed in version 20.0: |sequenceargs|
Changed in version 21.2: Bot API 7.3 adds support for
InputPollOptionobjects.is_anonymous (
bool|None, default:None) –True, if the poll needs to be anonymous, defaults toTrue.type (
str|None, default:None) – Poll type,telegram.Poll.QUIZortelegram.Poll.REGULAR, defaults totelegram.Poll.REGULAR.allows_multiple_answers (
bool|None, default:None) –True, if the poll allows multiple answers, ignored for polls in quiz mode, defaults toFalse.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_LENGTHcharacters with at mosttelegram.Poll.MAX_EXPLANATION_LINE_FEEDSline 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 intelegram.constants.ParseModefor 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 withclose_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 leasttelegram.Poll.MIN_OPEN_PERIODand no more thantelegram.Poll.MAX_OPEN_PERIODseconds in the future. Can’t be used together withopen_period. |tz-naive-dtms|is_closed (
bool|None, default:None) – PassTrue, 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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –Added in version 20.8.
business_connection_id (
str|None, default:None) –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.ParseModefor 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 ofquestion_parse_mode.Added in version 21.2.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
- Keyword Arguments:
allow_sending_without_reply (
bool, optional) –|allow_sending_without_reply| Mutually exclusive with
reply_parameters, which this is a convenience parameter forChanged 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 forChanged in version 20.8: Bot API 7.0 introduced
reply_parameters|rtm_aswr_deprecated|Changed in version 21.0: |keyword_only_arg|
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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.WEBMstickers.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.Stickerobject to send.Changed in version 13.2: Accept
bytesas 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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged in version 20.8: Bot API 7.0 introduced
reply_parameters|rtm_aswr_deprecated|Changed in version 21.0: |keyword_only_arg|
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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, orlatitude,longitude,titleandaddressand optionallyfoursquare_idandfoursquare_typeor optionallygoogle_place_idandgoogle_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|longitude (
float|None, default:None) – Longitude of 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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged in version 20.8: Bot API 7.0 introduced
reply_parameters|rtm_aswr_deprecated|Changed in version 21.0: |keyword_only_arg|
venue (
telegram.Venue, optional) – The venue to send.
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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_UPLOADin size, this limit may be changed in the future.Note
thumbnailwill 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. Usethumbnailinstead.- 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.Videoobject to send.Changed in version 13.2: Accept
bytesas 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|
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_LENGTHcharacters after entities parsing.parse_mode (DefaultValue[DVValueType] |
str| DefaultValue[None] |None, default:None) – |parse_mode|caption_entities (
Sequence[MessageEntity] |None, default:None) –Changed in version 20.0: |sequenceargs|
supports_streaming (
bool|None, default:None) – PassTrue, 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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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
Trueif 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) –Added in version 20.2.
reply_parameters (ReplyParameters |
None, default:None) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –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) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged 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
tempfilemodule.Added in version 13.1.
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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
thumbnailwill 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. Usethumbnailinstead.- 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.VideoNoteobject to send. Sending video notes by a URL is currently unsupported.Changed in version 13.2: Accept
bytesas 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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –Added in version 20.2.
reply_parameters (ReplyParameters |
None, default:None) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged 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
tempfilemodule.Added in version 13.1.
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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
.oggfile encoded with OPUS , or in .MP3 format, or in .M4A format (other formats may be sent asAudioorDocument). Bots can currently send voice messages of up totelegram.constants.FileSizeLimit.FILESIZE_UPLOADin 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_SIZEin size.telegram.constants.FileSizeLimit.VOICE_NOTE_FILE_SIZE-telegram.constants.FileSizeLimit.FILESIZE_DOWNLOADvoice notes will be sent as files.See also
Working with Files and Media <Working-with-Files-and-Media>- Parameters:
chat_id (
int|str) – |chat_id_channel|voice (
str|Path|IO[bytes] | InputFile |bytes| Voice) –Voice file to send. |fileinput| Lastly you can pass an existing
telegram.Voiceobject to send.Changed in version 13.2: Accept
bytesas 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) – Voice message caption, 0-telegram.constants.MessageLimit.CAPTION_LENGTHcharacters after entities parsing.parse_mode (DefaultValue[DVValueType] |
str| DefaultValue[None] |None, default:None) – |parse_mode|caption_entities (
Sequence[MessageEntity] |None, default:None) –Changed in version 20.0: |sequenceargs|
duration (
int|timedelta|None, default:None) –Duration of the voice message in seconds.
Changed in version 21.11: |time-period-input|
disable_notification (DefaultValue[DVValueType] |
bool| DefaultValue[None] |None, default:None) – |disable_notification|protect_content (DefaultValue[DVValueType] |
bool| DefaultValue[None] |None, default:None) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged 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
tempfilemodule.Added in version 13.1.
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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()
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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_biobusiness bot right.Added in version 22.1.
- 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_settingsbusiness bot right.Added in version 22.1.
- Parameters:
business_connection_id (
str) – Unique identifier of the business connectionshow_gift_button (
bool) – PassTrue, 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,
Trueis returned.- Returns:
bool–- Raises:
- 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_namebusiness bot right.Added in version 22.1.
- Parameters:
business_connection_id (
str) – Unique identifier of the business connectionfirst_name (
str) – New first name of the business account;telegram.constants.BusinessLimit.MIN_NAME_LENGTH-telegram.constants.BusinessLimit.MAX_NAME_LENGTHcharacters.last_name (
str|None, default:None) – New last name of the business account; 0-telegram.constants.BusinessLimit.MAX_NAME_LENGTHcharacters.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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_photobusiness 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) – PassTrueto 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,
Trueis returned.- Returns:
bool–- Raises:
- 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_usernamebusiness bot right.Added in version 22.1.
- 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_LENGTHcharacters, emoji are not allowed.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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.
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 changedmenu_button (
MenuButton|None, default:None) – An object for the new bot’s menu button. Defaults totelegram.MenuButtonDefault.
- Returns:
On success,
Trueis 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_membersadmin rights.- Parameters:
chat_id (
str|int) – |chat_id_group|permissions (
ChatPermissions) – New default chat permissions.use_independent_chat_permissions (
bool|None, default:None) –Pass
Trueif chat permissions are set independently. Otherwise, thecan_send_other_messagesandcan_add_web_page_previewspermissions will imply thecan_send_messages,can_send_audios,can_send_documents,can_send_photos,can_send_videos,can_send_video_notes, andcan_send_voice_notespermissions; thecan_send_pollspermission will imply thecan_send_messagespermission.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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:
chat_id (
str|int) – |chat_id_channel|photo (
str|Path|IO[bytes] | InputFile |bytes) –New chat photo. |uploadinput|
Changed in version 13.2: Accept
bytesas input.Changed in version 20.0: File paths as input is also accepted for bots not running in
~telegram.Bot.local_mode.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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_setoptionally returned inget_chat()requests to check if the bot can use this method.
- 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.
- 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.
- 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.
See also
- Parameters:
user_id (
int) – User identifier.score (
int) – New score, must be non-negative.force (
bool|None, default:None) – PassTrue, 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) – PassTrue, if the game message should not be automatically edited to include the current scoreboard.chat_id (
int|None, default:None) – Required ifinline_message_idis not specified. Unique identifier for the target chat.message_id (
int|None, default:None) – Required ifinline_message_idis not specified. Identifier of the sent message.inline_message_id (
str|None, default:None) – Required ifchat_idandmessage_idare not specified. Identifier of the inline message.
- Returns:
The edited message. If the message is not an inline message ,
True.- Returns:
- Raises:
telegram.error.TelegramError – If the new score is not greater than the user’s current score in the chat and
forceisFalse.
- 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
strvalues will be converted to eithertelegram.ReactionTypeEmojiortelegram.ReactionTypeCustomEmojidepending on whether they are listed inReactionEmoji.is_big (
bool|None, default:None) – PassTrueto set the reaction with a big animation.
- Returns:
- Raises:
- 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.
See also
- 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_NUMBERcommands can be specified.Note
If you pass in a sequence of
tuple, the order of elements in eachtuplemust correspond to the order of positional arguments to create aBotCommandinstance.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,
Trueis returned.- Returns:
bool–- Raises:
- 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) – Atelegram.ChatAdministratorRightsobject describing new default administrator rights. If not specified, the default administrator rights will be cleared.for_channels (
bool|None, default:None) – PassTrueto 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
Trueon success.- Returns:
bool–- Raises:
- 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_LENGTHcharacters. 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,
Trueis returned.- Returns:
bool–- Raises:
- 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_LENGTHcharacters. Pass an empty string to remove the dedicated name for the given language.Caution
If
language_codeis not specified, anamemust 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,
Trueis returned.- Returns:
bool–- Raises:
- 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_LENGTHcharacters. 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,
Trueis returned.- Returns:
bool–- Raises:
- 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 identifiererrors (
Sequence[PassportElementError]) –A Sequence describing the errors.
Changed in version 20.0: |sequenceargs|
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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.Stickerinstances.emoji_list (
Sequence[str]) – A sequence oftelegram.constants.StickerLimit.MIN_STICKER_EMOJI-telegram.constants.StickerLimit.MAX_STICKER_EMOJIemoji associated with the sticker.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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.Stickerinstances.keywords (
Sequence[str] |None, default:None) – A sequence of 0-telegram.constants.StickerLimit.MAX_SEARCH_KEYWORDSsearch keywords for the sticker with total length up totelegram.constants.StickerLimit.MAX_KEYWORD_LENGTHcharacters.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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.Stickerinstances.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,
Trueis returned.- Returns:
bool–- Raises:
- 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.Stickerinstances.position (
int) – New sticker position in the set, zero-based.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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
formatwill be required, and thus the order of the arguments had to be changed.- Parameters:
name (
str) – Sticker set nameuser_id (
int) – User identifier of created sticker set owner.format (
str) –Format of the added sticker, must be one of
telegram.constants.StickerFormat.STATICfor a.WEBPor.PNGimage,telegram.constants.StickerFormat.ANIMATEDfor a.TGSanimation,telegram.constants.StickerFormat.VIDEOfor a.WEBMvideo.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_SIZEkilobytes in size and have width and height of exactlytelegram.constants.StickerSetLimit.STATIC_THUMB_DIMENSIONSpx, or a .TGS animation with the thumbnail up totelegram.constants.StickerSetLimit.MAX_ANIMATED_THUMBNAIL_SIZEkilobytes in size; see the docs for animated sticker technical requirements, or a.WEBMvideo with the thumbnail up totelegram.constants.StickerSetLimit.MAX_ANIMATED_THUMBNAIL_SIZEkilobytes in size; see this for video sticker technical requirements.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,
Trueis returned.- Returns:
bool–- Raises:
- 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.
- 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 useremoji_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 ordatetime.datetimeobject. |tz-naive-dtms|
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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 headerX-Telegram-Bot-Api-Secret-Tokenwith the secret token as content.Note
You will not be able to receive updates using
get_updates()for long as an outgoing webhook is set up.To use a self-signed certificate, you need to upload your public key certificate using
certificateparameter. Please upload asInputFile, sending a String will not work.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 ourself-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 to40. 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.Updatefor a complete list of available update types. Specify an empty sequence to receive all updates excepttelegram.Update.chat_member,telegram.Update.message_reactionandtelegram.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) – PassTrueto drop all pending updates.secret_token (
str|None, default:None) –A secret token to be sent in a header
X-Telegram-Bot-Api-Secret-Tokenin every webhook request,telegram.constants.WebhookLimit.MIN_SECRET_TOKEN_LENGTH-telegram.constants.WebhookLimit.MAX_SECRET_TOKEN_LENGTHcharacters. Only charactersA-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:
- Raises:
- 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
Added in version 20.0.
- Return type:
- 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()
- 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:
- 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_periodexpires.- Parameters:
chat_id (
int|str|None, default:None) – Required ifinline_message_idis not specified. |chat_id_channel|message_id (
int|None, default:None) – Required ifinline_message_idis not specified. Identifier of the sent message with live location to stop.inline_message_id (
str|None, default:None) – Required ifchat_idandmessage_idare 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) –Added in version 21.4.
- Returns:
On success, if edited message is not an inline message, the edited message is returned, otherwise
Trueis returned.- Returns:
- 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:
- Returns:
On success, the stopped Poll is returned.
- Returns:
Poll–- Raises:
- property supports_inline_queries: bool
Bot’s
telegram.User.supports_inline_queriesattribute. Shortcut for the corresponding attribute ofbot.- Type:
- 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:
- 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:
- 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_starsbusiness bot right.Added in version 22.1.
- 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_giftsbusiness bot right. Requirescan_transfer_starsbusiness bot right if the transfer is paid.Added in version 22.1.
- Parameters:
business_connection_id (
str) – Unique identifier of the business connectionowned_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_TIMEOUTseconds.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 thecan_transfer_starsbusiness bot right is required.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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:
- 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.
- 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.
- 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:
- 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_topicsadministrator rights.Added in version 20.0.
- Parameters:
chat_id (
str|int) – |chat_id_group|- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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:
- 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:
- 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:
- 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_messagesadmin right in a supergroup orcan_edit_messagesadmin right in a channel.- Parameters:
chat_id (
str|int) – |chat_id_channel|- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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_messagesadministrator rights in the supergroup.Added in version 20.0.
- Parameters:
chat_id (
str|int) – |chat_id_group|message_thread_id (
int) – |message_thread_id|
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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_messagesadministrator rights in the supergroup.Added in version 20.5.
- Parameters:
chat_id (
str|int) – |chat_id_group|- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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_messagesadmin right in a supergroup orcan_edit_messagesadmin 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 ifbusiness_connection_idis 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,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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_giftsbusiness bot right. Additionally requires thecan_transfer_starsbusiness bot right if the upgrade is paid.Added in version 22.1.
- Parameters:
business_connection_id (
str) – Unique identifier of the business connectionowned_gift_id (
str) – Unique identifier of the regular gift that should be upgraded to a unique one.keep_original_details (
bool|None, default:None) – PassTrueto keep the original gift text, sender and receiver in the upgraded giftstar_count (
int|None, default:None) – The amount of Telegram Stars that will be paid for the upgrade from the business account balance. Ifgift.prepaid_upgrade_star_count > 0, then pass0, otherwise, thecan_transfer_starsbusiness bot right is required andtelegram.Gift.upgrade_star_countmust be passed.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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()andadd_sticker_to_set()methods (can be used multiple times).Changed in version 20.5: Removed deprecated parameter
png_sticker.- Parameters:
user_id (
int) – User identifier of sticker file owner.sticker (
str|Path|IO[bytes] | InputFile |bytes) –A file with the sticker in the
".WEBP",".PNG",".TGS"or".WEBM"format. See here for technical requirements . |uploadinput|Added in version 20.2.
sticker_format (
str) –Format of the sticker. Must be one of
telegram.constants.StickerFormat.STATIC,telegram.constants.StickerFormat.ANIMATED,telegram.constants.StickerFormat.VIDEO.Added in version 20.2.
- Returns:
On success, the uploaded File is returned.
- Returns:
File–- Raises:
- 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:
- 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:
- 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_LENGTHcharacters. Must be empty if the organization isn’t allowed to provide a custom verification description.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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.
- 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.BaseHandleror by thetelegram.ext.Applicationin an error handler added bytelegram.ext.Application.add_error_handleror to the callback of atelegram.ext.Job.Note
telegram.ext.Applicationwill 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 sameCallbackContextobject (of course with proper attributes likematchesdiffering). 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 onCallbackContextmight 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.blockset toFalseortelegram.ext.Application.concurrent_updatesset toTrue. 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
Genericclass and accepts four type variables:The type of
bot. Must betelegram.Botor a subclass of that class.
Examples
Context Types BotCustom 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 withblock=False.- Type:
- matches
Optional. If the associated update originated from a
filters.Regex, this will contain a list of match objects for every pattern wherere.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.PrefixHandlerortelegram.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:
- job
Optional. The job which originated this callback. Only present when passed to the callback of
telegram.ext.Jobor in error handlers if the error is caused by a job.Changed in version 20.0:
jobis now also present in error handlers if the error is caused by a job.- Type:
- property application: Application[BT, ST, UD, CD, BD, Any]
The application associated with this context.
- Type:
- property bot: BT
The bot associated with this context.
- Type:
- 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 todict.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 todict.Warning
When a group chat migrates to a supergroup, its chat id will change and the
chat_dataneeds to be transferred. For details see ourwiki 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
- 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
KeyErrorin 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 | RuntimeError –
KeyError, if the callback query can not be found in the cache andRuntimeError, if the bot doesn’t allow for arbitrary callback data.- Return type:
- classmethod from_error(update, error, application, job=None, coroutine=None)[source]
Constructs an instance of
telegram.ext.CallbackContextto be passed to the error handlers.Changed in version 20.0: Removed arguments
async_argsandasync_kwargs.- Parameters:
update (
object) – The update associated with the error. May beNone, 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 withblock=False.Added in version 20.0.
Changed in version 20.2: Accepts
asyncio.Futureand 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.CallbackContextto be passed to a job callback.See also
telegram.ext.JobQueue()- Parameters:
- Returns:
TypeVar(CCT, bound= CallbackContext[Any, Any, Any, Any]) –telegram.ext.CallbackContext
- classmethod from_update(update, application)[source]
Constructs an instance of
telegram.ext.CallbackContextto be passed to the handlers.- Parameters:
- Returns:
TypeVar(CCT, bound= CallbackContext[Any, Any, Any, Any]) –telegram.ext.CallbackContext
- property job_queue: JobQueue[ST] | None
The
JobQueueused by thetelegram.ext.Application.See also
Job Queue <Extensions---JobQueue>- Type:
- property match: Match[str] | None
The first match from
matches. Useful if you are only filtering using a single regex filter. ReturnsNoneifmatchesis empty.- Type:
- async refresh_data()[source]
If
applicationuses persistence, callstelegram.ext.BasePersistence.refresh_bot_data()onbot_data,telegram.ext.BasePersistence.refresh_chat_data()onchat_dataandtelegram.ext.BasePersistence.refresh_user_data()onuser_data, if appropriate.Will be called by
telegram.ext.Application.process_update()andtelegram.ext.Job.run().Added in version 13.6.
- Return type:
- property update_queue: Queue[object]
The
asyncio.Queueinstance used by thetelegram.ext.Applicationand (usually) thetelegram.ext.Updaterassociated with this context.- Type:
- 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 todict.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:
TelegramObjectThis 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
messagewill be present. If the button was attached to a message sent via the bot (in inline mode), the fieldinline_message_idwill be present.Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their
idis equal.Note
In Python
fromis a reserved word. Usefrom_userinstead.Exactly one of the fields
dataorgame_short_namewill be present.After the user presses an inline button, Telegram clients will display a progress bar until you call
answer. It is, therefore, necessary to react by callingtelegram.Bot.answer_callback_queryeven if no notification to the user is needed (e.g., without specifying any of the optional parameters).If you’re using
telegram.ext.ExtBot.callback_data_cache,datamay be an instance oftelegram.ext.InvalidCallbackData. This will be the case, if the data associated with the button triggering thetelegram.CallbackQuerywas already deleted or ifdatawas manipulated by a malicious client.Added in version 13.6.
- 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.MaybeInaccessibleMessagesince 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.
- from_user
Sender.
- Type:
- 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:
- 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.MaybeInaccessibleMessagesince Bot API 7.0.
- 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.
- inline_message_id
Optional. Identifier of the message sent via the bot in inline mode, that originated the query.
- Type:
- game_short_name
Optional. Short name of a Game to be returned, serves as the unique identifier for the game.
- Type:
- MAX_ANSWER_TEXT_LENGTH: Final[int] = 200
telegram.constants.CallbackQueryLimit.ANSWER_CALLBACK_QUERY_TEXT_LENGTHAdded 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().
- 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().- Returns:
On success, returns the MessageId of the sent message.
- Returns:
MessageId –
- Raises:
- classmethod de_json(data, bot=None)[source]
See
telegram.TelegramObject.de_json().- Return type:
- 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().
- 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()andtelegram.Message.edit_caption().
- 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.
- 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()andtelegram.Message.edit_live_location().
- 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()andtelegram.Message.edit_media().
- 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()andtelegram.Message.edit_reply_markup().
- 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()andtelegram.Message.edit_text().
- 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()andtelegram.Message.get_game_high_scores().- Returns:
tuple[GameHighScore,...] – tuple[telegram.GameHighScore]- Raises:
- 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().
- 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()andtelegram.Message.set_game_score().
- 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()andtelegram.Message.stop_live_location().
- 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().
- 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:
_ChatBaseThis object represents a chat.
Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their
idis equal.Changed in version 20.0:
Removed the deprecated methods
kick_memberandget_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 throughapi_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 eitherPRIVATE,GROUP,SUPERGROUPorCHANNEL.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.
- class spotted.utils.info_util.Config[source]
Bases:
objectConfigurations
- 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.
- 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:
- 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 getdefault (
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
- class spotted.utils.info_util.EventInfo(bot, ctx, update=None, message=None, query=None)[source]
Bases:
objectClass 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
- 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 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 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 Nonemessage_id (
int|None, default:None) – id of the message to edit. It is the current message if left Nonenew_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
- 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
- property inline_keyboard: InlineKeyboardMarkup | None
InlineKeyboard attached to the message
- property is_forwarded_post: bool
Whether the message is in fact a forwarded post from the channel to the group
- 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 forreason (
str|None, default:None) – reason for the rejection, currently used on autoreply
- class spotted.utils.info_util.InlineKeyboardMarkup(inline_keyboard, *, api_kwargs=None)[source]
Bases:
TelegramObjectThis 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_keyboardand all the buttons are equal.An inline keyboard on a message
See also
Another kind of keyboard would be the
telegram.ReplyKeyboardMarkup.Examples
Inline Keyboard 1Inline Keyboard 2
- Parameters:
inline_keyboard (
Sequence[Sequence[InlineKeyboardButton]]) –Sequence of button rows, each represented by a sequence of
InlineKeyboardButtonobjects.Changed in version 20.0: |sequenceclassargs|
- inline_keyboard
Tuple of button rows, each represented by a tuple of
InlineKeyboardButtonobjects.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:
- 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:
- 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:
- 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:
- 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:
TelegramObjectDescribes 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, andshow_above_textare 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.
- 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:
- 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:
- 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:
- 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:
MaybeInaccessibleMessageThis 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_idandchatare equal.Note
In Python
fromis a reserved word. Usefrom_userinstead.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_nameandforward_date.Changed in version 20.8: * This class is now a subclass of
telegram.MaybeInaccessibleMessage. * Thepinned_messagenow can be eithertelegram.Messageortelegram.InaccessibleMessage.Changed in version 20.0:
The arguments and attributes
voice_chat_scheduled,voice_chat_startedandvoice_chat_ended,voice_chat_participants_invitedwere renamed tovideo_chat_scheduled/video_chat_scheduled,video_chat_started/video_chat_started,video_chat_ended/video_chat_endedandvideo_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 be0and 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 furtherreply_to_messagefields 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_LENGTHcharacters.entities (
Sequence[MessageEntity] |None, default:None) –For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text. See
parse_entityandparse_entitiesmethods 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_entityandparse_caption_entitiesmethods 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) –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_LENGTHcharacters.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 inreply_to_messageif 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 inreply_to_messageif 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_messagefields even if it is itself a reply.Changed in version 20.8: This attribute now is either
telegram.Messageortelegram.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_urlbuttons 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
0and the relevant message will be unusable until it is actually sent.- Type:
- 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:
- 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:
- date
Date the message was sent in Unix time. Converted to
datetime.datetime.Changed in version 20.3: |datetime_localization|
- Type:
- chat
Conversation the message belongs to.
- Type:
- 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:
- reply_to_message
Optional. For replies, the original message. Note that the Message object in this field will not contain further
reply_to_messagefields even if it itself is a reply.- Type:
- edit_date
Optional. Date the message was last edited in Unix time. Converted to
datetime.datetime.Changed in version 20.3: |datetime_localization|
- Type:
- has_protected_content
Optional.
True, if the message can’t be forwarded.Added in version 13.9.
- Type:
- 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:
- media_group_id
Optional. The unique identifier of a media message group this message belongs to.
- Type:
- text
Optional. For text messages, the actual UTF-8 text of the message, 0-
telegram.constants.MessageLimit.MAX_TEXT_LENGTHcharacters.- Type:
- entities
Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text. See
parse_entityandparse_entitiesmethods 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]
- link_preview_options
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.
- 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.
- effect_id
Optional. Unique identifier of the message effect added to the message.
Added in version 21.3.
- Type:
- 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_entityandparse_caption_entitiesmethods 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:
- audio
Optional. Message is an audio file, information about the file.
See also
Working with Files and Media <Working-with-Files-and-Media>- Type:
- document
Optional. Message is a general file, information about the file.
See also
Working with Files and Media <Working-with-Files-and-Media>- Type:
- 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:
- game
Optional. Message is a game, information about the game. More about games >>.
- Type:
- 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:
- story
Optional. Message is a forwarded story.
Added in version 20.5.
- Type:
- video
Optional. Message is a video, information about the video.
See also
Working with Files and Media <Working-with-Files-and-Media>- Type:
- voice
Optional. Message is a voice message, information about the file.
See also
Working with Files and Media <Working-with-Files-and-Media>- Type:
- 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:
- 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_LENGTHcharacters.- Type:
- contact
Optional. Message is a shared contact, information about the contact.
- Type:
- location
Optional. Message is a shared location, information about the location.
- Type:
- 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:
- left_chat_member
Optional. A member was removed from the group, information about them (this member may be the bot itself).
- Type:
- 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]
- 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_messageif someone replies to a very first message in a directly created supergroup.- Type:
- 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_messageif someone replies to a very first message in a channel.- Type:
- message_auto_delete_timer_changed
Optional. Service message: auto-delete timer settings changed in the chat.
Added in version 13.4.
- migrate_to_chat_id
Optional. The group has been migrated to a supergroup with the specified identifier.
- Type:
- migrate_from_chat_id
Optional. The supergroup has been migrated from a group with the specified identifier.
- Type:
- pinned_message
Optional. Specified message was pinned. Note that the Message object in this field will not contain further
reply_to_messagefields even if it is itself a reply.Changed in version 20.8: This attribute now is either
telegram.Messageortelegram.InaccessibleMessage.
- invoice
Optional. Message is an invoice for a payment, information about the invoice. More about payments >>.
- Type:
- successful_payment
Optional. Message is a service message about a successful payment, information about the payment. More about payments >>.
- connected_website
Optional. The domain name of the website on which the user has logged in. More about Telegram Login >>.
- Type:
- author_signature
Optional. Signature of the post author for messages in channels, or the custom title of an anonymous group administrator.
- Type:
- 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:
- passport_data
Optional. Telegram Passport data.
Examples
Passport Bot- Type:
- poll
Optional. Message is a native poll, information about the poll.
- Type:
- dice
Optional. Message is a dice with random value.
- Type:
- via_bot
Optional. Bot through which message was sent.
- Type:
- proximity_alert_triggered
Optional. Service message. A user in the chat triggered another user’s proximity alert while sharing Live Location.
- video_chat_scheduled
Optional. Service message: video chat scheduled.
Added in version 20.0.
- video_chat_started
Optional. Service message: video chat started.
Added in version 20.0.
- video_chat_ended
Optional. Service message: video chat ended.
Added in version 20.0.
- Type:
- video_chat_participants_invited
Optional. Service message: new participants invited to a video chat.
Added in version 20.0.
- web_app_data
Optional. Service message: data sent by a Web App.
Added in version 20.0.
- Type:
- reply_markup
Optional. Inline keyboard attached to the message.
~telegram.InlineKeyboardButton.login_urlbuttons are represented as ordinary url buttons.
- is_topic_message
Optional.
True, if the message is sent to a forum topic.Added in version 20.0.
- Type:
- message_thread_id
Optional. Unique identifier of a message thread to which the message belongs; for supergroups only.
Added in version 20.0.
- Type:
- forum_topic_created
Optional. Service message: forum topic created.
Added in version 20.0.
- forum_topic_closed
Optional. Service message: forum topic closed.
Added in version 20.0.
- forum_topic_reopened
Optional. Service message: forum topic reopened.
Added in version 20.0.
- forum_topic_edited
Optional. Service message: forum topic edited.
Added in version 20.0.
Optional. Service message: General forum topic hidden.
Added in version 20.0.
Optional. Service message: General forum topic unhidden.
Added in version 20.0.
- write_access_allowed
Optional. Service message: the user allowed the bot added to the attachment menu to write messages.
Added in version 20.0.
- has_media_spoiler
Optional.
True, if the message media is covered by a spoiler animation.Added in version 20.0.
- Type:
- checklist
Optional. Message is a checklist
Added in version 22.3.
- Type:
Optional. Service message: users were shared with the bot
Added in version 20.8.
- Type:
Optional. Service message: a chat was shared with the bot.
Added in version 20.1.
- Type:
- gift
Optional. Service message: a regular gift was sent or received.
Added in version 22.1.
- Type:
- unique_gift
Optional. Service message: a unique gift was sent or received
Added in version 22.1.
- Type:
- giveaway_created
Optional. Service message: a scheduled giveaway was created
Added in version 20.8.
- Type:
- giveaway
Optional. The message is a scheduled giveaway message
Added in version 20.8.
- Type:
- giveaway_winners
Optional. A giveaway with public winners was completed
Added in version 20.8.
- Type:
- giveaway_completed
Optional. Service message: a giveaway without public winners was completed
Added in version 20.8.
- paid_message_price_changed
Optional. Service message: the price for paid messages has changed in the chat
Added in version 22.1.
- suggested_post_approved
Optional. Service message: a suggested post was approved.
Added in version 22.4.
- suggested_post_approval_failed
Optional. Service message: approval of a suggested post has failed.
Added in version 22.4.
- suggested_post_declined
Optional. Service message: a suggested post was declined.
Added in version 22.4.
- suggested_post_paid
Optional. Service message: payment for a suggested post was received.
Added in version 22.4.
- suggested_post_refunded
Optional. Service message: payment for a suggested post was refunded.
Added in version 22.4.
- 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.
- quote
Optional. For replies that quote part of the original message, the quoted part of the message.
Added in version 20.8.
- Type:
- forward_origin
Optional. Information about the original message for forwarded messages
Added in version 20.8.
- Type:
- reply_to_story
Optional. For replies to a story, the original story.
Added in version 21.0.
- Type:
- boost_added
Optional. Service message: user boosted the chat.
Added in version 21.0.
- Type:
- 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:
- 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:
- 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:
- chat_background_set
Optional. Service message: chat background set
Added in version 21.2.
- Type:
- checklist_tasks_done
Optional. Service message: some tasks in a checklist were marked as done or not done
Added in version 22.3.
- checklist_tasks_added
Optional. Service message: tasks were added to a checklist
Added in version 22.3.
- paid_media
Optional. Message contains paid media; information about the paid media.
Added in version 21.4.
- Type:
- refunded_payment
Optional. Message is a service message about a refunded payment, information about the payment.
Added in version 21.4.
- Type:
- 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.
- 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:
- direct_messages_topic
Optional. Information about the direct messages chat topic that contains the message.
Added in version 22.4.
- reply_to_checklist_task_id
Optional. Identifier of the specific checklist task that is being replied to.
Added in version 22.4.
- Type:
- 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.
- 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_idandreply_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:
quote (
str|None, default:None) – Passed incompute_quote_position_and_entities()as parameter~compute_quote_position_and_entities.quoteto compute quote entities. Defaults toNone.quote_index (
int|None, default:None) – Passed incompute_quote_position_and_entities()as parameter~compute_quote_position_and_entities.quote_indexto compute quote position. Defaults toNone.target_chat_id (
int|str|None, default:None) – |chat_id_channel| Defaults tochat_id.allow_sending_without_reply (DefaultValue[DVValueType] |
bool| DefaultValue[None] |None, default:None) – |allow_sending_without_reply| Will be applied only if the reply happens in the same chat and forum topic.message_thread_id (DefaultValue[DVValueType] |
int| DefaultValue[None] |None, default:None) – |message_thread_id|
- Returns:
_ReplyKwargs–
- 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
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:
- 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.URLas a hyperlink.Warning
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:
- 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
Note
telegram.constants.ParseMode.MARKDOWNis a legacy mode, retained by Telegram for backward compatibility. You should usecaption_markdown_v2()Changed in version 20.5: Since custom emoji entities are not supported by
MARKDOWN, this method now raises aValueErrorwhen encountering a custom emoji.Changed in version 20.8: Since block quotation entities are not supported by
MARKDOWN, this method now raises aValueErrorwhen encountering a block quotation.- Returns:
Message caption with caption entities formatted as Markdown.
- Return type:
- 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.URLas a hyperlink.Warning
Note
telegram.constants.ParseMode.MARKDOWNis a legacy mode, retained by Telegram for backward compatibility. You should usecaption_markdown_v2_urled()instead.Changed in version 20.5: Since custom emoji entities are not supported by
MARKDOWN, this method now raises aValueErrorwhen encountering a custom emoji.Changed in version 20.8: Since block quotation entities are not supported by
MARKDOWN, this method now raises aValueErrorwhen encountering a block quotation.- Returns:
Message caption with caption entities formatted as Markdown.
- Return type:
- 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
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:
- 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.URLas a hyperlink.Warning
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:
- property chat_id: int
Shortcut for
telegram.Chat.idforchat.- Type:
- 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.
- 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_positionand~telegram.ReplyParameters.quote_entitiesoftelegram.ReplyParameterswhen 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:
- Returns:
On success, a tuple containing information about quote position and entities is returned.
- Returns:
- Raises:
RuntimeError – If the message has neither
textnorcaption.ValueError – If the requested index of quote doesn’t exist in the message.
- 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:
- 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.
- 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()andtelegram.Bot.delete_business_messages().Changed in version 22.4: Calls either
telegram.Bot.delete_message()ortelegram.Bot.delete_business_messages()based onbusiness_connection_id.
- 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.
- 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
Trueis 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 –
- 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.
- 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.
- 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
Trueis 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
Trueis 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
Trueis returned.- Returns:
Message |
bool–
- 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
list[
telegram.PhotoSize]
Otherwise
Noneis returned.See also
Working with Files and Media <Working-with-Files-and-Media>Changed in version 20.0:
dice,passport_dataandpollare now also considered to be an attachment.Changed in version 21.4:
paid_mediais now also considered to be an attachment.Deprecated since version 21.4:
successful_paymentwill be removed in future major versions.
- 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_contentandtelegram.ChatFullInfo.has_protected_contentto 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 –
- 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]
- property id: int
Shortcut for
message_id.Added in version 20.0.
- Type:
- property link: str | 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:
- link_preview_options: LinkPreviewOptions | None
- parse_caption_entities(types=None)[source]
Returns a
dictthat mapstelegram.MessageEntitytostr. It contains entities from this message’s caption filtered by theirtelegram.MessageEntity.typeattribute as the key, and the text that each entity belongs to as the value of thedict.Note
This method should always be used instead of the
caption_entitiesattribute, since it calculates the correct substring from the message text based on UTF-16 codepoints. Seeparse_entityfor more info.- Parameters:
types (
list[str] |None, default:None) – List oftelegram.MessageEntitytypes as strings. If thetypeattribute 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 intelegram.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.captionwith 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
dictthat mapstelegram.MessageEntitytostr. It contains entities from this message filtered by theirtelegram.MessageEntity.typeattribute as the key, and the text that each entity belongs to as the value of thedict.Note
This method should always be used instead of the
entitiesattribute, since it calculates the correct substring from the message text based on UTF-16 codepoints. Seeparse_entityfor more info.- Parameters:
types (
list[str] |None, default:None) – List oftelegram.MessageEntitytypes as strings. If thetypeattribute 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 intelegram.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.textwith 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.
- 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_idtotelegram.Bot.pin_chat_message().
- 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.
- 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.
- 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_idis not provided, this will reply to the same thread (topic) of the original message.Changed in version 22.0: Removed deprecated parameter
quote. Usedo_quoteinstead.
- 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_idis not provided, this will reply to the same thread (topic) of the original message.Changed in version 22.0: Removed deprecated parameter
quote. Usedo_quoteinstead.
- 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_idis not provided, this will reply to the same thread (topic) of the original message.Added in version 13.2.
- 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_idis not provided, this will reply to the same thread (topic) of the original message.Changed in version 22.0: Removed deprecated parameter
quote. Usedo_quoteinstead.
- 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_idis not provided, this will reply to the same thread (topic) of the original message.Changed in version 22.0: Removed deprecated parameter
quote. Usedo_quoteinstead.
- 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_idis not provided, this will reply to the same thread (topic) of the original message.Changed in version 22.0: Removed deprecated parameter
quote. Usedo_quoteinstead.
- 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_idis not provided, this will reply to the same thread (topic) of the original message.Changed in version 22.0: Removed deprecated parameter
quote. Usedo_quoteinstead.
- 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_idis not provided, this will reply to the same thread (topic) of the original message.Changed in version 22.0: Removed deprecated parameter
quote. Usedo_quoteinstead.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_idis not provided, this will reply to the same thread (topic) of the original message.Changed in version 22.0: Removed deprecated parameter
quote. Usedo_quoteinstead.
- 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_idis not provided, this will reply to the same thread (topic) of the original message.Changed in version 22.0: Removed deprecated parameter
quote. Usedo_quoteinstead.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.
- 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_idis not provided, this will reply to the same thread (topic) of the original message.Changed in version 22.0: Removed deprecated parameter
quote. Usedo_quoteinstead.
- 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_idis not provided, this will reply to the same thread (topic) of the original message.Changed in version 22.0: Removed deprecated parameter
quote. Usedo_quoteinstead.Note
telegram.constants.ParseMode.MARKDOWNis a legacy mode, retained by Telegram for backward compatibility. You should usereply_markdown_v2()instead.
- 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_idis not provided, this will reply to the same thread (topic) of the original message.Changed in version 22.0: Removed deprecated parameter
quote. Usedo_quoteinstead.
- 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_idis not provided, this will reply to the same thread (topic) of the original message.Changed in version 22.0: Removed deprecated parameter
quote. Usedo_quoteinstead.
- 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_idis not provided, this will reply to the same thread (topic) of the original message.Changed in version 22.0: Removed deprecated parameter
quote. Usedo_quoteinstead.
- 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_idis not provided, this will reply to the same thread (topic) of the original message.Changed in version 22.0: Removed deprecated parameter
quote. Usedo_quoteinstead.
- 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_idis not provided, this will reply to the same thread (topic) of the original message.Changed in version 22.0: Removed deprecated parameter
quote. Usedo_quoteinstead.
- 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_idis not provided, this will reply to the same thread (topic) of the original message.Changed in version 22.0: Removed deprecated parameter
quote. Usedo_quoteinstead.
- 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_idis not provided, this will reply to the same thread (topic) of the original message.Changed in version 22.0: Removed deprecated parameter
quote. Usedo_quoteinstead.
- 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_idis not provided, this will reply to the same thread (topic) of the original message.Changed in version 22.0: Removed deprecated parameter
quote. Usedo_quoteinstead.
- 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_idis not provided, this will reply to the same thread (topic) of the original message.Changed in version 22.0: Removed deprecated parameter
quote. Usedo_quoteinstead.
- 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_idis not provided, this will reply to the same thread (topic) of the original message.Changed in version 22.0: Removed deprecated parameter
quote. Usedo_quoteinstead.
- 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.
- 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.
- 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.
- 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–
- 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
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:
- 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.URLas a hyperlink.Warning
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:
- 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
Note
telegram.constants.ParseMode.MARKDOWNis a legacy mode, retained by Telegram for backward compatibility. You should usetext_markdown_v2()instead.Changed in version 20.5: Since custom emoji entities are not supported by
MARKDOWN, this method now raises aValueErrorwhen encountering a custom emoji.Changed in version 20.8: Since block quotation entities are not supported by
MARKDOWN, this method now raises aValueErrorwhen encountering a block quotation.- Returns:
Message text with entities formatted as Markdown.
- Return type:
- 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.URLas a hyperlink.Warning
Note
telegram.constants.ParseMode.MARKDOWNis a legacy mode, retained by Telegram for backward compatibility. You should usetext_markdown_v2_urled()instead.Changed in version 20.5: Since custom emoji entities are not supported by
MARKDOWN, this method now raises aValueErrorwhen encountering a custom emoji.Changed in version 20.8: Since block quotation entities are not supported by
MARKDOWN, this method now raises aValueErrorwhen encountering a block quotation.- Returns:
Message text with entities formatted as Markdown.
- Return type:
- 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
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:
- 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.URLas a hyperlink.Warning
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:
- 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_idtotelegram.Bot.pin_chat_message().
- 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.
- class spotted.utils.info_util.MessageId(message_id, *, api_kwargs=None)[source]
Bases:
TelegramObjectThis 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_idis 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 be0and 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
0and the relevant message will be unusable until it is actually sent.- Type:
- class spotted.utils.info_util.MessageOriginChannel(date, chat, message_id, author_signature=None, *, api_kwargs=None)[source]
Bases:
MessageOriginThe message was originally sent to a channel chat.
Added in version 20.8.
- Parameters:
- date
Date the message was sent originally. |datetime_localization|
- Type:
- chat
Channel chat to which the message was originally sent.
- Type:
- class spotted.utils.info_util.MessageOriginChat(date, sender_chat, author_signature=None, *, api_kwargs=None)[source]
Bases:
MessageOriginThe 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
- date
Date the message was sent originally. |datetime_localization|
- Type:
- sender_chat
Chat that sent the message originally.
- Type:
- author_signature
Optional. For messages originally sent by an anonymous chat administrator, original message author signature
- Type:
- class spotted.utils.info_util.MessageOriginUser(date, sender_user, *, api_kwargs=None)[source]
Bases:
MessageOriginThe message was originally sent by a known user.
Added in version 20.8.
- Parameters:
date (
datetime) – Date the message was sent originally. |datetime_localization|sender_user (
User) – User that sent the message originally.
- date
Date the message was sent originally. |datetime_localization|
- Type:
- sender_user
User that sent the message originally.
- Type:
- class spotted.utils.info_util.PendingPost(user_id, u_message_id, g_message_id, admin_group_id, date, credit_username=None)[source]
Bases:
objectClass that represents a pending post
- Parameters:
user_id (
int) – id of the user that sent the postu_message_id (
int) – id of the original message of the postg_message_id (
int) – id of the post in the groupadmin_group_id (
int) – id of the admin groupcredit_username (
str|None, default:None) – username of the user that sent the post if it’s a credit postdate (
datetime) – when the post was sent
- 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:
- Returns:
PendingPost– instance of the class
- classmethod from_group(g_message_id, admin_group_id)[source]
Retrieves a pending post from the info related to the admin group
- Parameters:
- 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
- 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:
- Returns:
list[PendingPost] – list of ids of pending posts
- class spotted.utils.info_util.PublishedPost(channel_id, c_message_id, date)[source]
Bases:
objectClass that represents a published post
- classmethod create(channel_id, c_message_id)[source]
Inserts a new post in the table of published posts
- Parameters:
- Returns:
PublishedPost– instance of the class
- classmethod from_channel(channel_id, c_message_id)[source]
Retrieves a published post from the info related to the channel
- Parameters:
- Returns:
PublishedPost|None– instance of the class
- 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:
TelegramObjectThis 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_idis 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_MEMBERin the list oftelegram.ext.Application.run_polling.allowed_updatesto receive these updates (seetelegram.Bot.get_updates(),telegram.Bot.set_webhook(),telegram.ext.Application.run_polling()andtelegram.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_usersadministrator 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_REACTIONin the list oftelegram.ext.Application.run_polling.allowed_updatesto receive these updates (seetelegram.Bot.get_updates(),telegram.Bot.set_webhook(),telegram.ext.Application.run_polling()andtelegram.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_COUNTin the list oftelegram.ext.Application.run_polling.allowed_updatesto receive these updates (seetelegram.Bot.get_updates(),telegram.Bot.set_webhook(),telegram.ext.Application.run_polling()andtelegram.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:
- message
Optional. New incoming message of any kind - text, photo, sticker, etc.
- Type:
- 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:
- channel_post
Optional. New incoming channel post of any kind - text, photo, sticker, etc.
- Type:
- 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:
- inline_query
Optional. New incoming inline query.
- Type:
- chosen_inline_result
Optional. The result of an inline query that was chosen by a user and sent to their chat partner.
- callback_query
Optional. New incoming callback query.
Examples
Arbitrary Callback Data Bot- Type:
- shipping_query
Optional. New incoming shipping query. Only for invoices with flexible price.
- Type:
- pre_checkout_query
Optional. New incoming pre-checkout query. Contains full information about checkout.
- poll
Optional. New poll state. Bots receive only updates about manually stopped polls and polls, which are sent by the bot.
- Type:
- 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:
- 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.
- 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_MEMBERin the list oftelegram.ext.Application.run_polling.allowed_updatesto receive these updates (seetelegram.Bot.get_updates(),telegram.Bot.set_webhook(),telegram.ext.Application.run_polling()andtelegram.ext.Application.run_webhook()).Added in version 13.4.
- chat_join_request
Optional. A request to join the chat has been sent. The bot must have the
telegram.ChatPermissions.can_invite_usersadministrator right in the chat to receive these updates.Added in version 13.8.
- Type:
- 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.
- 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.
- 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_REACTIONin the list oftelegram.ext.Application.run_polling.allowed_updatesto receive these updates (seetelegram.Bot.get_updates(),telegram.Bot.set_webhook(),telegram.ext.Application.run_polling()andtelegram.ext.Application.run_webhook()). The update isn’t received for reactions set by bots.Added in version 20.8.
- 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_COUNTin the list oftelegram.ext.Application.run_polling.allowed_updatesto receive these updates (seetelegram.Bot.get_updates(),telegram.Bot.set_webhook(),telegram.ext.Application.run_polling()andtelegram.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
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.
- business_message
Optional. New message from a connected business account.
Added in version 21.1.
- Type:
- edited_business_message
Optional. New version of a message from a connected business account.
Added in version 21.1.
- Type:
- deleted_business_messages
Optional. Messages were deleted from a connected business account.
Added in version 21.1.
- 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.
- 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_CONNECTIONAdded in version 21.1.
- BUSINESS_MESSAGE: Final[str] = 'business_message'
telegram.constants.UpdateType.BUSINESS_MESSAGEAdded in version 21.1.
- CALLBACK_QUERY: Final[str] = 'callback_query'
telegram.constants.UpdateType.CALLBACK_QUERYAdded in version 13.5.
- CHANNEL_POST: Final[str] = 'channel_post'
telegram.constants.UpdateType.CHANNEL_POSTAdded in version 13.5.
- CHAT_BOOST: Final[str] = 'chat_boost'
telegram.constants.UpdateType.CHAT_BOOSTAdded in version 20.8.
- CHAT_JOIN_REQUEST: Final[str] = 'chat_join_request'
telegram.constants.UpdateType.CHAT_JOIN_REQUESTAdded in version 13.8.
- CHAT_MEMBER: Final[str] = 'chat_member'
telegram.constants.UpdateType.CHAT_MEMBERAdded in version 13.5.
- CHOSEN_INLINE_RESULT: Final[str] = 'chosen_inline_result'
telegram.constants.UpdateType.CHOSEN_INLINE_RESULTAdded in version 13.5.
- DELETED_BUSINESS_MESSAGES: Final[str] = 'deleted_business_messages'
telegram.constants.UpdateType.DELETED_BUSINESS_MESSAGESAdded in version 21.1.
- EDITED_BUSINESS_MESSAGE: Final[str] = 'edited_business_message'
telegram.constants.UpdateType.EDITED_BUSINESS_MESSAGEAdded in version 21.1.
- EDITED_CHANNEL_POST: Final[str] = 'edited_channel_post'
telegram.constants.UpdateType.EDITED_CHANNEL_POSTAdded in version 13.5.
- EDITED_MESSAGE: Final[str] = 'edited_message'
telegram.constants.UpdateType.EDITED_MESSAGEAdded in version 13.5.
- INLINE_QUERY: Final[str] = 'inline_query'
telegram.constants.UpdateType.INLINE_QUERYAdded in version 13.5.
- MESSAGE_REACTION: Final[str] = 'message_reaction'
telegram.constants.UpdateType.MESSAGE_REACTIONAdded in version 20.8.
- MESSAGE_REACTION_COUNT: Final[str] = 'message_reaction_count'
telegram.constants.UpdateType.MESSAGE_REACTION_COUNTAdded in version 20.8.
- MY_CHAT_MEMBER: Final[str] = 'my_chat_member'
telegram.constants.UpdateType.MY_CHAT_MEMBERAdded in version 13.5.
- POLL_ANSWER: Final[str] = 'poll_answer'
telegram.constants.UpdateType.POLL_ANSWERAdded in version 13.5.
- PRE_CHECKOUT_QUERY: Final[str] = 'pre_checkout_query'
telegram.constants.UpdateType.PRE_CHECKOUT_QUERYAdded in version 13.5.
- PURCHASED_PAID_MEDIA: Final[str] = 'purchased_paid_media'
telegram.constants.UpdateType.PURCHASED_PAID_MEDIAAdded in version 21.6.
- REMOVED_CHAT_BOOST: Final[str] = 'removed_chat_boost'
telegram.constants.UpdateType.REMOVED_CHAT_BOOSTAdded in version 20.8.
- SHIPPING_QUERY: Final[str] = 'shipping_query'
telegram.constants.UpdateType.SHIPPING_QUERYAdded in version 13.5.
- callback_query: CallbackQuery | None
- classmethod de_json(data, bot=None)[source]
See
telegram.TelegramObject.de_json().- Return type:
- 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, ifinline_query,chosen_inline_result,callback_queryfrom inline messages,shipping_query,pre_checkout_query,poll,poll_answer,business_connection, orpurchased_paid_mediais present.Changed in version 21.1: This property now also considers
business_message,edited_business_message, anddeleted_business_messages.Example
If
messageis present, this will givetelegram.Message.chat.- Type:
- 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_postorcallback_query(i.e.telegram.CallbackQuery.message) orNone, if none of those are present.
Changed in version 21.1: This property now also considers
business_message, andedited_business_message.Tip
This property will only ever return objects of type
telegram.MessageorNone, nevertelegram.MaybeInaccessibleMessageortelegram.InaccessibleMessage. Currently, this is only relevant forcallback_query, astelegram.CallbackQuery.messageis the only attribute considered by this property that can be an object of these types.- Type:
- property effective_sender: User | Chat | None
The user or chat that sent this update, no matter what kind of update this is.
Note
Depending on the type of update and the user’s ‘Remain anonymous’ setting, this could either be
telegram.User,telegram.ChatorNone.
If no user whatsoever is associated with this update, this gives
None. This is the case if any ofis present.
Example
If
messageis present, this will give eithertelegram.Message.from_userortelegram.Message.sender_chat.If
poll_answeris present, this will give eithertelegram.PollAnswer.userortelegram.PollAnswer.voter_chat.If
channel_postis present, this will givetelegram.Message.sender_chat.
Added in version 21.1.
- Type:
- 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 ofis present.
Changed in version 21.1: This property now also considers
business_connection,business_messageandedited_business_message.Changed in version 21.6: This property now also considers
purchased_paid_media.Example
If
messageis present, this will givetelegram.Message.from_user.If
poll_answeris present, this will givetelegram.PollAnswer.user.
- Type:
- 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:
objectClass that represents a user
- Parameters:
user_id (
int) – id of the userprivate_message_id (
int|None, default:None) – id of the private message sent by the user to the bot. Only used for followingban_date (
datetime|None, default:None) – datetime of when the user was banned. Only used for banned usersfollow_date (
datetime|None, default:None) – datetime of when the user started following a post. Only used for following users
- 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 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
- async get_user_sign(bot)[source]
Generates a sign for the user. It will be a random name for an anonym user
- 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.
- 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 attachedapprove (
int, default:-1) – number of approve votes known in advancereject (
int, default:-1) – number of reject votes known in advancecredited_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
- 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_kwargswhich 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 indo_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 raiseTypeError.
Examples
Raw API BotSee 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
botis equal.Changed in version 20.0:
Removed the deprecated methods
kick_chat_member,kickChatMember,get_chat_members_countandgetChatMembersCount.Removed the deprecated property
commands.Removed the deprecated
defaultsparameter. If you want to usetelegram.ext.Defaults, please use the subclasstelegram.ext.ExtBotinstead.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_modeisFalse, 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_thumbandsetStickerSetThumb. Useset_sticker_set_thumbnail()andsetStickerSetThumbnail()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 initializedtelegram.request.BaseRequestinstances. Will be used for all bot methods except forget_updates(). If not passed, an instance oftelegram.request.HTTPXRequestwill be used.get_updates_request (
BaseRequest|None, default:None) – Pre initializedtelegram.request.BaseRequestinstances. Will be used exclusively forget_updates(). If not passed, an instance oftelegram.request.HTTPXRequestwill 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 thebase_urlis the URI of a Local Bot API Server that runs with the--localflag. Currently, the only effect of this is that files are uploaded using their local path in the file URI scheme. Defaults toFalse.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:
- 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_STICKERSstickers. Other sticker sets can have up totelegram.constants.StickerSetLimit.MAX_STATIC_STICKERSstickers.Changed in version 20.2: Since Bot API 6.6, the parameter
stickerreplace the parameterspng_sticker,tgs_sticker,webm_sticker,emojis, andmask_position.Changed in version 20.5: Removed deprecated parameters
png_sticker,tgs_sticker,webm_sticker,emojis, andmask_position.
- 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:
- 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:
- 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:
- 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:
- 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:
- 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_LENGTHcharacters.show_alert (
bool|None, default:None) – IfTrue, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults toFalse.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:
- Raises:
- 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_RESULTSresults per query are allowed.Warning
In most use cases
current_offsetshould not be passed manually. Instead of calling this method directly, use the shortcuttelegram.InlineQuery.answer()withtelegram.InlineQuery.answer.auto_paginationset toTrue, 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_textandswitch_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 casecurrent_offsetis passed,resultsmay also be a callable that accepts the current page index starting from 0. It must return either a list oftelegram.InlineQueryResultinstances orNoneif 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) – PassTrue, 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 exceedtelegram.InlineQuery.MAX_OFFSET_LENGTHbytes.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) – Thetelegram.InlineQuery.offsetof the inline query to answer. If passed, PTB will automatically take care of the pagination for you, i.e. pass the correctnext_offsetand truncate the results list/get the results from the callable you passed.- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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.Updatewith the fieldtelegram.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) – SpecifyTrueif everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. UseFalseif there are any problems.error_message (
str|None, default:None) – Required ifokisFalse. 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,
Trueis returned- Returns:
bool–- Raises:
- 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_flexiblewas specified, the Bot API will send antelegram.Updatewith atelegram.Update.shipping_queryfield 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) – SpecifyTrueif delivery to the specified address is possible andFalseif there are any problems (for example, if delivery to the specified address is not possible).shipping_options (
Sequence[ShippingOption] |None, default:None) –Required if
okisTrue. A sequence of available shipping options.Changed in version 20.0: |sequenceargs|
error_message (
str|None, default:None) – Required ifokisFalse. 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,
Trueis returned.- Returns:
bool–- Raises:
- 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.SentWebAppMessageis returned.- Returns:
- Raises:
- 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:
- 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:
- 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_usersadministrator right.Added in version 13.8.
- 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_messagesadministrator 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_DATEseconds (30 days) in the future.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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:
- 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
Trueto delete all messages from the chat for the user that is being removed. IfFalse, the user will be able to see messages in the group that were sent before the user was removed. AlwaysTruefor supergroups and channels.Added in version 13.4.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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.
- property base_file_url: str
Telegram Bot API file URL, built from
Bot.base_file_urlandBot.token.Added in version 20.0.
- Type:
- property base_url: str
Telegram Bot API service URL, built from
Bot.base_urlandBot.token.Added in version 20.0.
- Type:
- 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 untilget_me()is called again.See also
- Type:
- property can_join_groups: bool
Bot’s
telegram.User.can_join_groupsattribute. Shortcut for the corresponding attribute ofbot.- Type:
- property can_read_all_group_messages: bool
Bot’s
telegram.User.can_read_all_group_messagesattribute. Shortcut for the corresponding attribute ofbot.- Type:
- 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.
- 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:
- 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:
- 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_topicsadministrator 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|
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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_topicsadministrator rights.Added in version 20.0.
- Parameters:
chat_id (
str|int) – |chat_id_group|- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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_starsbusiness bot right.Added in version 22.1.
- 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:
- 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()
- 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_LENGTHcharacters 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 intelegram.constants.ParseModefor the available modes.caption_entities (
Sequence[MessageEntity] |None, default:None) –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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –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) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged in version 20.8: Bot API 7.0 introduced
reply_parameters|rtm_aswr_deprecated|Changed in version 21.0: |keyword_only_arg|
- Returns:
- On success, the
telegram.MessageIdof the sent message is returned.
- On success, the
- Returns:
- Raises:
- 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_idis known to the bot. The method is analogous to the methodforward_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 oftelegram.constants.BulkRequestLimit.MIN_LIMIT-telegram.constants.BulkRequestLimit.MAX_LIMITidentifiers of messages in the chatfrom_chat_idto 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) – PassTrueto 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
MessageIdof the sent messages is returned.- Returns:
- Raises:
- async createChatInviteLink(chat_id, expire_date=None, member_limit=None, name=None, creates_join_request=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
create_chat_invite_link()- Return type:
- async createChatSubscriptionInviteLink(chat_id, subscription_period, subscription_price, name=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
create_chat_subscription_invite_link()- Return type:
- 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:
- async createInvoiceLink(title, description, payload, currency, prices, provider_token=None, max_tip_amount=None, suggested_tip_amounts=None, provider_data=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, send_phone_number_to_provider=None, send_email_to_provider=None, is_flexible=None, subscription_period=None, business_connection_id=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
create_invoice_link()- Return type:
- 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:
- async create_chat_invite_link(chat_id, expire_date=None, member_limit=None, name=None, creates_join_request=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]
Use this method to create an additional invite link for a chat. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. The link can be revoked using the method
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_requesthas 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_LENGTHcharacters.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. IfTrue,member_limitcan’t be specified.Added in version 13.8.
- Returns:
- Raises:
- async create_chat_subscription_invite_link(chat_id, subscription_period, subscription_price, name=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]
Use this method to create a subscription invite link for a channel chat. The bot must have the
can_invite_usersadministrator right. The link can be edited using theedit_chat_subscription_invite_link()or revoked using therevoke_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_LENGTHcharacters.
- Returns:
- Raises:
- 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_topicsadministrator 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_LENGTHcharacters.icon_color (
int|None, default:None) – Color of the topic icon in RGB format. Currently, must be one oftelegram.constants.ForumIconColor.BLUE,telegram.constants.ForumIconColor.YELLOW,telegram.constants.ForumIconColor.PURPLE,telegram.constants.ForumIconColor.GREEN,telegram.constants.ForumIconColor.PINK, ortelegram.constants.ForumIconColor.RED.icon_custom_emoji_id (
str|None, default:None) – New unique identifier of the custom emoji shown as the topic icon. Useget_forum_topic_icon_stickers()to get all allowed custom emoji identifiers.
- Returns:
- Raises:
- async create_invoice_link(title, description, payload, currency, prices, provider_token=None, max_tip_amount=None, suggested_tip_amounts=None, provider_data=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, send_phone_number_to_provider=None, send_email_to_provider=None, is_flexible=None, subscription_period=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 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_LENGTHcharacters.description (
str) – Product description.telegram.Invoice.MIN_DESCRIPTION_LENGTH-telegram.Invoice.MAX_DESCRIPTION_LENGTHcharacters.payload (
str) – Bot-defined invoice payload.telegram.Invoice.MIN_PAYLOAD_LENGTH-telegram.Invoice.MAX_PAYLOAD_LENGTHbytes. 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
XTRfor 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.timedeltaobject. The currency must be set to“XTR”(Telegram Stars) if the parameter is used. Currently, it must always betelegram.constants.InvoiceLimit.SUBSCRIPTION_PERIODif 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 exceedtelegram.constants.InvoiceLimit.SUBSCRIPTION_MAX_PRICETelegram 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.45passmax_tip_amount = 145. See theexpparameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to0. 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_AMOUNTSsuggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceedmax_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.need_name (
bool|None, default:None) – PassTrue, 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) – PassTrue, if you require the user’s phone number to complete the order. Ignored for payments in |tg_stars|.need_email (
bool|None, default:None) – PassTrue, 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) – PassTrue, 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) – PassTrue, if user’s phone number should be sent to provider. Ignored for payments in |tg_stars|.send_email_to_provider (
bool|None, default:None) – PassTrue, if user’s email address should be sent to provider. Ignored for payments in |tg_stars|.is_flexible (
bool|None, default:None) – PassTrue, 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_maskshas been removed. Usesticker_typeinstead.Changed in version 20.2: Since Bot API 6.6, the parameters
stickersandsticker_formatreplace the parameterspng_sticker,tgs_sticker,``webm_sticker``,emojis, andmask_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_TITLEcharacters.title (
str) – Sticker set title,telegram.constants.StickerLimit.MIN_NAME_AND_TITLE-telegram.constants.StickerLimit.MAX_NAME_AND_TITLEcharacters.stickers (
Sequence[InputSticker]) –A sequence of
telegram.constants.StickerSetLimit.MIN_INITIAL_STICKERS-telegram.constants.StickerSetLimit.MAX_INITIAL_STICKERSinitial 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.REGULARortelegram.Sticker.MASK, ortelegram.Sticker.CUSTOM_EMOJI. By default, a regular sticker set is createdAdded in version 20.0.
needs_repainting (
bool|None, default:None) –Pass
Trueif 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,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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:
- 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_usersadministrator right.Added in version 13.8.
- 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_messagesadministrator right in the corresponding channel chat.Added in version 22.4.
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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_messagesbusiness bot right to delete messages sent by the bot itself, or thecan_delete_all_messagesbusiness 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 messagesmessage_ids (
Sequence[int]) – A list oftelegram.constants.BulkRequestLimit.MIN_LIMIT-telegram.constants.BulkRequestLimit.MAX_LIMITidentifiers of messages to delete. Seedelete_message()for limitations on which messages can be deleted.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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,
Trueis returned.- Returns:
bool–- Raises:
- 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_setoptionally returned inget_chat()requests to check if the bot can use this method.- Parameters:
chat_id (
str|int) – |chat_id_group|- Returns:
On success,
Trueis 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_messagesadministrator rights.Added in version 20.0.
- Parameters:
chat_id (
str|int) – |chat_id_group|message_thread_id (
int) – |message_thread_id|
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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_messagespermissions 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_messagespermission in a supergroup or a channel, it can delete any message there.
See also
telegram.CallbackQuery.delete_message()(callsdelete_message()indirectly, viatelegram.Message.delete())
- 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 oftelegram.constants.BulkRequestLimit.MIN_LIMIT-telegram.constants.BulkRequestLimit.MAX_LIMITidentifiers of messages to delete. Seedelete_message()for limitations on which messages can be deleted.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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.
See also
- Parameters:
scope (
BotCommandScope|None, default:None) – An object, describing scope of users for which the commands are relevant. Defaults totelegram.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,
Trueis returned.- Returns:
bool–- Raises:
- 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.Stickerinstances.- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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.
- 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_storiesbusiness bot right.Added in version 22.1.
- 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().
- 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
telegrammodule is supportedwhen uploading files, a
telegram.InputFilemust 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.Defaultswill not work (only relevant fortelegram.ext.ExtBot).The only exception is
telegram.ext.Defaults.tzinfo, which will be correctly applied todatetime.datetimeobjects.
Added in version 20.8.
- Parameters:
endpoint (
str) – The API endpoint to use, e.g.getMeorget_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. Ifreturn_typeis not specified, this is adictorbool, otherwise an instance ofreturn_typeor a tuple ofreturn_type.- Raises:
- async editChatInviteLink(chat_id, invite_link, expire_date=None, member_limit=None, name=None, creates_join_request=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
edit_chat_invite_link()- Return type:
- async editChatSubscriptionInviteLink(chat_id, invite_link, name=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
edit_chat_subscription_invite_link()- Return type:
- 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:
- 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:
- 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()
- 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:
- 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()
- 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()
- 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()
- 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()
- 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:
- 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:
- async edit_chat_invite_link(chat_id, invite_link, expire_date=None, member_limit=None, name=None, creates_join_request=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]
Use this method to edit a non-primary invite link created by the bot. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
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.ChatInviteLinkinstances.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_LENGTHcharacters.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. IfTrue,member_limitcan’t be specified.Added in version 13.8.
- Returns:
- Raises:
- async edit_chat_subscription_invite_link(chat_id, invite_link, name=None, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]
Use this method to edit a subscription invite link created by the bot. The bot must have
telegram.ChatPermissions.can_invite_usersadministrator right.Added in version 21.5.
- Parameters:
- Returns:
- Raises:
- 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_topicsadministrator 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_LENGTHcharacters. 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. Useget_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,
Trueis returned.- Returns:
bool–- Raises:
- 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_topicsadministrator rights.Added in version 20.0.
- 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_LENGTHcharacters after entities parsing.parse_mode (DefaultValue[DVValueType] |
str| DefaultValue[None] |None, default:None) – |parse_mode|caption_entities (
Sequence[MessageEntity] |None, default:None) –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) –Added in version 21.4.
- Returns:
On success, if edited message is not an inline message, the edited message is returned, otherwise
Trueis returned.- Returns:
- Raises:
- 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:
- 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_periodexpires or editing is explicitly disabled by a call tostop_message_live_location().Note
You can either supply a
latitudeandlongitudeor alocation.- Parameters:
chat_id (
int|str|None, default:None) – Required ifinline_message_idis not specified. |chat_id_channel|message_id (
int|None, default:None) – Required ifinline_message_idis not specified. Identifier of the message to edit.inline_message_id (
str|None, default:None) – Required ifchat_idandmessage_idare 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 betweentelegram.constants.LocationLimit.MIN_HEADINGandtelegram.constants.LocationLimit.MAX_HEADINGif specified.proximity_alert_radius (
int|None, default:None) – Maximum distance for proximity alerts about approaching another chat member, in meters. Must be betweentelegram.constants.LocationLimit.MIN_PROXIMITY_ALERT_RADIUSandtelegram.constants.LocationLimit.MAX_PROXIMITY_ALERT_RADIUSif 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_FOREVERis specified, then the location can be updated forever. Otherwise, the new value must not exceed the currentlive_periodby more than a day, and the live location expiration date must remain within the next 90 days. If not specified, thenlive_periodremains unchangedAdded in version 21.2..
Changed in version 21.11: |time-period-input|
business_connection_id (
str|None, default:None) –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
Trueis returned.- Returns:
- 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_idor 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) –Added in version 21.4.
- Returns:
On success, if edited message is not an inline message, the edited Message is returned, otherwise
Trueis returned.- Returns:
- Raises:
- 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) –Added in version 21.4.
- Returns:
On success, if edited message is not an inline message, the edited message is returned, otherwise
Trueis returned.- Returns:
- Raises:
- 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.
See also
- Parameters:
chat_id (
int|str|None, default:None) – Required ifinline_message_idis not specified. |chat_id_channel|message_id (
int|None, default:None) – Required ifinline_message_idis not specified. Identifier of the message to edit.inline_message_id (
str|None, default:None) – Required ifchat_idandmessage_idare 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_LENGTHcharacters 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) –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 withlink_preview_options.Changed in version 20.8: Bot API 7.0 introduced
link_preview_optionsreplacing this argument. PTB will automatically convert this argument to that one, but for advanced options, please uselink_preview_optionsdirectly.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
Trueis returned.- Returns:
- Raises:
ValueError – If both
disable_web_page_previewandlink_preview_optionsare passed.telegram.error.TelegramError – For other errors.
- 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_storiesbusiness 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_LENGTHcharacters after entities parsing.parse_mode (DefaultValue[DVValueType] |
str| DefaultValue[None] |None, default:None) – Mode for parsing entities in the story caption. See the constants intelegram.constants.ParseModefor 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
areashas its own maximum limit:Up to
~telegram.constants.StoryAreaTypeLimit.MAX_LOCATION_AREASoftelegram.StoryAreaTypeLocation.Up to
~telegram.constants.StoryAreaTypeLimit.MAX_SUGGESTED_REACTION_AREASoftelegram.StoryAreaTypeSuggestedReaction.Up to
~telegram.constants.StoryAreaTypeLimit.MAX_LINK_AREASoftelegram.StoryAreaTypeLink.Up to
~telegram.constants.StoryAreaTypeLimit.MAX_WEATHER_AREASoftelegram.StoryAreaTypeWeather.Up to
~telegram.constants.StoryAreaTypeLimit.MAX_UNIQUE_GIFT_AREASoftelegram.StoryAreaTypeUniqueGift.
- Returns:
Story–Story- Raises:
- 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) – PassTrueto cancel extension of the user subscription; the subscription must be active up to the end of the current subscription period. PassFalseto allow the user to re-enable a subscription that was previously canceled by the bot.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- async exportChatInviteLink(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
export_chat_invite_link()- Return type:
- async export_chat_invite_link(chat_id, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]
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 theget_chat()method. If your bot needs to generate a new primary invite link replacing its previous one, useexport_chat_invite_link()again.- Parameters:
chat_id (
str|int) – |chat_id_channel|- Returns:
New invite link on success.
- Returns:
str–- Raises:
- 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:
- 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()
- 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_contentandtelegram.ChatFullInfo.has_protected_contentto 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 infrom_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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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:
- 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 oftelegram.constants.BulkRequestLimit.MIN_LIMIT-telegram.constants.BulkRequestLimit.MAX_LIMITidentifiers of messages in the chatfrom_chat_idto 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
MessageIdof sent messages is returned.- Returns:
- Raises:
- async getAvailableGifts(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
get_available_gifts()- Return type:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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()
- 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:
- async getForumTopicIconStickers(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
get_forum_topic_icon_stickers()
- 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:
- async getMe(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
get_me()- Return type:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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()
- 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:
- 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:
- async getWebhookInfo(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
get_webhook_info()- Return type:
- 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:
- Raises:
- 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_starsbusiness bot right.Added in version 22.1.
- Parameters:
business_connection_id (
str) – Unique identifier of the business connection.exclude_unsaved (
bool|None, default:None) – PassTrueto exclude gifts that aren’t saved to the account’s profile page.exclude_saved (
bool|None, default:None) – PassTrueto exclude gifts that are saved to the account’s profile page.exclude_unlimited (
bool|None, default:None) – PassTrueto exclude gifts that can be purchased an unlimited number of times.exclude_limited (
bool|None, default:None) – PassTrueto exclude gifts that can be purchased a limited number of times.exclude_unique (
bool|None, default:None) – PassTrueto exclude unique gifts.sort_by_price (
bool|None, default:None) – PassTrueto 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 totelegram.constants.BusinessLimit.MAX_GIFT_RESULTS.
- Returns:
- Raises:
- 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_starsbusiness bot right.Added in version 22.1.
- Parameters:
business_connection_id (
str) – Unique identifier of the business connection.- Returns:
- Raises:
- 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:
- Raises:
- 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:
- Raises:
- 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
ChatMemberobjects 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:
- 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:
chat_id (
str|int) – |chat_id_channel|user_id (
int) – Unique identifier of the target user.
- Returns:
- Raises:
- 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:
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.
- 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_LIMITcustom emoji identifiers can be specified.Changed in version 20.0: |sequenceargs|
- Returns:
tuple[Sticker,...] – tuple[telegram.Sticker]- Raises:
- 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_DOWNLOADin size. The file can then be e.g. downloaded withtelegram.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>
- 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:
- 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 ifinline_message_idis not specified. Unique identifier for the target chat.message_id (
int|None, default:None) – Required ifinline_message_idis not specified. Identifier of the sent message.inline_message_id (
str|None, default:None) – Required ifchat_idandmessage_idare not specified. Identifier of the inline message.
- Returns:
tuple[GameHighScore,...] – tuple[telegram.GameHighScore]- Raises:
- 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.Userinstance representing that bot if the credentials are valid,Noneotherwise.- Returns:
User–- Raises:
- 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.
See also
Changed in version 20.0: Returns a tuple instead of a list.
- Parameters:
scope (
BotCommandScope|None, default:None) –An object, describing scope of users. Defaults to
telegram.BotCommandScopeDefault.Added in version 13.7.
language_code (
str|None, default:None) –A two-letter ISO 639-1 language code or an empty string.
Added in version 13.7.
- Returns:
On success, the commands set for the bot. An empty tuple is returned if commands are not set.
- Returns:
tuple[BotCommand,...] –- Raises:
- 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.
- 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.
- 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.
- 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.
- 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:
- Raises:
- 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 betweentelegram.constants.StarTransactionsLimit.MIN_LIMIT-telegram.constants.StarTransactionsLimit.MAX_LIMITare accepted. Defaults totelegram.constants.StarTransactionsLimit.MAX_LIMIT.
- Returns:
On success.
- Returns:
- Raises:
- 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:
- Raises:
- 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
This method will not work if an outgoing webhook is set up.
In order to avoid getting duplicate updates, recalculate offset after each server response.
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 itstelegram.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 betweentelegram.constants.PollingLimit.MIN_LIMIT-telegram.constants.PollingLimit.MAX_LIMITare accepted. Defaults to100.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.Updatefor a complete list of available update types. Specify an empty sequence to receive all updates excepttelegram.Update.chat_member,telegram.Update.message_reactionandtelegram.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:
- 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:
chat_id (
str|int) – |chat_id_channel|user_id (
int) – Unique identifier of the target user.
- Returns:
- On success, the object containing the list of boosts
is returned.
- Returns:
- Raises:
- 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 betweentelegram.constants.UserProfilePhotosLimit.MIN_LIMIT-telegram.constants.UserProfilePhotosLimit.MAX_LIMITare accepted. Defaults to100.
- Returns:
- Raises:
- 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 thetelegram.WebhookInfo.urlfield empty.- Returns:
- 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:
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 oftelegram.constants.PremiumSubscription.MONTH_COUNT_THREE,telegram.constants.PremiumSubscription.MONTH_COUNT_SIX, ortelegram.constants.PremiumSubscription.MONTH_COUNT_TWELVE.star_count (
int) – Number of Telegram Stars to pay for the Telegram Premium subscription; must betelegram.constants.PremiumSubscription.STARS_THREE_MONTHSfortelegram.constants.PremiumSubscription.MONTH_COUNT_THREEmonths,telegram.constants.PremiumSubscription.STARS_SIX_MONTHSfortelegram.constants.PremiumSubscription.MONTH_COUNT_SIXmonths, andtelegram.constants.PremiumSubscription.STARS_TWELVE_MONTHSfortelegram.constants.PremiumSubscription.MONTH_COUNT_TWELVEmonths.text (
str|None, default:None) – Text that will be shown along with the service message about the subscription; 0-telegram.constants.PremiumSubscription.MAX_TEXT_LENGTHcharacters.text_parse_mode (DefaultValue[DVValueType] |
str| DefaultValue[None] |None, default:None) – Mode for parsing entities. Seetelegram.constants.ParseModeand formatting options for more details. Entities other thanBOLD,ITALIC,UNDERLINE,STRIKETHROUGH,SPOILER, andCUSTOM_EMOJIare ignored.text_entities (
Sequence[MessageEntity] |None, default:None) – A list of special entities that appear in the gift text. It can be specified instead oftext_parse_mode. Entities other thanBOLD,ITALIC,UNDERLINE,STRIKETHROUGH,SPOILER, andCUSTOM_EMOJIare ignored.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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_topicsadministrator 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,
Trueis returned.- Returns:
bool–- Raises:
- property id: int
Unique identifier for this bot. Shortcut for the corresponding attribute of
bot.- Type:
- async initialize()[source]
Initialize resources used by this class. Currently calls
get_me()to cachebotand callstelegram.request.BaseRequest.initialize()for the request objects used by this bot.See also
Added in version 20.0.
- Return type:
- property last_name: str
Optional. Bot’s last name. Shortcut for the corresponding attribute of
bot.- Type:
- 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:
- 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,
Trueis returned.- Returns:
bool–- Raises:
- async logOut(*, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
log_out()- Return type:
- 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.
- 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:
- 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_messagesadmin right in a supergroup orcan_edit_messagesadmin 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) – PassTrue, 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,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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_storiesbusiness 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_LENGTHcharacters after entities parsing.parse_mode (DefaultValue[DVValueType] |
str| DefaultValue[None] |None, default:None) – Mode for parsing entities in the story caption. See the constants intelegram.constants.ParseModefor 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
areashas its own maximum limit:Up to
~telegram.constants.StoryAreaTypeLimit.MAX_LOCATION_AREASoftelegram.StoryAreaTypeLocation.Up to
~telegram.constants.StoryAreaTypeLimit.MAX_SUGGESTED_REACTION_AREASoftelegram.StoryAreaTypeSuggestedReaction.Up to
~telegram.constants.StoryAreaTypeLimit.MAX_LINK_AREASoftelegram.StoryAreaTypeLink.Up to
~telegram.constants.StoryAreaTypeLimit.MAX_WEATHER_AREASoftelegram.StoryAreaTypeWeather.Up to
~telegram.constants.StoryAreaTypeLimit.MAX_UNIQUE_GIFT_AREASoftelegram.StoryAreaTypeUniqueGift.
post_to_chat_page (
bool|None, default:None) – PassTrueto keep the story accessible after it expires.protect_content (DefaultValue[DVValueType] |
bool| DefaultValue[None] |None, default:None) – PassTrueif the content of the story must be protected from forwarding and screenshotting
- Returns:
Story–Story- Raises:
- 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:
- 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
Falsefor all boolean parameters to demote a user.Changed in version 20.0: The argument
can_manage_voice_chatswas renamed tocan_manage_video_chatsin 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) – PassTrue, 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) – PassTrue, if the administrator can change chat title, photo and other settings.can_post_messages (
bool|None, default:None) – PassTrue, if the administrator can post messages in the channel, or access channel statistics; for channels only.can_edit_messages (
bool|None, default:None) – PassTrue, if the administrator can edit messages of other users and can pin messages, for channels only.can_delete_messages (
bool|None, default:None) – PassTrue, if the administrator can delete messages of other users.can_invite_users (
bool|None, default:None) – PassTrue, if the administrator can invite new users to the chat.can_restrict_members (
bool|None, default:None) – PassTrue, if the administrator can restrict, ban or unban chat members, or access supergroup statistics.can_pin_messages (
bool|None, default:None) – PassTrue, if the administrator can pin messages, for supergroups only.can_promote_members (
bool|None, default:None) – PassTrue, 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 archiveAdded 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 onlyAdded in version 22.4.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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_messagesbusiness 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_TIMEOUTseconds.message_id (
int) – Unique identifier of the message to mark as read.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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.
- 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:
- 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:
- 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:
- 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_photobusiness bot right.Added in version 22.1.
- Parameters:
business_connection_id (
str) – Unique identifier of the business connection.is_public (
bool|None, default:None) – PassTrueto 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,
Trueis returned.- Returns:
bool–- Raises:
- 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,
Trueis returned.- Returns:
bool–- Raises:
- 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.
- 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:
- 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:
- 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_topicsadministrator 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|
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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_topicsadministrator 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,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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(), thenadd_sticker_to_set(), thenset_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.Stickerinstances.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,
Trueis returned.- Returns:
bool–- Raises:
- property request: BaseRequest
The
BaseRequestobject 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:
- 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
Truefor all boolean parameters to lift restrictions from a user.- Parameters:
chat_id (
str|int) – |chat_id_group|user_id (
int) – Unique identifier of the target user.until_date (
int|datetime|None, default:None) – Date when restrictions will be lifted for the user, unix time. If user is restricted for more than 366 days or less than 30 seconds from the current time, they are considered to be restricted forever. |tz-naive-dtms|permissions (
ChatPermissions) – An object for new user permissions.use_independent_chat_permissions (
bool|None, default:None) –Pass
Trueif chat permissions are set independently. Otherwise, thecan_send_other_messagesandcan_add_web_page_previewspermissions will imply thecan_send_messages,can_send_audios,can_send_documents,can_send_photos,can_send_videos,can_send_video_notes, andcan_send_voice_notespermissions; thecan_send_pollspermission will imply thecan_send_messagespermission.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- async revokeChatInviteLink(chat_id, invite_link, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)
Alias for
revoke_chat_invite_link()- Return type:
- async revoke_chat_invite_link(chat_id, invite_link, *, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]
Use this method to revoke an invite link created by the bot. If the primary link is revoked, a new link is automatically generated. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights.
Added in version 13.4.
- Parameters:
chat_id (
str|int) – |chat_id_channel|invite_link (
str| ChatInviteLink) –The invite link to revoke.
Changed in version 20.0: Now also accepts
telegram.ChatInviteLinkinstances.
- Returns:
- Raises:
- 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:
- 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) – PassTrueif the message can be sent to private chats with usersallow_bot_chats (
bool|None, default:None) – PassTrueif the message can be sent to private chats with botsallow_group_chats (
bool|None, default:None) – PassTrueif the message can be sent to group and supergroup chatsallow_channel_chats (
bool|None, default:None) – PassTrueif the message can be sent to channels
- Returns:
On success, the prepared message is returned.
- Returns:
- Raises:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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()
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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_UPLOADin size, this limit may be changed in the future.Note
thumbnailwill 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. Usethumbnailinstead.- Parameters:
chat_id (
int|str) – |chat_id_channel|animation (
str|Path|IO[bytes] | InputFile |bytes| Animation) –Animation to send. |fileinput| Lastly you can pass an existing
telegram.Animationobject to send.Changed in version 13.2: Accept
bytesas input.duration (
int|timedelta|None, default:None) –Duration of sent animation in seconds.
Changed in version 21.11: |time-period-input|
caption (
str|None, default:None) – Animation caption (may also be used when resending animations by file_id), 0-telegram.constants.MessageLimit.CAPTION_LENGTHcharacters after entities parsing.parse_mode (DefaultValue[DVValueType] |
str| DefaultValue[None] |None, default:None) – |parse_mode|caption_entities (
Sequence[MessageEntity] |None, default:None) –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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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
Trueif the animation needs to be covered with a spoiler animation.Added in version 20.0.
thumbnail (
str|Path|IO[bytes] | InputFile |bytes|None, default:None) –Added in version 20.2.
reply_parameters (ReplyParameters |
None, default:None) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –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) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged 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
tempfilemodule.Added in version 13.1.
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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
.mp3or.m4aformat.Bots can currently send audio files of up to
telegram.constants.FileSizeLimit.FILESIZE_UPLOADin 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. Usethumbnailinstead.- Parameters:
chat_id (
int|str) – |chat_id_channel|audio (
str|Path|IO[bytes] | InputFile |bytes| Audio) –Audio file to send. |fileinput| Lastly you can pass an existing
telegram.Audioobject to send.Changed in version 13.2: Accept
bytesas 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) – Audio caption, 0-telegram.constants.MessageLimit.CAPTION_LENGTHcharacters after entities parsing.parse_mode (DefaultValue[DVValueType] |
str| DefaultValue[None] |None, default:None) – |parse_mode|caption_entities (
Sequence[MessageEntity] |None, default:None) –Changed in version 20.0: |sequenceargs|
duration (
int|timedelta|None, default:None) –Duration of sent audio in seconds.
Changed in version 21.11: |time-period-input|
disable_notification (DefaultValue[DVValueType] |
bool| DefaultValue[None] |None, default:None) – |disable_notification|protect_content (DefaultValue[DVValueType] |
bool| DefaultValue[None] |None, default:None) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –Added in version 20.2.
reply_parameters (ReplyParameters |
None, default:None) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged 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
tempfilemodule.Added in version 13.1.
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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:
chat_id (
str|int) – |chat_id_channel|action (
str) – Type of action to broadcast. Choose one, depending on what the user is about to receive. For convenience look at the constants intelegram.constants.ChatAction.message_thread_id (
int|None, default:None) –Added in version 20.0.
business_connection_id (
str|None, default:None) –Added in version 21.1.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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:
business_connection_id (
str) – |business_id_str|chat_id (
int) – Unique identifier for the target chat.checklist (
InputChecklist) – The checklist to send.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_effect_id (
str|None, default:None) – |message_effect_id|reply_parameters (ReplyParameters |
None, default:None) – |reply_parameters|reply_markup (InlineKeyboardMarkup |
None, default:None) – An object for an inline keyboard
- Keyword Arguments:
allow_sending_without_reply (
bool, optional) – |allow_sending_without_reply| Mutually exclusive withreply_parameters, which this is a convenience parameter forreply_to_message_id (
int, optional) – |reply_to_msg_id| Mutually exclusive withreply_parameters, which this is a convenience parameter for
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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
contactorphone_numberandfirst_namewith optionallylast_nameand optionallyvcard.- 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.VCARDbytes.disable_notification (DefaultValue[DVValueType] |
bool| DefaultValue[None] |None, default:None) – |disable_notification|protect_content (DefaultValue[DVValueType] |
bool| DefaultValue[None] |None, default:None) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged in version 20.8: Bot API 7.0 introduced
reply_parameters|rtm_aswr_deprecated|Changed in version 21.0: |keyword_only_arg|
contact (
telegram.Contact, optional) – The contact to send.
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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 useremoji (
str|None, default:None) –Emoji on which the dice throw animation is based. Currently, must be one of
telegram.constants.DiceEmoji. Dice can have valuestelegram.Dice.MIN_VALUE-telegram.Dice.MAX_VALUE_BOWLINGfortelegram.Dice.DICE,telegram.Dice.DARTSandtelegram.Dice.BOWLING, valuestelegram.Dice.MIN_VALUE-telegram.Dice.MAX_VALUE_BASKETBALLfortelegram.Dice.BASKETBALLandtelegram.Dice.FOOTBALL, and valuestelegram.Dice.MIN_VALUE-telegram.Dice.MAX_VALUE_SLOT_MACHINEfortelegram.Dice.SLOT_MACHINE. Defaults totelegram.Dice.DICE.Changed in version 13.4: Added the
telegram.Dice.BOWLINGemoji.protect_content (DefaultValue[DVValueType] |
bool| DefaultValue[None] |None, default:None) –Added in version 13.10.
message_thread_id (
int|None, default:None) –Added in version 20.0.
reply_parameters (ReplyParameters |
None, default:None) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged in version 20.8: Bot API 7.0 introduced
reply_parameters|rtm_aswr_deprecated|Changed in version 21.0: |keyword_only_arg|
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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_UPLOADin 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. Usethumbnailinstead.- 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.Documentobject to send.Note
Sending by URL will currently only work
GIF,PDF&ZIPfiles.Changed in version 13.2: Accept
bytesas 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_LENGTHcharacters 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) –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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –Added in version 20.2.
reply_parameters (ReplyParameters |
None, default:None) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged 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 thetempfilemodule.
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
- Keyword Arguments:
allow_sending_without_reply (
bool, optional) –|allow_sending_without_reply| Mutually exclusive with
reply_parameters, which this is a convenience parameter forChanged 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 forChanged in version 20.8: Bot API 7.0 introduced
reply_parameters|rtm_aswr_deprecated|Changed in version 21.0: |keyword_only_arg|
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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_idoptional. In version 22.1, the methods signature was changed accordingly.- Parameters:
gift_id (
str|Gift) – Identifier of the gift or aGiftobjectuser_id (
int|None, default:None) –Required if
chat_idis 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_idis 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_LENGTHcharacterstext_parse_mode (DefaultValue[DVValueType] |
str| DefaultValue[None] |None, default:None) – Mode for parsing entities. Seetelegram.constants.ParseModeand formatting options for more details. Entities other thanBOLD,ITALIC,UNDERLINE,STRIKETHROUGH,SPOILER, andCUSTOM_EMOJIare ignored.text_entities (
Sequence[MessageEntity] |None, default:None) – A list of special entities that appear in the gift text. It can be specified instead oftext_parse_mode. Entities other thanBOLD,ITALIC,UNDERLINE,STRIKETHROUGH,SPOILER, andCUSTOM_EMOJIare ignored.pay_for_upgrade (
bool|None, default:None) –Pass
Trueto 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,
Trueis returned.- Returns:
bool–- Raises:
- 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_parameteris 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_parameteris optional.- Parameters:
chat_id (
int|str) – |chat_id_channel|title (
str) – Product name.telegram.Invoice.MIN_TITLE_LENGTH-telegram.Invoice.MAX_TITLE_LENGTHcharacters.description (
str) – Product description.telegram.Invoice.MIN_DESCRIPTION_LENGTH-telegram.Invoice.MAX_DESCRIPTION_LENGTHcharacters.payload (
str) – Bot-defined invoice payload.telegram.Invoice.MIN_PAYLOAD_LENGTH-telegram.Invoice.MAX_PAYLOAD_LENGTHbytes. 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
XTRfor 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.45passmax_tip_amount = 145. See theexpparameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies). Defaults to0. 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_AMOUNTSsuggested tip amounts can be specified. The suggested tip amounts must be positive, passed in a strictly increased order and must not exceedmax_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.need_name (
bool|None, default:None) – PassTrue, 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) – PassTrue, if you require the user’s phone number to complete the order. Ignored for payments in |tg_stars|.need_email (
bool|None, default:None) – PassTrue, if you require the user’s email to complete the order. Ignored for payments in |tg_stars|.need_shipping_address (
bool|None, default:None) – PassTrue, 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) – PassTrue, if user’s phone number should be sent to provider. Ignored for payments in |tg_stars|.send_email_to_provider (
bool|None, default:None) – PassTrue, if user’s email address should be sent to provider. Ignored for payments in |tg_stars|.is_flexible (
bool|None, default:None) – PassTrue, 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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –Added in version 20.8.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged in version 20.8: Bot API 7.0 introduced
reply_parameters|rtm_aswr_deprecated|Changed in version 21.0: |keyword_only_arg|
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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
latitudeandlongitudeor alocation.- 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_PERIODandtelegram.constants.LocationLimit.MAX_LIVE_PERIOD, ortelegram.constants.LocationLimit.LIVE_PERIOD_FOREVERfor 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 betweentelegram.constants.LocationLimit.MIN_HEADINGandtelegram.constants.LocationLimit.MAX_HEADINGif 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 betweentelegram.constants.LocationLimit.MIN_PROXIMITY_ALERT_RADIUSandtelegram.constants.LocationLimit.MAX_PROXIMITY_ALERT_RADIUSif specified.disable_notification (DefaultValue[DVValueType] |
bool| DefaultValue[None] |None, default:None) – |disable_notification|protect_content (DefaultValue[DVValueType] |
bool| DefaultValue[None] |None, default:None) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged in version 20.8: Bot API 7.0 introduced
reply_parameters|rtm_aswr_deprecated|Changed in version 21.0: |keyword_only_arg|
location (
telegram.Location, optional) – The location to send.
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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 eitherparse_modeorcaption_entities), then items inmediamust 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_LENGTHitems.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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –Added in version 20.0.
reply_parameters (ReplyParameters |
None, default:None) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –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 forChanged 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 forChanged 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 toNone.Added in version 20.0.
parse_mode (
str|None, optional) –Parse mode for
caption. See the constants intelegram.constants.ParseModefor 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 ofparse_mode. Defaults toNone.Added in version 20.0.
- Returns:
An array of the sent Messages.
- Returns:
- Raises:
- 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. Maxtelegram.constants.MessageLimit.MAX_TEXT_LENGTHcharacters 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) –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) –Added in version 20.0.
reply_parameters (ReplyParameters |
None, default:None) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged 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 withlink_preview_options.Changed in version 20.8: Bot API 7.0 introduced
link_preview_optionsreplacing this argument. PTB will automatically convert this argument to that one, but for advanced options, please uselink_preview_optionsdirectly.Changed in version 21.0: |keyword_only_arg|
- Returns:
On success, the sent message is returned.
- Returns:
Message–- Raises:
ValueError – If both
disable_web_page_previewandlink_preview_optionsare passed.telegram.error.TelegramError – For other errors.
- 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 totelegram.constants.MediaGroupLimit.MAX_MEDIA_LENGTHitems.payload (
str|None, default:None) –Bot-defined paid media payload, 0-
telegram.constants.InvoiceLimit.MAX_PAYLOAD_LENGTHbytes. 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_LENGTHcharacters.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) –Added in version 21.5.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –Added in version 22.4.
message_thread_id (
int|None, default:None) –Added in version 22.4.
- Keyword Arguments:
allow_sending_without_reply (
bool, optional) – |allow_sending_without_reply| Mutually exclusive withreply_parameters, which this is a convenience parameter forreply_to_message_id (
int, optional) – |reply_to_msg_id| Mutually exclusive withreply_parameters, which this is a convenience parameter for
- Returns:
On success, the sent message is returned.
- Returns:
Message–- Raises:
- 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.PhotoSizeobject 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
bytesas 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_LENGTHcharacters after entities parsing.parse_mode (DefaultValue[DVValueType] |
str| DefaultValue[None] |None, default:None) – |parse_mode|caption_entities (
Sequence[MessageEntity] |None, default:None) –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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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
Trueif the photo needs to be covered with a spoiler animation.Added in version 20.0.
reply_parameters (ReplyParameters |
None, default:None) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –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) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged 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
tempfilemodule.Added in version 13.1.
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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_LENGTHcharacters.options (
Sequence[str| InputPollOption]) –Sequence of
telegram.Poll.MIN_OPTION_NUMBER-telegram.Poll.MAX_OPTION_NUMBERanswer options. Each option may either be a string withtelegram.Poll.MIN_OPTION_LENGTH-telegram.Poll.MAX_OPTION_LENGTHcharacters or anInputPollOptionobject. Strings are converted toInputPollOptionobjects automatically.Changed in version 20.0: |sequenceargs|
Changed in version 21.2: Bot API 7.3 adds support for
InputPollOptionobjects.is_anonymous (
bool|None, default:None) –True, if the poll needs to be anonymous, defaults toTrue.type (
str|None, default:None) – Poll type,telegram.Poll.QUIZortelegram.Poll.REGULAR, defaults totelegram.Poll.REGULAR.allows_multiple_answers (
bool|None, default:None) –True, if the poll allows multiple answers, ignored for polls in quiz mode, defaults toFalse.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_LENGTHcharacters with at mosttelegram.Poll.MAX_EXPLANATION_LINE_FEEDSline 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 intelegram.constants.ParseModefor 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 withclose_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 leasttelegram.Poll.MIN_OPEN_PERIODand no more thantelegram.Poll.MAX_OPEN_PERIODseconds in the future. Can’t be used together withopen_period. |tz-naive-dtms|is_closed (
bool|None, default:None) – PassTrue, 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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –Added in version 20.8.
business_connection_id (
str|None, default:None) –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.ParseModefor 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 ofquestion_parse_mode.Added in version 21.2.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
- Keyword Arguments:
allow_sending_without_reply (
bool, optional) –|allow_sending_without_reply| Mutually exclusive with
reply_parameters, which this is a convenience parameter forChanged 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 forChanged in version 20.8: Bot API 7.0 introduced
reply_parameters|rtm_aswr_deprecated|Changed in version 21.0: |keyword_only_arg|
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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.WEBMstickers.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.Stickerobject to send.Changed in version 13.2: Accept
bytesas 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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged in version 20.8: Bot API 7.0 introduced
reply_parameters|rtm_aswr_deprecated|Changed in version 21.0: |keyword_only_arg|
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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, orlatitude,longitude,titleandaddressand optionallyfoursquare_idandfoursquare_typeor optionallygoogle_place_idandgoogle_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|longitude (
float|None, default:None) – Longitude of 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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged in version 20.8: Bot API 7.0 introduced
reply_parameters|rtm_aswr_deprecated|Changed in version 21.0: |keyword_only_arg|
venue (
telegram.Venue, optional) – The venue to send.
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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_UPLOADin size, this limit may be changed in the future.Note
thumbnailwill 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. Usethumbnailinstead.- 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.Videoobject to send.Changed in version 13.2: Accept
bytesas 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|
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_LENGTHcharacters after entities parsing.parse_mode (DefaultValue[DVValueType] |
str| DefaultValue[None] |None, default:None) – |parse_mode|caption_entities (
Sequence[MessageEntity] |None, default:None) –Changed in version 20.0: |sequenceargs|
supports_streaming (
bool|None, default:None) – PassTrue, 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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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
Trueif 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) –Added in version 20.2.
reply_parameters (ReplyParameters |
None, default:None) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –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) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged 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
tempfilemodule.Added in version 13.1.
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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
thumbnailwill 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. Usethumbnailinstead.- 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.VideoNoteobject to send. Sending video notes by a URL is currently unsupported.Changed in version 13.2: Accept
bytesas 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) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –Added in version 20.2.
reply_parameters (ReplyParameters |
None, default:None) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged 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
tempfilemodule.Added in version 13.1.
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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
.oggfile encoded with OPUS , or in .MP3 format, or in .M4A format (other formats may be sent asAudioorDocument). Bots can currently send voice messages of up totelegram.constants.FileSizeLimit.FILESIZE_UPLOADin 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_SIZEin size.telegram.constants.FileSizeLimit.VOICE_NOTE_FILE_SIZE-telegram.constants.FileSizeLimit.FILESIZE_DOWNLOADvoice notes will be sent as files.See also
Working with Files and Media <Working-with-Files-and-Media>- Parameters:
chat_id (
int|str) – |chat_id_channel|voice (
str|Path|IO[bytes] | InputFile |bytes| Voice) –Voice file to send. |fileinput| Lastly you can pass an existing
telegram.Voiceobject to send.Changed in version 13.2: Accept
bytesas 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) – Voice message caption, 0-telegram.constants.MessageLimit.CAPTION_LENGTHcharacters after entities parsing.parse_mode (DefaultValue[DVValueType] |
str| DefaultValue[None] |None, default:None) – |parse_mode|caption_entities (
Sequence[MessageEntity] |None, default:None) –Changed in version 20.0: |sequenceargs|
duration (
int|timedelta|None, default:None) –Duration of the voice message in seconds.
Changed in version 21.11: |time-period-input|
disable_notification (DefaultValue[DVValueType] |
bool| DefaultValue[None] |None, default:None) – |disable_notification|protect_content (DefaultValue[DVValueType] |
bool| DefaultValue[None] |None, default:None) –Added in version 13.10.
message_thread_id (
int|None, default:None) –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) –Added in version 20.8.
business_connection_id (
str|None, default:None) –Added in version 21.1.
message_effect_id (
str|None, default:None) –Added in version 21.3.
allow_paid_broadcast (
bool|None, default:None) –Added in version 21.7.
suggested_post_parameters (SuggestedPostParameters |
None, default:None) –Added in version 22.4.
direct_messages_topic_id (
int|None, default:None) –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 forChanged 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 forChanged 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
tempfilemodule.Added in version 13.1.
- Returns:
On success, the sent Message is returned.
- Returns:
Message–- Raises:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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()
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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:
- 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_biobusiness bot right.Added in version 22.1.
- 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_settingsbusiness bot right.Added in version 22.1.
- Parameters:
business_connection_id (
str) – Unique identifier of the business connectionshow_gift_button (
bool) – PassTrue, 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,
Trueis returned.- Returns:
bool–- Raises:
- 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_namebusiness bot right.Added in version 22.1.
- Parameters:
business_connection_id (
str) – Unique identifier of the business connectionfirst_name (
str) – New first name of the business account;telegram.constants.BusinessLimit.MIN_NAME_LENGTH-telegram.constants.BusinessLimit.MAX_NAME_LENGTHcharacters.last_name (
str|None, default:None) – New last name of the business account; 0-telegram.constants.BusinessLimit.MAX_NAME_LENGTHcharacters.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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_photobusiness 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) – PassTrueto 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,
Trueis returned.- Returns:
bool–- Raises:
- 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_usernamebusiness bot right.Added in version 22.1.
- 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_LENGTHcharacters, emoji are not allowed.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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.
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 changedmenu_button (
MenuButton|None, default:None) – An object for the new bot’s menu button. Defaults totelegram.MenuButtonDefault.
- Returns:
On success,
Trueis 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_membersadmin rights.- Parameters:
chat_id (
str|int) – |chat_id_group|permissions (
ChatPermissions) – New default chat permissions.use_independent_chat_permissions (
bool|None, default:None) –Pass
Trueif chat permissions are set independently. Otherwise, thecan_send_other_messagesandcan_add_web_page_previewspermissions will imply thecan_send_messages,can_send_audios,can_send_documents,can_send_photos,can_send_videos,can_send_video_notes, andcan_send_voice_notespermissions; thecan_send_pollspermission will imply thecan_send_messagespermission.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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:
chat_id (
str|int) – |chat_id_channel|photo (
str|Path|IO[bytes] | InputFile |bytes) –New chat photo. |uploadinput|
Changed in version 13.2: Accept
bytesas input.Changed in version 20.0: File paths as input is also accepted for bots not running in
~telegram.Bot.local_mode.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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_setoptionally returned inget_chat()requests to check if the bot can use this method.
- 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.
- 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.
- 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.
See also
- Parameters:
user_id (
int) – User identifier.score (
int) – New score, must be non-negative.force (
bool|None, default:None) – PassTrue, 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) – PassTrue, if the game message should not be automatically edited to include the current scoreboard.chat_id (
int|None, default:None) – Required ifinline_message_idis not specified. Unique identifier for the target chat.message_id (
int|None, default:None) – Required ifinline_message_idis not specified. Identifier of the sent message.inline_message_id (
str|None, default:None) – Required ifchat_idandmessage_idare not specified. Identifier of the inline message.
- Returns:
The edited message. If the message is not an inline message ,
True.- Returns:
- Raises:
telegram.error.TelegramError – If the new score is not greater than the user’s current score in the chat and
forceisFalse.
- 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
strvalues will be converted to eithertelegram.ReactionTypeEmojiortelegram.ReactionTypeCustomEmojidepending on whether they are listed inReactionEmoji.is_big (
bool|None, default:None) – PassTrueto set the reaction with a big animation.
- Returns:
- Raises:
- 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.
See also
- 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_NUMBERcommands can be specified.Note
If you pass in a sequence of
tuple, the order of elements in eachtuplemust correspond to the order of positional arguments to create aBotCommandinstance.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,
Trueis returned.- Returns:
bool–- Raises:
- 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) – Atelegram.ChatAdministratorRightsobject describing new default administrator rights. If not specified, the default administrator rights will be cleared.for_channels (
bool|None, default:None) – PassTrueto 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
Trueon success.- Returns:
bool–- Raises:
- 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_LENGTHcharacters. 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,
Trueis returned.- Returns:
bool–- Raises:
- 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_LENGTHcharacters. Pass an empty string to remove the dedicated name for the given language.Caution
If
language_codeis not specified, anamemust 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,
Trueis returned.- Returns:
bool–- Raises:
- 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_LENGTHcharacters. 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,
Trueis returned.- Returns:
bool–- Raises:
- 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 identifiererrors (
Sequence[PassportElementError]) –A Sequence describing the errors.
Changed in version 20.0: |sequenceargs|
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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.Stickerinstances.emoji_list (
Sequence[str]) – A sequence oftelegram.constants.StickerLimit.MIN_STICKER_EMOJI-telegram.constants.StickerLimit.MAX_STICKER_EMOJIemoji associated with the sticker.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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.Stickerinstances.keywords (
Sequence[str] |None, default:None) – A sequence of 0-telegram.constants.StickerLimit.MAX_SEARCH_KEYWORDSsearch keywords for the sticker with total length up totelegram.constants.StickerLimit.MAX_KEYWORD_LENGTHcharacters.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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.Stickerinstances.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,
Trueis returned.- Returns:
bool–- Raises:
- 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.Stickerinstances.position (
int) – New sticker position in the set, zero-based.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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
formatwill be required, and thus the order of the arguments had to be changed.- Parameters:
name (
str) – Sticker set nameuser_id (
int) – User identifier of created sticker set owner.format (
str) –Format of the added sticker, must be one of
telegram.constants.StickerFormat.STATICfor a.WEBPor.PNGimage,telegram.constants.StickerFormat.ANIMATEDfor a.TGSanimation,telegram.constants.StickerFormat.VIDEOfor a.WEBMvideo.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_SIZEkilobytes in size and have width and height of exactlytelegram.constants.StickerSetLimit.STATIC_THUMB_DIMENSIONSpx, or a .TGS animation with the thumbnail up totelegram.constants.StickerSetLimit.MAX_ANIMATED_THUMBNAIL_SIZEkilobytes in size; see the docs for animated sticker technical requirements, or a.WEBMvideo with the thumbnail up totelegram.constants.StickerSetLimit.MAX_ANIMATED_THUMBNAIL_SIZEkilobytes in size; see this for video sticker technical requirements.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,
Trueis returned.- Returns:
bool–- Raises:
- 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.
- 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 useremoji_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 ordatetime.datetimeobject. |tz-naive-dtms|
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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 headerX-Telegram-Bot-Api-Secret-Tokenwith the secret token as content.Note
You will not be able to receive updates using
get_updates()for long as an outgoing webhook is set up.To use a self-signed certificate, you need to upload your public key certificate using
certificateparameter. Please upload asInputFile, sending a String will not work.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 ourself-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 to40. 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.Updatefor a complete list of available update types. Specify an empty sequence to receive all updates excepttelegram.Update.chat_member,telegram.Update.message_reactionandtelegram.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) – PassTrueto drop all pending updates.secret_token (
str|None, default:None) –A secret token to be sent in a header
X-Telegram-Bot-Api-Secret-Tokenin every webhook request,telegram.constants.WebhookLimit.MIN_SECRET_TOKEN_LENGTH-telegram.constants.WebhookLimit.MAX_SECRET_TOKEN_LENGTHcharacters. Only charactersA-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:
- Raises:
- 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
Added in version 20.0.
- Return type:
- 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()
- 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:
- 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_periodexpires.- Parameters:
chat_id (
int|str|None, default:None) – Required ifinline_message_idis not specified. |chat_id_channel|message_id (
int|None, default:None) – Required ifinline_message_idis not specified. Identifier of the sent message with live location to stop.inline_message_id (
str|None, default:None) – Required ifchat_idandmessage_idare 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) –Added in version 21.4.
- Returns:
On success, if edited message is not an inline message, the edited message is returned, otherwise
Trueis returned.- Returns:
- 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:
- Returns:
On success, the stopped Poll is returned.
- Returns:
Poll–- Raises:
- property supports_inline_queries: bool
Bot’s
telegram.User.supports_inline_queriesattribute. Shortcut for the corresponding attribute ofbot.- Type:
- 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:
- 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:
- 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_starsbusiness bot right.Added in version 22.1.
- 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_giftsbusiness bot right. Requirescan_transfer_starsbusiness bot right if the transfer is paid.Added in version 22.1.
- Parameters:
business_connection_id (
str) – Unique identifier of the business connectionowned_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_TIMEOUTseconds.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 thecan_transfer_starsbusiness bot right is required.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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:
- 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.
- 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.
- 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:
- 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_topicsadministrator rights.Added in version 20.0.
- Parameters:
chat_id (
str|int) – |chat_id_group|- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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:
- 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:
- 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:
- 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_messagesadmin right in a supergroup orcan_edit_messagesadmin right in a channel.- Parameters:
chat_id (
str|int) – |chat_id_channel|- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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_messagesadministrator rights in the supergroup.Added in version 20.0.
- Parameters:
chat_id (
str|int) – |chat_id_group|message_thread_id (
int) – |message_thread_id|
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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_messagesadministrator rights in the supergroup.Added in version 20.5.
- Parameters:
chat_id (
str|int) – |chat_id_group|- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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_messagesadmin right in a supergroup orcan_edit_messagesadmin 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 ifbusiness_connection_idis 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,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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_giftsbusiness bot right. Additionally requires thecan_transfer_starsbusiness bot right if the upgrade is paid.Added in version 22.1.
- Parameters:
business_connection_id (
str) – Unique identifier of the business connectionowned_gift_id (
str) – Unique identifier of the regular gift that should be upgraded to a unique one.keep_original_details (
bool|None, default:None) – PassTrueto keep the original gift text, sender and receiver in the upgraded giftstar_count (
int|None, default:None) – The amount of Telegram Stars that will be paid for the upgrade from the business account balance. Ifgift.prepaid_upgrade_star_count > 0, then pass0, otherwise, thecan_transfer_starsbusiness bot right is required andtelegram.Gift.upgrade_star_countmust be passed.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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:
- 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()andadd_sticker_to_set()methods (can be used multiple times).Changed in version 20.5: Removed deprecated parameter
png_sticker.- Parameters:
user_id (
int) – User identifier of sticker file owner.sticker (
str|Path|IO[bytes] | InputFile |bytes) –A file with the sticker in the
".WEBP",".PNG",".TGS"or".WEBM"format. See here for technical requirements . |uploadinput|Added in version 20.2.
sticker_format (
str) –Format of the sticker. Must be one of
telegram.constants.StickerFormat.STATIC,telegram.constants.StickerFormat.ANIMATED,telegram.constants.StickerFormat.VIDEO.Added in version 20.2.
- Returns:
On success, the uploaded File is returned.
- Returns:
File–- Raises:
- 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:
- 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:
- 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_LENGTHcharacters. Must be empty if the organization isn’t allowed to provide a custom verification description.
- Returns:
On success,
Trueis returned.- Returns:
bool–- Raises:
- 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.
- class spotted.utils.keyboard_util.Config[source]
Bases:
objectConfigurations
- 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.
- 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:
- 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 getdefault (
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
- 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:
TelegramObjectThis 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_appandpayare equal.Note
Exactly one of the optional fields must be used to specify type of the button.
Mind that
callback_gameis 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_datamay be an instance oftelegram.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 aTypeError.Changed in version 13.6.
After Bot API 6.1, only
HTTPSlinks will be allowed inlogin_url.
Examples
Inline Keyboard 1Inline Keyboard 2
See also
Changed in version 20.0:
web_appis 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
HTTPSURL used to automatically authorize the user. Can be used as a replacement for the Telegram Login Widget.Caution
Only
HTTPSlinks 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_DATAbytes. 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.
- 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:
- login_url
Optional. An
HTTPSURL used to automatically authorize the user. Can be used as a replacement for the Telegram Login Widget.Caution
Only
HTTPSlinks are allowed after Bot API 6.1.- Type:
- 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_DATAbytes.
- 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:
- 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:
- 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:
- copy_text
Optional. Description of the button that copies the specified text to the clipboard.
Added in version 21.7.
- Type:
- 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:
- 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:
- 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.
- MAX_CALLBACK_DATA: Final[int] = 64
telegram.constants.InlineKeyboardButtonLimit.MAX_CALLBACK_DATAAdded in version 20.0.
- MIN_CALLBACK_DATA: Final[int] = 1
telegram.constants.InlineKeyboardButtonLimit.MIN_CALLBACK_DATAAdded in version 20.0.
- classmethod de_json(data, bot=None)[source]
See
telegram.TelegramObject.de_json().- Return type:
- update_callback_data(callback_data)[source]
Sets
callback_datato the passed object. Intended to be used bytelegram.ext.CallbackDataCache.Added in version 13.6.
- class spotted.utils.keyboard_util.InlineKeyboardMarkup(inline_keyboard, *, api_kwargs=None)[source]
Bases:
TelegramObjectThis 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_keyboardand all the buttons are equal.An inline keyboard on a message
See also
Another kind of keyboard would be the
telegram.ReplyKeyboardMarkup.Examples
Inline Keyboard 1Inline Keyboard 2
- Parameters:
inline_keyboard (
Sequence[Sequence[InlineKeyboardButton]]) –Sequence of button rows, each represented by a sequence of
InlineKeyboardButtonobjects.Changed in version 20.0: |sequenceclassargs|
- inline_keyboard
Tuple of button rows, each represented by a tuple of
InlineKeyboardButtonobjects.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:
- 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:
- 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:
- 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:
- 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:
objectClass that represents a pending post
- Parameters:
user_id (
int) – id of the user that sent the postu_message_id (
int) – id of the original message of the postg_message_id (
int) – id of the post in the groupadmin_group_id (
int) – id of the admin groupcredit_username (
str|None, default:None) – username of the user that sent the post if it’s a credit postdate (
datetime) – when the post was sent
- 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:
- Returns:
PendingPost– instance of the class
- classmethod from_group(g_message_id, admin_group_id)[source]
Retrieves a pending post from the info related to the admin group
- Parameters:
- 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
- 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:
- Returns:
list[PendingPost] – list of ids of pending posts
- 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 attachedapprove (
int, default:-1) – number of approve votes known in advancereject (
int, default:-1) – number of reject votes known in advancecredited_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:
- 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
- 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:
objectislice(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:
objectReturn 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:
objectClass that represents a user
- Parameters:
user_id (
int) – id of the userprivate_message_id (
int|None, default:None) – id of the private message sent by the user to the bot. Only used for followingban_date (
datetime|None, default:None) – datetime of when the user was banned. Only used for banned usersfollow_date (
datetime|None, default:None) – datetime of when the user started following a post. Only used for following users
- 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 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
- async get_user_sign(bot)[source]
Generates a sign for the user. It will be a random name for an anonym user
- 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.
- 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.