Skip to content
Permalink
Browse files

Merge pull request #1111 from mozilla/handle_websocket_reconnection_bot

Add exception handling for websocket error slackbot
  • Loading branch information...
pwnbus committed Apr 11, 2019
2 parents 5cefe7c + 65f8bdb commit 52a16ce8b66f20c2eb99e8b1a0a3cfbae608025e
Showing with 11 additions and 5 deletions.
  1. +11 −5 bot/slack/slack_bot.py
@@ -2,6 +2,7 @@
import sys
import os
import time
import websocket

from slackclient import SlackClient

@@ -94,11 +95,16 @@ def handle_message(self, message):

def listen_for_messages(self):
while True:
for slack_message in self.slack_client.rtm_read():
message_type = slack_message.get('type')
if message_type == 'desktop_notification':
logger.info("Received message: {0}".format(slack_message['content']))
self.handle_message(slack_message)
try:
for slack_message in self.slack_client.rtm_read():
message_type = slack_message.get('type')
if message_type == 'desktop_notification':
logger.info("Received message: {0}".format(slack_message['content']))
self.handle_message(slack_message)
except websocket.WebSocketConnectionClosedException:
logger.info("Received WebSocketConnectionClosedException exception...reconnecting")
time.sleep(3)
self.slack_client.rtm_connect()
time.sleep(1)

def post_thread_message(self, text, channel, thread_ts):

0 comments on commit 52a16ce

Please sign in to comment.
You can’t perform that action at this time.