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