diff --git a/lib/Slackbot_worker.js b/lib/Slackbot_worker.js index 28cee1b89..868901724 100755 --- a/lib/Slackbot_worker.js +++ b/lib/Slackbot_worker.js @@ -158,6 +158,7 @@ module.exports = function(botkit, config) { }); bot.rtm.on('open', function() { + botkit.log.notice('RTM websocket opened'); pingIntervalId = setInterval(function() { if (lastPong && lastPong + 12000 < Date.now()) { @@ -204,11 +205,21 @@ module.exports = function(botkit, config) { botkit.trigger('rtm_close', [bot, err]); }); - bot.rtm.on('close', function() { + bot.rtm.on('close', function(code, message) { + botkit.log.notice('RTM close event: ' + code + ' : ' + message); if (pingIntervalId) { clearInterval(pingIntervalId); } botkit.trigger('rtm_close', [bot]); + + /** + * CLOSE_ABNORMAL error + * wasn't closed explicitly, should attempt to reconnect + */ + if (code === 1006) { + botkit.log.error('Abnormal websocket close event, attempting to reconnect'); + reconnect(); + } }); });