From 74f7ae525faca8e99d14ec2bad8bcf1157facf4f Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Fri, 12 Oct 2018 12:38:46 +0200 Subject: [PATCH] Document InlineBuilder --- .../extra/examples/telegram-client.rst | 25 +++++++++++++++++++ readthedocs/telethon.tl.custom.rst | 20 ++++++++++++--- telethon/events/inlinequery.py | 9 ++++--- telethon/tl/custom/inlinebuilder.py | 14 +++++------ telethon/tl/custom/inlineresults.py | 1 + 5 files changed, 54 insertions(+), 15 deletions(-) diff --git a/readthedocs/extra/examples/telegram-client.rst b/readthedocs/extra/examples/telegram-client.rst index 41fa2ca7..4c26edd6 100644 --- a/readthedocs/extra/examples/telegram-client.rst +++ b/readthedocs/extra/examples/telegram-client.rst @@ -435,6 +435,9 @@ where you want to send it to: Sending messages through inline bots lets you use buttons as a normal user. +It can look a bit strange at first, but you can make inline queries in no +chat in particular, and then click a *result* to send it to some chat. + Clicking Buttons **************** @@ -449,6 +452,28 @@ This will click the first button in the message. You could also ``click(row, column)``, using some text such as ``click(text='👍')`` or even the data directly ``click(data=b'payload')``. +Answering Inline Queries +************************ + +As a bot, you can answer to inline queries with `events.InlineQuery +`. You should make use of the +`builder ` property +to conveniently build the list of results to show to the user. Remember +to check the properties of the `InlineQuery.Event +`: + +.. code-block:: python + + @bot.on(events.InlineQuery) + async def handler(event): + builder = event.builder + + rev_text = event.text[::-1] + await event.answer([ + builder.article('Reverse text', text=rev_text), + builder.photo('/path/to/photo.jpg') + ]) + Conversations: Waiting for Messages or Replies ********************************************** diff --git a/readthedocs/telethon.tl.custom.rst b/readthedocs/telethon.tl.custom.rst index 571cf64f..1c1de4d0 100644 --- a/readthedocs/telethon.tl.custom.rst +++ b/readthedocs/telethon.tl.custom.rst @@ -10,8 +10,6 @@ telethon\.tl\.custom\.draft module :undoc-members: :show-inheritance: - - telethon\.tl\.custom\.dialog module ----------------------------------- @@ -20,7 +18,6 @@ telethon\.tl\.custom\.dialog module :undoc-members: :show-inheritance: - telethon\.tl\.custom\.message module ------------------------------------ @@ -29,7 +26,6 @@ telethon\.tl\.custom\.message module :undoc-members: :show-inheritance: - telethon\.tl\.custom\.messagebutton module ------------------------------------------ @@ -54,6 +50,14 @@ telethon\.tl\.custom\.button module :undoc-members: :show-inheritance: +telethon\.tl\.custom\.inlinebuilder module +------------------------------------------ + +.. automodule:: telethon.tl.custom.inlinebuilder + :members: + :undoc-members: + :show-inheritance: + telethon\.tl\.custom\.inlineresult module ----------------------------------------- @@ -62,6 +66,14 @@ telethon\.tl\.custom\.inlineresult module :undoc-members: :show-inheritance: +telethon\.tl\.custom\.inlineresults module +------------------------------------------ + +.. automodule:: telethon.tl.custom.inlineresults + :members: + :undoc-members: + :show-inheritance: + telethon\.tl\.custom\.chatgetter module --------------------------------------- diff --git a/telethon/events/inlinequery.py b/telethon/events/inlinequery.py index 4e3c6c1f..75c4542b 100644 --- a/telethon/events/inlinequery.py +++ b/telethon/events/inlinequery.py @@ -71,6 +71,9 @@ class InlineQuery(EventBuilder): query (:tl:`UpdateBotCallbackQuery`): The original :tl:`UpdateBotCallbackQuery`. + Make sure to access the `text` of the query if + that's what you want instead working with this. + pattern_match (`obj`, optional): The resulting object from calling the passed ``pattern`` function, which is ``re.compile(...).match`` by default. @@ -117,8 +120,8 @@ class InlineQuery(EventBuilder): @property def builder(self): """ - Returns a new `inline result builder - `. + Returns a new `InlineBuilder + ` instance. """ return custom.InlineBuilder(self._client) @@ -134,7 +137,7 @@ class InlineQuery(EventBuilder): A list of :tl:`InputBotInlineResult` to use. You should use `builder` to create these: - .. code-block: python + .. code-block:: python builder = inline.builder r1 = builder.article('Be nice', text='Have a nice day') diff --git a/telethon/tl/custom/inlinebuilder.py b/telethon/tl/custom/inlinebuilder.py index 8a9e6582..a03338bb 100644 --- a/telethon/tl/custom/inlinebuilder.py +++ b/telethon/tl/custom/inlinebuilder.py @@ -6,7 +6,8 @@ from ... import utils class InlineBuilder: """ - Helper class to allow defining inline queries ``results``. + Helper class to allow defining `InlineQuery + ` ``results``. Common arguments to all methods are explained here to avoid repetition: @@ -19,16 +20,13 @@ class InlineBuilder: Whether to show a link preview in the sent text message or not. - geo (:tl:`InputGeoPoint`, :tl:`GeoPoint`, - :tl:`InputMediaVenue`, :tl:`MessageMediaVenue`, - optional): + geo (:tl:`InputGeoPoint`, :tl:`GeoPoint`, :tl:`InputMediaVenue`, :tl:`MessageMediaVenue`, optional): If present, it may either be a geo point or a venue. period (int, optional): The period in seconds to be used for geo points. - contact (:tl:`InputMediaContact`, :tl:`MessageMediaContact`, - optional): + contact (:tl:`InputMediaContact`, :tl:`MessageMediaContact`, optional): If present, it must be the contact information to send. game (`bool`, optional): @@ -155,8 +153,8 @@ class InlineBuilder: Args: file (`obj`): - Same as ``file`` for ` - telethon.client.uploads.UploadMethods.send_file`. + Same as ``file`` for `client.send_file + `. title (`str`, optional): The title to be shown for this result. diff --git a/telethon/tl/custom/inlineresults.py b/telethon/tl/custom/inlineresults.py index 153e3bed..2ac5ebfa 100644 --- a/telethon/tl/custom/inlineresults.py +++ b/telethon/tl/custom/inlineresults.py @@ -2,6 +2,7 @@ import time from .inlineresult import InlineResult + class InlineResults(list): """ Custom class that encapsulates :tl:`BotResults` providing