单击电报中的菜单按钮后显示文本消息

时间:2019-05-25 09:32:13

标签: python telegram telegram-bot python-telegram-bot

  1. 添加第四个类别“关于”

  2. 点击“关于”会发送一条短信,例如“自1999年开始运营”

这是代码段:

def main_menu_keyboard():
    keyboard = [[InlineKeyboardButton('Bubble Tea', callback_data='m1')],
                  [InlineKeyboardButton('Waffle', callback_data='m2')],
                  [InlineKeyboardButton('Otah', callback_data='m3')]]
    return InlineKeyboardMarkup(keyboard)

enter image description here

# Add command handler to dispatcher
updater.dispatcher.add_handler(CommandHandler('start', start))
updater.dispatcher.add_handler(CallbackQueryHandler(main_menu, pattern='main'))
updater.dispatcher.add_handler(CallbackQueryHandler(first_menu, pattern='m1'))
updater.dispatcher.add_handler(CallbackQueryHandler(second_menu, pattern='m2'))
updater.dispatcher.add_handler(CallbackQueryHandler(third_menu,pattern='m3'))

我一直在尝试如下所示的不同方式来显示文本,但不太确定如何与调度程序一起将它们拼凑在一起

bot.send_message(chat_id=chat_id, text="About xxxxx details ")   
update.message.reply_text("About xxxx details ")

1 个答案:

答案 0 :(得分:1)

  

添加第四个类别“关于”

def main_menu_keyboard():
    keyboard = [[InlineKeyboardButton('Bubble Tea', callback_data='m1')],
                  [InlineKeyboardButton('Waffle', callback_data='m2')],
                  [InlineKeyboardButton('Otah', callback_data='m3')],
                  [InlineKeyboardButton('About', callback_data='m4')]]  # new button
    return InlineKeyboardMarkup(keyboard)
  

点击“关于”会发送一条短信,例如“自1999年开始运营”

def about_message(bot, update):  # handler for "About" button
    bot.send_message(chat_id=update.callback_query.from_user.id, text="Operating since 1999")  

# ... other existing code

# Add command handler to dispatcher
updater.dispatcher.add_handler(CommandHandler('start', start))
updater.dispatcher.add_handler(CallbackQueryHandler(main_menu, pattern='main'))
updater.dispatcher.add_handler(CallbackQueryHandler(first_menu, pattern='m1'))
updater.dispatcher.add_handler(CallbackQueryHandler(second_menu, pattern='m2'))
updater.dispatcher.add_handler(CallbackQueryHandler(third_menu, pattern='m3'))
updater.dispatcher.add_handler(CallbackQueryHandler(about_message, pattern='m4'))  # add handler for "About" button

# ... other existing code