Answer the question
In order to leave comments, you need to log in
Python Telegram bot how to make response on button click?
I'm learning Python, I ran into a problem:
if call.data == "first":
keyboard = types.InlineKeyboardMarkup()
rele_1 = types.InlineKeyboardButton(text="Apple iPhone 11", callback_data="1")
rele_2 = types.InlineKeyboardButton( text="Apple iPhone SE", callback_data="2")
rele_3 = types.InlineKeyboardButton(text="Apple iPhone XS", callback_data="3")
rele_4 = types.InlineKeyboardButton(text="Apple iPhone XR", callback_data= "4")
rele_5 = types.InlineKeyboardButton(text="Apple iPhone 8", callback_data="5")
rele_6 = types.InlineKeyboardButton(text="Apple iPhone 7", callback_data="6")
rele_7 = types.InlineKeyboardButton(text="Apple iPhone 6s", callback_data="7")
backbutton = types.InlineKeyboardButton(text="Back", callback_data="mainmenu")
keyboard.add(rele_1, rele_2, rele_3, rele_4, rele_5, rele_6, rele_7, backbutton)
bot.edit_message_text(chat_id=call.message.chat. id,message_id=call.message.message_id, text="Select a model:",reply_markup=keyboard)
The bottom line is that when I click on one of the buttons, the bot opens the phone's characteristics, how can I arrange this?
Answer the question
In order to leave comments, you need to log in
There are many options, here is one of the most primitive ones: Write a callback handler for each, for example, if the callback == 5, then we send the IPhone 7 characteristics to the client. Of course, this is just an example, I think it's best to implement it through the database, but that's a completely different story .. ..
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question