0

我有一个场景,我的机器人开始与另一个机器人对话,以接收带有内联键盘的回复。我的机器人如何使用内联键盘回复?

from pyrogram import Client

api_id = 12345
api_hash = "hash123"

with Client("my_account", api_id, api_hash) as app:
    app.send_message("otherbot", "Hello")  # This message is received by otherbot, which then triggers a reply that contains an inline keyboard
    # Here I need to reply to otherbot's message
4

2 回答 2

1

您正在寻找的是对话处理程序。

Pyrogram 中还没有类似对话的功能。一种方法是使用用户 ID 作为键将状态保存到字典中。在采取行动之前检查字典,以便您知道您的用户在哪一步,并在他们成功完成一项操作后更新它。

https://t.me/pyrogramchat/213488

(从我的另一个答案复制粘贴。)

于 2021-10-10T17:13:15.147 回答
0

正如@ColinShark 所述,pyrogram不支持对话处理程序。因此,这个简单的解决方法适用于我的用例:

from pyrogram import Client

api_id = 12345
api_hash = "hash123"
bot_name = "otherbot"

with Client("my_account", api_id, api_hash) as app:
    response = app.send_message(bot_name, "Hello")
    bot_reply_msg_id = int(response["message_id"]) + 1

    response = app.get_messages(bot_name, bot_reply_msg_id)
    try:
        response.click(2, timeout=1)  # to click on the third button/option. Index start at 0.
    except TimeoutError:
        pass
于 2021-10-10T22:00:50.880 回答