Skip to content

Commit 34acb88

Browse files
authored
Fix type issue parsing "entities" (#967)
1 parent 50b05f7 commit 34acb88

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/Commands/Command.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Support\Collection;
66
use Telegram\Bot\Answers\Answerable;
77
use Telegram\Bot\Api;
8+
use Telegram\Bot\Objects\MessageEntity;
89
use Telegram\Bot\Objects\Update;
910

1011
/**
@@ -352,8 +353,8 @@ private function allCommandOffsets()
352353
collect() :
353354
$message
354355
->get('entities', collect())
355-
->filter(function ($entity) {
356-
return $entity['type'] === 'bot_command';
356+
->filter(function (MessageEntity $entity) {
357+
return $entity->type === 'bot_command';
357358
})
358359
->pluck('offset');
359360
}

src/Commands/CommandBus.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Telegram\Bot\Answers\AnswerBus;
99
use Telegram\Bot\Api;
1010
use Telegram\Bot\Exceptions\TelegramSDKException;
11+
use Telegram\Bot\Objects\MessageEntity;
1112
use Telegram\Bot\Objects\Update;
1213
use Telegram\Bot\Traits\Singleton;
1314

@@ -173,8 +174,11 @@ protected function handler(Update $update): Update
173174

174175
if ($message->has('entities')) {
175176
$this->parseCommandsIn($message)
176-
->each(function (array $botCommand) use ($update) {
177-
$this->process($botCommand, $update);
177+
->each(function ($botCommandEntity) use ($update) {
178+
$botCommandAsArray = $botCommandEntity instanceof MessageEntity
179+
? $botCommandEntity->all()
180+
: $botCommandEntity;
181+
$this->process($botCommandAsArray, $update);
178182
});
179183
}
180184

@@ -186,13 +190,13 @@ protected function handler(Update $update): Update
186190
*
187191
* @param $message
188192
*
189-
* @return Collection
193+
* @return Collection<int, MessageEntity>
190194
*/
191195
protected function parseCommandsIn(Collection $message): Collection
192196
{
193-
return collect($message->get('entities'))
194-
->filter(function ($entity) {
195-
return $entity['type'] === 'bot_command';
197+
return Collection::wrap($message->get('entities'))
198+
->filter(function (MessageEntity $entity) {
199+
return $entity->type === 'bot_command';
196200
});
197201
}
198202

src/Traits/CommandsHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function processCommand(Update $update)
111111
*
112112
* @param string $name Command Name
113113
* @param Update $update Update Object
114-
* @param null $entity
114+
* @param array|null $entity
115115
*
116116
* @return mixed
117117
*/

0 commit comments

Comments
 (0)