Created
June 14, 2017 14:31
-
-
Save nakulrathore/69593251b4c2cf1694c8c2688e4267b7 to your computer and use it in GitHub Desktop.
Slack Incoming Web-hook via PHP
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
<?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