errbotio / err-backend-slackv3

Slack Events and RTM backend for Errbot
GNU General Public License v3.0
27 stars 28 forks source link

KeyError: 'event' in Slack Shotcuts (Global and Message) #70

Closed johnclark84 closed 2 years ago

johnclark84 commented 2 years ago

I create 2 shortcuts in my slack app: Create Incident (global) Add message to timeline (message)

Each time I call them I got an error for KeyError, these are the outputs: Global Shortcuts errbot | 2022-06-29 14:57:08,686 DEBUG slack_sdk.socket_mode.builtin.client on_message invoked: (message: {"envelope_id":"5e52dff0-ffe0-4665-989c-1ce859a5b8ec","payload":{"type":"shortcut","token":"r54I0FHrqju1kznGgGBAFjfS","action_ts":"1656514628.533123","team":{"id":"T0JF373M3","domain":"bfaindustries"},"user":{"id":"U0316G1MU68","username":"jonathanlinenberg","team_id":"T0JF373M3"},"is_enterprise_install":false,"enterprise":null,"callback_id":"incident_create","trigger_id":"3722463424407.18513241717.56efdf268a4fc66f0f58e0ff1d1e3c4a"},"type":"interactive","accepts_response_payload":false}) errbot | 2022-06-29 14:57:08,688 DEBUG slack_sdk.socket_mode.builtin.client A new message enqueued (current queue size: 1) errbot | 2022-06-29 14:57:08,689 DEBUG slack_sdk.socket_mode.builtin.client A message dequeued (current queue size: 0) errbot | 2022-06-29 14:57:08,692 DEBUG slack_sdk.socket_mode.builtin.client Message processing started (type: interactive, envelope_id: 5e52dff0-ffe0-4665-989c-1ce859a5b8ec) errbot | 2022-06-29 14:57:08,695 DEBUG errbot.backends.slackv3 Event type: interactive errbot | Envelope ID: 5e52dff0-ffe0-4665-989c-1ce859a5b8ec errbot | Accept Response Payload: False errbot | Retry Attempt: None errbot | Retry Reason: None errbot | errbot | 2022-06-29 14:57:08,696 DEBUG slack_sdk.socket_mode.builtin.client Sending a message (session id: 5de778a8-5c59-4373-ad68-e1aa4b125f58, message: {"envelope_id": "5e52dff0-ffe0-4665-989c-1ce859a5b8ec"}) errbot | 2022-06-29 14:57:08,698 DEBUG errbot.backends.slackv3 Received event: {'type': 'shortcut', 'token': 'r54I0FHrqju1kznGgGBAFjfS', 'action_ts': '1656514628.533123', 'team': {'id': 'T0JF373M3', 'domain': 'bfaindustries'}, 'user': {'id': 'U0316G1MU68', 'username': 'jonathanlinenberg', 'team_id': 'T0JF373M3'}, 'is_enterprise_install': False, 'enterprise': None, 'callback_id': 'incident_create', 'trigger_id': '3722463424407.18513241717.56efdf268a4fc66f0f58e0ff1d1e3c4a'} errbot | 2022-06-29 14:57:08,698 ERROR slack_sdk.socket_mode.builtin.client Failed to run a request listener: 'event' errbot | Traceback (most recent call last): errbot | File "/usr/local/lib/python3.8/site-packages/slack_sdk/socket_mode/client.py", line 143, in run_message_listeners errbot | listener(self, request) # type: ignore errbot | File "/home/errbot/backends/slackv3/slackv3.py", line 377, in _sm_generic_event_handler errbot | self._generic_wrapper(req.payload) errbot | File "/home/errbot/backends/slackv3/slackv3.py", line 357, in _generic_wrapper errbot | event = event_data["event"] errbot | KeyError: 'event' errbot | 2022-06-29 14:57:08,713 DEBUG slack_sdk.socket_mode.builtin.client Message processing completed (type: interactive, envelope_id: 5e52dff0-ffe0-4665-989c-1ce859a5b8ec) errbot | 2022-06-29 15:18:43,083 ERROR slack_sdk.socket_mode.builtin.client on_error invoked (session id: 5de778a8-5c59-4373-ad68-e1aa4b125f58, error: ConnectionResetError, message: [Errno 104] Connection reset by peer)

Message Shortcuts errbot | 2022-06-29 15:24:38,488 DEBUG errbot.backends.slackv3 Received event: {'type': 'message_action', 'token': 'r54I0FHrqju1kznGgGBAFjfS', 'action_ts': '1656516278.342702', 'team': {'id': 'T0JF373M3', 'domain': 'bfaindustries'}, 'user': {'id': 'U0316G1MU68', 'username': 'jonathanlinenberg', 'team_id': 'T0JF373M3', 'name': 'jonathanlinenberg'}, 'channel': {'id': 'D03JFG2HEA2', 'name': 'directmessage'}, 'is_enterprise_install': False, 'enterprise': None, 'callback_id': 'add_time_line', 'trigger_id': '3737206539171.18513241717.639ec83871e676c1339d70de41e4bcce', 'response_url': 'https://hooks.slack.com/app/T0JF373M3/3737257573314/vDWEyR03AUMiycPk1woYOhCF', 'message_ts': '1656445152.214729', 'message': {'bot_id': 'B03KBKYS7C0', 'type': 'message', 'text': 'Plugin Test reloaded.', 'user': 'U03JK0HQRQV', 'ts': '1656445152.214729', 'app_id': 'A03JF7E2KLN', 'team': 'T0JF373M3', 'bot_profile': {'id': 'B03KBKYS7C0', 'deleted': False, 'name': 'AEON Bot', 'updated': 1655924661, 'app_id': 'A03JF7E2KLN', 'icons': {'image_36': 'https://avatars.slack-edge.com/2022-06-22/3691515832135_3f2c588584a086c04e70_36.png', 'image_48': 'https://avatars.slack-edge.com/2022-06-22/3691515832135_3f2c588584a086c04e70_48.png', 'image_72': 'https://avatars.slack-edge.com/2022-06-22/3691515832135_3f2c588584a086c04e70_72.png'}, 'team_id': 'T0JF373M3'}, 'blocks': [{'type': 'rich_text', 'block_id': 'TMoV', 'elements': [{'type': 'rich_text_section', 'elements': [{'type': 'text', 'text': 'Plugin Test reloaded.'}]}]}]}} errbot | 2022-06-29 15:24:38,488 ERROR slack_sdk.socket_mode.builtin.client Failed to run a request listener: 'event' errbot | Traceback (most recent call last): errbot | File "/usr/local/lib/python3.8/site-packages/slack_sdk/socket_mode/client.py", line 143, in run_message_listeners errbot | listener(self, request) # type: ignore errbot | File "/home/errbot/backends/slackv3/slackv3.py", line 377, in _sm_generic_event_handler errbot | self._generic_wrapper(req.payload) errbot | File "/home/errbot/backends/slackv3/slackv3.py", line 357, in _generic_wrapper errbot | event = event_data["event"] errbot | KeyError: 'event' errbot | 2022-06-29 15:24:38,489 DEBUG slack_sdk.socket_mode.builtin.client Message processing completed (type: interactive, envelope_id: af9a3466-ec08-437b-a857-e296b25eb9b1)

Do we've any docs about who to manage this callbacks? ty

nzlosh commented 2 years ago

As mentioned in #69 processing GUI/interactive events is outside the scope of the SlackV3 backend. It appears the event structures produced by shortcuts don't conform to Slack message events that errbot expects.

I'm starting to question if errbot is the right fit for what you're attempting to do. Perhaps using Slack Bolt directly would be more appropriate since it's designed to build Slack Apps where as errbot is designed to process textual commands in a generic way to be portable between chat providers.

johnclark84 commented 2 years ago

@nzlosh I guess you're right. My last shot was trying to fit the slack event payloads using the socket mode, but looks like this is not prepared for that purpose.

nzlosh commented 2 years ago

I considered creating a plugin callback registration method so slack events that didn't have the key event could be passed through to plugins that register a callback function with the backend. However I suspect this hack would eventual become a limitation for your use case. This approach wouldn't be able to address the need to pass certain slack events that did contain the event key to be passed through to the plugin. Which lead me to question if errbot is the right fit. I'm not saying it's impossible, I just don't seen a clean way of supporting this sort of model and it would remain highly specialised to the Slack backend, which breaks the promise that errbot plugins are portable across chat backends.