I am using the same concept as mentioned in test code for one client and reapplying it if I retrieve a list of tokens from a database to create N websockets to support multiple slack teams. When doing so, the code always fails while trying to parse the slack output. Would really appreciate if you can help me understand what's happening wrong here
def parse_slack_output(bot,slack_rtm_output):
AT_BOT = bot
output_list = slack_rtm_output
if output_list and len(output_list) > 0:
for output in output_list:
if output and 'text' in output and AT_BOT in output['text']:
return output['text'].split(AT_BOT)[1].strip().lower(),
output['channel']
return None, None
if name == "main":
#botid is a list of dictionary that is represented in this format, retrieved from a backend db ( {"bot_token":y['bot_token'],"bot_id":y["bot_id"]} )
clients = [SlackClient(str(t['bot_token'])) for t in botid]
for c in clients:
c.rtm_connect()
while True:
for d in botid:
bot = "<@" + str(d["bot_id"]) + ">"
command, channel = parse_slack_output(bot,SlackClient(str(d['bot_token'])).rtm_read())
if command and channel:
handle_command(command, channel)
time.sleep(READ_WEBSOCKET_DELAY)
The error I am getting is:
command, channel = parse_slack_output(bot,SlackClient(str(d['bot_token'])) .rtm_read())
File "/usr/local/lib/python2.7/dist-packages/slackclient/_client.py", line 120 , in rtm_read
json_data = self.server.websocket_safe_read()
File "/usr/local/lib/python2.7/dist-packages/slackclient/_server.py", line 138 , in websocket_safe_read
data += "{0}\n".format(self.websocket.recv())
AttributeError: 'NoneType' object has no attribute 'recv'