-
Notifications
You must be signed in to change notification settings - Fork 175
/
Copy pathMessage.php
587 lines (507 loc) · 17 KB
/
Message.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
<?php
declare(strict_types=1);
namespace unreal4u\TelegramAPI\Telegram\Types;
use unreal4u\TelegramAPI\Abstracts\TelegramTypes;
use unreal4u\TelegramAPI\Telegram\Types\Custom\MessageEntityArray;
use unreal4u\TelegramAPI\Telegram\Types\Custom\PhotoSizeArray;
use unreal4u\TelegramAPI\Telegram\Types\Custom\UserArray;
use unreal4u\TelegramAPI\Telegram\Types\Inline\Keyboard\Markup;
use lucadevelop\TelegramEntitiesDecoder\EntityDecoder;
/**
* This object represents a message.
*
* Objects defined as-is november 2020, Bot API v5.0
*
* @see https://core.telegram.org/bots/api#message
*/
class Message extends TelegramTypes
{
/**
* Unique message identifier
* @var int
*/
public $message_id = 0;
/**
* Optional. Unique identifier of a message thread to which the message belongs; for supergroups only
* @var int
*/
public $message_thread_id = 0;
/**
* Optional. Sender, can be empty for messages sent to channels
* @var User
*/
public $from;
/**
* Optional. Sender of the message, sent on behalf of a chat. The channel itself for channel messages. The
* supergroup itself for messages from anonymous group administrators. The linked channel for messages automatically
* forwarded to the discussion group
* @var Chat
*/
public $sender_chat;
/**
* Date the message was sent in Unix time
* @var int
*/
public $date = 0;
/**
* Conversation the message belongs to
* @var Chat
*/
public $chat;
/**
* Optional. For forwarded messages, sender of the original message
* @var User
*/
public $forward_from;
/**
* Optional. For messages forwarded from a channel, information about the original channel
* @var Chat
*/
public $forward_from_chat;
/**
* Optional. For forwarded channel posts, identifier of the original message in the channel
* @var int
*/
public $forward_from_message_id = 0;
/**
* Optional. For messages forwarded from channels, signature of the post author if present
* @var string
*/
public $forward_signature = '';
/**
* Optional. Sender's name for messages forwarded from users who disallow adding a link to their account in
* forwarded messages
* @var string
*/
public $forward_sender_name = '';
/**
* Optional. For forwarded messages, date the original message was sent in Unix time
* @var int
*/
public $forward_date = 0;
/**
* Optional. True, if the message is sent to a forum topic
*/
public $is_topic_message = false;
/**
* @var bool
*/
public $is_automatic_forward = false;
/**
* Optional. For replies, the original message. Note that the Message object in this field will not contain further
* reply_to_message fields even if it itself is a reply.
* @var Message
*/
public $reply_to_message;
/**
* Optional. Bot through which the message was sent
* @var User
*/
public $via_bot;
/**
* Optional. Date the message was last edited in Unix time
* @var int
*/
public $edit_date = 0;
/**
* Optional. True, if the message can't be forwarded
* @var bool
*/
public $has_protected_content = false;
/**
* Optional. The unique identifier of a media message group this message belongs to
* @var string
*/
public $media_group_id;
/**
* Optional. Signature of the post author for messages in channels, or the custom title of an anonymous group
* administrator
* @var string
*/
public $author_signature = '';
/**
* Optional. For text messages, the actual UTF-8 text of the message, 0-4096 characters
* @var string
*/
public $text = '';
/**
* Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text
* @var MessageEntityArray
*/
public $entities = [];
/**
* Optional. Message is an animation, information about the animation. For backward compatibility, when this field
* is set, the document field will also be set
* @var Animation
*/
public $animation;
/**
* Optional. Message is an audio file, information about the file
* @var Audio
*/
public $audio;
/**
* Optional. Message is a general file, information about the file
* @var Document
*/
public $document;
/**
* Optional. Message is a photo, available sizes of the photo
* @var PhotoSizeArray
*/
public $photo = [];
/**
* Optional. Message is a sticker, information about the sticker
* @var Sticker
*/
public $sticker;
/**
* Optional. Message is a video, information about the video
* @var Video
*/
public $video;
/**
* Optional. Message is a video note, information about the video message
* @var VideoNote
*/
public $video_note;
/**
* Optional. Message is a voice message, information about the file
* @var Voice
*/
public $voice;
/**
* Optional. Caption for the photo or video
* @var string
*/
public $caption = '';
/**
* Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in
* the caption
* @var MessageEntityArray
*/
public $caption_entities = [];
/**
* Optional. True, if the message media is covered by a spoiler animation
* the caption
* @var bool
*/
public $has_media_spoiler = false;
/**
* Optional. Message is a shared contact, information about the contact
* @var Contact
*/
public $contact;
/**
* Optional. Message is a dice with random value from 1 to 6
* @var Dice
*/
public $dice;
/**
* Optional. Message is a game, information about the game
* @see https://core.telegram.org/bots/api#games
* @var Game
*/
public $game;
/**
* Optional. Message is a native poll, information about the poll
* @var Poll
*/
public $poll;
/**
* Optional. Message is a venue, information about the venue
* @var Venue
*/
public $venue;
/**
* Optional. Message is a shared location, information about the location
* @var Location
*/
public $location;
/**
* Optional. New members that were added to the group or supergroup and information about them (the bot itself may
* be one of these members)
* @var User[]
*/
public $new_chat_members;
/**
* Optional. A new member was added to the group, information about them (this member may be the bot itself)
*
* @deprecated Backward compatibility, use $new_chat_members array instead
* @var User
*/
public $new_chat_member;
/**
* Optional. A new member was added to the group, information about them (this member may be the bot itself)
*
* @deprecated Backward compatibility, use $new_chat_members array instead
* @var User
*/
public $new_chat_participant;
/**
* Optional. A member was removed from the group, information about them (this member may be the bot itself)
* @var User
*/
public $left_chat_member;
/**
* Optional. A member was removed from the group, information about them (this member may be the bot itself)
*
* @deprecated Backward compatibility, use $left_chat_member instead
* @var User
*/
public $left_chat_participant;
/**
* Optional. A chat title was changed to this value
* @var string
*/
public $new_chat_title = '';
/**
* Optional. A chat photo was change to this value
* @var PhotoSizeArray
*/
public $new_chat_photo = [];
/**
* Optional. Service message: the chat photo was deleted
* @var bool
*/
public $delete_chat_photo = false;
/**
* Optional. Service message: the group has been created
* @var bool
*/
public $group_chat_created = false;
/**
* Optional. Service message: the supergroup has been created. This field can‘t be received in a message coming
* through updates, because bot can’t be a member of a supergroup when it is created. It can only be found in
* reply_to_message if someone replies to a very first message in a directly created supergroup
* @var bool
*/
public $supergroup_chat_created = false;
/**
* Optional. Service message: the channel has been created. This field can‘t be received in a message coming
* through updates, because bot can’t be a member of a channel when it is created. It can only be found in
* reply_to_message if someone replies to a very first message in a channel
* @var bool
*/
public $channel_chat_created = false;
/**
* Optional. Service message: auto-delete timer settings changed in the chat
* @see https://core.telegram.org/bots/api#messageautodeletetimerchanged @TODO
*/
public $message_auto_delete_timer_changed;
/**
* Optional. The group has been migrated to a supergroup with the specified identifier. This number may be greater
* than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it smaller
* than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier
* @var int
*/
public $migrate_to_chat_id = 0;
/**
* Optional. The supergroup has been migrated from a group with the specified identifier. This number may be greater
* than 32 bits and some programming languages may have difficulty/silent defects in interpreting it. But it smaller
* than 52 bits, so a signed 64 bit integer or double-precision float type are safe for storing this identifier
* @var int
*/
public $migrate_from_chat_id = 0;
/**
* Optional. Specified message was pinned. Note that the Message object in this field will not contain further
* reply_to_message fields even if it is itself a reply.
* @var Message
*/
public $pinned_message;
/**
* Optional. Message is an invoice for a payment, information about the invoice
* @see https://core.telegram.org/bots/api#payments
* @var Invoice
*/
public $invoice;
/**
* Optional. Message is a service message about a successful payment, information about the payment
* @var SuccessfulPayment
*/
public $successful_payment;
/**
* Optional. Service message: a user was shared with the bot
* @see https://core.telegram.org/bots/api#usershared @TODO
*/
public $user_shared;
/**
* Optional. Service message: a chat was shared with the bot
* @see https://core.telegram.org/bots/api#chatshared @TODO
*/
public $chat_shared;
/**
* Optional. The domain name of the website on which the user has logged in
* @see https://core.telegram.org/widgets/login
* @var string
*/
public $connected_website = '';
/**
* Optional. Service message: the user allowed the bot added to the attachment menu to write messages
* @see https://core.telegram.org/bots/api#writeaccessallowed @TODO
*/
public $write_access_allowed;
/**
* Optional. Telegram Passport data
* @see https://core.telegram.org/bots/api#passportdata @TODO
*/
public $passport_data;
/**
* Optional. Service message. A user in the chat triggered another user's proximity alert while sharing Live
* Location
* @var ProximityAlertTriggered
*/
public $proximity_alert_triggered;
/**
* Optional. Service message: forum topic created
* @var ForumTopicCreated
*/
public $forum_topic_created;
/**
* Optional. Service message: forum topic edited
* @var ForumTopicEdited
*/
public $forum_topic_edited;
/**
* Optional. Service message: forum topic closed
* @var ForumTopicClosed
*/
public $forum_topic_closed;
/**
* Optional. Service message: forum topic reopened
* @var ForumTopicReopened
*/
public $forum_topic_reopened;
/**
* Optional. Service message: the 'General' forum topic hidden
* @see https://core.telegram.org/bots/api#generalforumtopichidden @TODO
*/
public $general_forum_topic_hidden;
/**
* Optional. Service message: the 'General' forum topic unhidden
* @see https://core.telegram.org/bots/api#generalforumtopicunhidden @TODO
*/
public $general_forum_topic_unhidden;
/**
* Optional. Service message: video chat scheduled
* @see https://core.telegram.org/bots/api#videochatscheduled @TODO
*/
public $video_chat_scheduled;
/**
* Optional. Service message: video chat started
* @see https://core.telegram.org/bots/api#videochatstarted @TODO
*/
public $video_chat_started;
/**
* Optional. Service message: video chat ended
* @see https://core.telegram.org/bots/api#videochatended @TODO
*/
public $video_chat_ended;
/**
* Optional. Service message: new participants invited to a video chat
* @see https://core.telegram.org/bots/api#videochatparticipantsinvited @TODO
*/
public $video_chat_participants_invited;
/**
* Optional. Service message: data sent by a Web App
* @see https://core.telegram.org/bots/api#webappdata @TODO
*/
public $web_app_data;
/**
* @var Markup
*/
public $reply_markup;
/**
* A message may contain one or more subobjects, map them always in this function
*
* @param string $key
* @param array $data
* @return TelegramTypes
*/
protected function mapSubObjects(string $key, array $data): TelegramTypes
{
switch ($key) {
case 'from':
case 'forward_from':
case 'new_chat_member':
case 'new_chat_participant':
case 'left_chat_member':
case 'left_chat_participant':
case 'via_bot':
return new User($data, $this->logger);
case 'new_chat_members':
return new UserArray($data, $this->logger);
case 'photo':
case 'new_chat_photo':
return new PhotoSizeArray($data, $this->logger);
case 'sender_chat':
case 'chat':
case 'forward_from_chat':
return new Chat($data, $this->logger);
case 'reply_to_message':
case 'pinned_message':
return new Message($data, $this->logger);
case 'entities':
case 'caption_entities':
return new MessageEntityArray($data, $this->logger);
case 'audio':
return new Audio($data, $this->logger);
case 'document':
return new Document($data, $this->logger);
case 'animation':
return new Animation($data, $this->logger);
case 'game':
return new Game($data, $this->logger);
case 'dice':
return new Dice($data, $this->logger);
case 'sticker':
return new Sticker($data, $this->logger);
case 'video':
return new Video($data, $this->logger);
case 'voice':
return new Voice($data, $this->logger);
case 'video_note':
return new VideoNote($data, $this->logger);
case 'contact':
return new Contact($data, $this->logger);
case 'location':
return new Location($data, $this->logger);
case 'venue':
return new Venue($data, $this->logger);
case 'poll':
return new Poll($data, $this->logger);
case 'invoice':
return new Invoice($data, $this->logger);
case 'successful_payment':
return new SuccessfulPayment($data, $this->logger);
case 'reply_markup':
return new Markup($data, $this->logger);
case 'proximity_alert_triggered':
return new ProximityAlertTriggered($data, $this->logger);
case 'forum_topic_created':
return new ForumTopicCreated($data, $this->logger);
case 'forum_topic_edited':
return new ForumTopicEdited($data, $this->logger);
case 'forum_topic_closed':
return new ForumTopicClosed($data, $this->logger);
case 'forum_topic_reopened':
return new ForumTopicReopened($data, $this->logger);
}
// Return always null if none of the objects above matches
return parent::mapSubObjects($key, $data);
}
/**
* Decode style entities from Telegram bot messages in text with inline entities.
*
* @param string $style Use 'HTML', 'MarkdownV2' or 'Markdown'
*
* @throws InvalidArgumentException if the provided style name is invalid.
*
* @return string
*/
public function decodeEntities($style = 'HTML'): string
{
$entitiesDecoder = new EntityDecoder($style);
return $entitiesDecoder->decode($this);
}
}