1

I am making a telegram-bot in NodeJS. This is a code snippet I am having an issue with:

    let counter = 0
    
    bot.onText(/\flexbox (.+)/i, async (msg, match) => {
    console.log(msg)
    console.log(match)
    const chatId = msg.chat.id;
    bot.sendMessage(msg.from.id, 'Original Text', {
        reply_markup: {
            inline_keyboard: [
                [
                    {
                        text: `sample text`,
                        callback_data: 'callbackData',
                        url: `https://example.com`,
                    }
                ]
            ]
        }
    });
    bot.on('callback_query', function onCallbackQuery(callbackQuery) {
      // increment counter when everytime the button is pressed
      counter = counter + 1
      console.log(counter)
    });

So basically what I am trying to achieve is that whenever the user clicks on the button, I want to increment the counter so that I can have a track/count of the total button clicks. The callback function is not getting triggered at all if I use the field url in the inline_keyboard. If I remove the url field the callback is triggered.

Can someone help me achieve this functionality?

Tiarait
  • 175
  • 1
  • 12
Karthik Varma
  • 121
  • 1
  • 7

2 Answers2

0

The API Documnetation explains that exactly one of the fields data or game_short_name will be present in a callback_query update. This means that the bot gets notified if and only if the button had a data field or a callback_game defined for it. Since your button has neither of them, pressing the button will not notify the bot.

0

Please remove the tag py-telegram-bot-api, py is for python.