Implement delayed Slack slash response
<p>I want to implement slack slash command that has to process fucntion <code>pipeline</code> which takes roughly 30 seconds to process. Now since <a href="https://api.slack.com/slash-commands#responding_to_a_command" rel="nofollow">Slack</a> slash commands only allows 3 seconds to respond, how to go about implementing this. I referred <a href="http://stackoverflow.com/questions/34896954/how-to-avoid-slack-command-timeout-error">this</a> but don't how to implement it. </p>

<p>Please hold up with me. I am doing this first time.
This is what I have tried. I know how to respond with <code>ok status</code> within 3 seconds but I don't understand how to again call <code>pipeline</code></p>

<pre><code>import requests
import json
from bottle import route, run, request
from S3_download import s3_download
from index import main_func

@route('/action')
def action():
        pipeline()
        return "ok"

def pipeline():
        s3_download()
        p = main_func()
        print (p)

if __name__ == "__main__":
      run(host='0.0.0.0', port=8082, debug=True)
</code></pre>

<p>I came across <a href="https://claudiajs.com/tutorials/slack-delayed-responses.html" rel="nofollow">this</a> article. Is using AWS lambda the only solution?
Can't we do this completely in python?</p>

<p>Something like this:</p>

<pre><code>from boto import sqs
@route('/action', method='POST')
def action():
    #retrieving all the required request example
    params = request.forms.get('response_url')

    sqs_queue = get_sqs_connection(queue_name)
    message_object = sqs.message.Message()
    message_object.set_body(params)
    mail_queue.write(message_object)
    return "request under process"
</code></pre>

<p>and you can have another process which processes the queue and call long running function:</p>

<pre><code>sqs_queue = get_sqs_connection(queue_name)
for sqs_msg in sqs_queue.get_messages(10, wait_time_seconds=5):
    processed_msg = json.loads(sqs_msg.get_body())
    response = pipeline(processed_msg)
    if response:
        sqs_queue.delete_message(sqs_msg)
</code></pre>

<p>you can run this 2nd process maybe in a diff standalone python file, as a daemon process or cron.</p>

<p>I`v used sqs <a href="http://boto.cloudhackers.com/en/latest/ref/sqs.html" rel="nofollow">Amazon Queue</a> here, but there are different options available.</p>

python response slack-api slack slash