kreait / laravel-firebase

A Laravel package for the Firebase PHP Admin SDK
https://github.com/kreait/firebase-php
MIT License
988 stars 162 forks source link

Push notifications are not getting displayed in IOS and Android randomly #204

Closed AravindhanRadhakrishnanTartLabs closed 5 months ago

AravindhanRadhakrishnanTartLabs commented 8 months ago

Describe the bug

I have used kreait/laravel-firebase package in Laravel framework. I'm trying to send bulk push notification, But some users are not getting the notification. It randomly occurs to some users. Can't find the exact solution for this problem.

Following the custom error logs from firebase: Requested entity was not found. Internal error encountered

Installed packages

kreait
/
laravel-firebase

PHP version and extensions

8.0.26

Steps to reproduce the issue.

$message = CloudMessage::new(); $androidConfig = AndroidConfig::fromArray([ 'ttl' => '3600s', 'priority' => 'normal', 'notification' => [ 'title' => $notificationBody['title'], 'body' => $notificationBody['body'], 'color' => '#16BFFF', ], ]);

                 $data = [
                        'click_action' => 'FLUTTER_NOTIFICATION_CLICK',
                        'sound' => 'default',
                        'default_sound' => true,
                        'id' => $id,
                        'notification_id' => $notificationData['id'],
                        'type' => $notificationData['type'],
                        'object' => isset($this->param)
                            ? json_encode($this->param)
                            : null,
                        'invite_by' => isset($this->inviteBy)
                            ? json_encode($this->inviteBy)
                            : null,
                    ];

                    $message = $message->withAndroidConfig($androidConfig);
                    $message = $message->withData($data);

                    $report = $messaging->sendMulticast(
                        $message,
                        $androidDeviceTokens
                    ); // Sent bulk push notification to user device using fcm

Error message/Stack trace

{"0":{"report":{}},"1":{"error_message":"Requested entity was not found.\n"},"2":{"error_code":0}}
{"0":{"report":{}},"1":{"error_message":"Internal error encountered.\n"},"2":{"error_code":0},"6":{"report":{}},"7":{"error_message":"Internal error encountered.\n"},"8":{"error_code":0},}

Additional information

No response

jeromegamez commented 8 months ago

Please see https://firebase-php.readthedocs.io/en/stable/cloud-messaging.html#error-handling for the different errors.

There's nothing this library can do about server errors, this is on the Firebase Service's side and sometimes happens.

Unknown registration tokens (the docs explain how this can happen) are not recoverable, I'd recommend removing them from your system (you can't do anything with them), but, of course, that's up to you 😅