D
D
Danil Andreev2020-06-24 21:27:20
Python
Danil Andreev, 2020-06-24 21:27:20

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

2 answer(s)
M
meaqese, 2020-06-24
@DanilAndreev_5

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 .. ..

S
soremix, 2020-06-24
@SoreMix

What does "open" mean?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question