内联键盘点击不会调用callback_query为什么?

时间:2017-03-23 14:25:49

标签: javascript telegram-bot

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);
});

我一直在寻找这个问题的答案,尝试了call_back上的所有可用资源。如 Telegram bot inline keyboard via Node.JS Telegram inline keyboard and keyboard How can create menu for telegram bot in bot father?

1 个答案:

答案 0 :(得分:0)

这样尝试怎么样?

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
        }
});

这就是我如何运作,希望它有所帮助!