python - 在发送消息之前等待用户输入

标签 python telegram-bot

我在处理传入消息时遇到问题。我的机器人中有一个带有一个 InlineKeyboardMarkup 的主菜单。按下按钮时,机器人应等待用户输入,然后发送消息。但就我而言,它发送消息,然后等待用户输入,然后再次发送消息。这是一个大问题,因为在发送消息后,它应该返回主菜单。

我正在使用 pythonTelegramBotAPI(远程机器人)

这就是代码:

  @bot.callback_query_handler(func = lambda call: True)
    def query_handler(call):
        bot.answer_callback_query(callback_query_id = call.id, text = '')
    
        cid = call.message.chat.id
        mid = call.message.message_id
        msg = call.message
    
     
        if call.data == 'request':
            bot.edit_message_text('Test - Answer to request', cid, mid, reply_markup = markup)
            request_handler(msg)
    
    ################# Keyboard sections #################
    
    @bot.message_handler()
    def request_handler(msg):
    
        if msg.content_type == 'text':
           bot.send_message(msg.chat.id, 'Request accepted')

# and here the code to go back, that I didn't do yet

最佳答案

也许是这个conversational bot example将帮助您了解如何与用户建立对话。

关于python - 在发送消息之前等待用户输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63531320/

相关文章:

python - 使用 telegram bot 返回 matplotlib 绘图

python - 检查回归中的两个系数在 Python statsmodels 中是否不同

python - 如何按行拆分 pandas 数据框并包含创建的每个新数据框的标题?

python - 错误 TypeError : 'NoneType' object is not iterable mean? 是什么意思

python - 错误日期时间字段输入格式

php - 在 Telegram Bot 中发送消息

telegram - 从 Telegram Bot API 获取回复消息

Python:如何将大文本输出格式化为 'prettier' 和用户定义

用于机器人对象的 Telegram 网络应用程序不包含用户数据

python - getChatMembersCount 远程机器人