Last active
September 30, 2018 19:21
-
-
Save pascalalich/5d0587127c5ee57c6912 to your computer and use it in GitHub Desktop.
Slack Notifications with 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 | |
$ch = curl_init(); | |
// The Webhook URL from Slack's integration detail page | |
curl_setopt($ch, CURLOPT_URL, 'https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX'); | |
// Only disable SSL checks like this for TESTING purposes if doesn't work otherwise. Make sure your PHP SSL certificates are up to date. | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
// Build an HTTP POST instead of a GET request | |
curl_setopt($ch, CURLOPT_POST, 1); | |
// CURL will return the actual response as text, "ok" on success | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
// Fail verbosely if Slack returns an error, use for TESTING purposes | |
curl_setopt($ch, CURLOPT_FAILONERROR, 1); | |
$payload = json_encode(array( | |
"username" => "Waste Seller GmbH", | |
"channel" => "#notifications", | |
"text" => "New waste entered" | |
)); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); | |
$result = curl_exec($ch); | |
curl_close($ch); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like this: