diff --git a/src/Commands/Command.php b/src/Commands/Command.php index 94a74f7c..41260034 100644 --- a/src/Commands/Command.php +++ b/src/Commands/Command.php @@ -5,6 +5,7 @@ use Illuminate\Support\Collection; use Telegram\Bot\Answers\Answerable; use Telegram\Bot\Api; +use Telegram\Bot\Objects\MessageEntity; use Telegram\Bot\Objects\Update; /** @@ -352,8 +353,8 @@ private function allCommandOffsets() collect() : $message ->get('entities', collect()) - ->filter(function ($entity) { - return $entity['type'] === 'bot_command'; + ->filter(function (MessageEntity $entity) { + return $entity->type === 'bot_command'; }) ->pluck('offset'); } diff --git a/src/Commands/CommandBus.php b/src/Commands/CommandBus.php index bbe224c3..c0de659f 100644 --- a/src/Commands/CommandBus.php +++ b/src/Commands/CommandBus.php @@ -8,6 +8,7 @@ use Telegram\Bot\Answers\AnswerBus; use Telegram\Bot\Api; use Telegram\Bot\Exceptions\TelegramSDKException; +use Telegram\Bot\Objects\MessageEntity; use Telegram\Bot\Objects\Update; use Telegram\Bot\Traits\Singleton; @@ -173,8 +174,11 @@ protected function handler(Update $update): Update if ($message->has('entities')) { $this->parseCommandsIn($message) - ->each(function (array $botCommand) use ($update) { - $this->process($botCommand, $update); + ->each(function ($botCommandEntity) use ($update) { + $botCommandAsArray = $botCommandEntity instanceof MessageEntity + ? $botCommandEntity->all() + : $botCommandEntity; + $this->process($botCommandAsArray, $update); }); } @@ -186,13 +190,13 @@ protected function handler(Update $update): Update * * @param $message * - * @return Collection + * @return Collection */ protected function parseCommandsIn(Collection $message): Collection { - return collect($message->get('entities')) - ->filter(function ($entity) { - return $entity['type'] === 'bot_command'; + return Collection::wrap($message->get('entities')) + ->filter(function (MessageEntity $entity) { + return $entity->type === 'bot_command'; }); } diff --git a/src/Traits/CommandsHandler.php b/src/Traits/CommandsHandler.php index d7526dfb..4cbf3145 100644 --- a/src/Traits/CommandsHandler.php +++ b/src/Traits/CommandsHandler.php @@ -111,7 +111,7 @@ public function processCommand(Update $update) * * @param string $name Command Name * @param Update $update Update Object - * @param null $entity + * @param array|null $entity * * @return mixed */