Проблема с декоратором callback_query_handler (с кнопками)
Новичок, создаю бота с помощью telebot на python 3.11. Хочу чтобы удалялись сами кнопки и сообщение, содержащее эти кнопки, после нажатия на одну из кнопок при выборе языка, они действительно удаляются и выводится соответствующее уведомление "Language preference saved"; но другие кнопки также задействованы в моем боте уже при выдаче списка блюд и при нажатии на них теперь сообщение с этими кнопками (и сами кнопки) тоже удаляется и выводится то же уведомление, что и при выборе языка. Подскажите, пожалуйста, как сделать так, чтобы удалялось сообщение с кнопками только относящиеся к выбору языка, и только в этом случае выводилось уведомление; а при нажатии на кнопки с названиями блюд сообщение с кнопками уже не удалялось и уведомление не выводилось. Код выбора языка:
@bot.callback_query_handler(func=lambda call: True)
def handle_language_selection(call):
user_id = call.message.chat.id
user_language = call.data
if user_language == 'ru':
bot.send_message(user_id, 'Введите список ингредиентов, разделенных запятыми: ')
elif user_language == 'en':
bot.send_message(user_id, 'Please enter the list of ingredients separated by commas')
set_user_language(user_id, user_language)
bot.answer_callback_query(call.id, text="Language preference saved.")
bot.delete_message(user_id, call.message.message_id)
Код с кнопками названий блюд:
@bot.message_handler(func=lambda message: True)
def get_recipes(message):
ingredients_list = message.text.split(",")
url = "https://api.spoonacular.com/recipes/findByIngredients"
params = {
"ingredients": ",".join(ingredients_list),
"number": "14",
"apiKey": api_key
}
response = requests.get(url, params=params)
recipes = response.json()
if "message" in recipes:
bot.send_message(message.chat.id, f"Error occurred {recipes['message']}")
return
recipe_titles = [recipe["title"] for recipe in recipes]
recipe_ids = [recipe["id"] for recipe in recipes]
if len(recipe_titles) > 0:
markup = types.InlineKeyboardMarkup(row_width=2)
for title, recipe_id in zip(recipe_titles, recipe_ids):
button = types.InlineKeyboardButton(title, callback_data=recipe_id)
markup.add(button)
bot.send_message(message.chat.id, "Please choose a dish:", reply_markup=markup)
else:
bot.send_message(message.chat.id, "Sorry, I couldn't find dishes with these ingredients. Try again after a while.")