I want to create a telegram bot with python.
First when a user sends /start command
, the bot send him/her and a welcome message. Then it ask users to click on menu button. After that, I want the bot to show new keyboard as sub-menu (for example 6 buttons).
Here is my code:
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()