irazasyed / telegram-bot-sdk

🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.
https://telegram-bot-sdk.com
BSD 3-Clause "New" or "Revised" License
3.04k stars 671 forks source link

Telegram\Bot\Objects\Update::getMessage(): Return value must be of type Illuminate\Support\Collection, Hyperf\Collection\Collection returned #1083

Closed guanzhihua168 closed 1 year ago

guanzhihua168 commented 1 year ago

PHP version

8.2

irazasyed/telegram-bot-sdk version

v3.13.0

Laravel version (if any)

No response

Code To Reproduce the bug

$manager = new BotsManager($config); try { $telegram = $manager->bot('mybot'); $update = $telegram->commandsHandler(); var_dump($update);

        } catch (Exception $e) {
            var_dump('exception: ' . $e->getMessage().$e->getTraceAsString());
        }

Error stacktrace (if any)

string(7) "message" string(7) "message" string(7) "message" string(14) "my_chat_member" vendor/irazasyed/telegram-bot-sdk/src/Objects/Update.php:133. Above output [var_dump($this->detectType())],Throws an exception while printing my chat member

Telegram\Bot\Objects\Update::getMessage(): Return value must be of type Illuminate\Support\Collection, Hyperf\Collection\Collection returned [ERROR] TypeError: Telegram\Bot\Objects\Update::getMessage(): Return value must be of type Illuminate\Support\Collection, Hyperf\Collection\Collection returned in /data/tgbot/vendor/irazasyed/telegram-bot-sdk/src/Objects/Update.php:145 Stack trace:

0 /data/tgbot/vendor/irazasyed/telegram-bot-sdk/src/Objects/Update.php(107): Telegram\Bot\Objects\Update->getMessage()

1 /data/tgbot/vendor/irazasyed/telegram-bot-sdk/src/Methods/Update.php(212): Telegram\Bot\Objects\Update->objectType()

2 /data/tgbot/vendor/irazasyed/telegram-bot-sdk/src/Methods/Update.php(57): Telegram\Bot\Api->dispatchUpdateEvent()

3 [internal function]: Telegram\Bot\Api->Telegram\Bot\Methods{closure}()

4 /data/tgbot/vendor/hyperf/collection/src/Collection.php(877): array_map()

5 /data/tgbot/vendor/irazasyed/telegram-bot-sdk/src/Methods/Update.php(53): Hyperf\Collection\Collection->map()

6 /data/tgbot/vendor/irazasyed/telegram-bot-sdk/src/Traits/CommandsHandler.php(60): Telegram\Bot\Api->getUpdates()

7 /data/tgbot/vendor/irazasyed/telegram-bot-sdk/src/Traits/CommandsHandler.php(37): Telegram\Bot\Api->useGetUpdates()

8 /data/tgbot/app/Command/TgBotCommand.php(43): Telegram\Bot\Api->commandsHandler()

9 /data/tgbot/vendor/hyperf/command/src/Command.php(428): App\Command\TgBotCommand->handle()

10 [internal function]: Hyperf\Command\Command->Hyperf\Command{closure}()

11 {main}

guanzhihua168 commented 1 year ago

My solution is on line 144, add 'my_chat_member' => $this->myChatMember

irazasyed commented 1 year ago

It seems like you have Hyperf Collection which is causing this conflict. Remove that and it should work.

guanzhihua168 commented 1 year ago

You're right, there is a conflict, but Hyperf's built-in can't remove it