Passed
Push — main ( 2e4cb3...b411b6 )
by Miaad
01:58
created

message   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 624
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 178
c 4
b 0
f 0
dl 0
loc 624
rs 10
wmc 24

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 2
A forward() 0 2 1
A isOwner() 0 2 1
B isMedia() 0 3 8
A banMember() 0 5 2
A pinChatMessage() 0 2 1
A delete() 0 2 1
A kickMember() 0 5 2
A isCommand() 0 2 1
A isForwarded() 0 2 1
A isReplied() 0 2 1
A copy() 0 2 1
A editText() 0 2 1
A isAdmin() 0 2 1
1
<?php
2
3
namespace BPT\types;
4
5
use BPT\constants\chatMemberStatus;
6
use BPT\telegram\telegram;
7
use stdClass;
8
9
/**
10
 * This object represents a message.
11
 */
12
class message extends types {
0 ignored issues
show
Bug introduced by
The type BPT\types\types was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
    /** Keep all properties which has sub properties */
14
    protected const subs = [
15
        'from' => 'BPT\types\user',
16
        'sender_chat' => 'BPT\types\chat',
17
        'sender_business_bot' => 'BPT\types\user',
18
        'chat' => 'BPT\types\chat',
19
        'forward_from' => 'BPT\types\user',
20
        'forward_from_chat' => 'BPT\types\chat',
21
        'forward_origin' => 'BPT\types\messageOrigin',
22
        'reply_to_message' => 'BPT\types\message',
23
        'external_reply' => 'BPT\types\externalReplyInfo',
24
        'quote' => 'BPT\types\textQuote',
25
        'reply_to_story' => 'BPT\types\story',
26
        'via_bot' => 'BPT\types\user',
27
        'array' => [
28
            'entities' => 'BPT\types\messageEntity',
29
            'photo' => 'BPT\types\photoSize',
30
            'caption_entities' => 'BPT\types\messageEntity',
31
            'new_chat_members' => 'BPT\types\user',
32
            'new_chat_photo' => 'BPT\types\photoSize',
33
        ],
34
        'link_preview_options' => 'BPT\types\linkPreviewOptions',
35
        'animation' => 'BPT\types\animation',
36
        'audio' => 'BPT\types\audio',
37
        'document' => 'BPT\types\document',
38
        'sticker' => 'BPT\types\sticker',
39
        'story' => 'BPT\types\story',
40
        'video' => 'BPT\types\video',
41
        'video_note' => 'BPT\types\videoNote',
42
        'voice' => 'BPT\types\voice',
43
        'contact' => 'BPT\types\contact',
44
        'dice' => 'BPT\types\dice',
45
        'game' => 'BPT\types\game',
46
        'poll' => 'BPT\types\poll',
47
        'venue' => 'BPT\types\venue',
48
        'location' => 'BPT\types\location',
49
        'left_chat_member' => 'BPT\types\user',
50
        'message_auto_delete_timer_changed' => 'BPT\types\messageAutoDeleteTimerChanged',
51
        'pinned_message' => 'BPT\types\maybeInaccessibleMessage',
52
        'invoice' => 'BPT\types\invoice',
53
        'successful_payment' => 'BPT\types\successfulPayment',
54
        'users_shared' => 'BPT\types\usersShared',
55
        'user_shared' => 'BPT\types\userShared',
56
        'chat_shared' => 'BPT\types\chatShared',
57
        'write_access_allowed' => 'BPT\types\writeAccessAllowed',
58
        'passport_data' => 'BPT\types\passportData',
59
        'proximity_alert_triggered' => 'BPT\types\proximityAlertTriggered',
60
        'boost_added' => 'BPT\types\chatBoostAdded',
61
        'chat_background_set' => 'BPT\types\chatBackground',
62
        'forum_topic_created' => 'BPT\types\forumTopicCreated',
63
        'forum_topic_edited' => 'BPT\types\forumTopicEdited',
64
        'forum_topic_closed' => 'BPT\types\forumTopicClosed',
65
        'forum_topic_reopened' => 'BPT\types\forumTopicReopened',
66
        'general_forum_topic_hidden' => 'BPT\types\generalForumTopicHidden',
67
        'general_forum_topic_unhidden' => 'BPT\types\generalForumTopicUnhidden',
68
        'giveaway_created' => 'BPT\types\giveawayCreated',
69
        'giveaway' => 'BPT\types\giveaway',
70
        'giveaway_winners' => 'BPT\types\giveawayWinners',
71
        'giveaway_completed' => 'BPT\types\giveawayCompleted',
72
        'video_chat_scheduled' => 'BPT\types\videoChatScheduled',
73
        'video_chat_started' => 'BPT\types\videoChatStarted',
74
        'video_chat_ended' => 'BPT\types\videoChatEnded',
75
        'video_chat_participants_invited' => 'BPT\types\videoChatParticipantsInvited',
76
        'web_app_data' => 'BPT\types\webAppData',
77
        'reply_markup' => 'BPT\types\inlineKeyboardMarkup',
78
    ];
79
80
    /** Unique message identifier inside this chat */
81
    public int $id;
82
83
    /** Unique message identifier inside this chat */
84
    public int $message_id;
85
86
    /** Optional. Unique identifier of a message thread to which the message belongs; for supergroups only */
87
    public null|int $message_thread_id = null;
88
89
    /**
90
     * Optional. Sender of the message; empty for messages sent to channels. For backward compatibility, the field
91
     * contains a fake sender user in non-channel chats, if the message was sent on behalf of a chat.
92
     */
93
    public null|user $from = null;
94
95
    /**
96
     * Optional. Sender of the message, sent on behalf of a chat. For example, the channel itself for channel posts,
97
     * the supergroup itself for messages from anonymous group administrators, the linked channel for messages
98
     * automatically forwarded to the discussion group. For backward compatibility, the field from contains a fake
99
     * sender user in non-channel chats, if the message was sent on behalf of a chat.
100
     */
101
    public null|chat $sender_chat = null;
102
103
    /** Optional. If the sender of the message boosted the chat, the number of boosts added by the user */
104
    public null|int $sender_boost_count = null;
105
106
    /**
107
     * Optional. The bot that actually sent the message on behalf of the business account. Available only for
108
     * outgoing messages sent on behalf of the connected business account.
109
     */
110
    public null|user $sender_business_bot = null;
111
112
    /** Date the message was sent in Unix time. It is always a positive number, representing a valid date. */
113
    public int $date;
114
115
    /**
116
     * Optional. Unique identifier of the business connection from which the message was received. If non-empty, the
117
     * message belongs to a chat of the corresponding business account that is independent from any potential bot
118
     * chat which might share the same identifier.
119
     */
120
    public null|string $business_connection_id = null;
121
122
    /** Chat the message belongs to */
123
    public chat $chat;
124
125
    /**
126
     * Optional. For forwarded messages, sender of the original message
127
     *
128
     * @deprecated used forward_origin instead
129
     */
130
    public null|user $forward_from = null;
131
132
    /**
133
     * Optional. For messages forwarded from channels or from anonymous administrators, information about the
134
     * original sender chat
135
     *
136
     * @deprecated used forward_origin instead
137
     */
138
    public null|chat $forward_from_chat = null;
139
140
    /**
141
     * Optional. For messages forwarded from channels, identifier of the original message in the channel
142
     *
143
     * @deprecated used forward_origin instead
144
     */
145
    public null|int $forward_from_message_id = null;
146
147
    /**
148
     * Optional. For forwarded messages that were originally sent in channels or by an anonymous chat administrator,
149
     * signature of the message sender if present
150
     *
151
     * @deprecated used forward_origin instead
152
     */
153
    public null|string $forward_signature = null;
154
155
    /**
156
     * Optional. Sender's name for messages forwarded from users who disallow adding a link to their account in
157
     * forwarded messages
158
     *
159
     * @deprecated used forward_origin instead
160
     */
161
    public null|string $forward_sender_name = null;
162
163
    /**
164
     * Optional. For forwarded messages, date the original message was sent in Unix time
165
     * @deprecated used forward_origin instead
166
     */
167
    public null|int $forward_date = null;
168
169
    /** Optional. Information about the original message for forwarded messages */
170
    public null|messageOrigin $forward_origin = null;
171
172
    /** Optional. True, if the message is sent to a forum topic */
173
    public null|bool $is_topic_message = null;
174
175
    /**
176
     * Optional. True, if the message is a channel post that was automatically forwarded to the connected discussion
177
     * group
178
     */
179
    public null|bool $is_automatic_forward = null;
180
181
    /**
182
     * Optional. For replies in the same chat and message thread, the original message. Note that the Message object
183
     * in this field will not contain further reply_to_message fields even if it itself is a reply.
184
     */
185
    public null|message $reply_to_message = null;
186
187
    /**
188
     * Optional. Information about the message that is being replied to, which may come from another chat or forum
189
     * topic
190
     */
191
    public null|externalReplyInfo $external_reply = null;
192
193
    /** Optional. For replies that quote part of the original message, the quoted part of the message */
194
    public null|textQuote $quote = null;
195
196
    /** Optional. For replies to a story, the original story */
197
    public null|story $reply_to_story = null;
198
199
    /** Optional. Bot through which the message was sent */
200
    public null|user $via_bot = null;
201
202
    /** Optional. Date the message was last edited in Unix time */
203
    public null|int $edit_date = null;
204
205
    /** Optional. True, if the message can't be forwarded */
206
    public null|bool $has_protected_content = null;
207
208
    /**
209
     * Optional. True, if the message was sent by an implicit action, for example, as an away or a greeting business
210
     * message, or as a scheduled message
211
     */
212
    public null|bool $is_from_offline = null;
213
214
    /** Optional. The unique identifier of a media message group this message belongs to */
215
    public null|string $media_group_id = null;
216
217
    /**
218
     * Optional. Signature of the post author for messages in channels, or the custom title of an anonymous group
219
     * administrator
220
     */
221
    public null|string $author_signature = null;
222
223
    /** Optional. For text messages, the actual UTF-8 text of the message */
224
    public null|string $text = null;
225
226
    /** Optional. If user message was a command , this parameter will be the command */
227
    public string|null $command = null;
228
229
    /** Optional. If user message was a command , this parameter will be the command username(if exist) */
230
    public string|null $command_username = null;
231
232
    /** Optional. If user message was a command , this parameter will be the command payload(if exist) */
233
    public string|null $command_payload = null;
234
235
    /**
236
     * Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text
237
     * @var messageEntity[]
238
     */
239
    public null|array $entities = null;
240
241
    /**
242
     * Optional. Options used for link preview generation for the message, if it is a text message and link preview
243
     * options were changed
244
     */
245
    public null|linkPreviewOptions $link_preview_options = null;
246
247
    /** Optional. Unique identifier of the message effect added to the message */
248
    public null|string $effect_id = null;
249
250
    /**
251
     * Optional. Message is an animation, information about the animation. For backward compatibility, when this
252
     * field is set, the document field will also be set
253
     */
254
    public null|animation $animation = null;
255
256
    /** Optional. Message is an audio file, information about the file */
257
    public null|audio $audio = null;
258
259
    /** Optional. Message is a general file, information about the file */
260
    public null|document $document = null;
261
262
    /**
263
     * Optional. Message is a photo, available sizes of the photo
264
     * @var photoSize[]
265
     */
266
    public null|array $photo = null;
267
268
    /** Optional. Message is a sticker, information about the sticker */
269
    public null|sticker $sticker = null;
270
271
    /** Optional. Message is a forwarded story */
272
    public null|story $story = null;
273
274
    /** Optional. Message is a video, information about the video */
275
    public null|video $video = null;
276
277
    /** Optional. Message is a video note, information about the video message */
278
    public null|videoNote $video_note = null;
279
280
    /** Optional. Message is a voice message, information about the file */
281
    public null|voice $voice = null;
282
283
    /** Optional. Caption for the animation, audio, document, photo, video or voice */
284
    public null|string $caption = null;
285
286
    /**
287
     * Optional. For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear
288
     * in the caption
289
     * @var messageEntity[]
290
     */
291
    public null|array $caption_entities = null;
292
293
    /** Optional. True, if the caption must be shown above the message media */
294
    public null|bool $show_caption_above_media = null;
295
296
    /** Optional. True, if the message media is covered by a spoiler animation */
297
    public null|bool $has_media_spoiler = null;
298
299
    /** Optional. Message is a shared contact, information about the contact */
300
    public null|contact $contact = null;
301
302
    /** Optional. Message is a dice with random value */
303
    public null|dice $dice = null;
304
305
    /** Optional. Message is a game, information about the game. More about games » */
306
    public null|game $game = null;
307
308
    /** Optional. Message is a native poll, information about the poll */
309
    public null|poll $poll = null;
310
311
    /**
312
     * Optional. Message is a venue, information about the venue. For backward compatibility, when this field is set,
313
     * the location field will also be set
314
     */
315
    public null|venue $venue = null;
316
317
    /** Optional. Message is a shared location, information about the location */
318
    public null|location $location = null;
319
320
    /**
321
     * Optional. New members that were added to the group or supergroup and information about them (the bot itself
322
     * may be one of these members)
323
     * @var user[]
324
     */
325
    public null|array $new_chat_members = null;
326
327
    /** Optional. A member was removed from the group, information about them (this member may be the bot itself) */
328
    public null|user $left_chat_member = null;
329
330
    /** Optional. A chat title was changed to this value */
331
    public null|string $new_chat_title = null;
332
333
    /**
334
     * Optional. A chat photo was change to this value
335
     * @var photoSize[]
336
     */
337
    public null|array $new_chat_photo = null;
338
339
    /** Optional. Service message: the chat photo was deleted */
340
    public null|bool $delete_chat_photo = null;
341
342
    /** Optional. Service message: the group has been created */
343
    public null|bool $group_chat_created = null;
344
345
    /**
346
     * Optional. Service message: the supergroup has been created. This field can't be received in a message coming
347
     * through updates, because bot can't be a member of a supergroup when it is created. It can only be found in
348
     * reply_to_message if someone replies to a very first message in a directly created supergroup.
349
     */
350
    public null|bool $supergroup_chat_created = null;
351
352
    /**
353
     * Optional. Service message: the channel has been created. This field can't be received in a message coming
354
     * through updates, because bot can't be a member of a channel when it is created. It can only be found in
355
     * reply_to_message if someone replies to a very first message in a channel.
356
     */
357
    public null|bool $channel_chat_created = null;
358
359
    /** Optional. Service message: auto-delete timer settings changed in the chat */
360
    public null|messageAutoDeleteTimerChanged $message_auto_delete_timer_changed = null;
361
362
    /**
363
     * Optional. The group has been migrated to a supergroup with the specified identifier. This number may have more
364
     * than 32 significant bits and some programming languages may have difficulty/silent defects in interpreting it.
365
     * But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float type are safe for
366
     * storing this identifier.
367
     */
368
    public null|int $migrate_to_chat_id = null;
369
370
    /**
371
     * Optional. The supergroup has been migrated from a group with the specified identifier. This number may have
372
     * more than 32 significant bits and some programming languages may have difficulty/silent defects in
373
     * interpreting it. But it has at most 52 significant bits, so a signed 64-bit integer or double-precision float
374
     * type are safe for storing this identifier.
375
     */
376
    public null|int $migrate_from_chat_id = null;
377
378
    /**
379
     * Optional. Specified message was pinned. Note that the Message object in this field will not contain further
380
     * reply_to_message fields even if it itself is a reply.
381
     */
382
    public null|maybeInaccessibleMessage $pinned_message = null;
383
384
    /** Optional. Message is an invoice for a payment, information about the invoice. More about payments » */
385
    public null|invoice $invoice = null;
386
387
    /**
388
     * Optional. Message is a service message about a successful payment, information about the payment. More about
389
     * payments »
390
     */
391
    public null|successfulPayment $successful_payment = null;
392
393
    /** Optional. Service message: users were shared with the bot */
394
    public null|usersShared $users_shared = null;
395
396
    /**
397
     * Optional. Service message: a user was shared with the bot
398
     *
399
     * This is a legacy property, and could be removed in the future
400
     *
401
     * @deprecated use users_shared instead
402
     */
403
    public null|userShared $user_shared = null;
404
405
    /** Optional. Service message: a chat was shared with the bot */
406
    public null|chatShared $chat_shared = null;
407
408
    /** Optional. The domain name of the website on which the user has logged in. More about Telegram Login » */
409
    public null|string $connected_website = null;
410
411
    /**
412
     * Optional. Service message: the user allowed the bot to write messages after adding it to the attachment or
413
     * side menu, launching a Web App from a link, or accepting an explicit request from a Web App sent by the method
414
     * requestWriteAccess
415
     */
416
    public null|writeAccessAllowed $write_access_allowed = null;
417
418
    /** Optional. Telegram Passport data */
419
    public null|passportData $passport_data = null;
420
421
    /**
422
     * Optional. Service message. A user in the chat triggered another user's proximity alert while sharing Live
423
     * Location.
424
     */
425
    public null|proximityAlertTriggered $proximity_alert_triggered = null;
426
427
    /** Optional. Service message: user boosted the chat */
428
    public null|chatBoostAdded $boost_added = null;
429
430
    /** Optional. Service message: chat background set */
431
    public null|chatBackground $chat_background_set = null;
432
433
    /** Optional. Service message: forum topic created */
434
    public null|forumTopicCreated $forum_topic_created = null;
435
436
    /** Optional. Service message: forum topic edited */
437
    public null|forumTopicEdited $forum_topic_edited = null;
438
439
    /** Optional. Service message: forum topic closed */
440
    public null|forumTopicClosed $forum_topic_closed = null;
441
442
    /** Optional. Service message: forum topic reopened */
443
    public null|forumTopicReopened $forum_topic_reopened = null;
444
445
    /** Optional. Service message: the 'General' forum topic hidden */
446
    public null|generalForumTopicHidden $general_forum_topic_hidden = null;
447
448
    /** Optional. Service message: the 'General' forum topic unhidden */
449
    public null|generalForumTopicUnhidden $general_forum_topic_unhidden = null;
450
451
    /** Optional. Service message: a scheduled giveaway was created */
452
    public null|giveawayCreated $giveaway_created = null;
453
454
    /** Optional. The message is a scheduled giveaway message */
455
    public null|giveaway $giveaway = null;
456
457
    /** Optional. A giveaway with public winners was completed */
458
    public null|giveawayWinners $giveaway_winners = null;
459
460
    /** Optional. Service message: a giveaway without public winners was completed */
461
    public null|giveawayCompleted $giveaway_completed = null;
462
463
    /** Optional. Service message: video chat scheduled */
464
    public null|videoChatScheduled $video_chat_scheduled = null;
465
466
    /** Optional. Service message: video chat started */
467
    public null|videoChatStarted $video_chat_started = null;
468
469
    /** Optional. Service message: video chat ended */
470
    public null|videoChatEnded $video_chat_ended = null;
471
472
    /** Optional. Service message: new participants invited to a video chat */
473
    public null|videoChatParticipantsInvited $video_chat_participants_invited = null;
474
475
    /** Optional. Service message: data sent by a Web App */
476
    public null|webAppData $web_app_data = null;
477
478
    /** Optional. Inline keyboard attached to the message. login_url buttons are represented as ordinary url buttons. */
479
    public null|inlineKeyboardMarkup $reply_markup = null;
480
481
482
    public function __construct(stdClass|null $object = null) {
483
        if ($object != null) {
484
            parent::__construct($object, self::subs);
485
486
        }
487
    }
488
489
    /**
490
     * Is it a media message or not
491
     *
492
     * @return bool
493
     */
494
    public function isMedia (): bool {
495
        return isset($this->animation) || isset($this->audio) || isset($this->document) || isset($this->video) ||
496
               isset($this->photo) || isset($this->voice) || isset($this->video_note) || isset($this->sticker);
497
    }
498
499
    /**
500
     * Is it a command message or not
501
     *
502
     * @return bool
503
     */
504
    public function isCommand (): bool {
505
        return !empty($this->command);
506
    }
507
508
    /**
509
     * Is it forwarded or not
510
     *
511
     * @return bool
512
     */
513
    public function isForwarded (): bool {
514
        return $this->forward_origin !== null;
515
    }
516
517
    /**
518
     * Is it replied or not
519
     *
520
     * @return bool
521
     */
522
    public function isReplied (): bool {
523
        return !empty($this->reply_to_message);
524
    }
525
526
    /**
527
     * Is user admin of the chat or not
528
     *
529
     * Only in not private chat
530
     *
531
     * @return bool
532
     */
533
    public function isAdmin (): bool {
534
        return $this->chat->getMember($this->from->id)->status === chatMemberStatus::ADMINISTRATOR;
535
    }
536
537
    /**
538
     * Is user owner of the chat or not
539
     *
540
     * Only in not private chat
541
     *
542
     * @return bool
543
     */
544
    public function isOwner (): bool {
545
        return $this->chat->getMember($this->from->id)->status === chatMemberStatus::CREATOR;
546
    }
547
548
    /**
549
     * Ban member from this chat
550
     *
551
     * return false in private chats
552
     *
553
     * @param bool|null $answer
554
     *
555
     * @return responseError|bool
556
     */
557
    public function banMember(bool $answer = null): responseError|bool {
558
        if ($this->chat->isPrivate()) {
559
            return false;
560
        }
561
        return telegram::banChatMember($this->chat->id, $this->from->id, answer: $answer);
562
    }
563
564
    /**
565
     * kick member from this chat
566
     *
567
     * return false in private chats
568
     *
569
     * @param bool|null $answer
570
     *
571
     * @return responseError|bool
572
     */
573
    public function kickMember(bool $answer = null): responseError|bool {
574
        if ($this->chat->isPrivate()) {
575
            return false;
576
        }
577
        return telegram::unbanChatMember($this->chat->id, $this->from->id, answer: $answer);
578
    }
579
580
    /**
581
     * Delete this message
582
     *
583
     * @param bool|null $answer
584
     *
585
     * @return responseError|bool
586
     */
587
    public function delete (bool $answer = null): responseError|bool {
588
        return telegram::deleteMessage($this->chat->id,$this->id, answer: $answer);
589
    }
590
591
    /**
592
     * Pin this message
593
     *
594
     * @param bool|null $answer
595
     *
596
     * @return responseError|bool
597
     */
598
    public function pinChatMessage (bool $answer = null): responseError|bool {
599
        return telegram::deleteMessage($this->chat->id,$this->id, answer: $answer);
600
    }
601
602
    /**
603
     * Edit message text(Only for bot messages or channel messages)
604
     *
605
     * @param string    $text
606
     * @param bool|null $answer
607
     *
608
     * @return message|responseError|bool
609
     */
610
    public function editText (string $text, bool $answer = null): message|responseError|bool {
611
        return telegram::editMessageText($text,  $this->chat->id, $this->message_id, answer: $answer);
612
    }
613
614
    /**
615
     * Copy this message(Anonymous forward)
616
     *
617
     * @param int|string $chat_id
618
     * @param bool|null  $answer
619
     *
620
     * @return messageId|responseError
621
     */
622
    public function copy (int|string $chat_id, bool $answer = null): messageId|responseError {
623
        return telegram::copyMessage($chat_id, answer: $answer);
624
    }
625
626
    /**
627
     * Forward this message
628
     *
629
     * @param int|string $chat_id
630
     * @param bool|null  $answer
631
     *
632
     * @return message|responseError
633
     */
634
    public function forward (int|string $chat_id, bool $answer = null): message|responseError {
635
        return telegram::forwardMessage($chat_id, answer: $answer);
636
    }
637
}
638