-
-
Save nickwanhere/8ef76eb48a2ca3f0cf59 to your computer and use it in GitHub Desktop.
php slack
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 | |
/** | |
* go to https://api.slack.com/web to create your access-token. The token will look somewhat like this: | |
* xoxo-2100000415-0000000000-0000000000-ab1ab1 | |
*/ | |
public static function slack($message, $channel) { | |
{ | |
$ch = curl_init("https://slack.com/api/chat.postMessage"); | |
$data = http_build_query([ | |
"token" => "YOUR_API_TOKEN", | |
"channel" => $channel, //"#mychannel", | |
"text" => $message, //"Hello, Foo-Bar channel message.", | |
"username" => "MySlackBot", | |
]); | |
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); | |
curl_close($ch); | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment