telegram.CallbackQuery#
- class telegram.CallbackQuery(*args, **kwargs)[source]#
Bases:
telegram.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
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.arbitrary_callback_data,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.New in version 13.6.
- Parameters
from_user (
telegram.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 (
telegram.Message, optional) – Message with the callback button that originated the query. Note that message content and message date will not be available if the message is too old.data (
str, optional) – Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field.inline_message_id (
str, optional) – Identifier of the message sent via the bot in inline mode, that originated the query.game_short_name (
str, optional) – Short name of a Game to be returned, serves as the unique identifier for the gamebot (
telegram.Bot, optional) – The Bot to use for instance methods.
- chat_instance[source]#
Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent.
- Type
- inline_message_id[source]#
Optional. Identifier of the message sent via the bot in inline mode, that originated the query.
- Type
- bot[source]#
The Bot to use for instance methods.
- Type
telegram.Bot, optional
- MAX_ANSWER_TEXT_LENGTH = 200[source]#
telegram.constants.CallbackQueryLimit.ANSWER_CALLBACK_QUERY_TEXT_LENGTHNew in version 13.2.
- async answer(text=None, show_alert=False, 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_to_message_id=None, allow_sending_without_reply=None, reply_markup=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None, protect_content=None)[source]#
Shortcut for:
update.callback_query.message.copy( chat_id, from_chat_id=update.message.chat_id, message_id=update.message.message_id, *args, **kwargs )
For the documentation of the arguments, please see
telegram.Message.copy().- Returns
On success, returns the MessageId of the sent message.
- Return type
- async delete_message(read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]#
Shortcut for:
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, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, parse_mode=None, api_kwargs=None, caption_entities=None)[source]#
Shortcut for either:
update.callback_query.message.edit_caption(caption, *args, **kwargs)
or:
bot.edit_message_caption(caption=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().- Returns
On success, if edited message is sent by the bot, the edited Message is returned, otherwise
Trueis returned.- Return type
- async edit_message_live_location(latitude=None, longitude=None, location=None, reply_markup=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None, horizontal_accuracy=None, heading=None, proximity_alert_radius=None)[source]#
Shortcut for either:
update.callback_query.message.edit_live_location(*args, **kwargs)
or:
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().- Returns
On success, if edited message is sent by the bot, the edited Message is returned, otherwise
Trueis returned.- Return type
- 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:
update.callback_query.message.edit_media(*args, **kwargs)
or:
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().- Returns
On success, if edited message is not an inline message, the edited Message is returned, otherwise
Trueis returned.- Return type
- 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:
update.callback_query.message.edit_reply_markup( reply_markup=reply_markup, *args, **kwargs )
or:
bot.edit_message_reply_markup inline_message_id=update.callback_query.inline_message_id, reply_markup=reply_markup, *args, **kwargs )
For the documentation of the arguments, please see
telegram.Bot.edit_message_reply_markup()andtelegram.Message.edit_reply_markup().- Returns
On success, if edited message is sent by the bot, the edited Message is returned, otherwise
Trueis returned.- Return type
- async edit_message_text(text, parse_mode=None, disable_web_page_preview=None, reply_markup=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None, entities=None)[source]#
Shortcut for either:
update.callback_query.message.edit_text(text, *args, **kwargs)
or:
bot.edit_message_text(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().- Returns
On success, if edited message is sent by the bot, the edited Message is returned, otherwise
Trueis returned.- Return type
- 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:
update.callback_query.message.get_game_high_score(*args, **kwargs)
or:
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
List[
telegram.GameHighScore]
- async pin_message(disable_notification=None, read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]#
Shortcut for:
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:
update.callback_query.message.set_game_score(*args, **kwargs)
or:
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().- Returns
On success, if edited message is sent by the bot, the edited Message is returned, otherwise
Trueis returned.- Return type
- 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:
update.callback_query.message.stop_live_location(*args, **kwargs)
or:
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().- Returns
On success, if edited message is sent by the bot, the edited Message is returned, otherwise
Trueis returned.- Return type
- async unpin_message(read_timeout=None, write_timeout=None, connect_timeout=None, pool_timeout=None, api_kwargs=None)[source]#
Shortcut for:
update.callback_query.message.unpin(*args, **kwargs)
For the documentation of the arguments, please see
telegram.Message.unpin().