Как сделать многоуровневое reply-меню телеграмм бота, библиотека pytelegrambotapi python
Есть код, с двух уровневым меню, помогите в разделе "многоразовые под-системы" сделать меню с 3 разделами(Н: многоразовые под-системы -> smoant -> knigt, под-системы -> smoant -> pasito и дальше список моделей этого производителя).Пока что только под-системы -> smoant
import telebot
import random
import sqlite3
from telebot import types
bot = telebot.TeleBot("TOKEN")
db = sqlite3.connect('db.db')
@bot.message_handler(commands=["start"])
def start(message):
sti = open("File/hi.webp", "rb")
bot.send_sticker(message.chat.id, sti)
mess = f"Привет, {message.from_user.first_name} {message.from_user.last_name} я твой личный помощник в выборе товара в магазине TumanPlace"
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
item1 = types.KeyboardButton("Жидкости")
item2 = types.KeyboardButton("Одноразовые pod-системы")
item3 = types.KeyboardButton("Многоразовые pod-системы")
btn4 = types.KeyboardButton('Наша локация')
markup.add(item1, item2, item3, btn4)
bot.send_message(message.chat.id, mess, parse_mode="html")
bot.send_message(message.chat.id, "Чем я могу помочь?", reply_markup=markup)
@bot.message_handler(content_types=['text'])
def items(message):
get_message_bot = message.text
@bot.message_handler(commands=["address"])
def address(message):
bot.send_location(message.chat.id, 56.144607, 40.419294)
if get_message_bot == "начать тест заново":
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)
btn1 = types.KeyboardButton('Жидкости')
btn2 = types.KeyboardButton('Одноразовые pod-системы')
btn3 = types.KeyboardButton('Многоразовые pod-системы')
btn4 = types.KeyboardButton('Наша локация')
markup.add(btn1, btn2, btn3, btn4)
final_message = "Чтобы вы хотели выбрать?"
elif get_message_bot == "Жидкости":
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)
btn1 = types.KeyboardButton('SOAK')
btn2 = types.KeyboardButton('HASKY')
btn3 = types.KeyboardButton('ЧТО-НИБУДЬ')
btn4 = types.KeyboardButton('DUALL')
btn5 = types.KeyboardButton('KAPUSTA')
btn6 = types.KeyboardButton('RELL')
btn7 = types.KeyboardButton('HOTSPOT')
btn8 = types.KeyboardButton('PLATINUM')
btn9 = types.KeyboardButton('MRAZZI')
btn10 = types.KeyboardButton('BOSHKI')
btn11 = types.KeyboardButton('DABLER')
btn12 = types.KeyboardButton('PADONKI')
btn13 = types.KeyboardButton('МИШКА')
btn14 = types.KeyboardButton('GLITCH SALT')
btn15 = types.KeyboardButton("Начать тест заново")
markup.add(btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btn10, btn11, btn12, btn13, btn14, btn15)
final_message = "Отлично, выберите еще пожалуйста"
elif get_message_bot == "Одноразовые pod-системы":
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)
btn1 = types.KeyboardButton('WIPO')
btn2 = types.KeyboardButton('PUFFMI')
btn3 = types.KeyboardButton('LOST MARY')
btn4 = types.KeyboardButton('SNOWWOOF')
btn5 = types.KeyboardButton('ATTACKER')
btn6 = types.KeyboardButton('SUPSMOK')
btn7 = types.KeyboardButton('HQD')
btn8 = types.KeyboardButton('LIO')
btn9 = types.KeyboardButton('LIO&UDN')
btn10 = types.KeyboardButton('LIO BOOM')
btn11 = types.KeyboardButton('ELFBAR')
btn12 = types.KeyboardButton('DRAGBAR')
btn13 = types.KeyboardButton('SOAK')
btn14 = types.KeyboardButton('UDN GEN')
btn15 = types.KeyboardButton("Начать тест заново")
markup.add(btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btn10, btn11, btn12, btn13, btn14, btn15)
final_message = "Отлично, выберите еще пожалуйста"
elif get_message_bot == "Многоразовые pod-системы":
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)
btn1 = types.KeyboardButton('Smoant')
btn2 = types.KeyboardButton('Vaporesso')
btn3 = types.KeyboardButton('GeekVape')
btn4 = types.KeyboardButton('VooPoo')
btn5 = types.KeyboardButton('JellyBox')
btn6 = types.KeyboardButton('Brusko')
btn7 = types.KeyboardButton('Rincoe')
btn8 = types.KeyboardButton('Nevoks')
btn9 = types.KeyboardButton('Smok')
btn10 = types.KeyboardButton("Начать тест заново")
final_message = "Осталось выбрать бренд который вам понравится :)"
markup.add(btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9)
@bot.message_handler(content_types=['text'])
def items2(message):
get_message_bot = message.text
if get_message_bot == "Smoant":
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
btn1 = types.KeyboardButton('PASITO II')
btn2 = types.KeyboardButton('CHARON BABY')
btn3 = types.KeyboardButton('CHARON BABY PLUS')
btn4 = types.KeyboardButton('KNIGHT 80')
btn5 = types.KeyboardButton('PASITO MINI')
btn6 = types.KeyboardButton('SANTI')
btn7 = types.KeyboardButton('KNIGHT 40')
btn8 = types.KeyboardButton("Начать тест заново")
markup.add(btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8)
final_message = "***ИНФОРМАЦИЯ***"
elif get_message_bot == "Vaporesso":
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
btn1 = types.KeyboardButton('XROS')
btn2 = types.KeyboardButton('XROS 2')
btn3 = types.KeyboardButton('XROS 3')
btn4 = types.KeyboardButton('XROS mini')
btn5 = types.KeyboardButton('XTRA')
btn6 = types.KeyboardButton("Начать тест заново")
markup.add(btn1, btn2, btn3, btn4, btn5, btn6)
final_message = "***ИНФОРМАЦИЯ***"
elif get_message_bot == "GeekVape":
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
btn1 = types.KeyboardButton('HERO H45')
btn2 = types.KeyboardButton('HERO')
btn3 = types.KeyboardButton('B100')
btn4 = types.KeyboardButton('NANO')
btn5 = types.KeyboardButton('ONE')
btn6 = types.KeyboardButton('OBELISK 65PS')
btn7 = types.KeyboardButton("Начать тест заново")
markup.add(btn1, btn2, btn3, btn4, btn5, btn6, btn7)
final_message = "***ИНФОРМАЦИЯ***"
elif get_message_bot == "VooPoo":
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
btn1 = types.KeyboardButton('DRAG S')
btn2 = types.KeyboardButton('DRAG X')
btn3 = types.KeyboardButton('DRAG H80S')
btn4 = types.KeyboardButton('DRAG X PRO')
btn5 = types.KeyboardButton('DRAG S PRO')
btn6 = types.KeyboardButton('DRAG NANO 2')
btn7 = types.KeyboardButton('ARGUS AIR')
btn8 = types.KeyboardButton('ARGUS')
btn9 = types.KeyboardButton('VTHRU PRO')
btn10 = types.KeyboardButton('VTHRU')
btn11 = types.KeyboardButton('VINCI')
btn12 = types.KeyboardButton("Начать тест заново")
markup.add(btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btn10, btn11, btn12)
final_message = "***ИНФОРМАЦИЯ***"
elif get_message_bot == "JellyBox":
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
btn1 = types.KeyboardButton('NANO')
btn2 = types.KeyboardButton('AIR X')
btn3 = types.KeyboardButton("Начать тест заново")
markup.add(btn1, btn2, btn3)
final_message = "***ИНФОРМАЦИЯ***"
elif get_message_bot == "Brusko":
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
btn1 = types.KeyboardButton('MINICAN')
btn2 = types.KeyboardButton('MINICAN 2')
btn3 = types.KeyboardButton('MINICAN PLUS')
btn4 = types.KeyboardButton("Начать тест заново")
markup.add(btn1, btn2, btn3, btn4)
final_message = "***ИНФОРМАЦИЯ***"
elif get_message_bot == "Rincoe":
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
btn1 = types.KeyboardButton('MANTO AIO')
btn2 = types.KeyboardButton('MANTO AIO PLUS')
btn3 = types.KeyboardButton("Начать тест заново")
markup.add(btn1, btn2, btn3)
final_message = "***ИНФОРМАЦИЯ***"
elif get_message_bot == "Nevoks":
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
btn1 = types.KeyboardButton('FEELIN')
btn2 = types.KeyboardButton('FEELIN X')
btn3 = types.KeyboardButton("Начать тест заново")
markup.add(btn1, btn2, btn3)
final_message = "***ИНФОРМАЦИЯ***"
elif get_message_bot == "Smok":
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
btn1 = types.KeyboardButton('RPM 4')
btn2 = types.KeyboardButton('RPM 3')
btn3 = types.KeyboardButton('NFIX')
btn4 = types.KeyboardButton('NOVO 2')
btn5 = types.KeyboardButton('NORD PRO')
btn6 = types.KeyboardButton("Начать тест заново")
markup.add(btn1, btn2, btn3, btn4, btn5, btn6)
final_message = "***ИНФОРМАЦИЯ***"
else:
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)
btn1 = types.KeyboardButton('Smoant')
btn2 = types.KeyboardButton('Vaporesso')
btn3 = types.KeyboardButton('GeekVape')
btn4 = types.KeyboardButton('VooPoo')
btn5 = types.KeyboardButton('JellyBox')
btn6 = types.KeyboardButton('Brusko')
btn7 = types.KeyboardButton('Rincoe')
btn8 = types.KeyboardButton('Nevoks')
btn9 = types.KeyboardButton('Smok')
btn10 = types.KeyboardButton("Начать тест заново")
markup.add(btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btn10)
final_message = "Ой неполадка :)"
elif message.text == "Наша локация":
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
bot.send_location(message.chat.id, 56.144607, 40.419294)
final_message = "Мы здесь"
else:
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)
btn1 = types.KeyboardButton('Жидкости')
btn2 = types.KeyboardButton('Одноразовые pod-системы')
btn3 = types.KeyboardButton('Многоразовые pod-системы')
btn4 = types.KeyboardButton('Наша локация')
markup.add(btn1, btn2, btn3, btn4)
final_message = "Выберите тип товара"
bot.send_message(message.chat.id, final_message, parse_mode='html', reply_markup=markup)
bot.polling(none_stop=True)
Источник: Stack Overflow на русском