Reputation: 331
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.
Upvotes: 3
Views: 3563
Reputation: 331
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.commands.commandStart, 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);
});
Upvotes: 7