diff --git a/docs/source/api/bound-methods.rst b/docs/source/api/bound-methods.rst index d01a4383..38389ae6 100644 --- a/docs/source/api/bound-methods.rst +++ b/docs/source/api/bound-methods.rst @@ -81,9 +81,13 @@ CallbackQuery ^^^^^^^^^^^^^ .. hlist:: - :columns: 2 + :columns: 5 - :meth:`~CallbackQuery.answer` + - :meth:`~CallbackQuery.edit` + - :meth:`~CallbackQuery.edit_caption` + - :meth:`~CallbackQuery.edit_media` + - :meth:`~CallbackQuery.edit_reply_markup` InlineQuery ^^^^^^^^^^^ @@ -137,6 +141,10 @@ Details .. CallbackQuery .. automethod:: CallbackQuery.answer() +.. automethod:: CallbackQuery.edit() +.. automethod:: CallbackQuery.edit_caption() +.. automethod:: CallbackQuery.edit_media() +.. automethod:: CallbackQuery.edit_reply_markup() .. InlineQuery .. automethod:: InlineQuery.answer() diff --git a/pyrogram/client/ext/base_client.py b/pyrogram/client/ext/base_client.py index b4c16666..e584c743 100644 --- a/pyrogram/client/ext/base_client.py +++ b/pyrogram/client/ext/base_client.py @@ -159,3 +159,9 @@ class BaseClient: def edit_message_text(self, *args, **kwargs): pass + + def edit_message_media(self, *args, **kwargs): + pass + + def edit_message_reply_markup(self, *args, **kwargs): + pass diff --git a/pyrogram/client/types/bots_and_keyboards/callback_query.py b/pyrogram/client/types/bots_and_keyboards/callback_query.py index fa0d8be2..df0f6d33 100644 --- a/pyrogram/client/types/bots_and_keyboards/callback_query.py +++ b/pyrogram/client/types/bots_and_keyboards/callback_query.py @@ -172,3 +172,175 @@ class CallbackQuery(Object, Update): url=url, cache_time=cache_time ) + + def edit( + self, + text: str, + parse_mode: str = "", + disable_web_page_preview: bool = None, + reply_markup: "pyrogram.InlineKeyboardMarkup" = None + ) -> Union["pyrogram.Message", bool]: + """Bound method *edit* of :obj:`CallbackQuery`. + + Parameters: + text (``str``): + New text of the message. + + parse_mode (``str``, *optional*): + Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline + URLs in your message. Defaults to "markdown". + + disable_web_page_preview (``bool``, *optional*): + Disables link previews for links in this message. + + reply_markup (:obj:`InlineKeyboardMarkup`, *optional*): + An InlineKeyboardMarkup object. + + Returns: + :obj:`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. + """ + chat_id = None + message_id = None + inline_message_id = None + + if self.message is not None: + chat_id = self.message.chat.id + message_id = self.message.message_id + + if self.inline_message_id is not None: + inline_message_id = self.inline_message_id + + return self._client.edit_message_text( + text=text, + chat_id=chat_id, + message_id=message_id, + inline_message_id=inline_message_id, + parse_mode=parse_mode, + disable_web_page_preview=disable_web_page_preview, + reply_markup=reply_markup + ) + + def edit_caption( + self, + caption: str, + parse_mode: str = "", + reply_markup: "pyrogram.InlineKeyboardMarkup" = None + ) -> Union["pyrogram.Message", bool]: + """Bound method *edit_caption* of :obj:`Message`. + + Parameters: + caption (``str``): + New caption of the message. + + parse_mode (``str``, *optional*): + Pass "markdown" or "html" if you want Telegram apps to show bold, italic, fixed-width text or inline + URLs in your message. Defaults to "markdown". + + reply_markup (:obj:`InlineKeyboardMarkup`, *optional*): + An InlineKeyboardMarkup object. + + Returns: + :obj:`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. + """ + chat_id = None + message_id = None + inline_message_id = None + + if self.message is not None: + chat_id = self.message.chat.id + message_id = self.message.message_id + + if self.inline_message_id is not None: + inline_message_id = self.inline_message_id + + return self._client.edit_message_text( + text=caption, + chat_id=chat_id, + message_id=message_id, + inline_message_id=inline_message_id, + parse_mode=parse_mode, + reply_markup=reply_markup + ) + + def edit_media( + self, + media: "pyrogram.InputMedia", + reply_markup: "pyrogram.InlineKeyboardMarkup" = None + ) -> Union["pyrogram.Message", bool]: + """Bound method *edit_media* of :obj:`Message`. + + Parameters: + media (:obj:`InputMedia`): + One of the InputMedia objects describing an animation, audio, document, photo or video. + + reply_markup (:obj:`InlineKeyboardMarkup`, *optional*): + An InlineKeyboardMarkup object. + + Returns: + :obj:`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. + """ + chat_id = None + message_id = None + inline_message_id = None + + if self.message is not None: + chat_id = self.message.chat.id + message_id = self.message.message_id + + if self.inline_message_id is not None: + inline_message_id = self.inline_message_id + + return self._client.edit_message_media( + media=media, + chat_id=chat_id, + message_id=message_id, + inline_message_id=inline_message_id, + reply_markup=reply_markup + ) + + def edit_reply_markup( + self, + reply_markup: "pyrogram.InlineKeyboardMarkup" = None + ) -> Union["pyrogram.Message", bool]: + """Bound method *edit_reply_markup* of :obj:`Message`. + + Parameters: + reply_markup (:obj:`InlineKeyboardMarkup`): + An InlineKeyboardMarkup object. + + Returns: + :obj:`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. + """ + chat_id = None + message_id = None + inline_message_id = None + + if self.message is not None: + chat_id = self.message.chat.id + message_id = self.message.message_id + + if self.inline_message_id is not None: + inline_message_id = self.inline_message_id + + return self._client.edit_message_reply_markup( + reply_markup=reply_markup, + chat_id=chat_id, + message_id=message_id, + inline_message_id=inline_message_id + )