diff --git a/src/bot.coffee b/src/bot.coffee index a44ba84a..8779dc0a 100644 --- a/src/bot.coffee +++ b/src/bot.coffee @@ -37,6 +37,7 @@ class SlackBot extends Adapter # SlackClient event handlers @client.rtm.on "open", @open @client.rtm.on "close", @close + @client.rtm.on "disconnect", @disconnect @client.rtm.on "error", @error @client.rtm.on "authenticated", @authenticated @client.onEvent @eventHandler @@ -177,16 +178,24 @@ class SlackBot extends Adapter # @private ### close: => - @robot.logger.info "Disconnected from Slack RTM" # NOTE: not confident that @options.autoReconnect works if @options.autoReconnect + @robot.logger.info "Disconnected from Slack RTM" @robot.logger.info "Waiting for reconnect..." else - @robot.logger.info "Exiting..." - @client.disconnect() - # NOTE: Node recommends not to call process.exit() but Hubot itself uses this mechanism for shutting down - # Can we make sure the brain is flushed to persistence? Do we need to cleanup any state (or timestamp anything)? - process.exit 1 + @disconnect() + + ###* + # Slack client has closed the connection and will not reconnect + # @private + ### + disconnect: => + @robot.logger.info "Disconnected from Slack RTM" + @robot.logger.info "Exiting..." + @client.disconnect() + # NOTE: Node recommends not to call process.exit() but Hubot itself uses this mechanism for shutting down + # Can we make sure the brain is flushed to persistence? Do we need to cleanup any state (or timestamp anything)? + process.exit 1 ###* # Slack client received an error