I am trying to use Slack Custom command and not pretty sure how to use delayed messages since the Yoda Speak External API takes more than 3 seconds to respond.
I have done the following:
- Sent the slack command
/Yodain my case and received thereponse_url. - Used the following to
postthe following to the response URL.
$data_string = '{"response_type": "in_channel", "text":"Checking,please wait..."}' ; $chs = curl_init(); curl_setopt($chs, CURLOPT_URL, $response_url); curl_setopt($chs, CURLOPT_POST, true); curl_setopt($chs, CURLOPT_POSTFIELDS, $data_string); curl_setopt($chs, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($chs, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($chs, CURLOPT_RETURNTRANSFER, true); curl_setopt($chs, CURLOPT_POST, 1); curl_setopt($chs, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); $results = curl_exec($chs);
- Now, when I call the Yoda API, it gives the following error "Timeout was reached". I read about delayed responses but not sure how should I proceed from here.
$chsres = curl_init(); curl_setopt($chsres, CURLOPT_URL, "https://yoda.p.mashape.com/yoda?sentence=welcome+to+stack"); curl_setopt($chsres, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($chsres, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($chsres, CURLOPT_VERBOSE, true); curl_setopt($chsres, CURLOPT_TIMEOUT, 45); curl_setopt($chsres, CURLOPT_RETURNTRANSFER, true); curl_setopt($chsres, CURLOPT_HTTPHEADER, array('Content-Type:application/json', "X-Mashape-Key:> deMeGoBfMvmshQSemozTqJEY9z0jp1eIhuAjsnx9cQAQsHUifD")); $resultchsres = curl_exec($chsres); echo $resultchsres;
Can someone please let me know how to get rid of the timeout error using delayed responses?
UPDATED CODE:
$response_url = $_POST['response_url']; $text = $_POST['text']; $term = str_replace(' ', '+', $text); //https://paypal.slack.com/services/B0VQMHX8W#service_setup //initial respond with 200OK for timeout ignore_user_abort(true); set_time_limit(0); ob_start(); echo('{"response_type": "in_channel", "text": "Checking, please wait..."}'); header($_SERVER["SERVER_PROTOCOL"] . " 200 OK"); header("Content-Type: application/json"); header('Content-Length: '.ob_get_length()); ob_end_flush(); ob_flush(); flush(); $chsres = curl_init(); curl_setopt_array($chsres, array( CURLOPT_URL => "https://yoda.p.mashape.com/yoda?sentence=$term", CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_SSL_VERIFYHOST => FALSE, CURLOPT_VERBOSE => true, CURLOPT_RETURNTRANSFER => FALSE, CURLOPT_HTTPHEADER => array('Content-Type:application/json', "X-Mashape-Key: deMeGoBfMvmshQSemozTqJEY9z0jp1eIhuAjsnx9cQAQsHUifD"), CURLOPT_RETURNTRANSFER => true )); $yodaresponse = curl_exec($chsres); $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $response_url, CURLOPT_POST => 1, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => $yodaresponse )); $resp = curl_exec($curl); var_dump($resp); curl_close($curl); I still get the same error "Darn – that slash command didn't work (error message: Timeout was reached). Manage the command at slash-command"

HTTP 200(within the max of 3000ms), perhaps you can then reply to the same response url later.response_urlagain?header("HTTP/1.1 200 OK");code will do?