-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfunctions.php
executable file
·37 lines (30 loc) · 998 Bytes
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
require_once('setup.php');
function slackMessage($message, $channel="#analytics") {
// Get cURL resource
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => SLACK_WEBHOOK_URL,
CURLOPT_USERAGENT => 'Google Analytics Slack Integration',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
"payload" => json_encode(array(
"channel" => $channel,
"username" => "Google Analytics",
"text" => $message,
"icon_emoji" => ":chart_with_upwards_trend:",
)),
)
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
echo $resp;
if(!$resp){
die('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
}
// Close request to clear up some resources
curl_close($curl);
}
?>