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