Skip to content

Instantly share code, notes, and snippets.

@nakulrathore
Created June 14, 2017 14:31
Show Gist options
  • Save nakulrathore/69593251b4c2cf1694c8c2688e4267b7 to your computer and use it in GitHub Desktop.
Save nakulrathore/69593251b4c2cf1694c8c2688e4267b7 to your computer and use it in GitHub Desktop.
Slack Incoming Web-hook via PHP
<?php
function slack($message, $room, $icon) {
$room = ($room) ? $room : "defoult_room";
$data = "payload=" . json_encode(array(
"channel" => "$room",
"username" => "Name your Bot",
"text" => $message,
"icon_emoji" => $icon
));
$ch = curl_init("YOUR_SLACK_DOMAIN_____WITH____SLACK_TOKEN___GOES_HERE");
//the url looks like this "https://hooks.slack.com/services/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T9"
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
// calling the slack webhook function
$message = 'YOUR MESSAGE STRING GOES HERE';
$room = '#MY_ROOM_WITH_HASHTAG';
$icon = ":ghost:";
// replace icon with any emoji you want
slack($message,$room,$icon);
// end calling the slack webhook function
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment