What should be done, so that when clicking on the InlineKeyboardButton URL button, an action was taken before following the link, for example, adding a record to the database. An event similar to onclick in js, but I can't find anything like it in the documentation.
- it is impossible by regular means - Anatol
- And how can this be realized? Or how to initiate the transition to the link without pressing a button - Ivan Demyanov
|
2 answers
Forced user redirection by reference ( opening the browser ) is impossible.
Try using a bitly service to track click statistics. If you need to record some data about the user in the database and the link leads to your web service, then add the necessary data to the link parameters and save to the database on the web service side.
|
For example, register button
keyboard = telebot.types.InlineKeyboardMarkup() key_help = telebot.types.InlineKeyboardButton(text="\u2139 Что я умею?", callback_data="help") keyboard.add(key_help) key_search = telebot.types.InlineKeyboardButton(text="\ud83d\udd0d Искать программу", callback_data="search") keyboard.add(key_search) Next, write the function callback
@bot.callback_query_handler(func=lambda call: True) def callback_inline(call): if call.message: if call.data == "search": search(call.message) elif call.data == "help": send_help(call.message) - oneIn the buttons when they are exactly c URL can not configure callback_data. InlineKeyboardButton (text = "Go", url = " yandex.ru ", callback_data = "1") tried to write like this gives an error - Ivan Demyanov
- And in more detail what kind of error? Can callback_data not need to be specified? - SnakeMS pm
- TypeError: add () got an unexpected keyword keyword argument 'callback_data' - Ivan Demyanov
|