telegram.CallbackQuery

class telegram.CallbackQuery(id, from_user, chat_instance, message=None, data=None, inline_message_id=None, game_short_name=None, bot=None, **kwargs)

Bases: telegram.base.TelegramObject

This object represents an incoming callback query from a callback button in an inline keyboard.

If the button that originated the query was attached to a message sent by the bot, the field message will be present. If the button was attached to a message sent via the bot (in inline mode), the field inline_message_id will be present.

Note

  • In Python from is a reserved word, use from_user instead.

Exactly one of the fields data or game_short_name will be present.

id

str – Unique identifier for this query.

from_user

telegram.User – Sender.

message

telegram.Message – Optional. Message with the callback button that originated the query.

inline_message_id

str – Optional. Identifier of the message sent via the bot in inline mode, that originated the query.

chat_instance

str – Optional. Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent.

data

str – Optional. Data associated with the callback button.

game_short_name

str – Optional. Short name of a Game to be returned.

Parameters:
  • id (str) – Unique identifier for this query.
  • from_user (telegram.User) – Sender.
  • 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.
  • inline_message_id (str, optional) – Identifier of the message sent via the bot in inline mode, that originated the query.
  • chat_instance (str, optional) – Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. Useful for high scores in games.
  • data (str, optional) – Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field.
  • game_short_name (str, optional) – Short name of a Game to be returned, serves as the unique identifier for the game

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 calling telegram.Bot.answer_callback_query even if no notification to the user is needed (e.g., without specifying any of the optional parameters).

answer(*args, **kwargs)

Shortcut for:

bot.answer_callback_query(update.callback_query.id, *args, **kwargs)
Returns:On success, True is returned.
Return type:bool
edit_message_caption(*args, **kwargs)

Shortcut for either:

bot.edit_message_caption(chat_id=update.callback_query.message.chat_id,
                       message_id=update.callback_query.message.message_id,
                       *args, **kwargs)

or:

bot.edit_message_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 True is returned.
Return type:telegram.Message
edit_message_reply_markup(*args, **kwargs)

Shortcut for either:

bot.edit_message_replyMarkup(chat_id=update.callback_query.message.chat_id,
                           message_id=update.callback_query.message.message_id,
                           *args, **kwargs)

or:

bot.edit_message_reply_markup(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 True is returned.
Return type:telegram.Message
edit_message_text(*args, **kwargs)

Shortcut for either:

bot.edit_message_text(chat_id=update.callback_query.message.chat_id,
                    message_id=update.callback_query.message.message_id,
                    *args, **kwargs)

or:

bot.edit_message_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 True is returned.
Return type:telegram.Message