Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 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 Reply

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...