|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the TelegramBot package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Avtandil Kikabidze aka LONGMAN <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Longman\TelegramBot\Entities; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class Chat |
|
16
|
|
|
* |
|
17
|
|
|
* @link https://core.telegram.org/bots/api#chat |
|
18
|
|
|
* |
|
19
|
|
|
* @property string type Type of chat, can be either "private ", "group", "supergroup" or "channel" |
|
20
|
|
|
* |
|
21
|
|
|
* @method int getId() Unique identifier for this chat. 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. |
|
22
|
|
|
* @method string getType() Type of chat, can be either "private ", "group", "supergroup" or "channel" |
|
23
|
|
|
* @method string getTitle() Optional. Title, for channels and group chats |
|
24
|
|
|
* @method string getUsername() Optional. Username, for private chats, supergroups and channels if available |
|
25
|
|
|
* @method string getFirstName() Optional. First name of the other party in a private chat |
|
26
|
|
|
* @method string getLastName() Optional. Last name of the other party in a private chat |
|
27
|
|
|
* @method ChatPhoto getPhoto() Optional. Chat photo. Returned only in getChat. |
|
28
|
|
|
* @method string getDescription() Optional. Description, for groups, supergroups and channel chats. Returned only in getChat. |
|
29
|
|
|
* @method string getInviteLink() Optional. Chat invite link, for groups, supergroups and channel chats. Each administrator in a chat generates their own invite links, so the bot must first generate the link using exportChatInviteLink. Returned only in getChat. |
|
30
|
|
|
* @method Message getPinnedMessage() Optional. Pinned message, for groups, supergroups and channels. Returned only in getChat. |
|
31
|
|
|
* @method ChatPermissions getPermissions() Optional. Default chat member permissions, for groups and supergroups. Returned only in getChat. |
|
32
|
|
|
* @method int getSlowModeDelay() Optional. For supergroups, the minimum allowed delay between consecutive messages sent by each unpriviledged user. Returned only in getChat. |
|
33
|
|
|
* @method string getStickerSetName() Optional. For supergroups, name of group sticker set. Returned only in getChat. |
|
34
|
|
|
* @method bool getCanSetStickerSet() Optional. True, if the bot can change the group sticker set. Returned only in getChat. |
|
35
|
|
|
*/ |
|
36
|
|
|
class Chat extends Entity |
|
37
|
|
|
{ |
|
38
|
|
|
/** |
|
39
|
|
|
* {@inheritdoc} |
|
40
|
|
|
*/ |
|
41
|
11 |
|
protected function subEntities() |
|
42
|
|
|
{ |
|
43
|
|
|
return [ |
|
44
|
11 |
|
'photo' => ChatPhoto::class, |
|
45
|
|
|
'pinned_message' => Message::class, |
|
46
|
|
|
'permissions' => ChatPermissions::class, |
|
47
|
|
|
]; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
11 |
|
public function __construct($data) |
|
51
|
|
|
{ |
|
52
|
11 |
|
parent::__construct($data); |
|
53
|
|
|
|
|
54
|
11 |
|
$id = $this->getId(); |
|
55
|
11 |
|
$type = $this->getType(); |
|
56
|
11 |
|
if (!$type) { |
|
57
|
5 |
|
$id > 0 && $this->type = 'private'; |
|
58
|
5 |
|
$id < 0 && $this->type = 'group'; |
|
59
|
|
|
} |
|
60
|
11 |
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Try to mention the user of this chat, else return the title |
|
64
|
|
|
* |
|
65
|
|
|
* @param bool $escape_markdown |
|
66
|
|
|
* |
|
67
|
|
|
* @return string|null |
|
68
|
|
|
*/ |
|
69
|
1 |
|
public function tryMention($escape_markdown = false) |
|
70
|
|
|
{ |
|
71
|
1 |
|
if ($this->isPrivateChat()) { |
|
72
|
1 |
|
return parent::tryMention($escape_markdown); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
1 |
|
return $this->getTitle(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Check if this is a group chat |
|
80
|
|
|
* |
|
81
|
|
|
* @return bool |
|
82
|
|
|
*/ |
|
83
|
1 |
|
public function isGroupChat() |
|
84
|
|
|
{ |
|
85
|
1 |
|
return $this->getType() === 'group' || $this->getId() < 0; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Check if this is a private chat |
|
90
|
|
|
* |
|
91
|
|
|
* @return bool |
|
92
|
|
|
*/ |
|
93
|
2 |
|
public function isPrivateChat() |
|
94
|
|
|
{ |
|
95
|
2 |
|
return $this->getType() === 'private'; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Check if this is a super group |
|
100
|
|
|
* |
|
101
|
|
|
* @return bool |
|
102
|
|
|
*/ |
|
103
|
1 |
|
public function isSuperGroup() |
|
104
|
|
|
{ |
|
105
|
1 |
|
return $this->getType() === 'supergroup'; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Check if this is a channel |
|
110
|
|
|
* |
|
111
|
|
|
* @return bool |
|
112
|
|
|
*/ |
|
113
|
1 |
|
public function isChannel() |
|
114
|
|
|
{ |
|
115
|
1 |
|
return $this->getType() === 'channel'; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Optional. True if a group has 'All Members Are Admins' enabled. |
|
120
|
|
|
* |
|
121
|
|
|
* @deprecated |
|
122
|
|
|
* @see Chat::getPermissions() |
|
123
|
|
|
* |
|
124
|
|
|
* @return bool |
|
125
|
|
|
*/ |
|
126
|
6 |
|
public function getAllMembersAreAdministrators() |
|
127
|
|
|
{ |
|
128
|
6 |
|
return $this->getProperty('all_members_are_administrators'); |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|