最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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);
});
发布评论

评论列表(0)

  1. 暂无评论