Last active
February 3, 2018 03:01
-
-
Save davidsword/938acb2e9fa5fecf938c4391376ef44c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
function sendToSlack($to,$title,$text,$color = "good") { | |
$inHook = 'https://hooks.slack.com/services/###/###/###'; | |
$data = json_encode(array( | |
"channel" => $to, | |
"username" => "Your App Name", | |
"icon_emoji" => ":beers:", // your app icon | |
"attachments" => array(array( | |
"fallback" => $title, | |
"pretext" => $title, | |
"mrkdwn" => true, | |
"mrkdwn_in" => array('text'), | |
"color" => $color, | |
"text" => $text | |
)) | |
)); | |
$ch = curl_init($inHook); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
$result = curl_exec($ch); | |
curl_close($ch); | |
} | |
// EXAMPLE USAGE | |
$message = "My oh my, something happened and it's now being pushed to Slack immediately."; | |
$message .= "Please be aware *formatting* works here, so take full advantage of it.\n"; | |
$message .= "```" | |
$message .= "12:00 - Log : Details of something here\n"; | |
$message .= "12:01 - Log : Details of something else here\n"; | |
$message .= "```"; | |
// go go go | |
sendToSlack('@davidsword', 'A Something Occurred', $message, '#fd8f31'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment