Skip to content

Instantly share code, notes, and snippets.

@JacobBennett
Forked from pugwonk/slack_notification.php
Last active November 16, 2015 15:24
Show Gist options
  • Save JacobBennett/3c73246faaa2c5e53844 to your computer and use it in GitHub Desktop.
Save JacobBennett/3c73246faaa2c5e53844 to your computer and use it in GitHub Desktop.
<?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 static function slack($message, $room = "general", $icon = ":longbox:") {
$data = json_encode(array(
"channel" => "#{$room}",
"text" => $message,
"icon_emoji" => $icon
));
// You can get your webhook endpoint from your Slack settings
$ch = curl_init("WEBHOOK ENDPOINT GOES HERE");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, array('payload' => $data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
// Laravel-specific log writing method
// Log::info("Sent to Slack: " . $message, array('context' => 'Notifications'));
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment