Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

Catching disconnects and reconnecting listener #70

Closed
mastef opened this issue May 6, 2017 · 2 comments
Closed

Catching disconnects and reconnecting listener #70

mastef opened this issue May 6, 2017 · 2 comments

Comments

@mastef
Copy link

mastef commented May 6, 2017

Hey there! So sometimes ( not regularly ) the client just stops listening while the node script is still running. On the local mac environment I can trigger this with a wifi disconnect or going into sleep mode. On servers it also seems to happen from time to time, although they should be pretty much online 24/7.

How to catch disconnects and then restart the client?

var client = slack.rtm.client()

client.message(function(message) {
	// do something with message
});

client.listen(
	{token:sl.slacktoken}
);

// how to catch disconnects and reconnect client?
@statico
Copy link

statico commented May 11, 2017

FWIW, botkit had to address this problem too: howdyai/botkit#261 (comment)

@pandark
Copy link

pandark commented May 23, 2017

I have this in my script… Maybe it (or something similar) should be in the documentation :

// WebSocket reconnection
const listenCb = () => {
  bot.ws.on('close', (code, reason) => {
    console.log(`${new Date()} - WebSocket closed, reconnecting…`)
    bot.listen({token:token}, listenCb)
  })
}

// start listening to the slack team associated to the token
bot.listen({token:token}, listenCb)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants