CallbackQuery

class ftmgram.types.CallbackQuery(*, client: Client = None, id: str, from_user: User, chat_instance: str, message: Message = None, inline_message_id: str = None, data: str | bytes = None, game_short_name: str = None, matches: List[Match] = None)

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. Exactly one of the fields data or game_short_name will be present.

Parameters:
  • id (str) – Unique identifier for this query.

  • from_user (User) – Sender.

  • 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.

  • message (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) – Identifier of the message sent via the bot in inline mode, that originated the query.

  • data (str | bytes, 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.

  • matches (List of regex Matches, *optional*) – A list containing all Match Objects that match the data of this callback query. Only applicable when using Filters.regex.

answer(text: str = None, show_alert: bool = None, url: str = None, cache_time: int = 0)

Bound method answer of CallbackQuery.

Use this method as a shortcut for:

await client.answer_callback_query(
    callback_query.id,
    text="Hello",
    show_alert=True
)

Example

await callback_query.answer("Hello", show_alert=True)
Parameters:
  • text (str, optional) – Text of the notification. If not specified, nothing will be shown to the user, 0-200 characters.

  • show_alert (bool optional) – If true, an alert will be shown by the client instead of a notification at the top of the chat screen. Defaults to False.

  • url (str optional) – 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 optional) – The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0.

edit_message_text(text: str, parse_mode: ParseMode | None = None, link_preview_options: LinkPreviewOptions = None, reply_markup: InlineKeyboardMarkup = None, disable_web_page_preview: bool = None) Message | bool

Edit the text of messages attached to callback queries.

Bound method edit_message_text of CallbackQuery.

Parameters:
  • text (str) – New text of the message.

  • parse_mode (ParseMode, optional) – By default, texts are parsed using both Markdown and HTML styles. You can combine both syntaxes together.

  • link_preview_options (LinkPreviewOptions, optional) – Options used for link preview generation for the message.

  • reply_markup (InlineKeyboardMarkup, optional) – An InlineKeyboardMarkup object.

Returns:

Message | bool – On success, if the edited message was sent by the bot, the edited message is returned, otherwise True is returned (message sent via the bot, as inline query result).

Raises:

RPCError – In case of a Telegram RPC error.

edit_message_caption(caption: str, parse_mode: ParseMode | None = None, reply_markup: InlineKeyboardMarkup = None) Message | bool

Edit the caption of media messages attached to callback queries.

Bound method edit_message_caption of CallbackQuery.

Parameters:
  • caption (str) – New caption of the message.

  • parse_mode (ParseMode, optional) – By default, texts are parsed using both Markdown and HTML styles. You can combine both syntaxes together.

  • reply_markup (InlineKeyboardMarkup, optional) – An InlineKeyboardMarkup object.

Returns:

Message | bool – On success, if the edited message was sent by the bot, the edited message is returned, otherwise True is returned (message sent via the bot, as inline query result).

Raises:

RPCError – In case of a Telegram RPC error.

edit_message_media(media: InputMedia, reply_markup: InlineKeyboardMarkup = None) Message | bool

Edit animation, audio, document, photo or video messages attached to callback queries.

Bound method edit_message_media of CallbackQuery.

Parameters:
  • media (InputMedia) – One of the InputMedia objects describing an animation, audio, document, photo or video.

  • reply_markup (InlineKeyboardMarkup, optional) – An InlineKeyboardMarkup object.

Returns:

Message | bool – On success, if the edited message was sent by the bot, the edited message is returned, otherwise True is returned (message sent via the bot, as inline query result).

Raises:

RPCError – In case of a Telegram RPC error.

edit_message_reply_markup(reply_markup: InlineKeyboardMarkup = None) Message | bool

Edit only the reply markup of messages attached to callback queries.

Bound method edit_message_reply_markup of CallbackQuery.

Parameters:

reply_markup (InlineKeyboardMarkup) – An InlineKeyboardMarkup object.

Returns:

Message | bool – On success, if the edited message was sent by the bot, the edited message is returned, otherwise True is returned (message sent via the bot, as inline query result).

Raises:

RPCError – In case of a Telegram RPC error.