How to avoid slack command timeout error?

Vikas Saini picture Vikas Saini · Jan 20, 2016 · Viewed 23.8k times · Source

I am working with slack command (python code is running behind this), it works fine, but this gives error

This slash command experienced a problem: 'Timeout was reached' (error detail provided only to team owning command).

How to avoid this ?

Answer

rcoup picture rcoup · Jan 22, 2016

According to the Slack slash command documentation, you need to respond within 3000ms (three seconds). If your command takes longer then you get the Timeout was reached error. Your code obviously won't stop running, but the user won't get any response to their command.

Three seconds is fine for a quick thing where your command has instant access to data, but might not be long enough if you're calling out to external APIs or doing something complicated. If you do need to take longer, then see the Delayed responses and multiple responses section of the documentation:

  1. Validate the request is okay.
  2. Return a 200 response immediately, maybe something along the lines of {'text': 'ok, got that'}
  3. Go and perform the actual action you want to do.
  4. In the original request, you get passed a unique response_url parameter. Make a POST request to that URL with your follow-up message:
    • Content-type needs to be application/json
    • With the body as a JSON-encoded message: {'text': 'all done :)'}
    • you can return ephemeral or in-channel responses, and add attachments the same as the immediate approach

According to the docs, "you can respond to a user commands up to 5 times within 30 minutes of the user's invocation".