Skip to content

Instantly share code, notes, and snippets.

@quawn
Last active September 15, 2015 20:17
Show Gist options
  • Save quawn/51bdc40b6da04aac7b8b to your computer and use it in GitHub Desktop.
Save quawn/51bdc40b6da04aac7b8b to your computer and use it in GitHub Desktop.
Slack notification with attachment
<?php
// Source: http://blog.eddokloosterman.com/2015/09/useful-slack-notifications-for-developers/
private function _notifySlackChannel($success)
{
$attachment = new stdClass();
$attachment->fallback = "Build tests ". ($success == true? "passed" : "failed") . " for last '" . $this->_testType . "' build";
$attachment->title = "Last '" . $this->_testType . "' build " . ($success == true? "OK" : "failed" );
$attachment->text = "Check <http://tfs_url/tfs/DefaultCollection/RoosterWeb/_build|build log> for more details";
$attachment->color = $success == true? "good" : "danger" ;
$params = array(
'payload' => json_encode(array('attachments' => array($attachment)))
);
$ch = curl_init("https://hooks.slack.com/services/something" );
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_exec($ch);
curl_close($ch);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment