Skip to content

Commit

Permalink
Update slack plugin.py to check if user exists before send direct (#4217
Browse files Browse the repository at this point in the history
)

It is possible that a message could be attempted to send for a slack account that does not exist anymore. This performs a check before attempting to send so it does not raise an exception if the user does not exist.

This causes two looks ups for every direct or ephemeral send, but will prevent exceptions.
  • Loading branch information
jschroth authored Jan 8, 2024
1 parent 5fcfbeb commit 18c176b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/dispatch/plugins/dispatch_slack/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,10 @@ def send_direct(
blocks: Optional[List] = None,
**kwargs,
):
"""Sends a message directly to a user."""
"""Sends a message directly to a user if the user exists."""
client = create_slack_client(self.configuration)
if not does_user_exist(client, user):
return {}
user_id = resolve_user(client, user)["id"]

if not blocks:
Expand All @@ -227,8 +229,10 @@ def send_ephemeral(
blocks: Optional[List] = None,
**kwargs,
):
"""Sends an ephemeral message to a user in a channel."""
"""Sends an ephemeral message to a user in a channel if the user exists."""
client = create_slack_client(self.configuration)
if not does_user_exist(client, user):
return {}
user_id = resolve_user(client, user)["id"]

if not blocks:
Expand Down

0 comments on commit 18c176b

Please sign in to comment.