Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forwarding a message from a deleted chat gave an error #1480

Open
augushong opened this issue Oct 4, 2024 · 0 comments
Open

Forwarding a message from a deleted chat gave an error #1480

augushong opened this issue Oct 4, 2024 · 0 comments
Labels

Comments

@augushong
Copy link

🐞 Bug Report

If the forwarded message comes from a deleted chat, it seems that an error will be reported.
Now forward the message to the save message of telegram, delete the original channel or chat of the message, and then forward the message from the save message to the robot, it seems that an error will be reported.

Error: Call to a member function getId() on null in /var/www/html/vendor/longman/telegram-bot/src/DB.php:1301
Stack trace:
#0 /var/www/html/vendor/longman/telegram-bot/src/DB.php(583): Longman\TelegramBot\DB::insertMessageRequest(Object(Longman\TelegramBot\Entities\Message))
#1 /var/www/html/vendor/longman/telegram-bot/src/Telegram.php(655): Longman\TelegramBot\DB::insertRequest(Object(Longman\TelegramBot\Entities\Update))
#2 /var/www/html/vendor/longman/telegram-bot/src/Telegram.php(527): Longman\TelegramBot\Telegram->processUpdate(Object(Longman\TelegramBot\Entities\Update))

I simply changed the code and the program ran normally, but it may need more sanity considerations.

        if ($forward_origin = $message->getForwardOrigin()) {
            $forward_date = self::getTimestamp($forward_origin->getDate());

            if ($forward_origin instanceof MessageOriginUser) {
                self::insertUser($forward_origin->getSenderUser());
                $forward_from = $forward_origin->getSenderUser()->getId();
            } elseif ($forward_origin instanceof MessageOriginHiddenUser) {
                $forward_sender_name = $forward_origin->getSenderUserName();
            } elseif ($forward_origin instanceof MessageOriginChat) {
                if(!empty($forward_origin->getChat())){
                    self::insertChat($forward_origin->getChat());
                    $forward_from_chat = $forward_origin->getChat()->getId();
                    $forward_signature = $forward_origin->getAuthorSignature();
                }
            } elseif ($forward_origin instanceof MessageOriginChannel) {
                self::insertChat($forward_origin->getChat());
                $forward_from_chat = $forward_origin->getChat()->getId();
                $forward_from_message_id = $forward_origin->getMessageId();
                $forward_signature = $forward_origin->getAuthorSignature();
            }
        }

Required Information

? !
Operating system debian
PHP Telegram Bot version docker php:8.1.29-fpm-bullseye
PHP version x.y.z
@augushong augushong added the bug label Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant