-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
67 lines (51 loc) · 1.43 KB
/
test.php
File metadata and controls
67 lines (51 loc) · 1.43 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
declare(strict_types=1);
require __DIR__ . '/packages/default/notifier/vendor/autoload.php';
// Constants
const OK = 1;
const HTTP_OK = 200;
const ERROR = -1;
$args = [
// you can find out the CHAT_ID in the output of https://api.telegram.org/bot{token}/getUpdates
'dsn' => 'telegram://TOKEN@default?channel=CHAT_ID',
'text' => implode(PHP_EOL, [
'<b>hello</b>',
'world',
]),
];
$client = new \GuzzleHttp\Client();
$url = 'https://faas-fra1-afec6ce7.doserverless.co/api/v1/web/fn-23d0dc89-648f-49d6-bf44-72388e68288c/default/notifier';
$response = $client->post($url, [
// Config
'connect_timeout' => 20,
'read_timeout' => 20,
'timeout' => 30,
// The data
'json' => $args,
]);
$responseBody = $response->getBody()->getContents();
$responseCode = $response->getStatusCode();
if (HTTP_OK !== $responseCode) {
echo "Something went wrong!\n";
exit(1);
}
echo "HTTP call was successful!\n";
/**
* @var array $parsedData
*/
$parsedData = json_decode($responseBody, true);
/**
* @var array $response
*/
$response = $parsedData['response'];
switch ($response['status']) {
case OK:
echo "Notification sent successfully!\n";
break;
case ERROR:
echo "Notification failed to send! Use parsedData variable to find out more.\n";
break;
default:
echo "Something went wrong! Use parsedData variable to find out more.\n";
break;
}