如何使用Python在telegram bot上创建菜单然后再创建子菜单?

时间:2018-01-30 16:30:23

标签: python-2.7 bots telegram-bot submenu

我想用python创建一个电报机器人。

首先,当用户发送/start command时,机器人会发送给他/她并发送欢迎消息。然后它要求用户点击菜单按钮。之后,我希望机器人将新键盘显示为子菜单(例如6个按钮)。

这是我的代码:

from telegram import ReplyKeyboardMarkup , reply_markup
from telegram.ext import Updater , CommandHandler
from emoji import emojize

updater = Updater("token")

def start(bot , update):
    chat_id = update.message.chat_id
    text1 = emojize(':rose: <b>Welcome to ....!</b> :rose: \n \n :information_source: In this bot you can .....  \n \n >> Lets Start!', use_aliases=True)
    bot.sendMessage(chat_id=chat_id, text=text1, parse_mode='html')

mainbutton = [
    ['Menu']
]

keyBoard1 = ReplyKeyboardMarkup(mainbutton , resize_keyboard=True)
bot.sendMessage(chat_id=chat_id , text="Click on Menu" , reply_markup=keyBoard1)

def menu(bot , update):
    chat_id = update.message.chat_id
    bot.sendMessage(chat_id=chat_id , text='test' , parse_mode='html')

menubuttons = [
    ['btn1' , 'btn2' ,'btn3'],
    ['btn4' , 'btn5' ,'btn6']
]

keyBoard2 = ReplyKeyboardMarkup(menubuttons, resize_keyboard=True)
bot.sendMessage(chat_id=chat_id , text='Please choose one:', reply_markup=keyBoard2)

command_start = CommandHandler('start', start)
updater.dispatcher.add_handler(command_start)

command_Menu = CommandHandler('menu' , menu)
updater.dispatcher.add_handler(command_Menu)

# Start my bot
updater.start_polling()
updater.idle()

1 个答案:

答案 0 :(得分:0)

您将需要构建一个可以单击“下一步”按钮并生成下一个菜单的功能。