|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Kerox\Messenger\Model\Callback; |
|
6
|
|
|
|
|
7
|
|
|
class Message |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @var string |
|
11
|
|
|
*/ |
|
12
|
|
|
protected $messageId; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var string|null |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $text; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var string|null |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $quickReply; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var array |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $attachments; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var array |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $entities; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Message constructor. |
|
36
|
|
|
* |
|
37
|
|
|
* @param string $messageId |
|
38
|
|
|
* @param string $text |
|
39
|
|
|
* @param string $quickReply |
|
40
|
|
|
* @param array $attachments |
|
41
|
|
|
* @param array $entities |
|
42
|
|
|
*/ |
|
43
|
9 |
|
public function __construct( |
|
44
|
|
|
string $messageId, |
|
45
|
|
|
?string $text = null, |
|
46
|
|
|
?string $quickReply = null, |
|
47
|
|
|
array $attachments = [], |
|
48
|
|
|
array $entities = [] |
|
49
|
|
|
) { |
|
50
|
9 |
|
$this->messageId = $messageId; |
|
51
|
9 |
|
$this->text = $text; |
|
52
|
9 |
|
$this->quickReply = $quickReply; |
|
53
|
9 |
|
$this->attachments = $attachments; |
|
54
|
9 |
|
$this->entities = $entities; |
|
55
|
9 |
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @return string |
|
59
|
|
|
*/ |
|
60
|
3 |
|
public function getMessageId(): string |
|
61
|
|
|
{ |
|
62
|
3 |
|
return $this->messageId; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return string|null |
|
67
|
|
|
*/ |
|
68
|
2 |
|
public function getText(): ?string |
|
69
|
|
|
{ |
|
70
|
2 |
|
return $this->text; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return bool |
|
75
|
|
|
*/ |
|
76
|
2 |
|
public function hasText(): bool |
|
77
|
|
|
{ |
|
78
|
2 |
|
return $this->text !== null && $this->text !== ''; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return string|null |
|
83
|
|
|
*/ |
|
84
|
2 |
|
public function getQuickReply(): ?string |
|
85
|
|
|
{ |
|
86
|
2 |
|
return $this->quickReply; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @return bool |
|
91
|
|
|
*/ |
|
92
|
2 |
|
public function hasQuickReply(): bool |
|
93
|
|
|
{ |
|
94
|
2 |
|
return $this->quickReply !== null && $this->quickReply !== ''; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return array |
|
99
|
|
|
*/ |
|
100
|
2 |
|
public function getAttachments(): array |
|
101
|
|
|
{ |
|
102
|
2 |
|
return $this->attachments; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @return bool |
|
107
|
|
|
*/ |
|
108
|
2 |
|
public function hasAttachments(): bool |
|
109
|
|
|
{ |
|
110
|
2 |
|
return !empty($this->attachments); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @return array |
|
115
|
|
|
*/ |
|
116
|
1 |
|
public function getEntities(): array |
|
117
|
|
|
{ |
|
118
|
1 |
|
return $this->entities; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @return bool |
|
123
|
|
|
*/ |
|
124
|
1 |
|
public function hasEntities(): bool |
|
125
|
|
|
{ |
|
126
|
1 |
|
return !empty($this->entities); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @param array $callbackData |
|
131
|
|
|
* |
|
132
|
|
|
* @return \Kerox\Messenger\Model\Callback\Message |
|
133
|
|
|
*/ |
|
134
|
6 |
|
public static function create(array $callbackData) |
|
135
|
|
|
{ |
|
136
|
6 |
|
$text = $callbackData['text'] ?? null; |
|
137
|
6 |
|
$quickReply = $callbackData['quick_reply']['payload'] ?? null; |
|
138
|
6 |
|
$attachments = $callbackData['attachments'] ?? []; |
|
139
|
6 |
|
$entities = $callbackData['nlp']['entities'] ?? []; |
|
140
|
|
|
|
|
141
|
6 |
|
return new self($callbackData['mid'], $text, $quickReply, $attachments, $entities); |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|