如何通过按下按钮开始处理对话?
How to start handling the converstation by pressing a button?
我有一个按钮菜单,其中一个是 Research ,当你点击它时,它应该会问“你想知道什么?”然后收到你的答案,并从维基百科给你一个总结......
而且我希望它也可以作为命令访问,例如在您键入 /Research 时为您提供摘要 ...
现在我的代码使用 /Research 可以完美运行,因为这个命令是我的 ConverstationHandler
的 entry_point
但现在我希望也可以通过按“研究”按钮来访问它:
def Click_Button(update, context):
query = update.callback_query
if query.data == "MeMe":
MeMe(update,context)
if query.data == "Joke":
Joke(update,context)
if query.data == "Research":
#Here I need to call the following ConverstaionHandler somehow .....
query_handler = CallbackQueryHandler(Click_Button)
dispatcher.add_handler(query_handler)
这是我的对话处理程序
About = 0
handle_converstation=ConversationHandler(
'''it calls the ask_wikipedia function using command /Research now I want it to
have another entry points too and it's going to be when we press the Research
button or in another word when query.data == "Research" '''
entry_points=[CommandHandler('Research', ask_wikipedia)],
states={
About: [MessageHandler(Filters.text, callback=about)]
},
fallbacks=[CommandHandler('quit', quit)])
dispatcher.add_handler(handle_converstation)
谁能告诉我在 query.data == "Research" 时按下 Research 按钮时如何启动对话处理程序....
您可以将 CallbackQueryHandler
添加为具有属性 pattern="Research"
的入口点
所以最后你应该有这样的东西
entry_points=[CommandHandler('Research', ask_wikipedia),
CallbackQueryHandler(pattern='Research', callback=func_to_call)],
官方可以看到这个docs
并且还用于 their examples
之一(不在 entry_points
中)
我有一个按钮菜单,其中一个是 Research ,当你点击它时,它应该会问“你想知道什么?”然后收到你的答案,并从维基百科给你一个总结......
而且我希望它也可以作为命令访问,例如在您键入 /Research 时为您提供摘要 ...
现在我的代码使用 /Research 可以完美运行,因为这个命令是我的 ConverstationHandler
的 entry_point但现在我希望也可以通过按“研究”按钮来访问它:
def Click_Button(update, context):
query = update.callback_query
if query.data == "MeMe":
MeMe(update,context)
if query.data == "Joke":
Joke(update,context)
if query.data == "Research":
#Here I need to call the following ConverstaionHandler somehow .....
query_handler = CallbackQueryHandler(Click_Button)
dispatcher.add_handler(query_handler)
这是我的对话处理程序
About = 0
handle_converstation=ConversationHandler(
'''it calls the ask_wikipedia function using command /Research now I want it to
have another entry points too and it's going to be when we press the Research
button or in another word when query.data == "Research" '''
entry_points=[CommandHandler('Research', ask_wikipedia)],
states={
About: [MessageHandler(Filters.text, callback=about)]
},
fallbacks=[CommandHandler('quit', quit)])
dispatcher.add_handler(handle_converstation)
谁能告诉我在 query.data == "Research" 时按下 Research 按钮时如何启动对话处理程序....
您可以将 CallbackQueryHandler
添加为具有属性 pattern="Research"
所以最后你应该有这样的东西
entry_points=[CommandHandler('Research', ask_wikipedia),
CallbackQueryHandler(pattern='Research', callback=func_to_call)],
官方可以看到这个docs
并且还用于 their examples
entry_points
中)