Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 电报机器人-如何绑定带回调查询的InlineKeyboardButton_Javascript_Node.js_Telegram_Telegram Bot - Fatal编程技术网

Javascript 电报机器人-如何绑定带回调查询的InlineKeyboardButton

Javascript 电报机器人-如何绑定带回调查询的InlineKeyboardButton,javascript,node.js,telegram,telegram-bot,Javascript,Node.js,Telegram,Telegram Bot,我正在使用节点电报机器人api。我会有多个,并用不同的throw-answerCallbackQuery方法绑定它们。你能给我举个例子吗?谢谢。我使用了以下解决方法: ... var eventEmitter = new events.EventEmitter(); eventEmitter.on('my_fancy_event_1', function(){ ... }) eventEmitter.on('my_fancy_event_2', function(){ ... })

我正在使用节点电报机器人api。我会有多个,并用不同的throw-answerCallbackQuery方法绑定它们。你能给我举个例子吗?谢谢。

我使用了以下解决方法:

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