node-pushnotifications icon indicating copy to clipboard operation
node-pushnotifications copied to clipboard

Sending of `badge` causes Invalid JSON payload

Open multi opened this issue 1 year ago • 8 comments

When badge is used, that's the response from FCM

Invalid JSON payload received. Unknown name \"badge\" at 'message.android.notification': Cannot find field.

I've tried removing that line and it works, also there's a badge dot icon on the phone, so notification_count is sufficient for Android?

multi avatar Jul 10 '24 12:07 multi

Looks like you're still using the deprecated GCM method for sending Android notifications. Have you tried setting isLegacyGCM: false and using FCM ?

Alternatively, if you want to continue using the deprecated GCM API, then you could wrap your fixed payload via data.fcm_notification and it should work as well (the line you linked checks that key first before defaulting to the object construction with the incorrect badge usage)

alex-friedl avatar Jul 10 '24 18:07 alex-friedl

@alex-friedl Hey 👋

As far as I can see, the new FCM implementation uses node-gcm to build the message here and here.

isLegacyGCM is false by default

The only option I've changed is isAlwaysUseFCM: true (false by default)

multi avatar Jul 12 '24 05:07 multi

I'm seeing the same issue.

SingleMalted avatar Jul 12 '24 21:07 SingleMalted

@multi @SingleMalted Does it work for you to wrap your payload in a fcm_notification ?

alex-friedl avatar Jul 16 '24 18:07 alex-friedl

@alex-friedl I'm using the v1 API and it's sent via fcm.

SingleMalted avatar Jul 29 '24 21:07 SingleMalted

@SingleMalted The line you referenced allows you to pass a custom payload as { fcm_notification: { ... } }. Couldn't you simply pass it there without badge in it? I am not sure about simply removing that line and possibly breaking things for other users

alex-friedl avatar Aug 10 '24 15:08 alex-friedl

@alex-friedl Yes, that's what I'm currently doing. Thanks

SingleMalted avatar Aug 13 '24 22:08 SingleMalted

Still not clear how to set badge number with recent update both for apn and fcm? badge is documented as a shortcut for gcm + apn

vitalyster avatar Sep 02 '24 04:09 vitalyster