Answer the question
In order to leave comments, you need to log in
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('Нажата кнопка')
@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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question