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?