Developer Snippet Diary

Send messages to slack using php | slack api

1. goto here and create an app

https://api.slack.com/apps

2.  select app and click on incoming-webhooks and add new webhook you will get an url

3. use this code 

$ch = curl_init();
$url_bitsleader = "https://hooks.slack.com/services/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";
$url_notify ="https://hooks.slack.com/services/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";
curl_setopt($ch, CURLOPT_URL, $url_notify);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"text\":\"Awesom, Farhan is gay!\"}");
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close ($ch);

print_r($result);

 

Posted by: R GONDAL
Email: rizikmw@gmail.com