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 badges1 Answer
Reset to default 7I 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);
});