0

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()
Omar Einea
  • 2,478
  • 7
  • 23
  • 35
farid
  • 1
  • 1
  • 2
  • https://stackoverflow.com/a/42621392/7828402 this url shows your near logic of code exactly you wants. – VISHAL LIMGIRE Feb 13 '18 at 12:43
  • I suggest that you can find ways through this code. https://stackoverflow.com/questions/51125356/proper-way-to-build-menus-with-python-telegram-bot – Kunwoo Kim Aug 22 '19 at 00:24

1 Answers1

0

You will need to build a function that will catch "next" button and generate next menu.