Answer the question
In order to leave comments, you need to log in
How to properly organize the work of callback buttons?
Hello!
I use the PyTelegramBotApi library
The database has a list of URLs, which is constantly updated, the number of addresses increases accordingly. It is necessary to make it convenient to view the URL in the telegram bot.
Task: it is
necessary to organize the work of callback buttons in such a way that when you click on the next_url button, the bot changes the content of the message in accordance with a specific URL.
I hope I explained clearly.
That is, you press the next_url button -> the content of the message changes to the next URL, the url of the get_url button changes, etc.
There are ideas how to do this with a constantly changing number of URLs, because the number of callback_data also changes.
Here is a simple code for discussion:
@bot.message_handler(func=lambda message: message.text == 'message')
def idea(message):
markup = types.InlineKeyboardMarkup()
k1 = types.InlineKeyboardButton(text='get_url', url='http://url.ru')
k2 = types.InlineKeyboardButton(text='prev_url', callback_data='1')
k3 = types.InlineKeyboardButton(text='next_url', callback_data='2')
markup.add(k1)
markup.add(k2, k3)
bot.send_message(text='URL Title', chat_id=message.chat.id, reply_markup=markup)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question