使用 ForceReply 时如何处理 Pyrogram 中的回复?

How to handle replies in with Pyrogram when using ForceReply?

我正在构建一个电报机器人,我试图让用户填写有关事件的详细信息并将它们存储在本身位于列表中的字典中。

不过我希望它是 link 一次对话。我希望它看起来像:

用户:/创建

bot-reply: 你想怎么称呼它?

用户回复:克里斯的生日

机器人回复:什么时候?

用户回复:08/11/2021

机器人回复:2021 年 8 月 11 日克里斯生日活动已保存!

为了实现这一点,我计划使用 ForceReply 文档中的说明

This can be extremely useful if you want to create user-friendly step-by-step interfaces without having to sacrifice privacy mode.

问题是文档似乎没有解释如何处理响应。

目前我的代码是这样的:

@app.on_message(filters.command('create'))
async def create_countdown(client, message):
    global countdowns
    countdown = {
        'countdown_id': str(uuid4())[:8],
        'countdown_owner_id': message.from_user.id,
        'countdown_onwner_username': message.from_user.username,
        }
    try:
        await message.reply('What do you want to name the countdown?', 
                            reply_markup=ForceReply()
        )

    except FloodWait as e:
        await asyncio.sleep(e.x)

通过查看表格,我发现了如下选项: python telegram bot ForceReply callback 这正是我正在寻找的,但他们使用不同的库,如 python-telegram-bot,允许他们使用 ConversationHandler。它似乎不是 pyrogram

的一部分

如何使用热解图创建用户友好的分步界面

Pyrogram 没有 ConversationHandler。

您可以使用 dict,以您的用户 ID 作为键,将他们所处的状态作为值,然后您可以使用该状态字典作为您的参考,以了解您的用户所在的位置在对话中。

Dan: (Pyrogram creator)
A conversation-like feature is not available yet in the lib. One way to do that is saving states into a dictionary using user IDs as keys. Check the dictionary before taking actions so that you know in which step your users are and update it once they successfully go past one action
https://t.me/pyrogramchat/213488