javascript - Telegram Bot - How bind an InlineKeyboardButton with a CallbackQuery - Stack Overflow

I'm using node-telegram-bot-api. I would have multiple InlineKeyboardButton and bind them with dif

I'm using node-telegram-bot-api. I would have multiple InlineKeyboardButton and bind them with different CallbackQuery throw answerCallbackQuery method. Can you show me an example please? Thank you.

I'm using node-telegram-bot-api. I would have multiple InlineKeyboardButton and bind them with different CallbackQuery throw answerCallbackQuery method. Can you show me an example please? Thank you.

Share Improve this question edited Dec 21, 2016 at 21:12 Matteo Enna 1,3011 gold badge15 silver badges36 bronze badges asked Dec 20, 2016 at 11:28 Luca MottaLuca Motta 3313 silver badges14 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

I have used the following workaround:

...
var eventEmitter = new events.EventEmitter();


eventEmitter.on('my_fancy_event_1', function(){
  ...
})

eventEmitter.on('my_fancy_event_2', function(){
  ...
})

eventEmitter.on('my_fancy_event_3', function(){
  ...
})


var options = {
  polling: true
};

...

var bot = new TelegramBot(token, options);

bot.onText(config.mands.mandStart, function onMessage(msg) {
  var options = {
    reply_markup: {
        inline_keyboard: [
            [{text: config.inlineText.addPurchase, callback_data: 'my_fancy_event_1'}],
            [{text: config.inlineText.addRevenue, callback_data: 'my_fancy_event_2'}],
            [{text: config.inlineText.getReport, callback_data: 'my_fancy_event_3'}]
        ]
    }
};
bot.sendMessage(msg.from.id, "Choose an operation.",options);
});

bot.on('callback_query', function onCallbackQuery(callbackQuery) {
   eventEmitter.emit(callbackQuery.data);
   bot.answerCallbackQuery(callbackQuery.id, "Hi", false);
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745145188a4613615.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信