[英]Telegram-python-Bot get user text input with callback_query
I'm trying to get input text from the user..我正在尝试从用户那里获取输入文本..
He arrive to the function after he interact with他在与 function
keyboard = [[InlineKeyboardButton("exapmple", callback_data='example')]]
reply_markup = InlineKeyboardMarkup(keyboard)
so in update I'm getting callback_query所以在更新中我得到了 callback_query
after he choose the button example I ask him for input text.在他选择按钮示例后,我要求他输入文本。
this work for me I get input with the button but not with his own input这项工作对我来说,我得到了按钮的输入,而不是他自己的输入
def getInput(update, context):
query = update.callback_query
query.answer()
input = query.data
I want to get the input like我想得到像这样的输入
input = update.message.text
but since I get callback_query I don't have the message.. so how I switch to message or get input with callback_query但是因为我得到 callback_query 我没有消息..所以我如何切换到消息或使用 callback_query 获取输入
edit: I arrive to getInput with编辑:我到达 getInput 与
dp.add_handler(CallbackQueryHandler(getInput, pattern='example'))
If you want to get the text just after the user clicks the button, use ConversationHandler.如果您想在用户单击按钮后立即获取文本,请使用 ConversationHandler。
Docs: https://python-telegram-bot.readthedocs.io/en/stable/telegram.ext.conversationhandler.html文档: https : //python-telegram-bot.readthedocs.io/en/stable/telegram.ext.conversationhandler.html
Example: https://github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/conversationbot.py示例: https : //github.com/python-telegram-bot/python-telegram-bot/blob/master/examples/conversationbot.py
The response from a callback query is来自回调查询的响应是
text = update.callback_query.data
If the user decides to type instead something then the message is processed as a default text message如果用户决定输入某些内容,则该消息将作为默认文本消息进行处理
def main_handler(update, context):
print(update.message.text)
updater.dispatcher.add_handler(MessageHandler(Filters.text, main_handler))
def get_text_from_user(updater, context): text = updater.message.text # <- this is text from user print(text) def get_text_from_user(updater, context): text = updater.message.text # <- 这是来自用户的文本 print(text)
updater.dispatcher.add_handler(telegram.exe.MessageHandler(telegram.exe.Filters.text,get_text_from_user)) updater.dispatcher.add_handler(telegram.exe.MessageHandler(telegram.exe.Filters.text,get_text_from_user))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.