Created
August 24, 2018 21:57
-
-
Save rbocchinfuso/0c94211cc641a2bfd9f0445f9660b94b to your computer and use it in GitHub Desktop.
PHP Slack CURL Post Snippet
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
// post message | |
$message = "@$username is working on $text"; | |
$data = "payload=" . json_encode(array( | |
'response_type' => $response_type, | |
"text" => $message, | |
"icon_emoji" => $icon | |
)); | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, SLACK_WEBHOOK); | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
$result = curl_exec($ch); | |
// var_dump($result); | |
if($result === false) { | |
echo 'Curl error: ' . curl_error($ch); | |
} | |
curl_close($ch); | |
// send ephemeral notification let user know that thier | |
echo "@$username you've let everyone on #the-railroad know you are working on $text"; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment