slack-bot-api icon indicating copy to clipboard operation
slack-bot-api copied to clipboard

Publish Latest Version to NPM

Open eponymz opened this issue 6 years ago • 5 comments

Seems that the disconnect issue mentioned multiple times has been addressed.. Can you please publish this to NPM so we can benefit from this? I am tired of silent disconnects from the bot with the server still living.

eponymz avatar Oct 15 '18 21:10 eponymz

Wrote up #110 to allow custom handling of disconnects.

eponymz avatar Oct 15 '18 21:10 eponymz

I need this.

motionharvest avatar Oct 24 '18 12:10 motionharvest

@motionharvest this is the workaround i have found to be successful (just confirmed today) on the bot im working with

let bot
const startBot = () => {
  bot = new SlackBot({
    token: // bot token,
    name: // app name
  })
  bot.on('start', err => {
    if (err) {
      massLog.genWarn(`Issues connecting RTM ${err}`)
      // login function is what actually starts the RTM connection. set retry to 10 secs if fail
      setTimeout(bot.login(), 10000)
    }
    massLog.genInfo(`bot has started successfully`)
  })
  /**
   * The 'close' event refers to the Slack server closing the RTM connection
   * adding startBot() to the close event handler and wrapping in a try catch "should" remedy silent disconnects.
  */
  bot.on('close', err => {
    try {
      // this will attempt to reconnect before failing the bot. Will also log the error that occurred.
      if (err) {
        massLog.genErr(`Error ${err} occured. Retrying RTM connect.`)
        startBot()
      }
    } catch (err) {
      massLog.genErr(`Bot crashed.. \n ${err}`)
    }
  })
  bot.on('error', err => {
    massLog.genErr(err.stack)
  })
  bot.on('message', async message => {
    // handling message event
  }
}
startBot()

eponymz avatar Oct 25 '18 20:10 eponymz

keep in mind the logging does refer to my logger.. i figure you would know but i wanted to throw the disclaimer on there. im pretty sure other than that the rest is generic code

eponymz avatar Oct 25 '18 20:10 eponymz

@eponymz Thank you.

motionharvest avatar Oct 25 '18 23:10 motionharvest