-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathFCM.php
More file actions
64 lines (58 loc) · 1.58 KB
/
FCM.php
File metadata and controls
64 lines (58 loc) · 1.58 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
<?php
namespace Utopia\Messaging\Adapters\Push;
use Utopia\Messaging\Adapters\Push as PushAdapter;
use Utopia\Messaging\Messages\Push;
class FCM extends PushAdapter
{
/**
* @param string $serverKey The FCM server key.
*/
public function __construct(
private string $serverKey,
) {
}
/**
* Get adapter name.
*/
public function getName(): string
{
return 'FCM';
}
/**
* Get max messages per request.
*/
public function getMaxMessagesPerRequest(): int
{
return 1000;
}
/**
* {@inheritdoc}
*
* @throws \Exception
*/
protected function process(Push $message): string
{
return $this->request(
method: 'POST',
url: 'https://fcm.googleapis.com/fcm/send',
headers: [
'Content-Type: application/json',
"Authorization: key={$this->serverKey}",
],
body: \json_encode([
'registration_ids' => $message->getTo(),
'notification' => [
'title' => $message->getTitle(),
'body' => $message->getBody(),
'click_action' => $message->getAction(),
'icon' => $message->getIcon(),
'badge' => $message->getBadge(),
'color' => $message->getColor(),
'sound' => $message->getSound(),
'tag' => $message->getTag(),
],
'data' => $message->getData(),
])
);
}
}