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: Any)¶ 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.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).
- 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 gamebot (
telegram.Bot, optional) – The Bot to use for instance methods.
-
id¶ Unique identifier for this query.
- Type
str
-
from_user¶ Sender.
- Type
-
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
-
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
-
MAX_ANSWER_TEXT_LENGTH: ClassVar[int] = 200¶ telegram.constants.MAX_ANSWER_CALLBACK_QUERY_TEXT_LENGTHNew in version 13.2.
-
answer(text: Optional[str] = None, show_alert: bool = False, url: Optional[str] = None, cache_time: Optional[int] = None, timeout: Optional[float] = None, api_kwargs: Optional[Dict[str, Any]] = None) → bool¶ Shortcut for:
bot.answer_callback_query(update.callback_query.id, *args, **kwargs)
For the documentation of the arguments, please see
telegram.Bot.answer_callback_query().- Returns
On success,
Trueis returned.- Return type
bool
-
copy_message(chat_id: Union[int, str], caption: str = None, parse_mode: str = None, caption_entities: Union[Tuple[MessageEntity, …], List[MessageEntity]] = None, disable_notification: bool = False, reply_to_message_id: Union[int, str] = None, allow_sending_without_reply: bool = False, reply_markup: telegram.replymarkup.ReplyMarkup = None, timeout: float = None, api_kwargs: Dict[str, Any] = None) → MessageId¶ 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.Bot.copy_message().- Returns
On success, returns the MessageId of the sent message.
- Return type
-
delete_message(timeout: Optional[float] = None, api_kwargs: Optional[Dict[str, Any]] = None) → bool¶ Shortcut for:
update.callback_query.message.delete(*args, **kwargs)
For the documentation of the arguments, please see
telegram.Bot.delete_message().- Returns
On success,
Trueis returned.- Return type
bool
-
edit_message_caption(caption: str = None, reply_markup: InlineKeyboardMarkup = None, timeout: float = None, parse_mode: str = None, api_kwargs: Dict[str, Any] = None, caption_entities: Union[List[MessageEntity], Tuple[MessageEntity, …]] = None) → Union[telegram.message.Message, bool]¶ 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().- Returns
On success, if edited message is sent by the bot, the edited Message is returned, otherwise
Trueis returned.- Return type
-
edit_message_live_location(latitude: float = None, longitude: float = None, location: telegram.files.location.Location = None, reply_markup: InlineKeyboardMarkup = None, timeout: float = None, api_kwargs: Dict[str, Any] = None, horizontal_accuracy: float = None, heading: int = None, proximity_alert_radius: int = None) → Union[telegram.message.Message, bool]¶ 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().- Returns
On success, if edited message is sent by the bot, the edited Message is returned, otherwise
Trueis returned.- Return type
-
edit_message_media(media: InputMedia = None, reply_markup: InlineKeyboardMarkup = None, timeout: float = None, api_kwargs: Dict[str, Any] = None) → Union[telegram.message.Message, bool]¶ 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().- Returns
On success, if edited message is sent by the bot, the edited Message is returned, otherwise
Trueis returned.- Return type
-
edit_message_reply_markup(reply_markup: Optional[InlineKeyboardMarkup] = None, timeout: float = None, api_kwargs: Dict[str, Any] = None) → Union[telegram.message.Message, bool]¶ 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().- Returns
On success, if edited message is sent by the bot, the edited Message is returned, otherwise
Trueis returned.- Return type
-
edit_message_text(text: str, parse_mode: str = None, disable_web_page_preview: bool = None, reply_markup: InlineKeyboardMarkup = None, timeout: float = None, api_kwargs: Dict[str, Any] = None, entities: Union[List[MessageEntity], Tuple[MessageEntity, …]] = None) → Union[telegram.message.Message, bool]¶ 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().- Returns
On success, if edited message is sent by the bot, the edited Message is returned, otherwise
Trueis returned.- Return type
-
get_game_high_scores(user_id: Union[int, str], timeout: float = None, api_kwargs: Dict[str, Any] = None) → List[GameHighScore]¶ 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().- Returns
List[
telegram.GameHighScore]
-
pin_message(disable_notification: Optional[bool] = None, timeout: Optional[float] = None, api_kwargs: Optional[Dict[str, Any]] = None) → bool¶ Shortcut for:
bot.pin_chat_message(chat_id=message.chat_id, message_id=message.message_id, *args, **kwargs)
For the documentation of the arguments, please see
telegram.Bot.pin_chat_message().- Returns
On success,
Trueis returned.- Return type
bool
-
set_game_score(user_id: Union[int, str], score: int, force: Optional[bool] = None, disable_edit_message: Optional[bool] = None, timeout: Optional[float] = None, api_kwargs: Optional[Dict[str, Any]] = None) → Union[telegram.message.Message, bool]¶ 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().- Returns
On success, if edited message is sent by the bot, the edited Message is returned, otherwise
Trueis returned.- Return type
-
stop_message_live_location(reply_markup: InlineKeyboardMarkup = None, timeout: float = None, api_kwargs: Dict[str, Any] = None) → Union[telegram.message.Message, bool]¶ 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().- Returns
On success, if edited message is sent by the bot, the edited Message is returned, otherwise
Trueis returned.- Return type
-
unpin_message(timeout: Optional[float] = None, api_kwargs: Optional[Dict[str, Any]] = None) → bool¶ Shortcut for:
bot.unpin_chat_message(chat_id=message.chat_id, message_id=message.message_id, *args, **kwargs)
For the documentation of the arguments, please see
telegram.Bot.unpin_chat_message().- Returns
On success,
Trueis returned.- Return type
bool