Skip to content

Commit

Permalink
bug(slack/api): Make slack /event respond to challenge (#5375)
Browse files Browse the repository at this point in the history
* fix(slack): Make slack /events respond to challenge

When configuring event listening for a slack app, your endpoint is
required to respond correctly to the slack challenge that is sent. If
your endpoint does not respond correctly, slack will not let you use it.
Currently, the events endpoint does not respond correctly to the
challenge because it is using a background thread to process all
incoming events and responding with a static response. In order to use
the events endpoint correctly (including using an @ in the incident
channel to add an observer), that endpoint has to respond. I altered the
event post to check the body for a "url_verification" type and, if it
exists, process the event synchronously in the same way the `actions`
endpoint does. Otherwise, process async like it always has.

* add reformatting

---------

Co-authored-by: Marc Vilanova <[email protected]>
  • Loading branch information
bashbreakpoint and mvilanova authored Oct 22, 2024
1 parent 295a60f commit 9f7ecd7
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/dispatch/plugins/dispatch_slack/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,18 @@ def get_request_handler(request: Request, body: bytes, organization: str) -> Sla
)
async def slack_events(request: Request, organization: str, body: bytes = Depends(get_body)):
"""Handle all incoming Slack events."""

handler = get_request_handler(request=request, body=body, organization=organization)
try:
body_json = json.loads(body)
# if we're getting the url verification request,
# handle it synchronously so that slack api verification works
if body_json.get("type") == "url_verification":
return handler.handle(req=request, body=body)
except json.JSONDecodeError:
pass

# otherwise, handle it asynchronously
task = BackgroundTask(handler.handle, req=request, body=body)
return JSONResponse(
background=task,
Expand Down

0 comments on commit 9f7ecd7

Please sign in to comment.