diff --git a/pyrogram/methods/messages/edit_inline_caption.py b/pyrogram/methods/messages/edit_inline_caption.py index 69c733341..fd2f9442c 100644 --- a/pyrogram/methods/messages/edit_inline_caption.py +++ b/pyrogram/methods/messages/edit_inline_caption.py @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . -from typing import Optional +from typing import Optional, List import pyrogram from pyrogram import types, enums @@ -28,6 +28,8 @@ async def edit_inline_caption( inline_message_id: str, caption: str, parse_mode: Optional["enums.ParseMode"] = None, + caption_entities: List["types.MessageEntity"] = None, + show_caption_above_media: bool = None, reply_markup: "types.InlineKeyboardMarkup" = None ) -> bool: """Edit the caption of inline media messages. @@ -45,6 +47,12 @@ async def edit_inline_caption( By default, texts are parsed using both Markdown and HTML styles. You can combine both syntaxes together. + caption_entities (List of :obj:`~pyrogram.types.MessageEntity`): + List of special entities that appear in the caption, which can be specified instead of *parse_mode*. + + show_caption_above_media (``bool``, *optional*): + Pass True, if the caption must be shown above the message media. Supported only for animation, photo and video messages. + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): An InlineKeyboardMarkup object. @@ -57,9 +65,16 @@ async def edit_inline_caption( # Bots only await app.edit_inline_caption(inline_message_id, "new media caption") """ + link_preview_options = None + if show_caption_above_media: + link_preview_options = types.LinkPreviewOptions( + show_above_text=show_caption_above_media + ) return await self.edit_inline_text( inline_message_id=inline_message_id, text=caption, parse_mode=parse_mode, + entities=caption_entities, + link_preview_options=link_preview_options, reply_markup=reply_markup ) diff --git a/pyrogram/methods/messages/edit_inline_media.py b/pyrogram/methods/messages/edit_inline_media.py index 3b2909f4c..8308d80e5 100644 --- a/pyrogram/methods/messages/edit_inline_media.py +++ b/pyrogram/methods/messages/edit_inline_media.py @@ -79,6 +79,8 @@ async def edit_inline_media( parse_mode = media.parse_mode caption_entities = media.caption_entities + show_caption_above_media = [] + is_bytes_io = isinstance(media.media, io.BytesIO) is_uploaded_file = is_bytes_io or os.path.isfile(media.media) @@ -109,6 +111,7 @@ async def edit_inline_media( ) else: media = utils.get_input_media_from_file_id(media.media, FileType.PHOTO, has_spoiler=media.has_spoiler) + show_caption_above_media.append(media.show_caption_above_media) elif isinstance(media, types.InputMediaVideo): if is_uploaded_file: media = raw.types.InputMediaUploadedDocument( @@ -132,6 +135,7 @@ async def edit_inline_media( ) else: media = utils.get_input_media_from_file_id(media.media, FileType.VIDEO, has_spoiler=media.has_spoiler) + show_caption_above_media.append(media.show_caption_above_media) elif isinstance(media, types.InputMediaAudio): if is_uploaded_file: media = raw.types.InputMediaUploadedDocument( @@ -178,6 +182,7 @@ async def edit_inline_media( ) else: media = utils.get_input_media_from_file_id(media.media, FileType.ANIMATION) + show_caption_above_media.append(media.show_caption_above_media) elif isinstance(media, types.InputMediaDocument): if is_uploaded_file: media = raw.types.InputMediaUploadedDocument( @@ -232,6 +237,7 @@ async def edit_inline_media( raw.functions.messages.EditInlineBotMessage( id=unpacked, media=actual_media, + invert_media=any(show_caption_above_media), reply_markup=await reply_markup.write(self) if reply_markup else None, **await utils.parse_text_entities(self, caption, parse_mode, caption_entities) ), diff --git a/pyrogram/methods/messages/edit_message_media.py b/pyrogram/methods/messages/edit_message_media.py index f73a44ca7..cbf41a867 100644 --- a/pyrogram/methods/messages/edit_message_media.py +++ b/pyrogram/methods/messages/edit_message_media.py @@ -98,6 +98,8 @@ async def edit_message_media( parse_mode = media.parse_mode caption_entities = media.caption_entities + show_caption_above_media = [] + message, entities = None, None if caption is not None: @@ -148,6 +150,7 @@ async def edit_message_media( ) else: media = utils.get_input_media_from_file_id(media.media, FileType.PHOTO, has_spoiler=media.has_spoiler) + show_caption_above_media.append(media.show_caption_above_media) elif isinstance(media, types.InputMediaVideo): if is_uploaded_file: uploaded_media = await self.invoke( @@ -188,6 +191,7 @@ async def edit_message_media( ) else: media = utils.get_input_media_from_file_id(media.media, FileType.VIDEO, has_spoiler=media.has_spoiler) + show_caption_above_media.append(media.show_caption_above_media) elif isinstance(media, types.InputMediaAudio): if is_uploaded_file: media = await self.invoke( @@ -261,6 +265,7 @@ async def edit_message_media( ) else: media = utils.get_input_media_from_file_id(media.media, FileType.ANIMATION, has_spoiler=media.has_spoiler) + show_caption_above_media.append(media.show_caption_above_media) elif isinstance(media, types.InputMediaDocument): if is_uploaded_file: media = await self.invoke( @@ -298,7 +303,7 @@ async def edit_message_media( reply_markup=await reply_markup.write(self) if reply_markup else None, message=message, entities=entities, - # TODO + invert_media=any(show_caption_above_media), schedule_date=utils.datetime_to_timestamp(schedule_date) ) session = None