How to send out message to Slack?

For example, if you are using PHP, you could write an agent php script called slack-webhook-some_secret_letters.php, with the following codes (adjust $url and text message in the codes according to your own data):

<?php
$url = 'https://hooks.slack.com/services/xxxx';
$content = json_encode('{"text":"Message to send"}');
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);
$json_response = curl_exec($curl);
curl_close($curl);
echo $json_response;
?>

place this slack-webhook-some_secret_letters.php to your website.
And then at EasyCron's side, in the webhook tab,
1) choose to Send a request "if cron job execution fails" or "after each cron job execution",
2) fill the to URL field with the URL of your slack-webhook-some_secret_letters.php.

« Back to the full FAQ list