slack-bot-api
slack-bot-api copied to clipboard
Publish Latest Version to NPM
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.
Wrote up #110 to allow custom handling of disconnects.
I need this.
@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()
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 Thank you.