Document InlineBuilder

This commit is contained in:
Lonami Exo 2018-10-12 12:38:46 +02:00
parent 9ee415749d
commit 74f7ae525f
5 changed files with 54 additions and 15 deletions

View File

@ -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
<telethon.events.inlinequery.InlineQuery>`. You should make use of the
`builder <telethon.tl.custom.inlinebuilder.InlineBuilder>` property
to conveniently build the list of results to show to the user. Remember
to check the properties of the `InlineQuery.Event
<telethon.events.inlinequery.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
**********************************************

View File

@ -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
---------------------------------------

View File

@ -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
<telethon.tl.custom.inline.InlineBuilder>`.
Returns a new `InlineBuilder
<telethon.tl.custom.inlinebuilder.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')

View File

@ -6,7 +6,8 @@ from ... import utils
class InlineBuilder:
"""
Helper class to allow defining inline queries ``results``.
Helper class to allow defining `InlineQuery
<telethon.events.inlinequery.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 `<client.send_file>
telethon.client.uploads.UploadMethods.send_file`.
Same as ``file`` for `client.send_file
<telethon.client.uploads.UploadMethods.send_file>`.
title (`str`, optional):
The title to be shown for this result.

View File

@ -2,6 +2,7 @@ import time
from .inlineresult import InlineResult
class InlineResults(list):
"""
Custom class that encapsulates :tl:`BotResults` providing