import telebot from telebot import types bot = telebot.TeleBot(TELEGRAM_TOKEN, parse_mode=None) markup_menu = types.ReplyKeyboardMarkup(resize_keyboard=True) btns = ["Order"] for btn in btns: markup_menu.add(types.KeyboardButton(btn)) menu = {"Snacks": {"Sweet Snack": 150, "Salt snak": 320}, "Drinks": {"Cola": 100, "Sprite": 90}, "Meat": {"Pork": 228, "Beef": 56}} @bot.message_handler(commands=['start']) def start(message): bot.send_message(message.chat.id, f"Wellcome, {message.from_user.first_name}", reply_markup=markup_menu, parse_mode="html") @bot.message_handler(content_types="text") def order(message): # These are variable values to help change next message after "Choose category:" order_counter = 0 product_message = 0 switcher = {product_message: order_counter} if message.text == 'Order': order_menu = types.InlineKeyboardMarkup() order_menu.row_width = 2 for category in menu: order_menu.add(types.InlineKeyboardButton(category, callback_data=f"{category}")) bot.send_message(message.chat.id, "Choose category:", reply_markup=order_menu) if order_counter == 0: @bot.callback_query_handler(func=lambda call: call.data in menu.keys()) def callback_product(call): product_menu = types.InlineKeyboardMarkup() product_menu.row_width = 4 for product in menu[call.data]: product_menu.add(types.InlineKeyboardButton (f"{product}" + f" - {menu[call.data][product]}", callback_data=f"{product}") ) product_message = bot.send_message(message.chat.id, f'Choose {call.data}:', reply_markup=product_menu, ) product_message order_counter == 1 switcher = {product_message: order_counter} return switcher elif switcher.keys() == 1: @bot.callback_query_handler(func=lambda call: call.data in menu.keys()) def callback_product1(call): product_menu = types.InlineKeyboardMarkup() product_menu.row_width = 4 for product in menu[call.data]: product_menu.add(types.InlineKeyboardButton (f"{product}" + f" - {menu[call.data][product]}", callback_data=f"{product}") ) product_message = bot.edit_message_text(chat_id=switcher[0][0].message.chat.id, message_id=switcher[0][0].message_id, text=f'Choose {call.data}:', reply_markup=product_menu ) product_message order_counter == 1 return order_counter, product_message @bot.message_handler(content_types="text") def missunderstand(message): bot.reply_to(message, "I don't understand you", reply_markup=markup_menu) bot.infinity_polling()