|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Teebot\Api\Entity; |
|
4
|
|
|
|
|
5
|
|
|
class Message extends AbstractEntity |
|
6
|
|
|
{ |
|
7
|
|
|
const ENTITY_TYPE = 'Message'; |
|
8
|
|
|
|
|
9
|
|
|
const MESSAGE_TYPE_REGEXP_COMMAND = 'RegexpCommand'; |
|
10
|
|
|
|
|
11
|
|
|
protected $messageType = self::ENTITY_TYPE; |
|
12
|
|
|
|
|
13
|
|
|
protected $message_id; |
|
14
|
|
|
|
|
15
|
|
|
/** @var User $from */ |
|
16
|
|
|
protected $from; |
|
17
|
|
|
|
|
18
|
|
|
protected $date; |
|
19
|
|
|
|
|
20
|
|
|
/** @var Chat $chat */ |
|
21
|
|
|
protected $chat; |
|
22
|
|
|
|
|
23
|
|
|
/** @var User $forward_from */ |
|
24
|
|
|
protected $forward_from; |
|
25
|
|
|
|
|
26
|
|
|
protected $forward_date; |
|
27
|
|
|
|
|
28
|
|
|
/** @var Message $reply_to_message */ |
|
29
|
|
|
protected $reply_to_message; |
|
30
|
|
|
|
|
31
|
|
|
protected $text; |
|
32
|
|
|
|
|
33
|
|
|
/** @var MessageEntityArray */ |
|
34
|
|
|
protected $entities; |
|
35
|
|
|
|
|
36
|
|
|
/** @var Audio $audio */ |
|
37
|
|
|
protected $audio; |
|
38
|
|
|
|
|
39
|
|
|
/** @var Document $document */ |
|
40
|
|
|
protected $document; |
|
41
|
|
|
|
|
42
|
|
|
/** @var PhotoSizeArray $photo */ |
|
43
|
|
|
protected $photo; |
|
44
|
|
|
|
|
45
|
|
|
/** @var Sticker $sticker */ |
|
46
|
|
|
protected $sticker; |
|
47
|
|
|
|
|
48
|
|
|
/** @var Video $video */ |
|
49
|
|
|
protected $video; |
|
50
|
|
|
|
|
51
|
|
|
/** @var Voice $voice */ |
|
52
|
|
|
protected $voice; |
|
53
|
|
|
|
|
54
|
|
|
protected $caption; |
|
55
|
|
|
|
|
56
|
|
|
/** @var Contact $contact */ |
|
57
|
|
|
protected $contact; |
|
58
|
|
|
|
|
59
|
|
|
/** @var Location $location */ |
|
60
|
|
|
protected $location; |
|
61
|
|
|
|
|
62
|
|
|
/** @var User $new_chat_participant */ |
|
63
|
|
|
protected $new_chat_participant; |
|
64
|
|
|
|
|
65
|
|
|
/** @var User $left_chat_participant */ |
|
66
|
|
|
protected $left_chat_participant; |
|
67
|
|
|
|
|
68
|
|
|
protected $new_chat_title; |
|
69
|
|
|
|
|
70
|
|
|
/** @var PhotoSize[] $new_chat_photo */ |
|
71
|
|
|
protected $new_chat_photo; |
|
72
|
|
|
|
|
73
|
|
|
protected $delete_chat_photo; |
|
74
|
|
|
|
|
75
|
|
|
protected $group_chat_created; |
|
76
|
|
|
|
|
77
|
|
|
protected $supergroup_chat_created; |
|
78
|
|
|
|
|
79
|
|
|
protected $channel_chat_created; |
|
80
|
|
|
|
|
81
|
|
|
protected $migrate_to_chat_id; |
|
82
|
|
|
|
|
83
|
|
|
protected $migrate_from_chat_id; |
|
84
|
|
|
|
|
85
|
|
|
protected $pinned_message; |
|
86
|
|
|
|
|
87
|
|
|
protected $builtInEntities = [ |
|
88
|
|
|
'from' => User::class, |
|
89
|
|
|
'chat' => Chat::class, |
|
90
|
|
|
'location' => Location::class, |
|
91
|
|
|
'document' => Document::class, |
|
92
|
|
|
'sticker' => Sticker::class, |
|
93
|
|
|
'video' => Video::class, |
|
94
|
|
|
'voice' => Voice::class, |
|
95
|
|
|
'contact' => Contact::class, |
|
96
|
|
|
'audio' => Audio::class, |
|
97
|
|
|
'photo' => PhotoSizeArray::class, |
|
98
|
|
|
'entities' => MessageEntityArray::class |
|
99
|
|
|
]; |
|
100
|
|
|
|
|
101
|
|
|
public function __construct(array $data) |
|
102
|
|
|
{ |
|
103
|
|
|
$data = isset($data['message']) ? $data['message'] : $data; |
|
104
|
|
|
|
|
105
|
|
|
parent::__construct($data); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @return null |
|
110
|
|
|
*/ |
|
111
|
|
|
public function getMessageId() |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->message_id; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* @return User |
|
118
|
|
|
*/ |
|
119
|
|
|
public function getFrom() |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->from; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* @return null |
|
126
|
|
|
*/ |
|
127
|
|
|
public function getChatId() |
|
128
|
|
|
{ |
|
129
|
|
|
if ($this->chat instanceof Chat) { |
|
130
|
|
|
return $this->chat->getId(); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
return null; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @return null |
|
138
|
|
|
*/ |
|
139
|
|
|
public function getDate() |
|
140
|
|
|
{ |
|
141
|
|
|
return $this->date; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @param mixed $text |
|
146
|
|
|
*/ |
|
147
|
|
|
public function setText($text) |
|
148
|
|
|
{ |
|
149
|
|
|
$this->text = $text; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @return null |
|
154
|
|
|
*/ |
|
155
|
|
|
public function getText() |
|
156
|
|
|
{ |
|
157
|
|
|
return $this->text; |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @return array |
|
162
|
|
|
*/ |
|
163
|
|
|
public function getEntities() |
|
164
|
|
|
{ |
|
165
|
|
|
return $this->entities; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @param array $entities |
|
170
|
|
|
*/ |
|
171
|
|
|
public function setEntities($entities) |
|
172
|
|
|
{ |
|
173
|
|
|
if (is_array($entities)) { |
|
174
|
|
|
$source = $this->getText(); |
|
|
|
|
|
|
175
|
|
|
|
|
176
|
|
|
$entities = array_map(function($element) use ($source) { |
|
177
|
|
|
$element['source'] = $source; |
|
178
|
|
|
|
|
179
|
|
|
return $element; |
|
180
|
|
|
}, $entities); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
|
|
184
|
|
|
$this->entities = $entities; |
|
|
|
|
|
|
185
|
|
|
$this->setMessageType($entities); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* @return Chat |
|
190
|
|
|
*/ |
|
191
|
|
|
public function getChat() |
|
192
|
|
|
{ |
|
193
|
|
|
return $this->chat; |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* @return string |
|
198
|
|
|
*/ |
|
199
|
|
|
public function getMessageType() |
|
200
|
|
|
{ |
|
201
|
|
|
return $this->messageType; |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* @return Location |
|
206
|
|
|
*/ |
|
207
|
|
|
public function getLocation() |
|
208
|
|
|
{ |
|
209
|
|
|
return $this->location; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* @param Location $location |
|
214
|
|
|
*/ |
|
215
|
|
|
protected function setLocation($location) |
|
216
|
|
|
{ |
|
217
|
|
|
$this->location = $location; |
|
218
|
|
|
$this->setMessageType($location); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* @return Document |
|
223
|
|
|
*/ |
|
224
|
|
|
public function getDocument() |
|
225
|
|
|
{ |
|
226
|
|
|
return $this->document; |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
/** |
|
230
|
|
|
* @param Document $document |
|
231
|
|
|
*/ |
|
232
|
|
|
public function setDocument($document) |
|
233
|
|
|
{ |
|
234
|
|
|
$this->document = $document; |
|
235
|
|
|
$this->setMessageType($document); |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* @return Sticker |
|
240
|
|
|
*/ |
|
241
|
|
|
public function getSticker() |
|
242
|
|
|
{ |
|
243
|
|
|
return $this->sticker; |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
/** |
|
247
|
|
|
* @param Sticker $sticker |
|
248
|
|
|
*/ |
|
249
|
|
|
public function setSticker($sticker) |
|
250
|
|
|
{ |
|
251
|
|
|
$this->sticker = $sticker; |
|
252
|
|
|
$this->setMessageType($sticker); |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* @return Video |
|
257
|
|
|
*/ |
|
258
|
|
|
public function getVideo() |
|
259
|
|
|
{ |
|
260
|
|
|
return $this->video; |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
/** |
|
264
|
|
|
* @param Video $video |
|
265
|
|
|
*/ |
|
266
|
|
|
public function setVideo($video) |
|
267
|
|
|
{ |
|
268
|
|
|
$this->video = $video; |
|
269
|
|
|
$this->setMessageType($video); |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* @return Voice |
|
274
|
|
|
*/ |
|
275
|
|
|
public function getVoice() |
|
276
|
|
|
{ |
|
277
|
|
|
return $this->voice; |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
/** |
|
281
|
|
|
* @param Voice $voice |
|
282
|
|
|
*/ |
|
283
|
|
|
public function setVoice($voice) |
|
284
|
|
|
{ |
|
285
|
|
|
$this->voice = $voice; |
|
286
|
|
|
$this->setMessageType($voice); |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
/** |
|
290
|
|
|
* @return Contact |
|
291
|
|
|
*/ |
|
292
|
|
|
public function getContact() |
|
293
|
|
|
{ |
|
294
|
|
|
return $this->contact; |
|
295
|
|
|
} |
|
296
|
|
|
|
|
297
|
|
|
/** |
|
298
|
|
|
* @param Contact $contact |
|
299
|
|
|
*/ |
|
300
|
|
|
public function setContact($contact) |
|
301
|
|
|
{ |
|
302
|
|
|
$this->contact = $contact; |
|
303
|
|
|
$this->setMessageType($contact); |
|
304
|
|
|
} |
|
305
|
|
|
|
|
306
|
|
|
/** |
|
307
|
|
|
* @return Audio |
|
308
|
|
|
*/ |
|
309
|
|
|
public function getAudio() |
|
310
|
|
|
{ |
|
311
|
|
|
return $this->audio; |
|
312
|
|
|
} |
|
313
|
|
|
|
|
314
|
|
|
/** |
|
315
|
|
|
* @param Audio $audio |
|
316
|
|
|
*/ |
|
317
|
|
|
public function setAudio($audio) |
|
318
|
|
|
{ |
|
319
|
|
|
$this->audio = $audio; |
|
320
|
|
|
$this->setMessageType($audio); |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
/** |
|
324
|
|
|
* @return PhotoSizeArray |
|
325
|
|
|
*/ |
|
326
|
|
|
public function getPhoto() |
|
327
|
|
|
{ |
|
328
|
|
|
return $this->photo; |
|
329
|
|
|
} |
|
330
|
|
|
|
|
331
|
|
|
/** |
|
332
|
|
|
* @param PhotoSizeArray $photo |
|
333
|
|
|
*/ |
|
334
|
|
|
public function setPhoto($photo) |
|
335
|
|
|
{ |
|
336
|
|
|
$this->photo = $photo; |
|
337
|
|
|
$this->setMessageType($photo); |
|
338
|
|
|
} |
|
339
|
|
|
|
|
340
|
|
|
protected function setMessageType($object) |
|
341
|
|
|
{ |
|
342
|
|
|
$this->messageType = static::ENTITY_TYPE; |
|
343
|
|
|
|
|
344
|
|
|
if ($object instanceof AbstractEntity) { |
|
345
|
|
|
$this->messageType = $object->getEntityType(); |
|
346
|
|
|
} |
|
347
|
|
|
} |
|
348
|
|
|
|
|
349
|
|
|
public function getMessageTypeEntity() |
|
350
|
|
|
{ |
|
351
|
|
|
$messageTypeEntity = null; |
|
352
|
|
|
|
|
353
|
|
|
switch ($this->getMessageType()) { |
|
354
|
|
|
case Location::ENTITY_TYPE: |
|
355
|
|
|
$messageTypeEntity = $this->location; |
|
356
|
|
|
break; |
|
357
|
|
|
case Document::ENTITY_TYPE: |
|
358
|
|
|
$messageTypeEntity = $this->document; |
|
359
|
|
|
break; |
|
360
|
|
|
case Sticker::ENTITY_TYPE: |
|
361
|
|
|
$messageTypeEntity = $this->sticker; |
|
362
|
|
|
break; |
|
363
|
|
|
case Video::ENTITY_TYPE: |
|
364
|
|
|
$messageTypeEntity = $this->video; |
|
365
|
|
|
break; |
|
366
|
|
|
case Voice::ENTITY_TYPE: |
|
367
|
|
|
$messageTypeEntity = $this->voice; |
|
368
|
|
|
break; |
|
369
|
|
|
case Contact::ENTITY_TYPE: |
|
370
|
|
|
$messageTypeEntity = $this->contact; |
|
371
|
|
|
break; |
|
372
|
|
|
case Audio::ENTITY_TYPE: |
|
373
|
|
|
$messageTypeEntity = $this->audio; |
|
374
|
|
|
break; |
|
375
|
|
|
case PhotoSizeArray::ENTITY_TYPE: |
|
376
|
|
|
$messageTypeEntity = $this->photo; |
|
377
|
|
|
break; |
|
378
|
|
|
case MessageEntityArray::ENTITY_TYPE: |
|
379
|
|
|
$messageTypeEntity = $this->entities; |
|
380
|
|
|
break; |
|
381
|
|
|
} |
|
382
|
|
|
|
|
383
|
|
|
return $messageTypeEntity; |
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
|
|
public function hasBuiltinRegexpCommand($pattern) |
|
387
|
|
|
{ |
|
388
|
|
|
return (bool) preg_match($pattern, $this->getText()); |
|
389
|
|
|
} |
|
390
|
|
|
} |
|
391
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.