Skip to content

Commit a9427b4

Browse files
inline_mode Improvements according to Bot API 6.6 (#156)
- Added the class InlineQueryResultGame. - Added the bound methods ChosenInlineResult.edit_message_text, ChosenInlineResult.edit_message_caption, ChosenInlineResult.edit_message_media and ChosenInlineResult.edit_message_reply_markup. - Renamed the fields thumb_url, thumb_width, and thumb_height in the classes InlineQueryResultArticle, InlineQueryResultContact, InlineQueryResultDocument, InlineQueryResultLocation, and InlineQueryResultVenue to thumbnail_url, thumbnail_width, and thumbnail_height respectively. - Renamed the field thumb_url in the classes InlineQueryResultPhoto and InlineQueryResultVideo to thumbnail_url. - Added the field animation_mime_type and renamed the fields thumb_url and thumb_mime_type in the classes InlineQueryResultAnimation to thumbnail_url and thumbnail_mime_type respectively. - Fixed a bug with _client being None in ChosenInlineResultHandler. Co-authored-by: anonymousx97 <[email protected]>
1 parent b9e2f86 commit a9427b4

18 files changed

+755
-105
lines changed

compiler/docs/compiler.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,7 @@ def get_title_list(s: str) -> list:
624624
InlineQueryResultVoice
625625
InlineQueryResultArticle
626626
InlineQueryResultContact
627+
InlineQueryResultGame
627628
InlineQueryResultLocation
628629
InlineQueryResultVenue
629630
""",
@@ -795,6 +796,10 @@ def get_title_list(s: str) -> list:
795796
CallbackQuery.edit_message_caption
796797
CallbackQuery.edit_message_media
797798
CallbackQuery.edit_message_reply_markup
799+
ChosenInlineResult.edit_message_text
800+
ChosenInlineResult.edit_message_caption
801+
ChosenInlineResult.edit_message_media
802+
ChosenInlineResult.edit_message_reply_markup
798803
""",
799804
inline_query="""
800805
InlineQuery

docs/source/releases/changes-in-this-fork.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11

2+
Changes in this Fork
3+
=====================
4+
25
.. admonition :: A Word of Warning
36
:class: tip
47
@@ -29,6 +32,12 @@ Changes in this Fork
2932
| Scheme layer used: 199 |
3033
+------------------------+
3134

35+
- Added the class :obj:`~pyrogram.types.InlineQueryResultGame`.
36+
- 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`.
37+
- 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.
38+
- Renamed the field ``thumb_url`` in the classes :obj:`~pyrogram.types.InlineQueryResultPhoto` and :obj:`~pyrogram.types.InlineQueryResultVideo` to ``thumbnail_url``.
39+
- 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.
40+
- Fixed a bug with ``_client`` being None in :obj:`~pyrogram.handlers.ChosenInlineResultHandler`.
3241
- 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.
3342
- Added ``for_paid_reactions`` in :meth:`~pyrogram.Client.get_send_as_chats`.
3443
- `Updated documentation and parameter names according to BOT API 8.3 <https://github.com/TelegramPlayGround/pyrogram/commit/7675b40>`__

pyrogram/types/bots_and_keyboards/callback_query.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,16 @@ def __init__(
8989
self.matches = matches
9090

9191
@staticmethod
92-
async def _parse(client: "pyrogram.Client", callback_query, users, chats) -> "CallbackQuery":
92+
async def _parse(
93+
client: "pyrogram.Client",
94+
callback_query: Union[
95+
"raw.types.UpdateBotCallbackQuery",
96+
"raw.types.UpdateInlineBotCallbackQuery",
97+
"raw.types.UpdateBusinessBotCallbackQuery",
98+
],
99+
users: dict,
100+
chats: dict,
101+
) -> "CallbackQuery":
93102
message = None
94103
inline_message_id = None
95104

pyrogram/types/inline_mode/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from .inline_query_result_cached_video import InlineQueryResultCachedVideo
3030
from .inline_query_result_cached_voice import InlineQueryResultCachedVoice
3131
from .inline_query_result_contact import InlineQueryResultContact
32+
from .inline_query_result_game import InlineQueryResultGame
3233
from .inline_query_result_document import InlineQueryResultDocument
3334
from .inline_query_result_location import InlineQueryResultLocation
3435
from .inline_query_result_photo import InlineQueryResultPhoto
@@ -56,6 +57,7 @@
5657
"InlineQueryResultVoice",
5758
"InlineQueryResultArticle",
5859
"InlineQueryResultContact",
60+
"InlineQueryResultGame",
5961
"InlineQueryResultLocation",
6062
"InlineQueryResultVenue",
6163
]

pyrogram/types/inline_mode/chosen_inline_result.py

Lines changed: 152 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818

19+
from typing import Optional
1920

2021
import pyrogram
2122
from pyrogram import raw, types, utils
@@ -28,8 +29,8 @@ class ChosenInlineResult(Object, Update):
2829
2930
.. note::
3031
31-
In order to receive these updates, your bot must have "inline feedback" enabled. You can enable this feature
32-
with `@BotFather <https://t.me/botfather>`_.
32+
In order to receive these updates, your bot must have "inline feedback" enabled.
33+
You can enable this feature with `@BotFather <https://t.me/botfather>`_.
3334
3435
Parameters:
3536
result_id (``str``):
@@ -83,5 +84,153 @@ def _parse(client, chosen_inline_result: raw.types.UpdateBotInlineSend, users) -
8384
latitude=chosen_inline_result.geo.lat,
8485
client=client
8586
) if chosen_inline_result.geo else None,
86-
inline_message_id=inline_message_id
87+
inline_message_id=inline_message_id,
88+
client=client
8789
)
90+
91+
async def edit_message_text(
92+
self,
93+
text: str,
94+
parse_mode: Optional["enums.ParseMode"] = None,
95+
entities: list["types.MessageEntity"] = None,
96+
link_preview_options: "types.LinkPreviewOptions" = None,
97+
reply_markup: "types.InlineKeyboardMarkup" = None
98+
) -> bool:
99+
"""Edit the text of messages attached to sent :obj:`~pyrogram.types.InlineQueryResult` messages.
100+
101+
Bound method *edit_message_text* of :obj:`~pyrogram.types.ChosenInlineResult`.
102+
103+
Parameters:
104+
text (``str``):
105+
New text of the message.
106+
107+
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
108+
By default, texts are parsed using both Markdown and HTML styles.
109+
You can combine both syntaxes together.
110+
111+
entities (List of :obj:`~pyrogram.types.MessageEntity`):
112+
List of special entities that appear in message text, which can be specified instead of *parse_mode*.
113+
114+
link_preview_options (:obj:`~pyrogram.types.LinkPreviewOptions`, *optional*):
115+
Link preview generation options for the message
116+
117+
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
118+
An InlineKeyboardMarkup object.
119+
120+
Returns:
121+
``bool``: On success, True is returned.
122+
123+
Raises:
124+
RPCError: In case of a Telegram RPC error.
125+
"""
126+
if self.inline_message_id is None:
127+
raise ValueError("Identifier of the inline message is required to edit the message")
128+
else:
129+
return await self._client.edit_inline_text(
130+
inline_message_id=self.inline_message_id,
131+
text=text,
132+
parse_mode=parse_mode,
133+
entities=entities,
134+
link_preview_options=link_preview_options,
135+
reply_markup=reply_markup
136+
)
137+
138+
async def edit_message_caption(
139+
self,
140+
caption: str,
141+
parse_mode: Optional["enums.ParseMode"] = None,
142+
caption_entities: list["types.MessageEntity"] = None,
143+
reply_markup: "types.InlineKeyboardMarkup" = None
144+
) -> bool:
145+
"""Edit the caption of media messages attached to sent :obj:`~pyrogram.types.InlineQueryResult` messages.
146+
147+
Bound method *edit_message_caption* of :obj:`~pyrogram.types.ChosenInlineResult`.
148+
149+
Parameters:
150+
caption (``str``):
151+
New caption of the message.
152+
153+
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
154+
By default, texts are parsed using both Markdown and HTML styles.
155+
You can combine both syntaxes together.
156+
157+
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
158+
List of special entities that appear in message text, which can be specified instead of *parse_mode*.
159+
160+
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
161+
An InlineKeyboardMarkup object.
162+
163+
Returns:
164+
``bool``: On success, True is returned.
165+
166+
Raises:
167+
RPCError: In case of a Telegram RPC error.
168+
"""
169+
return await self.edit_message_text(
170+
text=caption,
171+
parse_mode=parse_mode,
172+
entities=caption_entities,
173+
reply_markup=reply_markup
174+
)
175+
176+
async def edit_message_media(
177+
self,
178+
media: "types.InputMedia",
179+
reply_markup: "types.InlineKeyboardMarkup" = None,
180+
file_name: str = None
181+
) -> bool:
182+
"""Edit animation, audio, document, photo or video messages attached to sent :obj:`~pyrogram.types.InlineQueryResult` messages.
183+
184+
Bound method *edit_message_media* of :obj:`~pyrogram.types.ChosenInlineResult`.
185+
186+
Parameters:
187+
media (:obj:`~pyrogram.types.InputMedia`):
188+
One of the InputMedia objects describing an animation, audio, document, photo or video.
189+
190+
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`, *optional*):
191+
An InlineKeyboardMarkup object.
192+
193+
file_name (``str``, *optional*):
194+
File name of the media to be sent. Not applicable to photos.
195+
Defaults to file's path basename.
196+
197+
Returns:
198+
``bool``: On success, True is returned.
199+
200+
Raises:
201+
RPCError: In case of a Telegram RPC error.
202+
"""
203+
if self.inline_message_id is None:
204+
raise ValueError("Identifier of the inline message is required to edit the message")
205+
else:
206+
return await self._client.edit_inline_media(
207+
inline_message_id=self.inline_message_id,
208+
media=media,
209+
reply_markup=reply_markup
210+
)
211+
212+
async def edit_message_reply_markup(
213+
self,
214+
reply_markup: "types.InlineKeyboardMarkup" = None
215+
) -> bool:
216+
"""Edit only the reply markup of messages attached to sent :obj:`~pyrogram.types.InlineQueryResult` messages.
217+
218+
Bound method *edit_message_reply_markup* of :obj:`~pyrogram.types.ChosenInlineResult`.
219+
220+
Parameters:
221+
reply_markup (:obj:`~pyrogram.types.InlineKeyboardMarkup`):
222+
An InlineKeyboardMarkup object.
223+
224+
Returns:
225+
``bool``: On success, True is returned.
226+
227+
Raises:
228+
RPCError: In case of a Telegram RPC error.
229+
"""
230+
if self.inline_message_id is None:
231+
raise ValueError("Identifier of the inline message is required to edit the message")
232+
else:
233+
return await self._client.edit_inline_reply_markup(
234+
inline_message_id=self.inline_message_id,
235+
reply_markup=reply_markup
236+
)

pyrogram/types/inline_mode/inline_query_result.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626
class InlineQueryResult(Object):
27-
"""One result of an inline query.
27+
"""This object represents one result of an inline query. Telegram clients currently support results of the following 20 types:
2828
2929
- :obj:`~pyrogram.types.InlineQueryResultCachedAudio`
3030
- :obj:`~pyrogram.types.InlineQueryResultCachedDocument`
@@ -36,13 +36,19 @@ class InlineQueryResult(Object):
3636
- :obj:`~pyrogram.types.InlineQueryResultArticle`
3737
- :obj:`~pyrogram.types.InlineQueryResultAudio`
3838
- :obj:`~pyrogram.types.InlineQueryResultContact`
39+
- :obj:`~pyrogram.types.InlineQueryResultGame`
3940
- :obj:`~pyrogram.types.InlineQueryResultDocument`
4041
- :obj:`~pyrogram.types.InlineQueryResultAnimation`
4142
- :obj:`~pyrogram.types.InlineQueryResultLocation`
4243
- :obj:`~pyrogram.types.InlineQueryResultPhoto`
4344
- :obj:`~pyrogram.types.InlineQueryResultVenue`
4445
- :obj:`~pyrogram.types.InlineQueryResultVideo`
4546
- :obj:`~pyrogram.types.InlineQueryResultVoice`
47+
48+
.. note::
49+
50+
All URLs passed in inline query results will be available to end users and therefore must be assumed to be *public*.
51+
4652
"""
4753

4854
def __init__(

0 commit comments

Comments
 (0)