Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
385 views
in Technique[技术] by (71.8m points)

python - How to avoid slack command timeout error?

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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...