kawankoding / laravel-fcm

Firebase Cloud Messaging (FCM) sender for Laravel
172 stars 56 forks source link

Notification not send after migrating application to AWS server #62

Closed nurrasyidahabd closed 1 year ago

nurrasyidahabd commented 1 year ago

Hello, my application server was migrated to AWS from Dewaweb. After the migration, the notification is not send to users. Is there any possibility that the issue is related to server migration?

erlangparasu commented 1 year ago

Hi, @nurrasyidahabd.. maybe you can try to enable debug response. Then check the firebase log in the laravel.log file.

fcm()
    ->to($recipients)
    // ...
    ->enableResponseLog()
    ->send();

if you like, please share the response log here so we can see the problem.

nurrasyidahabd commented 1 year ago

Hi @erlangparasu, I enabled the log before I posted question here. However, in my laravel.log I don't see anything related to firebase log.

nurrasyidahabd commented 1 year ago

Hi @erlangparasu,

Here's the log that I have. I'm not sure what does "NotRegistered" is referring to.

nurrasyidahabd-kawankoding-laravel-fcm-issue-log.txt

Hopefully you can help. Thank you.

erlangparasu commented 1 year ago

@nurrasyidahabd it looks like the device token that you saved on the server has expired. You have to listen then update the token and re-save the new device token to the server. For android you can read in more detail here: https://firebase.google.com/docs/cloud-messaging/android/client#monitor-token-generation

erlangparasu commented 1 year ago

@nurrasyidahabd Here is the part of your log: {"response":"{\"multicast_id\":5482354466318196625,\"success\":117,\"failure\":325,\"canonical_ids\", it informs that there are several messages that were successfully sent (117) and there were some that failed to be sent (325). The "NotRegistered" errors are caused invalid device token, as I said above.

nurrasyidahabd commented 1 year ago

Hi @erlangparasu ,

Thank you for the reply. I'm still checking on the device token issue. Meanwhile I have another question.

The following code is placed under app/Console/Commands in Laravel: $status = fcm() ->to($recipients) ->priority('high') ->timeToLive(0) ->data([ 'title' => $notif->title, 'body' => $notif->message, ]) ->enableResponseLog() ->send();

The code will not run unless I run the php artisan command manually. My question is, is it not running because of invalid device token, or is it because of other issue?

Thank you.

erlangparasu commented 1 year ago

@nurrasyidahabd using command to run it manually is no different than running it through a controller etc. The most important thing is that the configuration is correct. From the log that you provided, the cause was an expired device token. But if you don't receive a notification even though you have updated the device token, maybe you can try changing the value of the ->timeToLive(...) options.

nurrasyidahabd commented 1 year ago

Hi @erlangparasu,

My application is trying to send notification to multiple devices. So if let's say a few of them have expired token, while the rest are fine, the issue will still persist?

erlangparasu commented 1 year ago

Yes, it's true that some devices will receive messages and some others will not. Note: this is not a problem with this library, it is a problem with the device token being input.