-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
36 lines (29 loc) · 957 Bytes
/
index.php
File metadata and controls
36 lines (29 loc) · 957 Bytes
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
<?php
use Psr\Http\Message\ServerRequestInterface;
function sendMessageToSlack(ServerRequestInterface $request)
{
include 'config.php';
$data = json_decode($request->getBody(), true);
if (is_null($data)) {
return 'Something went wrong: no data!';
}
if (!array_key_exists('message', $data)) {
return 'Something went wrong: wrong payload!';
}
$text['text'] = $data["message"];
$text_to_send = json_encode($text);
$url = $slack_webhook;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = [
"Content-Type: application/json",
"Accept: application/json",
];
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $text_to_send);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}