Increase timeout from slack slash command in python "operation_timeout" Increase timeout from slack slash command in python "operation_timeout" kubernetes kubernetes

Increase timeout from slack slash command in python "operation_timeout"


It is not possible to increase the default timeout from Slack to slash commands. It's always 3 seconds. But it's possible to send a delayed response for up to 30 minutes.

For that you need to first respond within 3 secs to acknowledge the initial request by sending back a HTTP 200 OK. Since that requires you to complete the current request, and terminate your main script, you need to run the function for the delayed response in parallel. That can be in a process, thread, by calling a celery task or any other means that allows you spawn a parallel running python function.

The parallel function can then respond to Slack by sending the message to the URL provided in response_url from the Slack request.

Here is an example implementation that uses threads:

import threadingfrom time import sleepfrom flask import Flask, json, requestimport requestsapp = Flask(__name__) #create the Flask app@app.route('/slash', methods=['POST'])def slash_response():                    """endpoint for receiving all slash command requests from Slack"""    # get the full request from Slack    slack_request = request.form    # starting a new thread for doing the actual processing        x = threading.Thread(            target=some_processing,            args=(slack_request,)        )    x.start()    ## respond to Slack with quick message    # and end the main thread for this request    return "Processing information.... please wait"def some_processing(slack_request):    """function for doing the actual work in a thread"""    # lets simulate heavy processing by waiting 7 seconds    sleep(7)    # response to Slack after processing is finished    response_url = slack_request["response_url"]        message = {                "text": "We found a result!"    }    res = requests.post(response_url, json=message)if __name__ == '__main__':    app.run(debug=True, port=8000) #run app in debug mode on port 8000