0

we have 2 servers backend-api and slack-api. slack api is serving every requests from slack(ui) using backend-api for any read/write operation in db.

for some events we are receiving multiple requests that is breaking our expected flow.

backend-api(django) <=> slack-api(fastapi) <=> slack(ui)

backend-api : responsible for every read/write in our db.

slack-api : handles requests from slack(ui), process it (calls backend-api) and responds acordingly.

slack(ui) : accepts user inputs/commands and sends to slack-api, shows outupt received from slack-api

we already have this logic at entry point of our slack-api.

retry_num = req.headers.get("x-slack-retry-num")
    if retry_num is not None:
        return

but we are still receiving multiple requests for same events some time.attaching a screenshot of log for confirmation.

enter image description here

1 Answers1

0

Returning None from a Fast API view function is a 204 No Content.

Slack expects a 200 OK response code within 3 seconds from your web integration and retries the request if your response code is something other than that.

Set the status code for the response to mark that the Slack event was processed.

from fastapi import FastAPI, Response, status

@app.post("/events")
def handle_slack_event(response: Response):
    retry_num = req.headers.get("x-slack-retry-num")
    if retry_num is not None:
        response.status_code = status.HTTP_200_OK
        return 
Oluwafemi Sule
  • 36,144
  • 1
  • 56
  • 81