1 | <?php |
||
48 | class Message extends Entity |
||
49 | { |
||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | 3 | protected function subEntities() |
|
77 | |||
78 | /** |
||
79 | * Message constructor |
||
80 | * |
||
81 | * @param array $data |
||
82 | * @param string $bot_username |
||
83 | * |
||
84 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
85 | */ |
||
86 | 5 | public function __construct(array $data, $bot_username = '') |
|
100 | |||
101 | /** |
||
102 | * Optional. Message is a photo, available sizes of the photo |
||
103 | * |
||
104 | * This method overrides the default getPhoto method |
||
105 | * and returns a nice array of PhotoSize objects. |
||
106 | * |
||
107 | * @return null|PhotoSize[] |
||
108 | */ |
||
109 | public function getPhoto() |
||
110 | { |
||
111 | $pretty_array = $this->makePrettyObjectArray(PhotoSize::class, 'photo'); |
||
112 | |||
113 | return empty($pretty_array) ? null : $pretty_array; |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * Optional. A chat photo was changed to this value |
||
118 | * |
||
119 | * This method overrides the default getNewChatPhoto method |
||
120 | * and returns a nice array of PhotoSize objects. |
||
121 | * |
||
122 | * @return null|PhotoSize[] |
||
123 | */ |
||
124 | public function getNewChatPhoto() |
||
125 | { |
||
126 | $pretty_array = $this->makePrettyObjectArray(PhotoSize::class, 'new_chat_photo'); |
||
127 | |||
128 | return empty($pretty_array) ? null : $pretty_array; |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * Optional. For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text |
||
133 | * |
||
134 | * This method overrides the default getEntities method |
||
135 | * and returns a nice array of MessageEntity objects. |
||
136 | * |
||
137 | * @return null|MessageEntity[] |
||
138 | */ |
||
139 | public function getEntities() |
||
140 | { |
||
141 | $pretty_array = $this->makePrettyObjectArray(MessageEntity::class, 'entities'); |
||
142 | |||
143 | return empty($pretty_array) ? null : $pretty_array; |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * return the entire command like /echo or /echo@bot1 if specified |
||
148 | * |
||
149 | * @return string|null |
||
150 | */ |
||
151 | 2 | public function getFullCommand() |
|
164 | |||
165 | /** |
||
166 | * Get command |
||
167 | * |
||
168 | * @return bool|string |
||
169 | */ |
||
170 | 2 | public function getCommand() |
|
171 | { |
||
172 | 2 | $command = $this->getProperty('command'); |
|
173 | 2 | if (!empty($command)) { |
|
174 | return $command; |
||
175 | } |
||
176 | |||
177 | 2 | $full_command = $this->getFullCommand(); |
|
178 | |||
179 | 2 | if (strpos($full_command, '/') === 0) { |
|
180 | 2 | $full_command = substr($full_command, 1); |
|
181 | |||
182 | //check if command is follow by botname |
||
183 | 2 | $split_cmd = explode('@', $full_command); |
|
184 | 2 | if (isset($split_cmd[1])) { |
|
185 | //command is followed by name check if is addressed to me |
||
186 | 1 | if (strtolower($split_cmd[1]) === strtolower($this->getBotName())) { |
|
187 | 1 | return $split_cmd[0]; |
|
188 | } |
||
189 | } else { |
||
190 | //command is not followed by name |
||
191 | 2 | return $full_command; |
|
192 | } |
||
193 | } |
||
194 | |||
195 | 2 | return false; |
|
196 | } |
||
197 | |||
198 | /** |
||
199 | * For text messages, the actual UTF-8 text of the message, 0-4096 characters. |
||
200 | * |
||
201 | * @param bool $without_cmd |
||
202 | * |
||
203 | * @return string |
||
204 | */ |
||
205 | 3 | public function getText($without_cmd = false) |
|
206 | { |
||
207 | 3 | $text = $this->getProperty('text'); |
|
208 | |||
209 | 3 | if ($without_cmd && $command = $this->getFullCommand()) { |
|
210 | 1 | if (strlen($command) + 1 < strlen($text)) { |
|
211 | return substr($text, strlen($command) + 1); |
||
212 | } |
||
213 | |||
214 | 1 | return ''; |
|
215 | } |
||
216 | |||
217 | 3 | return $text; |
|
218 | } |
||
219 | |||
220 | /** |
||
221 | * Bot added in chat |
||
222 | * |
||
223 | * @return bool |
||
224 | */ |
||
225 | public function botAddedInChat() |
||
231 | |||
232 | /** |
||
233 | * Detect type based on properties. |
||
234 | * |
||
235 | * @return string|null |
||
236 | */ |
||
237 | 1 | public function getType() |
|
275 | } |
||
276 |