slack-bot-api
slack-bot-api copied to clipboard
Reconnect not working
Hi! I added a listener for the 'close' event in order to handle disconnections. I'm seeing the message in the logs but the bot is offline now. What I'm doing wrong? Thanks!
// handle disconnections
bot.on('close', function(data){
console.log("Connection closed... Reconnecting.")
bot.login();
});
I have the same doubts
same issues how to handle reconnects?
Having the same issue. Does the above not work?
Same here
Thanks for the issue. What data is coming with a close event? Because when I try to emulate it and close a websocket manually, login() works fine.
Shouldn't this be a part of the library itself?
var bot = new Slackbot({});
bot.on('message', function(ev) {
if (ev.type == 'reconnect_url') {
bot.wsUrl = ev.url;
return;
}
// ...
});
bot.on('close', function() {
bot.connect();
});
I'm seeing the close event in my logs after which my bot goes offline. How can I always keep the bot online? What is the way to properly restart the bot after the close event?
Has someone managed to fix this issue?
Same question. How to keep bot always connected?
I have absolutely no idea, but the only solution I can think of is deploying the bot on a ubuntu server and making sure the crontab will run a bash script to turn off and on the bot every hour.
This is not a root solution, but rather work around it (not the most ideal way to do it).
I seriously hope someone could try and find a solution on how to fix this.
I've noticed this solution bot.on('close', function(data) { console.log(data) bot.connect(); }); fails with infinitive loop and 1006 error in response.
So you managed to track down the problem, but is there a solution for this?
Based on official docs and other sources I think we need to "ping" in regular intervals...
https://api.slack.com/rtm
Clients should try to quickly detect disconnections, even in idle periods, so that users can easily tell the difference between being disconnected and everyone being quiet. Not all web browsers support the WebSocket ping spec, so the RTM protocol also supports ping/pong messages. When there is no other activity clients should send a ping every few seconds. To send a ping, send the following JSON:
{ "id": 1234, // ID, see "sending messages" above "type": "ping", ... }
But how do we do it using slackbots?
I don't know if this is still relevant, but I fixed this problem by adding to the source code a reconnect method. I was told by Slack Help Center that this is normal, and that simply what you need to do is call a method on the api to tell Slack that your app is still running. The reconnect method simply calls the method on the real time messaging api (rtm.connect) which to my understanding sends over a new url to set as your web socket. My pull request didn't go through due to some weird error, and it doesn't seem like anyone is still keeping tabs on this repository. For more clarification take a look at the slack-api documentation here: https://api.slack.com/methods/rtm.connect