1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kerox\Messenger\Request; |
4
|
|
|
|
5
|
|
|
use Kerox\Messenger\Model\Message; |
6
|
|
|
|
7
|
|
|
class SendRequest extends AbstractRequest |
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
const TYPE_MESSAGE = 'message'; |
11
|
|
|
const TYPE_ACTION = 'action'; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @var null|array |
15
|
|
|
*/ |
16
|
|
|
protected $recipient; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var null|string|\Kerox\Messenger\Model\Message |
20
|
|
|
*/ |
21
|
|
|
protected $message; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var null|string |
25
|
|
|
*/ |
26
|
|
|
protected $senderAction; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var null|string |
30
|
|
|
*/ |
31
|
|
|
protected $notificationType; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var null|string |
35
|
|
|
*/ |
36
|
|
|
protected $tag; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Request constructor. |
40
|
|
|
* |
41
|
|
|
* @param string $pageToken |
42
|
|
|
* @param string|\Kerox\Messenger\Model\Message $content |
43
|
|
|
* @param string|null $recipient |
44
|
|
|
* @param string $requestType |
45
|
|
|
* @param string|null $notificationType |
46
|
|
|
* @param string|null $tag |
47
|
|
|
*/ |
48
|
5 |
|
public function __construct( |
49
|
|
|
string $pageToken, |
50
|
|
|
$content, |
51
|
|
|
string $recipient = null, |
52
|
|
|
string $notificationType = null, |
53
|
|
|
$tag = null, |
54
|
|
|
string $requestType = self::TYPE_MESSAGE |
55
|
|
|
) { |
56
|
5 |
|
parent::__construct($pageToken); |
57
|
|
|
|
58
|
5 |
|
if ($content instanceof Message || $requestType === self::TYPE_MESSAGE) { |
59
|
5 |
|
$this->message = $content; |
60
|
|
|
} else { |
61
|
|
|
$this->senderAction = $content; |
62
|
|
|
} |
63
|
|
|
|
64
|
5 |
|
$this->recipient = (is_string($recipient)) ? ['id' => $recipient] : $recipient; |
65
|
5 |
|
$this->notificationType = $notificationType; |
66
|
5 |
|
$this->tag = $tag; |
67
|
5 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return array |
71
|
|
|
*/ |
72
|
5 |
|
protected function buildHeaders(): array |
73
|
|
|
{ |
74
|
|
|
return [ |
75
|
5 |
|
'Content-Type' => 'application/json', |
76
|
|
|
]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return array |
81
|
|
|
*/ |
82
|
5 |
|
protected function buildBody(): array |
83
|
|
|
{ |
84
|
|
|
$body = [ |
85
|
5 |
|
'recipient' => $this->recipient, |
86
|
5 |
|
'message' => $this->message, |
87
|
5 |
|
'sender_action' => $this->senderAction, |
88
|
5 |
|
'notification_type' => $this->notificationType, |
89
|
5 |
|
'tag' => $this->tag, |
90
|
|
|
]; |
91
|
|
|
|
92
|
5 |
|
return array_filter($body); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return array |
97
|
|
|
*/ |
98
|
5 |
|
protected function buildQuery(): array |
99
|
|
|
{ |
100
|
5 |
|
return parent::buildQuery(); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|