我正在python上建立一些电报机器人(使用此框架pyTelegramBotAPI)。我遇到了用户输入的问题。我需要在某些机器人消息后保存用户输入(可以是任何文本)。例如:保存用户输入后,某些消息电报机器人
机器人: - 请描述您的问题。
用户: - 我们的电脑无法使用。
然后,我需要将此文字“我们的计算机不工作”保存到某个变量,然后转到下一步。 这里是我的代码:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import telebot
import constants
from telebot import types
bot = telebot.TeleBot(constants.token)
@bot.message_handler(commands=['start'])
def handle_start(message):
keyboard = types.InlineKeyboardMarkup()
callback_button = types.InlineKeyboardButton(text="Help me!", callback_data="start")
keyboard.add(callback_button)
bot.send_message(message.chat.id, "Welcome I am helper bot!", reply_markup=keyboard)
@bot.inline_handler(lambda query: len(query.query) > 0)
def query_text(query):
kb = types.InlineKeyboardMarkup()
kb.add(types.InlineKeyboardButton(text="Help me!", callback_data="start"))
results = []
single_msg = types.InlineQueryResultArticle(
id="1", title="Press me",
input_message_content=types.InputTextMessageContent(message_text="Welcome I am helper bot!"),
reply_markup=kb
)
results.append(single_msg)
bot.answer_inline_query(query.id, results)
@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
if call.message:
if call.data == "start":
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Please describe your problem.")
#here I need wait for user text response, save it and go to the next step
我有在语句中使用MESSAGE_ID的想法,但仍然无法实现它。我如何解决这个问题?有任何想法吗?谢谢。