Skip to content

Instantly share code, notes, and snippets.

@Bouhnosaure
Forked from alexstone/slack_notification.php
Last active July 27, 2016 11:32
Show Gist options
  • Save Bouhnosaure/4b2f14a3f841ba7e18950a42dde4732c to your computer and use it in GitHub Desktop.
Save Bouhnosaure/4b2f14a3f841ba7e18950a42dde4732c to your computer and use it in GitHub Desktop.
Fire a Slack Notification via CURL
<?php
// (string) $message - message to be passed to Slack
// (string) $room - room in which to write the message, too
// (string) $icon - You can set up custom emoji icons to use with each message
public function slack($message) {
$data = "payload=" . json_encode(array(
"channel" => "#webhooks",
"text" => $message,
"icon_emoji" => ":longbox:"
));
// You can get your webhook endpoint from your Slack settings
$ch = curl_init("https://hooks.slack.com/services/##TOKEN##");
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);
//$this->slack("Sent to Slack: " . $message);
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment