Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import telebot
- bot = telebot.TeleBot("ТВОЙ ТОКЕН")
- m = telebot.types.Message
- last_messages_data = {}
- @bot.message_handler(['start'])
- def start(msg: m):
- keyboard = telebot.types.InlineKeyboardMarkup()
- data = {"Товар 1": "t_1", "Товар 2": "t_2"}
- for text, key in data.items():
- keyboard.add(telebot.types.InlineKeyboardButton(text, callback_data=key))
- bot.send_message(msg.chat.id, "Твои товары:", reply_markup=keyboard)
- @bot.callback_query_handler(func=lambda call: True)
- def callback(call: telebot.types.CallbackQuery):
- global last_messages_data
- if call.data == "t_1":
- last = t_1(call.message)
- last_messages_data[call.from_user.id] = last
- if call.data == "t_2":
- last = t_2(call.message)
- last_messages_data[call.from_user.id] = last
- if call.data == "back":
- bot.delete_message(call.message.chat.id, last_messages_data[call.from_user.id])
- def t_1(msg: m):
- keyboard = telebot.types.InlineKeyboardMarkup().add(
- telebot.types.InlineKeyboardButton("Назад", callback_data="back")
- )
- mess = bot.send_message(msg.chat.id, "Вот описание товара 1", reply_markup=keyboard)
- return mess.message_id
- def t_2(msg: m):
- keyboard = telebot.types.InlineKeyboardMarkup().add(
- telebot.types.InlineKeyboardButton("Назад", callback_data="back")
- )
- mess = bot.send_message(msg.chat.id, "Вот описание товара 2", reply_markup=keyboard)
- return mess.message_id
- bot.infinity_polling()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement