Skip to content

Instantly share code, notes, and snippets.

@markbiek
Last active September 20, 2016 17:38
Show Gist options
  • Save markbiek/a6b202357605c3e6e117ea87106bddc5 to your computer and use it in GitHub Desktop.
Save markbiek/a6b202357605c3e6e117ea87106bddc5 to your computer and use it in GitHub Desktop.
<?php
//Check to make sure the token is valid
if (!isset($_POST['token']) || $_POST['token'] != SLACK_TOKEN) {
throw new Exception("Shenanigans!");
}
/*
* This sends a message back to the user immediately so they know something's happening.
* The `ignore_user_abort` allows the script to keep running,
* even after the user has disconnected
*/
ignore_user_abort(true);
ob_start();
echo('{ "text": ":timer_clock: Doing some stuff, 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();
//Wait for 5 seconds
sleep(5);
$payload = [
'text' => 'Hello World!'
];
//Send the final response back to the webhook
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $params['response_url'],
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => array("Content-Type: application/json"),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => json_encode($payload)
));
$resp = curl_exec($curl);
curl_close($curl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment