Skip to content

Slack handler currently crashes on unsupported message subtypes #4

@jlumbroso

Description

@jlumbroso

The Slack handler currently does not seem to deal well with non-user events. For instance:

[2018-05-05 11:24:15 -0400] [19213] [ERROR] Error handling request /slack/conversations/C6T2Z0FA9/messages?token=XXXXXXXXXXXXXXXXXX
Traceback (most recent call last):
  File "/Users/jlumbroso/.local/share/virtualenvs/Uniform-Chat-API-IVqOXXDs/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 135, in handle
    self.handle_request(listener, req, client, addr)
  File "/Users/jlumbroso/.local/share/virtualenvs/Uniform-Chat-API-IVqOXXDs/lib/python3.6/site-packages/gunicorn/workers/sync.py", line 176, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/Users/jlumbroso/.local/share/virtualenvs/Uniform-Chat-API-IVqOXXDs/lib/python3.6/site-packages/falcon/api.py", line 244, in __call__
    responder(req, resp, **params)
  File "/Users/jlumbroso/GoogleDrive/Programming/unichat/Uniform-Chat-API/unichat/handlers.py", line 95, in on_get
    result = self.translators[service].get_messages(convo_id, auth, page)
  File "/Users/jlumbroso/GoogleDrive/Programming/unichat/Uniform-Chat-API/unichat/translators/slack.py", line 101, in get_messages
    user_id = message['user']
KeyError: 'user'

This seems to be the case when an event does not naturally require a user. For example, in the 'file_comment' event below (more detailed JSON is in attached file). The 'user' field is in the 'file' sub-tree.

{  
   'type':'message',
   'subtype':'file_comment',
   'text':'<@U6T0S2L0L> commented on <@U6T0S2L0L>’s file <https://princeton-csfac.slack.com/files/U6T0S2L0L/FA8QMAJUW/cosphd__accept_decline_report_highlighted_4-16-18__2_.xlsx|COSPHD  Accept Decline Report Highlighted 4-16-18 (2).xlsx>: ^ cc: <@U6V34EB38>',
   'file':{  },
   'comment':{  },
   'is_intro':False,
   'ts':'1523971026.000393'
}

There are several event subtypes which do not seem to have a user field: https://api.slack.com/events/message

Some seem like they should be implemented separately (in particular "message_changed" which is currently unsupported, but has important information on the content of a message).

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions