telegram.CallbackQuery¶
-
class
telegram.CallbackQuery(id: str, from_user: telegram.user.User, chat_instance: str, message: telegram.message.Message = None, data: str = None, inline_message_id: str = None, game_short_name: str = None, bot: Bot = None, **kwargs)¶ Bases:
telegram.base.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 from is a reserved word, use from_user instead.
- Exactly one of the fields
dataorgame_short_namewill be present.
-
id¶ Unique identifier for this query.
Type: str
-
from_user¶ Sender.
Type: telegram.User
-
chat_instance¶ Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent.
Type: str
-
message¶ Optional. Message with the callback button that originated the query.
Type: telegram.Message
-
data¶ Optional. Data associated with the callback button.
Type: str
-
inline_message_id¶ Optional. Identifier of the message sent via the bot in inline mode, that originated the query.
Type: str
-
game_short_name¶ Optional. Short name of a Game to be returned.
Type: str
-
bot¶ The Bot to use for instance methods.
Type: telegram.Bot, optional
Parameters: - id (
str) – Unique identifier for this query. - 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 game - bot (
telegram.Bot, optional) – The Bot to use for instance methods.
Note
After the user presses an inline button, Telegram clients will display a progress bar until you call
answer. It is, therefore, necessary to react by callingtelegram.Bot.answer_callback_queryeven if no notification to the user is needed (e.g., without specifying any of the optional parameters).-
answer(*args, **kwargs) → bool¶ Shortcut for:
bot.answer_callback_query(update.callback_query.id, *args, **kwargs)
Returns: On success, Trueis returned.Return type: bool
-
edit_message_caption(caption: str, *args, **kwargs) → Union[telegram.message.Message, bool]¶ Shortcut for either:
bot.edit_message_caption(caption=caption, chat_id=update.callback_query.message.chat_id, message_id=update.callback_query.message.message_id, *args, **kwargs)
or:
bot.edit_message_caption(caption=caption inline_message_id=update.callback_query.inline_message_id, *args, **kwargs)
Returns: On success, if edited message is sent by the bot, the edited Message is returned, otherwise Trueis returned.Return type: telegram.Message
-
edit_message_live_location(*args, **kwargs) → Union[telegram.message.Message, bool]¶ Shortcut for either:
bot.edit_message_live_location(chat_id=update.callback_query.message.chat_id, message_id=update.callback_query.message.message_id, reply_markup=reply_markup, *args, **kwargs)
or:
bot.edit_message_live_location( inline_message_id=update.callback_query.inline_message_id, reply_markup=reply_markup, *args, **kwargs )
Returns: On success, if edited message is sent by the bot, the edited Message is returned, otherwise Trueis returned.Return type: telegram.Message
-
edit_message_media(*args, **kwargs) → Union[telegram.message.Message, bool]¶ Shortcut for either:
bot.edit_message_media(chat_id=update.callback_query.message.chat_id, message_id=update.callback_query.message.message_id, media=media, *args, **kwargs)
or:
bot.edit_message_media(inline_message_id=update.callback_query.inline_message_id, media=media, *args, **kwargs)
Returns: On success, if edited message is sent by the bot, the edited Message is returned, otherwise Trueis returned.Return type: telegram.Message
-
edit_message_reply_markup(reply_markup: InlineKeyboardMarkup, *args, **kwargs) → Union[telegram.message.Message, bool]¶ Shortcut for either:
bot.edit_message_reply_markup(chat_id=update.callback_query.message.chat_id, message_id=update.callback_query.message.message_id, reply_markup=reply_markup, *args, **kwargs)
or:
bot.edit_message_reply_markup(inline_message_id=update.callback_query.inline_message_id, reply_markup=reply_markup, *args, **kwargs)
Returns: On success, if edited message is sent by the bot, the edited Message is returned, otherwise Trueis returned.Return type: telegram.Message
-
edit_message_text(text: str, *args, **kwargs) → Union[telegram.message.Message, bool]¶ Shortcut for either:
bot.edit_message_text(text, chat_id=update.callback_query.message.chat_id, message_id=update.callback_query.message.message_id, *args, **kwargs)
or:
bot.edit_message_text(text, inline_message_id=update.callback_query.inline_message_id, *args, **kwargs)
Returns: On success, if edited message is sent by the bot, the edited Message is returned, otherwise Trueis returned.Return type: telegram.Message
-
get_game_high_scores(*args, **kwargs) → List[GameHighScore]¶ Shortcut for either:
bot.get_game_high_scores(chat_id=update.callback_query.message.chat_id, message_id=update.callback_query.message.message_id, reply_markup=reply_markup, *args, **kwargs)
or:
bot.get_game_high_scores(inline_message_id=update.callback_query.inline_message_id, reply_markup=reply_markup, *args, **kwargs)
Returns: List[ telegram.GameHighScore]
-
set_game_score(*args, **kwargs) → Union[telegram.message.Message, bool]¶ Shortcut for either:
bot.set_game_score(chat_id=update.callback_query.message.chat_id, message_id=update.callback_query.message.message_id, reply_markup=reply_markup, *args, **kwargs)
or:
bot.set_game_score(inline_message_id=update.callback_query.inline_message_id, reply_markup=reply_markup, *args, **kwargs)
Returns: On success, if edited message is sent by the bot, the edited Message is returned, otherwise Trueis returned.Return type: telegram.Message
-
stop_message_live_location(*args, **kwargs) → Union[telegram.message.Message, bool]¶ Shortcut for either:
bot.stop_message_live_location(chat_id=update.callback_query.message.chat_id, message_id=update.callback_query.message.message_id, reply_markup=reply_markup, *args, **kwargs)
or:
bot.stop_message_live_location( inline_message_id=update.callback_query.inline_message_id, reply_markup=reply_markup, *args, **kwargs )
Returns: On success, if edited message is sent by the bot, the edited Message is returned, otherwise Trueis returned.Return type: telegram.Message