Slack + Botkit:RTM关闭后自动重连

Slack + Botkit: Automatic reconnect after RTM closure

我使用 Howdy.ai's Botkit for a simple bot application and have it running on node.js on a VPS. Basically, I customized the example for a Slack App from here,现在正努力 使机器人保持活动状态 - 在一段未定义的时间后,到 Slack API 的 RTM 通道关闭而且我找不到重新连接的正确方法。到目前为止我试过了

controller.on('rtm_close',function(bot) {
   console.log('** The RTM api just closed. Trying reconnect...');
   // Try a reconnect
   bot.startRTM(function(err) {
      if (!err) {
          trackBot(bot);
      } else {
          console.log('** The RTM api couldn\'t be reopened. It\'s closed now.'); 
      }
   });
});

trackBot函数控制日志记录:

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

我似乎不知道整个方法是如何工作的。非常感谢任何帮助!

您是否尝试过使用 forever 模块? https://www.npmjs.com/package/forever

然后 运行 它与 forever stop bot.js; forever start bot.js && forever logs bot.js -f

希望对你有所帮助

要启用重新连接,您需要将 retry 配置值设置为 true

  // Launch bot
  bot = controller.spawn({
    retry: true,
    token: 'xxx'
  })

https://github.com/howdyai/botkit/blob/master/readme-slack.md#slack-controller