Как написать динамическую c клавиатуру с обработчиком разговоров в python боте telegram? - PullRequest
0 голосов
/ 14 января 2020

Я пытаюсь написать динамическую c клавиатуру (кнопки из таблицы в базе данных), но я не могу получить ответ в обработчике обратных вызовов в обработчике разговора.

enter image description here

Я не могу go перейти к следующему состоянию, в котором хранится ответ из столбца базы данных,

Мой код:

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() 
...