2018-01-05 02:59:53 +03:00
|
|
|
====
|
2017-11-20 07:12:31 +03:00
|
|
|
Bots
|
2018-01-05 02:59:53 +03:00
|
|
|
====
|
|
|
|
|
2017-11-20 07:12:31 +03:00
|
|
|
|
2018-01-20 13:47:17 +03:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
These examples assume you have read :ref:`accessing-the-full-api`.
|
|
|
|
|
2018-10-06 21:20:11 +03:00
|
|
|
.. contents::
|
|
|
|
|
2018-01-20 13:47:17 +03:00
|
|
|
|
2017-11-20 07:12:31 +03:00
|
|
|
Talking to Inline Bots
|
2018-01-05 02:59:53 +03:00
|
|
|
**********************
|
2017-11-20 07:12:31 +03:00
|
|
|
|
2018-01-05 02:59:53 +03:00
|
|
|
You can query an inline bot, such as `@VoteBot`__ (note, *query*,
|
|
|
|
not *interact* with a voting message), by making use of the
|
2018-04-08 15:15:26 +03:00
|
|
|
:tl:`GetInlineBotResultsRequest` request:
|
2017-11-20 07:12:31 +03:00
|
|
|
|
2018-06-20 12:05:33 +03:00
|
|
|
.. code-block:: python
|
2017-11-20 07:12:31 +03:00
|
|
|
|
2018-06-20 12:05:33 +03:00
|
|
|
from telethon.tl.functions.messages import GetInlineBotResultsRequest
|
2017-11-20 07:12:31 +03:00
|
|
|
|
2018-06-25 22:14:58 +03:00
|
|
|
bot_results = client(GetInlineBotResultsRequest(
|
2018-06-20 12:05:33 +03:00
|
|
|
bot, user_or_chat, 'query', ''
|
2018-06-25 22:14:58 +03:00
|
|
|
))
|
2017-11-20 07:12:31 +03:00
|
|
|
|
|
|
|
And you can select any of their results by using
|
2018-04-08 15:15:26 +03:00
|
|
|
:tl:`SendInlineBotResultRequest`:
|
2017-11-20 07:12:31 +03:00
|
|
|
|
2018-06-20 12:05:33 +03:00
|
|
|
.. code-block:: python
|
2017-11-20 07:12:31 +03:00
|
|
|
|
2018-06-20 12:05:33 +03:00
|
|
|
from telethon.tl.functions.messages import SendInlineBotResultRequest
|
2017-11-20 07:12:31 +03:00
|
|
|
|
2018-06-25 22:14:58 +03:00
|
|
|
client(SendInlineBotResultRequest(
|
2018-06-20 12:05:33 +03:00
|
|
|
get_input_peer(user_or_chat),
|
|
|
|
obtained_query_id,
|
|
|
|
obtained_str_id
|
2018-06-25 22:14:58 +03:00
|
|
|
))
|
2017-11-20 07:12:31 +03:00
|
|
|
|
|
|
|
|
|
|
|
Talking to Bots with special reply markup
|
2018-01-05 02:59:53 +03:00
|
|
|
*****************************************
|
2017-11-20 07:12:31 +03:00
|
|
|
|
2018-06-22 15:44:59 +03:00
|
|
|
Generally, you just use the `message.click()
|
|
|
|
<telethon.tl.custom.message.Message.click>` method:
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
2018-06-25 22:14:58 +03:00
|
|
|
messages = client.get_messages('somebot')
|
|
|
|
messages[0].click(0)
|
2018-06-22 15:44:59 +03:00
|
|
|
|
|
|
|
You can also do it manually.
|
|
|
|
|
2017-11-20 07:12:31 +03:00
|
|
|
To interact with a message that has a special reply markup, such as
|
2018-04-08 15:15:26 +03:00
|
|
|
`@VoteBot`__ polls, you would use :tl:`GetBotCallbackAnswerRequest`:
|
2017-11-20 07:12:31 +03:00
|
|
|
|
2018-06-20 12:05:33 +03:00
|
|
|
.. code-block:: python
|
2017-11-20 07:12:31 +03:00
|
|
|
|
2018-06-20 12:05:33 +03:00
|
|
|
from telethon.tl.functions.messages import GetBotCallbackAnswerRequest
|
2017-11-20 07:12:31 +03:00
|
|
|
|
2018-06-25 22:14:58 +03:00
|
|
|
client(GetBotCallbackAnswerRequest(
|
2018-06-20 12:05:33 +03:00
|
|
|
user_or_chat,
|
|
|
|
msg.id,
|
|
|
|
data=msg.reply_markup.rows[wanted_row].buttons[wanted_button].data
|
2018-06-25 22:14:58 +03:00
|
|
|
))
|
2017-11-20 07:12:31 +03:00
|
|
|
|
2018-01-05 02:59:53 +03:00
|
|
|
It's a bit verbose, but it has all the information you would need to
|
2017-11-20 07:12:31 +03:00
|
|
|
show it visually (button rows, and buttons within each row, each with
|
|
|
|
its own data).
|
|
|
|
|
|
|
|
__ https://t.me/vote
|
2018-01-05 02:59:53 +03:00
|
|
|
__ https://t.me/vote
|