M
M
MinTnt2021-01-14 19:34:39
Python
MinTnt, 2021-01-14 19:34:39

How to track InlineKeyboard button click when using url parameter without callback?

Recently, I just wanted to create a button with a url, and to track its pressing, use callback_data, something like types.InlineKeyboardButton(text='Press', url = ' https://example.com ', callback_data = 'test') , but the problem is that when you click, even though a window pops up, about the proposal to follow the link, but it doesn’t seem to go.

@bot.callback_query_handler(func=lambda call: True)
def callback_worker(call):
  if call.data == 'test':
    print('Нажата кнопка')


Whole picture

@bot.message_handler(content_types=['text'])
def start(message):
  if message.text.lower() == '/test':
    keyboard = types.InlineKeyboardMarkup()
    key_note = types.InlineKeyboardButton(text='Нажми', url = 'https://example.com', callback_data = 'test')
    keyboard.add(key_note)
    bot.send_message(message.from_user.id, 'Нажми.', reply_markup = keyboard)
    @bot.callback_query_handler(func=lambda call: True)
    def callback_worker(call):
      if call.data == 'test':
        print('Нажата кнопка')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-01-14
@MinTnt

We open the documentation and see that it says in bold that you can select only one argument
https://core.telegram.org/bots/api#inlinekeyboardbutton

This object represents one button of an inline keyboard. You must use exactly one of the optional fields.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question