diff --git a/compiler/docs/compiler.py b/compiler/docs/compiler.py index a9ae31b25f..fee159e0b0 100644 --- a/compiler/docs/compiler.py +++ b/compiler/docs/compiler.py @@ -624,6 +624,7 @@ def get_title_list(s: str) -> list: InlineQueryResultVoice InlineQueryResultArticle InlineQueryResultContact + InlineQueryResultGame InlineQueryResultLocation InlineQueryResultVenue """, @@ -795,6 +796,10 @@ def get_title_list(s: str) -> list: CallbackQuery.edit_message_caption CallbackQuery.edit_message_media CallbackQuery.edit_message_reply_markup + ChosenInlineResult.edit_message_text + ChosenInlineResult.edit_message_caption + ChosenInlineResult.edit_message_media + ChosenInlineResult.edit_message_reply_markup """, inline_query=""" InlineQuery diff --git a/docs/source/releases/changes-in-this-fork.rst b/docs/source/releases/changes-in-this-fork.rst index f259aaa21f..51973d8012 100644 --- a/docs/source/releases/changes-in-this-fork.rst +++ b/docs/source/releases/changes-in-this-fork.rst @@ -1,4 +1,7 @@ +Changes in this Fork +===================== + .. admonition :: A Word of Warning :class: tip @@ -29,6 +32,12 @@ Changes in this Fork | Scheme layer used: 199 | +------------------------+ +- Added the class :obj:`~pyrogram.types.InlineQueryResultGame`. +- Added the bound methods :meth:`~pyrogram.types.ChosenInlineResult.edit_message_text`, :meth:`~pyrogram.types.ChosenInlineResult.edit_message_caption`, :meth:`~pyrogram.types.ChosenInlineResult.edit_message_media` and :meth:`~pyrogram.types.ChosenInlineResult.edit_message_reply_markup`. +- Renamed the fields ``thumb_url``, ``thumb_width``, and ``thumb_height`` in the classes :obj:`~pyrogram.types.InlineQueryResultArticle`, :obj:`~pyrogram.types.InlineQueryResultContact`, :obj:`~pyrogram.types.InlineQueryResultDocument`, :obj:`~pyrogram.types.InlineQueryResultLocation`, and :obj:`~pyrogram.types.InlineQueryResultVenue` to ``thumbnail_url``, ``thumbnail_width``, and ``thumbnail_height`` respectively. +- Renamed the field ``thumb_url`` in the classes :obj:`~pyrogram.types.InlineQueryResultPhoto` and :obj:`~pyrogram.types.InlineQueryResultVideo` to ``thumbnail_url``. +- Added the field ``animation_mime_type`` and renamed the fields ``thumb_url`` and ``thumb_mime_type`` in the classes :obj:`~pyrogram.types.InlineQueryResultAnimation` to ``thumbnail_url`` and ``thumbnail_mime_type`` respectively. +- Fixed a bug with ``_client`` being None in :obj:`~pyrogram.handlers.ChosenInlineResultHandler`. - Added the parameters ``video_cover`` and ``video_start_timestamp`` to the method :meth:`~pyrogram.Client.copy_message`, allowing bots to change the start timestamp for copied videos. - Added ``for_paid_reactions`` in :meth:`~pyrogram.Client.get_send_as_chats`. - `Updated documentation and parameter names according to BOT API 8.3 `__ diff --git a/pyrogram/types/bots_and_keyboards/callback_query.py b/pyrogram/types/bots_and_keyboards/callback_query.py index 796750e77d..f040487656 100644 --- a/pyrogram/types/bots_and_keyboards/callback_query.py +++ b/pyrogram/types/bots_and_keyboards/callback_query.py @@ -89,7 +89,16 @@ def __init__( self.matches = matches @staticmethod - async def _parse(client: "pyrogram.Client", callback_query, users, chats) -> "CallbackQuery": + async def _parse( + client: "pyrogram.Client", + callback_query: Union[ + "raw.types.UpdateBotCallbackQuery", + "raw.types.UpdateInlineBotCallbackQuery", + "raw.types.UpdateBusinessBotCallbackQuery", + ], + users: dict, + chats: dict, + ) -> "CallbackQuery": message = None inline_message_id = None diff --git a/pyrogram/types/inline_mode/__init__.py b/pyrogram/types/inline_mode/__init__.py index 53e883ce9c..4c43876e06 100644 --- a/pyrogram/types/inline_mode/__init__.py +++ b/pyrogram/types/inline_mode/__init__.py @@ -29,6 +29,7 @@ from .inline_query_result_cached_video import InlineQueryResultCachedVideo from .inline_query_result_cached_voice import InlineQueryResultCachedVoice from .inline_query_result_contact import InlineQueryResultContact +from .inline_query_result_game import InlineQueryResultGame from .inline_query_result_document import InlineQueryResultDocument from .inline_query_result_location import InlineQueryResultLocation from .inline_query_result_photo import InlineQueryResultPhoto @@ -56,6 +57,7 @@ "InlineQueryResultVoice", "InlineQueryResultArticle", "InlineQueryResultContact", + "InlineQueryResultGame", "InlineQueryResultLocation", "InlineQueryResultVenue", ] diff --git a/pyrogram/types/inline_mode/chosen_inline_result.py b/pyrogram/types/inline_mode/chosen_inline_result.py index 367039e3e7..a3c7a4e27c 100644 --- a/pyrogram/types/inline_mode/chosen_inline_result.py +++ b/pyrogram/types/inline_mode/chosen_inline_result.py @@ -16,6 +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 import pyrogram from pyrogram import raw, types, utils @@ -28,8 +29,8 @@ class ChosenInlineResult(Object, Update): .. note:: - In order to receive these updates, your bot must have "inline feedback" enabled. You can enable this feature - with `@BotFather `_. + In order to receive these updates, your bot must have "inline feedback" enabled. + You can enable this feature with `@BotFather `_. Parameters: result_id (``str``): @@ -83,5 +84,153 @@ def _parse(client, chosen_inline_result: raw.types.UpdateBotInlineSend, users) - latitude=chosen_inline_result.geo.lat, client=client ) if chosen_inline_result.geo else None, - inline_message_id=inline_message_id + inline_message_id=inline_message_id, + client=client ) + + async def edit_message_text( + self, + text: str, + parse_mode: Optional["enums.ParseMode"] = None, + entities: list["types.MessageEntity"] = None, + link_preview_options: "types.LinkPreviewOptions" = None, + reply_markup: "types.InlineKeyboardMarkup" = None + ) -> bool: + """Edit the text of messages attached to sent :obj:`~pyrogram.types.InlineQueryResult` messages. + + Bound method *edit_message_text* of :obj:`~pyrogram.types.ChosenInlineResult`. + + Parameters: + text (``str``): + New text of the message. + + parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): + By default, texts are parsed using both Markdown and HTML styles. + You can combine both syntaxes together. + + entities (List of :obj:`~pyrogram.types.MessageEntity`): + List of special entities that appear in message text, which can be specified instead of *parse_mode*. + + link_preview_options (:obj:`~pyrogram.types.LinkPreviewOptions`, *optional*): + Link preview generation options for the message + + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): + An InlineKeyboardMarkup object. + + Returns: + ``bool``: On success, True is returned. + + Raises: + RPCError: In case of a Telegram RPC error. + """ + if self.inline_message_id is None: + raise ValueError("Identifier of the inline message is required to edit the message") + else: + return await self._client.edit_inline_text( + inline_message_id=self.inline_message_id, + text=text, + parse_mode=parse_mode, + entities=entities, + link_preview_options=link_preview_options, + reply_markup=reply_markup + ) + + async def edit_message_caption( + self, + caption: str, + parse_mode: Optional["enums.ParseMode"] = None, + caption_entities: list["types.MessageEntity"] = None, + reply_markup: "types.InlineKeyboardMarkup" = None + ) -> bool: + """Edit the caption of media messages attached to sent :obj:`~pyrogram.types.InlineQueryResult` messages. + + Bound method *edit_message_caption* of :obj:`~pyrogram.types.ChosenInlineResult`. + + Parameters: + caption (``str``): + New caption of the message. + + parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): + 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 message text, which can be specified instead of *parse_mode*. + + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): + An InlineKeyboardMarkup object. + + Returns: + ``bool``: On success, True is returned. + + Raises: + RPCError: In case of a Telegram RPC error. + """ + return await self.edit_message_text( + text=caption, + parse_mode=parse_mode, + entities=caption_entities, + reply_markup=reply_markup + ) + + async def edit_message_media( + self, + media: "types.InputMedia", + reply_markup: "types.InlineKeyboardMarkup" = None, + file_name: str = None + ) -> bool: + """Edit animation, audio, document, photo or video messages attached to sent :obj:`~pyrogram.types.InlineQueryResult` messages. + + Bound method *edit_message_media* of :obj:`~pyrogram.types.ChosenInlineResult`. + + Parameters: + media (:obj:`~pyrogram.types.InputMedia`): + One of the InputMedia objects describing an animation, audio, document, photo or video. + + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): + An InlineKeyboardMarkup object. + + file_name (``str``, *optional*): + File name of the media to be sent. Not applicable to photos. + Defaults to file's path basename. + + Returns: + ``bool``: On success, True is returned. + + Raises: + RPCError: In case of a Telegram RPC error. + """ + if self.inline_message_id is None: + raise ValueError("Identifier of the inline message is required to edit the message") + else: + return await self._client.edit_inline_media( + inline_message_id=self.inline_message_id, + media=media, + reply_markup=reply_markup + ) + + async def edit_message_reply_markup( + self, + reply_markup: "types.InlineKeyboardMarkup" = None + ) -> bool: + """Edit only the reply markup of messages attached to sent :obj:`~pyrogram.types.InlineQueryResult` messages. + + Bound method *edit_message_reply_markup* of :obj:`~pyrogram.types.ChosenInlineResult`. + + Parameters: + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`): + An InlineKeyboardMarkup object. + + Returns: + ``bool``: On success, True is returned. + + Raises: + RPCError: In case of a Telegram RPC error. + """ + if self.inline_message_id is None: + raise ValueError("Identifier of the inline message is required to edit the message") + else: + return await self._client.edit_inline_reply_markup( + inline_message_id=self.inline_message_id, + reply_markup=reply_markup + ) diff --git a/pyrogram/types/inline_mode/inline_query_result.py b/pyrogram/types/inline_mode/inline_query_result.py index 8548e023c7..35a2c5cd48 100644 --- a/pyrogram/types/inline_mode/inline_query_result.py +++ b/pyrogram/types/inline_mode/inline_query_result.py @@ -24,7 +24,7 @@ class InlineQueryResult(Object): - """One result of an inline query. + """This object represents one result of an inline query. Telegram clients currently support results of the following 20 types: - :obj:`~pyrogram.types.InlineQueryResultCachedAudio` - :obj:`~pyrogram.types.InlineQueryResultCachedDocument` @@ -36,6 +36,7 @@ class InlineQueryResult(Object): - :obj:`~pyrogram.types.InlineQueryResultArticle` - :obj:`~pyrogram.types.InlineQueryResultAudio` - :obj:`~pyrogram.types.InlineQueryResultContact` + - :obj:`~pyrogram.types.InlineQueryResultGame` - :obj:`~pyrogram.types.InlineQueryResultDocument` - :obj:`~pyrogram.types.InlineQueryResultAnimation` - :obj:`~pyrogram.types.InlineQueryResultLocation` @@ -43,6 +44,11 @@ class InlineQueryResult(Object): - :obj:`~pyrogram.types.InlineQueryResultVenue` - :obj:`~pyrogram.types.InlineQueryResultVideo` - :obj:`~pyrogram.types.InlineQueryResultVoice` + + .. note:: + + All URLs passed in inline query results will be available to end users and therefore must be assumed to be *public*. + """ def __init__( diff --git a/pyrogram/types/inline_mode/inline_query_result_animation.py b/pyrogram/types/inline_mode/inline_query_result_animation.py index a51c571494..3c0a168c6b 100644 --- a/pyrogram/types/inline_mode/inline_query_result_animation.py +++ b/pyrogram/types/inline_mode/inline_query_result_animation.py @@ -16,12 +16,15 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import logging from typing import Optional import pyrogram from pyrogram import raw, types, utils, enums from .inline_query_result import InlineQueryResult +log = logging.getLogger(__name__) + class InlineQueryResultAnimation(InlineQueryResult): """Link to an animated GIF file. @@ -35,20 +38,23 @@ class InlineQueryResultAnimation(InlineQueryResult): A valid URL for the animated GIF file. File size must not exceed 1 MB. - animation_width (``int``, *optional*) + animation_mime_type (``str``, *optional*): + MIME type of the video file. Must be one of "image/gif" and "video/mp4" + + animation_width (``int``, *optional*): Width of the animation. - animation_height (``int``, *optional*) + animation_height (``int``, *optional*): Height of the animation. - animation_duration (``int``, *optional*) + animation_duration (``int``, *optional*): Duration of the animation in seconds. - thumb_url (``str``, *optional*): + thumbnail_url (``str``, *optional*): URL of the static thumbnail for the result (jpeg or gif) Defaults to the value passed in *animation_url*. - thumb_mime_type (``str``, *optional*) + thumbnail_mime_type (``str``, *optional*) MIME type of the thumbnail, must be one of "image/jpeg", "image/gif", or "video/mp4". Defaults to "image/jpeg". @@ -77,16 +83,18 @@ class InlineQueryResultAnimation(InlineQueryResult): input_message_content (:obj:`~pyrogram.types.InputMessageContent`): Content of the message to be sent instead of the photo. + """ def __init__( self, animation_url: str, + animation_mime_type: str = "image/gif", animation_width: int = 0, animation_height: int = 0, animation_duration: int = 0, - thumb_url: str = None, - thumb_mime_type: str = "image/jpeg", + thumbnail_url: str = None, + thumbnail_mime_type: str = "image/jpeg", id: str = None, title: str = None, description: str = None, @@ -95,16 +103,45 @@ def __init__( caption_entities: list["types.MessageEntity"] = None, show_caption_above_media: bool = None, reply_markup: "types.InlineKeyboardMarkup" = None, - input_message_content: "types.InputMessageContent" = None + input_message_content: "types.InputMessageContent" = None, + thumb_url: str = None, + thumb_mime_type: str = None, ): + if thumb_url and thumbnail_url: + raise ValueError( + "Parameters `thumb_url` and `thumbnail_url` are mutually " + "exclusive." + ) + + if thumb_url is not None: + log.warning( + "This property is deprecated. " + "Please use thumbnail_url instead" + ) + thumbnail_url = thumb_url + + if thumb_mime_type and thumbnail_mime_type: + raise ValueError( + "Parameters `thumb_mime_type` and `thumbnail_mime_type` are mutually " + "exclusive." + ) + + if thumb_mime_type is not None: + log.warning( + "This property is deprecated. " + "Please use thumbnail_mime_type instead" + ) + thumbnail_mime_type = thumb_mime_type + super().__init__("gif", id, input_message_content, reply_markup) self.animation_url = animation_url + self.animation_mime_type = animation_mime_type self.animation_width = animation_width self.animation_height = animation_height self.animation_duration = animation_duration - self.thumb_url = thumb_url - self.thumb_mime_type = thumb_mime_type + self.thumbnail_url = thumbnail_url + self.thumbnail_mime_type = thumbnail_mime_type self.title = title self.description = description self.caption = caption @@ -118,7 +155,7 @@ async def write(self, client: "pyrogram.Client"): animation = raw.types.InputWebDocument( url=self.animation_url, size=0, - mime_type="image/gif", + mime_type=self.animation_mime_type, attributes=[ raw.types.DocumentAttributeVideo( w=self.animation_width, @@ -128,13 +165,13 @@ async def write(self, client: "pyrogram.Client"): ] ) - if self.thumb_url is None: + if self.thumbnail_url is None: thumb = animation else: thumb = raw.types.InputWebDocument( - url=self.thumb_url, + url=self.thumbnail_url, size=0, - mime_type=self.thumb_mime_type, + mime_type=self.thumbnail_mime_type, attributes=[] ) diff --git a/pyrogram/types/inline_mode/inline_query_result_article.py b/pyrogram/types/inline_mode/inline_query_result_article.py index 096273f15b..fd6faaca14 100644 --- a/pyrogram/types/inline_mode/inline_query_result_article.py +++ b/pyrogram/types/inline_mode/inline_query_result_article.py @@ -16,12 +16,16 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import logging + import pyrogram from pyrogram import raw from pyrogram import types from .inline_query_result import InlineQueryResult +log = logging.getLogger(__name__) + class InlineQueryResultArticle(InlineQueryResult): """Link to an article or web page. @@ -46,14 +50,14 @@ class InlineQueryResultArticle(InlineQueryResult): reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): Inline keyboard attached to the message. - thumb_url (``str``, *optional*): + thumbnail_url (``str``, *optional*): Url of the thumbnail for the result. - thumb_width (``int``, *optional*): + thumbnail_width (``int``, *optional*): Thumbnail width. - thumb_height (``int``, *optional*): - Thumbnail height + thumbnail_height (``int``, *optional*): + Thumbnail height. """ def __init__( @@ -64,18 +68,60 @@ def __init__( url: str = None, description: str = None, reply_markup: "types.InlineKeyboardMarkup" = None, + thumbnail_url: str = None, + thumbnail_width: int = 0, + thumbnail_height: int = 0, thumb_url: str = None, - thumb_width: int = 0, - thumb_height: int = 0 + thumb_width: int = None, + thumb_height: int = None ): + if thumb_url and thumbnail_url: + raise ValueError( + "Parameters `thumb_url` and `thumbnail_url` are mutually " + "exclusive." + ) + + if thumb_url is not None: + log.warning( + "This property is deprecated. " + "Please use thumbnail_url instead" + ) + thumbnail_url = thumb_url + + if thumb_width and thumbnail_width: + raise ValueError( + "Parameters `thumb_width` and `thumbnail_width` are mutually " + "exclusive." + ) + + if thumb_width is not None: + log.warning( + "This property is deprecated. " + "Please use thumbnail_width instead" + ) + thumbnail_width = thumb_width + + if thumb_height and thumbnail_height: + raise ValueError( + "Parameters `thumb_height` and `thumbnail_height` are mutually " + "exclusive." + ) + + if thumb_height is not None: + log.warning( + "This property is deprecated. " + "Please use thumbnail_height instead" + ) + thumbnail_height = thumb_height + super().__init__("article", id, input_message_content, reply_markup) self.title = title self.url = url self.description = description - self.thumb_url = thumb_url - self.thumb_width = thumb_width - self.thumb_height = thumb_height + self.thumbnail_url = thumbnail_url + self.thumbnail_width = thumbnail_width + self.thumbnail_height = thumbnail_height async def write(self, client: "pyrogram.Client"): return raw.types.InputBotInlineResult( @@ -86,14 +132,14 @@ async def write(self, client: "pyrogram.Client"): description=self.description, url=self.url, thumb=raw.types.InputWebDocument( - url=self.thumb_url, + url=self.thumbnail_url, size=0, mime_type="image/jpeg", attributes=[ raw.types.DocumentAttributeImageSize( - w=self.thumb_width, - h=self.thumb_height + w=self.thumbnail_width, + h=self.thumbnail_height ) ] - ) if self.thumb_url else None + ) if self.thumbnail_url else None ) diff --git a/pyrogram/types/inline_mode/inline_query_result_audio.py b/pyrogram/types/inline_mode/inline_query_result_audio.py index b53c8d027b..30c1313043 100644 --- a/pyrogram/types/inline_mode/inline_query_result_audio.py +++ b/pyrogram/types/inline_mode/inline_query_result_audio.py @@ -24,18 +24,17 @@ class InlineQueryResultAudio(InlineQueryResult): - """Link to an audio file. + """Link to an MP3 audio file. By default, this audio file will be sent by the user with optional caption. - Alternatively, you can use *input_message_content* to send a message with the specified content instead of the - audio. + Alternatively, you can use *input_message_content* to send a message with the specified content instead of the audio. Parameters: audio_url (``str``): A valid URL for the audio file. title (``str``): - Title for the result. + Audio title. id (``str``, *optional*): Unique identifier for this result, 1-64 bytes. @@ -62,6 +61,16 @@ class InlineQueryResultAudio(InlineQueryResult): input_message_content (:obj:`~pyrogram.types.InputMessageContent`, *optional*): Content of the message to be sent instead of the audio. + + thumbnail_url (``str``, *optional*): + Url of the thumbnail for the result. + + thumbnail_width (``int``, *optional*): + Thumbnail width. + + thumbnail_height (``int``, *optional*): + Thumbnail height. + """ def __init__( @@ -75,7 +84,10 @@ def __init__( parse_mode: Optional["enums.ParseMode"] = None, caption_entities: list["types.MessageEntity"] = None, reply_markup: "types.InlineKeyboardMarkup" = None, - input_message_content: "types.InputMessageContent" = None + input_message_content: "types.InputMessageContent" = None, + thumbnail_url: str = None, + thumbnail_width: int = 0, + thumbnail_height: int = 0 ): super().__init__("audio", id, input_message_content, reply_markup) @@ -86,6 +98,9 @@ def __init__( self.caption = caption self.parse_mode = parse_mode self.caption_entities = caption_entities + self.thumbnail_url = thumbnail_url + self.thumbnail_width = thumbnail_width + self.thumbnail_height = thumbnail_height async def write(self, client: "pyrogram.Client"): audio = raw.types.InputWebDocument( @@ -116,5 +131,16 @@ async def write(self, client: "pyrogram.Client"): message=message, entities=entities ) - ) + ), + thumb=raw.types.InputWebDocument( + url=self.thumbnail_url, + size=0, + mime_type="image/jpeg", + attributes=[ + raw.types.DocumentAttributeImageSize( + w=self.thumbnail_width, + h=self.thumbnail_height + ) + ] + ) if self.thumbnail_url else None ) diff --git a/pyrogram/types/inline_mode/inline_query_result_cached_sticker.py b/pyrogram/types/inline_mode/inline_query_result_cached_sticker.py index 06d012fbe6..084d7e126f 100644 --- a/pyrogram/types/inline_mode/inline_query_result_cached_sticker.py +++ b/pyrogram/types/inline_mode/inline_query_result_cached_sticker.py @@ -16,8 +16,10 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Optional + import pyrogram -from pyrogram import raw, types +from pyrogram import enums, raw, types from .inline_query_result import InlineQueryResult from ...file_id import FileId @@ -36,6 +38,16 @@ class InlineQueryResultCachedSticker(InlineQueryResult): Unique identifier for this result, 1-64 bytes. Defaults to a randomly generated UUID4. + caption (``str``, *optional*): + Caption of the audio to be sent, 0-1024 characters. + + parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*): + 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*. + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): An InlineKeyboardMarkup object. @@ -47,18 +59,28 @@ def __init__( self, sticker_file_id: str, id: str = None, + caption: str = "", + parse_mode: Optional["enums.ParseMode"] = None, + caption_entities: list["types.MessageEntity"] = None, reply_markup: "types.InlineKeyboardMarkup" = None, input_message_content: "types.InputMessageContent" = None ): super().__init__("sticker", id, input_message_content, reply_markup) self.sticker_file_id = sticker_file_id + self.caption = caption + self.parse_mode = parse_mode + self.caption_entities = caption_entities self.reply_markup = reply_markup self.input_message_content = input_message_content async def write(self, client: "pyrogram.Client"): file_id = FileId.decode(self.sticker_file_id) + message, entities = (await utils.parse_text_entities( + client, self.caption, self.parse_mode, self.caption_entities + )).values() + return raw.types.InputBotInlineResultDocument( id=self.id, type=self.type, @@ -72,7 +94,8 @@ async def write(self, client: "pyrogram.Client"): if self.input_message_content else raw.types.InputBotInlineMessageMediaAuto( reply_markup=await self.reply_markup.write(client) if self.reply_markup else None, - message="", + message=message, + entities=entities ) ) ) diff --git a/pyrogram/types/inline_mode/inline_query_result_contact.py b/pyrogram/types/inline_mode/inline_query_result_contact.py index d55a624450..63c1bf3e39 100644 --- a/pyrogram/types/inline_mode/inline_query_result_contact.py +++ b/pyrogram/types/inline_mode/inline_query_result_contact.py @@ -16,13 +16,17 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import logging + import pyrogram from pyrogram import raw, types from .inline_query_result import InlineQueryResult +log = logging.getLogger(__name__) + class InlineQueryResultContact(InlineQueryResult): - """Contact with a phone number + """Contact with a phone number. By default, this contact will be sent by the user. Alternatively, you can use *input_message_content* to send a message with the specified content instead of the @@ -39,7 +43,7 @@ class InlineQueryResultContact(InlineQueryResult): Contact's last name. vcard (``str``, *optional*): - Additional data about the contact in the form of a `vCard `_. + Additional data about the contact in the form of a `vCard `_, 0-2048 bytes. id (``str``, *optional*): Unique identifier for this result, 1-64 bytes. @@ -51,13 +55,13 @@ class InlineQueryResultContact(InlineQueryResult): input_message_content (:obj:`~pyrogram.types.InputMessageContent`, *optional*): Content of the message to be sent instead of the contact. - thumb_url (``str``, *optional*): + thumbnail_url (``str``, *optional*): Url of the thumbnail for the result. - thumb_width (``int``, *optional*): + thumbnail_width (``int``, *optional*): Thumbnail width. - thumb_height (``int``, *optional*): + thumbnail_height (``int``, *optional*): Thumbnail height. """ @@ -70,19 +74,61 @@ def __init__( id: str = None, reply_markup: "types.InlineKeyboardMarkup" = None, input_message_content: "types.InputMessageContent" = None, + thumbnail_url: str = None, + thumbnail_width: int = 0, + thumbnail_height: int = 0, thumb_url: str = None, - thumb_width: int = 0, - thumb_height: int = 0 + thumb_width: int = None, + thumb_height: int = None ): + if thumb_url and thumbnail_url: + raise ValueError( + "Parameters `thumb_url` and `thumbnail_url` are mutually " + "exclusive." + ) + + if thumb_url is not None: + log.warning( + "This property is deprecated. " + "Please use thumbnail_url instead" + ) + thumbnail_url = thumb_url + + if thumb_width and thumbnail_width: + raise ValueError( + "Parameters `thumb_width` and `thumbnail_width` are mutually " + "exclusive." + ) + + if thumb_width is not None: + log.warning( + "This property is deprecated. " + "Please use thumbnail_width instead" + ) + thumbnail_width = thumb_width + + if thumb_height and thumbnail_height: + raise ValueError( + "Parameters `thumb_height` and `thumbnail_height` are mutually " + "exclusive." + ) + + if thumb_height is not None: + log.warning( + "This property is deprecated. " + "Please use thumbnail_height instead" + ) + thumbnail_height = thumb_height + super().__init__("contact", id, input_message_content, reply_markup) self.phone_number = phone_number self.first_name = first_name self.last_name = last_name self.vcard = vcard - self.thumb_url = thumb_url - self.thumb_width = thumb_width - self.thumb_height = thumb_height + self.thumbnail_url = thumbnail_url + self.thumbnail_width = thumbnail_width + self.thumbnail_height = thumbnail_height async def write(self, client: "pyrogram.Client"): return raw.types.InputBotInlineResult( @@ -101,14 +147,14 @@ async def write(self, client: "pyrogram.Client"): ) ), thumb=raw.types.InputWebDocument( - url=self.thumb_url, + url=self.thumbnail_url, size=0, mime_type="image/jpg", attributes=[ raw.types.DocumentAttributeImageSize( - w=self.thumb_width, - h=self.thumb_height + w=self.thumbnail_width, + h=self.thumbnail_height ) ] - ) if self.thumb_url else None + ) if self.thumbnail_url else None ) diff --git a/pyrogram/types/inline_mode/inline_query_result_document.py b/pyrogram/types/inline_mode/inline_query_result_document.py index eac7901b14..7905c63d9c 100644 --- a/pyrogram/types/inline_mode/inline_query_result_document.py +++ b/pyrogram/types/inline_mode/inline_query_result_document.py @@ -16,18 +16,22 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import logging from typing import Optional, List import pyrogram from pyrogram import raw, types, utils, enums from .inline_query_result import InlineQueryResult +log = logging.getLogger(__name__) + class InlineQueryResultDocument(InlineQueryResult): """Link to a file. By default, this file will be sent by the user with an optional caption. Alternatively, you can use *input_message_content* to send a message with the specified content instead of the file. + Currently, only **.PDF** and **.ZIP** files can be sent using this method. Parameters: document_url (``str``): @@ -63,13 +67,13 @@ class InlineQueryResultDocument(InlineQueryResult): input_message_content (:obj:`~pyrogram.types.InputMessageContent`): Content of the message to be sent instead of the file. - thumb_url (``str``, *optional*): - Url of the thumbnail for the result. + thumbnail_url (``str``, *optional*): + URL of the thumbnail (JPEG only) for the file. - thumb_width (``int``, *optional*): + thumbnail_width (``int``, *optional*): Thumbnail width. - thumb_height (``int``, *optional*): + thumbnail_height (``int``, *optional*): Thumbnail height. """ @@ -85,10 +89,52 @@ def __init__( description: str = "", reply_markup: "types.InlineKeyboardMarkup" = None, input_message_content: "types.InputMessageContent" = None, + thumbnail_url: str = None, + thumbnail_width: int = 0, + thumbnail_height: int = 0, thumb_url: str = None, - thumb_width: int = 0, - thumb_height: int = 0 + thumb_width: int = None, + thumb_height: int = None ): + if thumb_url and thumbnail_url: + raise ValueError( + "Parameters `thumb_url` and `thumbnail_url` are mutually " + "exclusive." + ) + + if thumb_url is not None: + log.warning( + "This property is deprecated. " + "Please use thumbnail_url instead" + ) + thumbnail_url = thumb_url + + if thumb_width and thumbnail_width: + raise ValueError( + "Parameters `thumb_width` and `thumbnail_width` are mutually " + "exclusive." + ) + + if thumb_width is not None: + log.warning( + "This property is deprecated. " + "Please use thumbnail_width instead" + ) + thumbnail_width = thumb_width + + if thumb_height and thumbnail_height: + raise ValueError( + "Parameters `thumb_height` and `thumbnail_height` are mutually " + "exclusive." + ) + + if thumb_height is not None: + log.warning( + "This property is deprecated. " + "Please use thumbnail_height instead" + ) + thumbnail_height = thumb_height + super().__init__("file", id, input_message_content, reply_markup) self.document_url = document_url @@ -98,9 +144,9 @@ def __init__( self.parse_mode = parse_mode self.caption_entities = caption_entities self.description = description - self.thumb_url = thumb_url - self.thumb_width = thumb_width - self.thumb_height = thumb_height + self.thumbnail_url = thumbnail_url + self.thumbnail_width = thumbnail_width + self.thumbnail_height = thumbnail_height async def write(self, client: "pyrogram.Client"): document = raw.types.InputWebDocument( @@ -111,16 +157,16 @@ async def write(self, client: "pyrogram.Client"): ) thumb = raw.types.InputWebDocument( - url=self.thumb_url, + url=self.thumbnail_url, size=0, mime_type="image/jpeg", attributes=[ raw.types.DocumentAttributeImageSize( - w=self.thumb_width, - h=self.thumb_height + w=self.thumbnail_width, + h=self.thumbnail_height ) ] - ) if self.thumb_url else None + ) if self.thumbnail_url else None message, entities = (await utils.parse_text_entities( client, self.caption, self.parse_mode, self.caption_entities diff --git a/pyrogram/types/inline_mode/inline_query_result_game.py b/pyrogram/types/inline_mode/inline_query_result_game.py new file mode 100644 index 0000000000..e5de782b4b --- /dev/null +++ b/pyrogram/types/inline_mode/inline_query_result_game.py @@ -0,0 +1,62 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +import logging + +import pyrogram +from pyrogram import raw, types +from .inline_query_result import InlineQueryResult + +log = logging.getLogger(__name__) + + +class InlineQueryResultGame(InlineQueryResult): + """Represents a :obj:`~pyrogram.types.Game`. + + Parameters: + game_short_name (``str``): + Short name of the game. + + id (``str``, *optional*): + Unique identifier for this result, 1-64 bytes. + Defaults to a randomly generated UUID4. + + reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): + Inline keyboard attached to the message. + + """ + + def __init__( + self, + game_short_name: str, + id: str = None, + reply_markup: "types.InlineKeyboardMarkup" = None + ): + super().__init__("game", id, None, reply_markup) + + self.game_short_name = game_short_name + + async def write(self, client: "pyrogram.Client"): + return raw.types.InputBotInlineResultGame( + id=self.id, + short_name=self.game_short_name, + title=self.first_name, + send_message=raw.types.InputBotInlineMessageGame( + reply_markup=await self.reply_markup.write(client) if self.reply_markup else None, + ) + ) diff --git a/pyrogram/types/inline_mode/inline_query_result_location.py b/pyrogram/types/inline_mode/inline_query_result_location.py index 236f39a624..4bbe32f536 100644 --- a/pyrogram/types/inline_mode/inline_query_result_location.py +++ b/pyrogram/types/inline_mode/inline_query_result_location.py @@ -16,10 +16,14 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import logging + import pyrogram from pyrogram import raw, types from .inline_query_result import InlineQueryResult +log = logging.getLogger(__name__) + class InlineQueryResultLocation(InlineQueryResult): """A location on a map. @@ -45,7 +49,8 @@ class InlineQueryResultLocation(InlineQueryResult): The radius of uncertainty for the location, measured in meters; 0-1500. live_period (``int``, *optional*): - Period in seconds for which the location can be updated, should be between 60 and 86400. + Period in seconds during which the location can be updated, should be between 60 and 86400, + or 0x7FFFFFFF for live locations that can be edited indefinitely. heading (``int``, *optional*): For live locations, a direction in which the user is moving, in degrees. @@ -61,13 +66,13 @@ class InlineQueryResultLocation(InlineQueryResult): input_message_content (:obj:`~pyrogram.types.InputMessageContent`): Content of the message to be sent instead of the file. - thumb_url (``str``, *optional*): + thumbnail_url (``str``, *optional*): Url of the thumbnail for the result. - thumb_width (``int``, *optional*): + thumbnail_width (``int``, *optional*): Thumbnail width. - thumb_height (``int``, *optional*): + thumbnail_height (``int``, *optional*): Thumbnail height. """ @@ -83,10 +88,52 @@ def __init__( id: str = None, reply_markup: "types.InlineKeyboardMarkup" = None, input_message_content: "types.InputMessageContent" = None, + thumbnail_url: str = None, + thumbnail_width: int = 0, + thumbnail_height: int = 0, thumb_url: str = None, - thumb_width: int = 0, - thumb_height: int = 0 + thumb_width: int = None, + thumb_height: int = None ): + if thumb_url and thumbnail_url: + raise ValueError( + "Parameters `thumb_url` and `thumbnail_url` are mutually " + "exclusive." + ) + + if thumb_url is not None: + log.warning( + "This property is deprecated. " + "Please use thumbnail_url instead" + ) + thumbnail_url = thumb_url + + if thumb_width and thumbnail_width: + raise ValueError( + "Parameters `thumb_width` and `thumbnail_width` are mutually " + "exclusive." + ) + + if thumb_width is not None: + log.warning( + "This property is deprecated. " + "Please use thumbnail_width instead" + ) + thumbnail_width = thumb_width + + if thumb_height and thumbnail_height: + raise ValueError( + "Parameters `thumb_height` and `thumbnail_height` are mutually " + "exclusive." + ) + + if thumb_height is not None: + log.warning( + "This property is deprecated. " + "Please use thumbnail_height instead" + ) + thumbnail_height = thumb_height + super().__init__("location", id, input_message_content, reply_markup) self.title = title @@ -96,9 +143,9 @@ def __init__( self.live_period = live_period self.heading = heading self.proximity_alert_radius = proximity_alert_radius - self.thumb_url = thumb_url - self.thumb_width = thumb_width - self.thumb_height = thumb_height + self.thumbnail_url = thumbnail_url + self.thumbnail_width = thumbnail_width + self.thumbnail_height = thumbnail_height async def write(self, client: "pyrogram.Client"): return raw.types.InputBotInlineResult( @@ -111,12 +158,24 @@ async def write(self, client: "pyrogram.Client"): else raw.types.InputBotInlineMessageMediaGeo( geo_point=raw.types.InputGeoPoint( lat=self.latitude, - long=self.longitude + long=self.longitude, + accuracy_radius=self.horizontal_accuracy ), heading=self.heading, period=self.live_period, proximity_notification_radius=self.proximity_alert_radius, reply_markup=await self.reply_markup.write(client) if self.reply_markup else None ) - ) + ), + thumb=raw.types.InputWebDocument( + url=self.thumbnail_url, + size=0, + mime_type="image/jpeg", + attributes=[ + raw.types.DocumentAttributeImageSize( + w=self.thumbnail_width, + h=self.thumbnail_height + ) + ] + ) if self.thumbnail_url else None ) diff --git a/pyrogram/types/inline_mode/inline_query_result_photo.py b/pyrogram/types/inline_mode/inline_query_result_photo.py index 2ccc7a1c35..5699f9858a 100644 --- a/pyrogram/types/inline_mode/inline_query_result_photo.py +++ b/pyrogram/types/inline_mode/inline_query_result_photo.py @@ -16,12 +16,15 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import logging from typing import Optional import pyrogram from pyrogram import raw, types, utils, enums from .inline_query_result import InlineQueryResult +log = logging.getLogger(__name__) + class InlineQueryResultPhoto(InlineQueryResult): """Link to a photo. @@ -33,9 +36,10 @@ class InlineQueryResultPhoto(InlineQueryResult): Parameters: photo_url (``str``): A valid URL of the photo. - Photo must be in jpeg format an must not exceed 5 MB. + Photo must be in *JPEG* format. + Photo size must not exceed 5MB. - thumb_url (``str``, *optional*): + thumbnail_url (``str``, *optional*): URL of the thumbnail for the photo. Defaults to the value passed in *photo_url*. @@ -78,7 +82,7 @@ class InlineQueryResultPhoto(InlineQueryResult): def __init__( self, photo_url: str, - thumb_url: str = None, + thumbnail_url: str = None, photo_width: int = 0, photo_height: int = 0, id: str = None, @@ -89,12 +93,26 @@ def __init__( caption_entities: list["types.MessageEntity"] = None, show_caption_above_media: bool = None, reply_markup: "types.InlineKeyboardMarkup" = None, - input_message_content: "types.InputMessageContent" = None + input_message_content: "types.InputMessageContent" = None, + thumb_url: str = None ): + if thumb_url and thumbnail_url: + raise ValueError( + "Parameters `thumb_url` and `thumbnail_url` are mutually " + "exclusive." + ) + + if thumb_url is not None: + log.warning( + "This property is deprecated. " + "Please use thumbnail_url instead" + ) + thumbnail_url = thumb_url + super().__init__("photo", id, input_message_content, reply_markup) self.photo_url = photo_url - self.thumb_url = thumb_url + self.thumbnail_url = thumbnail_url self.photo_width = photo_width self.photo_height = photo_height self.title = title @@ -119,11 +137,11 @@ async def write(self, client: "pyrogram.Client"): ] ) - if self.thumb_url is None: + if self.thumbnail_url is None: thumb = photo else: thumb = raw.types.InputWebDocument( - url=self.thumb_url, + url=self.thumbnail_url, size=0, mime_type="image/jpeg", attributes=[] diff --git a/pyrogram/types/inline_mode/inline_query_result_venue.py b/pyrogram/types/inline_mode/inline_query_result_venue.py index b3b513a55d..1418d68f57 100644 --- a/pyrogram/types/inline_mode/inline_query_result_venue.py +++ b/pyrogram/types/inline_mode/inline_query_result_venue.py @@ -16,10 +16,14 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import logging + import pyrogram from pyrogram import raw, types from .inline_query_result import InlineQueryResult +log = logging.getLogger(__name__) + class InlineQueryResultVenue(InlineQueryResult): """A venue. @@ -48,13 +52,13 @@ class InlineQueryResultVenue(InlineQueryResult): Foursquare identifier of the venue if known. foursquare_type (``str``, *optional*): - Foursquare type of the venue, if known. + Foursquare type of the venue, if known. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.) google_place_id (``str``, *optional*): Google Places identifier of the venue. google_place_type (``str``, *optional*): - Google Places type of the venue. + Google Places type of the venue. (See `supported types `_.) reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*): Inline keyboard attached to the message. @@ -62,13 +66,13 @@ class InlineQueryResultVenue(InlineQueryResult): input_message_content (:obj:`~pyrogram.types.InputMessageContent`): Content of the message to be sent instead of the file. - thumb_url (``str``, *optional*): + thumbnail_url (``str``, *optional*): Url of the thumbnail for the result. - thumb_width (``int``, *optional*): + thumbnail_width (``int``, *optional*): Thumbnail width. - thumb_height (``int``, *optional*): + thumbnail_height (``int``, *optional*): Thumbnail height. """ @@ -85,10 +89,52 @@ def __init__( google_place_type: str = None, reply_markup: "types.InlineKeyboardMarkup" = None, input_message_content: "types.InputMessageContent" = None, + thumbnail_url: str = None, + thumbnail_width: int = 0, + thumbnail_height: int = 0, thumb_url: str = None, - thumb_width: int = 0, - thumb_height: int = 0 + thumb_width: int = None, + thumb_height: int = None ): + if thumb_url and thumbnail_url: + raise ValueError( + "Parameters `thumb_url` and `thumbnail_url` are mutually " + "exclusive." + ) + + if thumb_url is not None: + log.warning( + "This property is deprecated. " + "Please use thumbnail_url instead" + ) + thumbnail_url = thumb_url + + if thumb_width and thumbnail_width: + raise ValueError( + "Parameters `thumb_width` and `thumbnail_width` are mutually " + "exclusive." + ) + + if thumb_width is not None: + log.warning( + "This property is deprecated. " + "Please use thumbnail_width instead" + ) + thumbnail_width = thumb_width + + if thumb_height and thumbnail_height: + raise ValueError( + "Parameters `thumb_height` and `thumbnail_height` are mutually " + "exclusive." + ) + + if thumb_height is not None: + log.warning( + "This property is deprecated. " + "Please use thumbnail_height instead" + ) + thumbnail_height = thumb_height + super().__init__("venue", id, input_message_content, reply_markup) self.title = title @@ -99,9 +145,9 @@ def __init__( self.foursquare_type = foursquare_type self.google_place_id = google_place_id self.google_place_type = google_place_type - self.thumb_url = thumb_url - self.thumb_width = thumb_width - self.thumb_height = thumb_height + self.thumbnail_url = thumbnail_url + self.thumbnail_width = thumbnail_width + self.thumbnail_height = thumbnail_height async def write(self, client: "pyrogram.Client"): return raw.types.InputBotInlineResult( @@ -127,5 +173,16 @@ async def write(self, client: "pyrogram.Client"): venue_type=self.foursquare_type or self.google_place_type or "", reply_markup=await self.reply_markup.write(client) if self.reply_markup else None ) - ) + ), + thumb=raw.types.InputWebDocument( + url=self.thumbnail_url, + size=0, + mime_type="image/jpeg", + attributes=[ + raw.types.DocumentAttributeImageSize( + w=self.thumbnail_width, + h=self.thumbnail_height + ) + ] + ) if self.thumbnail_url else None ) diff --git a/pyrogram/types/inline_mode/inline_query_result_video.py b/pyrogram/types/inline_mode/inline_query_result_video.py index 7db59d37f1..a17ff21cbe 100644 --- a/pyrogram/types/inline_mode/inline_query_result_video.py +++ b/pyrogram/types/inline_mode/inline_query_result_video.py @@ -16,12 +16,15 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +import logging from typing import Optional import pyrogram from pyrogram import raw, types, utils, enums from .inline_query_result import InlineQueryResult +log = logging.getLogger(__name__) + class InlineQueryResultVideo(InlineQueryResult): """Link to a page containing an embedded video player or a video file. @@ -30,12 +33,18 @@ class InlineQueryResultVideo(InlineQueryResult): Alternatively, you can use *input_message_content* to send a message with the specified content instead of the video. + .. note:: + + If an InlineQueryResultVideo message contains an embedded video (e.g., YouTube), + you must replace its content using *input_message_content*. + + Parameters: video_url (``str``): A valid URL for the embedded video player or video file. - thumb_url (``str``): - URL of the thumbnail (jpeg only) for the video. + thumbnail_url (``str``): + URL of the thumbnail (JPEG only) for the video. title (``str``): Title for the result. @@ -84,7 +93,7 @@ class InlineQueryResultVideo(InlineQueryResult): def __init__( self, video_url: str, - thumb_url: str, + thumbnail_url: str, title: str, id: str = None, mime_type: str = "video/mp4", @@ -97,12 +106,26 @@ def __init__( caption_entities: list["types.MessageEntity"] = None, show_caption_above_media: bool = None, reply_markup: "types.InlineKeyboardMarkup" = None, - input_message_content: "types.InputMessageContent" = None + input_message_content: "types.InputMessageContent" = None, + thumb_url: str = None, ): + if thumb_url and thumbnail_url: + raise ValueError( + "Parameters `thumb_url` and `thumbnail_url` are mutually " + "exclusive." + ) + + if thumb_url is not None: + log.warning( + "This property is deprecated. " + "Please use thumbnail_url instead" + ) + thumbnail_url = thumb_url + super().__init__("video", id, input_message_content, reply_markup) self.video_url = video_url - self.thumb_url = thumb_url + self.thumbnail_url = thumbnail_url self.title = title self.video_width = video_width self.video_height = video_height @@ -127,7 +150,7 @@ async def write(self, client: "pyrogram.Client"): ) thumb = raw.types.InputWebDocument( - url=self.thumb_url, + url=self.thumbnail_url, size=0, mime_type="image/jpeg", attributes=[] diff --git a/pyrogram/types/inline_mode/inline_query_result_voice.py b/pyrogram/types/inline_mode/inline_query_result_voice.py index 3d955a0e0b..03ca01c7fd 100644 --- a/pyrogram/types/inline_mode/inline_query_result_voice.py +++ b/pyrogram/types/inline_mode/inline_query_result_voice.py @@ -35,7 +35,7 @@ class InlineQueryResultVoice(InlineQueryResult): A valid URL for the voice recording. title (``str``): - Title for the result. + Recording title. id (``str``, *optional*): Unique identifier for this result, 1-64 bytes. @@ -59,6 +59,16 @@ class InlineQueryResultVoice(InlineQueryResult): input_message_content (:obj:`~pyrogram.types.InputMessageContent`, *optional*): Content of the message to be sent instead of the audio. + + thumbnail_url (``str``, *optional*): + Url of the thumbnail for the result. + + thumbnail_width (``int``, *optional*): + Thumbnail width. + + thumbnail_height (``int``, *optional*): + Thumbnail height. + """ def __init__( @@ -71,7 +81,10 @@ def __init__( parse_mode: Optional["enums.ParseMode"] = None, caption_entities: list["types.MessageEntity"] = None, reply_markup: "types.InlineKeyboardMarkup" = None, - input_message_content: "types.InputMessageContent" = None + input_message_content: "types.InputMessageContent" = None, + thumbnail_url: str = None, + thumbnail_width: int = 0, + thumbnail_height: int = 0 ): super().__init__("voice", id, input_message_content, reply_markup) @@ -81,6 +94,9 @@ def __init__( self.caption = caption self.parse_mode = parse_mode self.caption_entities = caption_entities + self.thumbnail_url = thumbnail_url + self.thumbnail_width = thumbnail_width + self.thumbnail_height = thumbnail_height async def write(self, client: "pyrogram.Client"): audio = raw.types.InputWebDocument( @@ -110,5 +126,16 @@ async def write(self, client: "pyrogram.Client"): message=message, entities=entities ) - ) + ), + thumb=raw.types.InputWebDocument( + url=self.thumbnail_url, + size=0, + mime_type="image/jpeg", + attributes=[ + raw.types.DocumentAttributeImageSize( + w=self.thumbnail_width, + h=self.thumbnail_height + ) + ] + ) if self.thumbnail_url else None )