Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.

Commit 9f7ecd7

Browse files
bug(slack/api): Make slack /event respond to challenge (#5375)
* 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]>
1 parent 295a60f commit 9f7ecd7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/dispatch/plugins/dispatch_slack/endpoints.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,18 @@ def get_request_handler(request: Request, body: bytes, organization: str) -> Sla
8181
)
8282
async def slack_events(request: Request, organization: str, body: bytes = Depends(get_body)):
8383
"""Handle all incoming Slack events."""
84+
8485
handler = get_request_handler(request=request, body=body, organization=organization)
86+
try:
87+
body_json = json.loads(body)
88+
# if we're getting the url verification request,
89+
# handle it synchronously so that slack api verification works
90+
if body_json.get("type") == "url_verification":
91+
return handler.handle(req=request, body=body)
92+
except json.JSONDecodeError:
93+
pass
94+
95+
# otherwise, handle it asynchronously
8596
task = BackgroundTask(handler.handle, req=request, body=body)
8697
return JSONResponse(
8798
background=task,

0 commit comments

Comments
 (0)