You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! I'm completely new to programming.
I use pyTelegramBotAPI.
I want my TG bot to have inlinebuttons with categories and subcategories in chat with dynamic change.
But how to send message with subcategories if it doesnt exist and edit message with subcategories if it already exists?
Also, I wish to have a "back" inlinebutton among categories that will delete messages with categories and subcategories and turn to main menu.
I have tried to create a switcher that would signal to func. if message with subcategories exists, but it didn't work.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello! I'm completely new to programming.
I use pyTelegramBotAPI.
I want my TG bot to have inlinebuttons with categories and subcategories in chat with dynamic change.
But how to send message with subcategories if it doesnt exist and edit message with subcategories if it already exists?
Also, I wish to have a "back" inlinebutton among categories that will delete messages with categories and subcategories and turn to main menu.
I have tried to create a switcher that would signal to func. if message with subcategories exists, but it didn't work.
Attached my code and illustration of goal.
Help me please!
inline_edit.txt
[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
bot.infinity_polling()]
Beta Was this translation helpful? Give feedback.
All reactions