我在处理传入消息时遇到问题。我的机器人中有一个带有一个 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/