如何在python电报机器人中使用conversationhandler编写动态键盘?
我正在尝试编写动态键盘(数据库表中的按钮),但无法在对话处理程序中的callbackqueryhandler中获得响应 我无法进入下一个状态,即从数据库列存储的响应 我的代码:如何在python电报机器人中使用conversationhandler编写动态键盘?,python,telegram,python-telegram-bot,Python,Telegram,Python Telegram Bot,我正在尝试编写动态键盘(数据库表中的按钮),但无法在对话处理程序中的callbackqueryhandler中获得响应 我无法进入下一个状态,即从数据库列存储的响应 我的代码: def menu(update,context): bot = context.bot name = db_execute("SELECT event_name FROM menu ", fetchall=True) button_list = [] for each in name:
def menu(update,context):
bot = context.bot
name = db_execute("SELECT event_name FROM menu ", fetchall=True)
button_list = []
for each in name:
button_list.append(InlineKeyboardButton(each, callback_data = each))
reply_markup = InlineKeyboardMarkup(build_menu(button_list,n_cols=1))
bot.send_message(chat_id=update.message.chat_id, text='Choose from the following',reply_markup=reply_markup)
return FIRST
def one(update, context):
query = update.callback_query
bot = context.bot
print(query)
name = db_execute("SELECT event_name FROM menu ", fetchall=True)
content = db_execute("SELECT event_content FROM menu ", fetchall=True)
post = dict(zip(name, content))
for k,v in post.items():
if query == k:
bot.edit_message_text(chat_id=query.message.chat_id,
message_id=query.message.message_id,
text= "{}".format(v),
reply_markup=reply_markup
)
return SECOND
updater = Updater(token , use_context=True)
create_db()
dp = updater.dispatcher
conv_handler = ConversationHandler(
entry_points=[CommandHandler('menu', menu)],
states={
FIRST: [CallbackQueryHandler(one)],
SECOND: [CallbackQueryHandler(end)]
},
fallbacks=[CommandHandler('menu', menu)]
)
dp.add_handler(conv_handler)
updater.start_polling()