Created
January 29, 2018 12:07
-
-
Save szabacsik/86a1c37bf699a5023bdbe047cce00f7e to your computer and use it in GitHub Desktop.
slack php function
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 | |
define ( 'SLACK_WEBHOOK', 'https://hooks.slack.com/services/' ); | |
function slack ( $message, $username, $channel ) | |
{ | |
switch ( $channel ) | |
{ | |
case 'delivery-form': | |
$token = '...'; | |
break; | |
} | |
$msg = array ( 'text' => $message, "username" => "..." ); | |
$c = curl_init ( SLACK_WEBHOOK . $token ); | |
curl_setopt ( $c, CURLOPT_RETURNTRANSFER, true ); | |
curl_setopt ( $c, CURLOPT_SSL_VERIFYPEER, false ); | |
curl_setopt ( $c, CURLOPT_POST, true ); | |
curl_setopt ( $c, CURLOPT_POSTFIELDS, array ( 'payload' => json_encode ( $msg ) ) ); | |
curl_exec ( $c ); | |
curl_close ( $c ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment