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

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 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(caption, *args, **kwargs)

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

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