1
bot.onText(/(.+)$/, function (msg, match) {
    const opts = {
    reply_markup: {
      inline_keyboard: [
        [
          {
            text: 'Edit Text',
            callback_data: 'edit'
          }
        ]
      ]
    }
  };
  bot.sendMessage(msg.from.id, 'Original Text', opts);
});

bot.on("callback_query", function(callbackQuery) {
    // 'callbackQuery' is of type CallbackQuery
    console.log(callbackQuery);
});

I have looking for answer to this question, tried all the resources available on call_back. Such as Telegram bot inline keyboard via Node.JS Telegram inline keyboard and keyboard How can create menu for telegram bot in bot father?

Community
  • 1
  • 1
User1911
  • 394
  • 1
  • 5
  • 22

1 Answers1

0

How about trying this like that?

bot.on('callback_query', function onCallbackQuery(callbackQuery) {
        const action = callbackQuery.data;
        const msg = callbackQuery.message;
        // do your stuff
        if (action === 'adress') {
        // do something if callback data is "adress", you can have multiple if statements for various cases
        }
});

That's how I got it working, hope it helps!

Monochrome
  • 153
  • 2
  • 6
  • Nope it is not working. Is there any special setup needs to be done in BotFather? – User1911 Mar 26 '17 at 06:05
  • @Smit Sad to hear that. I am most certain that absolutely no setup is required to be done in BotFather. Have you tried running the example from [this page in the docs?](https://github.com/yagop/node-telegram-bot-api/blob/master/examples/polling.js) And are you sure there is no issue with your polling / webHook setup? It might also be the case: as far as I know, this stuff is responsible for dealing with any feedback the bot receives. – Monochrome Mar 26 '17 at 08:19
  • @Smit Also in the comment section for the original question (where I can't comment for now, unfortunately) you asked if the bot needs to be deployed to a server. And the answer is no, it is not required. You can absolutely handle callback queries running the bot on your machine. – Monochrome Mar 26 '17 at 08:27