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 string|null |
31
|
|
|
*/ |
32
|
|
|
protected $replyTo; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
protected $entities; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Message constructor. |
41
|
|
|
* |
42
|
|
|
* @param string $text |
43
|
|
|
* @param string $quickReply |
44
|
|
|
*/ |
45
|
9 |
|
public function __construct( |
46
|
|
|
string $messageId, |
47
|
|
|
?string $text = null, |
48
|
|
|
?string $quickReply = null, |
49
|
|
|
array $attachments = [], |
50
|
|
|
?string $replyTo = null, |
51
|
|
|
array $entities = [] |
52
|
|
|
) { |
53
|
9 |
|
$this->messageId = $messageId; |
54
|
9 |
|
$this->text = $text; |
55
|
9 |
|
$this->quickReply = $quickReply; |
56
|
9 |
|
$this->attachments = $attachments; |
57
|
9 |
|
$this->replyTo = $replyTo; |
58
|
9 |
|
$this->entities = $entities; |
59
|
9 |
|
} |
60
|
|
|
|
61
|
3 |
|
public function getMessageId(): string |
62
|
|
|
{ |
63
|
3 |
|
return $this->messageId; |
64
|
|
|
} |
65
|
|
|
|
66
|
2 |
|
public function getText(): ?string |
67
|
|
|
{ |
68
|
2 |
|
return $this->text; |
69
|
|
|
} |
70
|
|
|
|
71
|
2 |
|
public function hasText(): bool |
72
|
|
|
{ |
73
|
2 |
|
return $this->text !== null && $this->text !== ''; |
74
|
|
|
} |
75
|
|
|
|
76
|
2 |
|
public function getQuickReply(): ?string |
77
|
|
|
{ |
78
|
2 |
|
return $this->quickReply; |
79
|
|
|
} |
80
|
|
|
|
81
|
2 |
|
public function hasQuickReply(): bool |
82
|
|
|
{ |
83
|
2 |
|
return $this->quickReply !== null && $this->quickReply !== ''; |
84
|
|
|
} |
85
|
|
|
|
86
|
2 |
|
public function getAttachments(): array |
87
|
|
|
{ |
88
|
2 |
|
return $this->attachments; |
89
|
|
|
} |
90
|
|
|
|
91
|
2 |
|
public function hasAttachments(): bool |
92
|
|
|
{ |
93
|
2 |
|
return !empty($this->attachments); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function getReplyTo(): ?string |
97
|
|
|
{ |
98
|
|
|
return $this->replyTo; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function isReply(): bool |
102
|
|
|
{ |
103
|
|
|
return $this->replyTo !== null && $this->replyTo !== ''; |
104
|
|
|
} |
105
|
|
|
|
106
|
1 |
|
public function getEntities(): array |
107
|
|
|
{ |
108
|
1 |
|
return $this->entities; |
109
|
|
|
} |
110
|
|
|
|
111
|
1 |
|
public function hasEntities(): bool |
112
|
|
|
{ |
113
|
1 |
|
return !empty($this->entities); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return \Kerox\Messenger\Model\Callback\Message |
118
|
|
|
*/ |
119
|
6 |
|
public static function create(array $callbackData) |
120
|
|
|
{ |
121
|
6 |
|
$text = $callbackData['text'] ?? null; |
122
|
6 |
|
$attachments = $callbackData['attachments'] ?? []; |
123
|
6 |
|
$quickReply = $callbackData['quick_reply']['payload'] ?? null; |
124
|
6 |
|
$replyTo = $callbackData['reply_to']['mid'] ?? null; |
125
|
6 |
|
$entities = $callbackData['nlp']['entities'] ?? []; |
126
|
|
|
|
127
|
6 |
|
return new self($callbackData['mid'], $text, $quickReply, $attachments, $replyTo, $entities); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|