Botkit多次获得回复

时间:2016-08-28 21:13:36

标签: node.js slack-api slack botkit

我使用Botkit和wit.ai创建了一个机器人。它运行得非常好。但是,经过一段时间后,我开始从机器人那里收到多条消息。重新启动node.js服务后,它开始正常工作。

这是我写的代码,

const _bots = {};
function trackBot(bot) {
  _bots[bot.config.token] = bot;
}

 const controller = Botkit.slackbot({
     json_file_store: './db_slackbutton_bot/',
     logger: new winston.Logger({
       transports: [
        new (winston.transports.Console)(),
        new (winston.transports.File)({ filename: './bot.log' })
       ]
      }),
     debug: true
 })
 .configureSlackApp({
   clientId: config.slack.clientId,
   clientSecret: config.slack.clientSecret,
   scopes: ['bot'],
 });

 // Handle events related to the websocket connection to Slack

controller.on('rtm_open',function(bot) {
  console.log('** The RTM api just connected!');
});

controller.on('rtm_close',function(bot) {
  // you may want to attempt to re-open
  console.log('** The RTM api just closed');
  bot.startRTM(function(err) {
    if (!err) {
      trackBot(bot);
    }
  });
});



/*
  code for starting RTM
*/
controller.storage.teams.all(function(err,teams) {
  if (err) {
    throw new Error(err);
  }

  // connect all teams   with bots up to slack!
  for (var t  in teams) {
    if (teams[t].bot) {
      controller.spawn(teams[t]).startRTM(function(err, bot) {
        if (err) {
          console.log('Error connecting bot to Slack:',err);
        } else {
          trackBot(bot);
        }
      });
    }
  }
});

我无法弄清楚代码中的问题。这些错误日志中的错误很少,

{"level":"error","message":"** BOT ID: after5 ...reconnect failed after #4 attempts and 8050ms","timestamp":"2016-08-26T10:53:19.175Z"}
{"level":"error","message":"Abnormal websocket close event, attempting to reconnect","timestamp":"2016-08-27T03:08:30.972Z"}

以及消息的屏幕截图

enter image description here

0 个答案:

没有答案