Forums

How to conditionally execute correctly?

@bot.message_handler(commands=['start']) def get_filial(message: types.Message): markup_inline_filial=types.InlineKeyboardMarkup() item_shop1=types.InlineKeyboardButton(text='Shop1', callback_data='shop1') item_shop2=types.InlineKeyboardButton(text='Shop2', callback_data='shop2') markup_inline_filial.add(item_shop1,item_shop2)

@bot.callback_query_handler(func=lambda call:call.data=='shop1') def get_select_button_shop1(call: types.CallbackQuery): markup_inline_item=types.InlineKeyboardMarkup() markup_inline_item.add() bot.edit_message_text(chat_id=call.message.chat.id,message_id=call.message.id,text="Choose
one:",reply_markup=markup_inline_item)

@bot.message_handler()
def message_handler_shop1(message):
    if message.text in ['1','2','3','4']:
        send_docs_shop1(message)
    else:
        send_query_shop1(message)

def send_docs_shop1(message):
    file_source=open(f"E:\shop1_{message.text}.csv")
    bot.send_document(message.chat.id, file_source)

def send_query_shop1(message):
    bot.send_document(message.chat.id, "Hello from shop1")

@bot.callback_query_handler(func=lambda call:call.data=='shop2')
def get_select_button_shop2(call: types.CallbackQuery):
    markup_inline_item=types.InlineKeyboardMarkup()
    markup_inline_item.add()
    bot.edit_message_text(chat_id=call.message.chat.id,message_id=call.message.id,text="Choose 
one:",reply_markup=markup_inline_item)

@bot.message_handler()
def message_handler_shop2(message):
    if message.text =='o':
        send_docs_shop2(message)
    else:
        send_query_shop2(message)

def send_docs_shop2(message):
    file_source=open(f"E:\shop2_{message.text}.csv")
    bot.send_document(message.chat.id, file_source)

def send_query_shop2(message):
    bot.send_document(message.chat.id, "Hello from shop2")

I need that when "Shop1" is selected, the code for "shop1" is executed, and when "Shop2" is selected, the code for "shop2" is executed.

Currently both "Shop1" and "Shop2" execute "Shop1".

There are multiple references to shop1 and shop2 in your code and you have not made it clear in your question which of them is exhibiting the problem.