-
Notifications
You must be signed in to change notification settings - Fork 1
/
create-with-extras.php
56 lines (45 loc) · 1.42 KB
/
create-with-extras.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* Code example for sending a message with message extras
*
* see: https://gotify.net/docs/msgextras
*/
include '../vendor/autoload.php';
use Gotify\Server;
use Gotify\Auth\Token;
use Gotify\Endpoint\Message;
use Gotify\Exception\GotifyException;
use Gotify\Exception\EndpointException;
try {
// Set server
$server = new Server('https://gotify.example.com/');
// Set application token
$auth = new Token('TokenHere');
// Create Message class instance
$message = new Message($server, $auth);
// Message extra for opening a URL on notification click.
// https://gotify.net/docs/msgextras#clientnotification
$extras = [
'client::notification' => [
'click' => ['url' => 'https://example.com/']
]
];
// Send message and get details
$details = $message->create(
title: 'hello?',
message: 'Hello World',
priority: Message::PRIORITY_HIGH,
extras: $extras
);
// Display sent message details
echo 'Id: ' . $details->id . PHP_EOL;
echo 'Date: ' . $details->date . PHP_EOL;
echo 'Title: ' . $details->title . PHP_EOL;
echo 'Message: ' . $details->message . PHP_EOL;
echo 'Priority: ' . $details->priority . PHP_EOL;
echo 'App Id: ' . $details->appid . PHP_EOL;
echo 'Extras: ' . PHP_EOL;
var_dump($details->extras);
} catch (EndpointException | GotifyException $err) {
echo $err->getMessage();
}