How do I issue an HTTP response within Slack's timeout limit of 3 seconds?

This topic was automatically generated from Slack. You can find the original thread here.

Teddy Hwang : Hey! I’m sure it’s asked before, but I cannot find a documentation for this.
Slack requires pipedream to respond within 3 seconds, otherwise it throws an error.
How do I make sure Pipedream can give a response by the end of 3 seconds?

Dylan Sather (Pipedream) : how are you integrating with Slack in this specific case? For example, are you trying to build a bot with a slash command?

Teddy Hwang : I have it subscribed to mentions, and respond after receiving the mention event.
Slack sends the event 2-3 times because im supposed to return it with a 200 ok in 3 seconds, but I can’t figure out how.

Dylan Sather (Pipedream) : We respond with a 200 OK automatically if you don’t use $respond(). Would that work for this use case?

Dylan Sather (Pipedream) : in that case we respond immediately, without running the workflow (which can take some time if the workflow hasn’t processed an event in a while). That default response should be issued within the 3 second window.

Teddy Hwang : I do have it $respond(), but I’m not sure if Pipedream is responding within 3 seconds… Maybe something is wrong with my workflow? I can DM it to you if you would like to take a look.

Dylan Sather (Pipedream) : sure, feel free to share the workflow with dylan@pipedream.com if you’d like.

If Slack just expects a 200 OK, you can remove $respond() - that’s what I was trying to say above. We automatically respond with a 200 OK, so if you don’t need to issue a custom response, you can rely on the default response, which will be much faster. Try removing $respond() and see if that works

Teddy Hwang : Even when I delete the $respond, I am greeted by the same duplicate queries. I did solve the issue by noticing one thing: Slack will let you know how many times they tried the query. So I added a nodejs block that checks if this query is the first of the kind or if it is a duplicate. A bit hacky, but it gets the job done.

if (typeof steps.trigger.event.headers["x-slack-retry-num"] !== 'undefined') {
  $end("Duplicate Query!")
}

Dylan Sather (Pipedream) : That’s great, nice find!