parse-server-push-adapter icon indicating copy to clipboard operation
parse-server-push-adapter copied to clipboard

Not able to get notification using fcm http v1 api ,from parse dashboard it is showing successful pushes

Open mrutyunjaypowerschool opened this issue 1 year ago • 3 comments

New Issue Checklist

Issue Description

Steps to reproduce

Actual Outcome

Expected Outcome

should send notification to device

Environment

Client

  • Parse Server Push Adapter version: Parse server:3.9.0,parse-push-adapter:5.2.0

Server

  • Parse Server version: 3.9.0,
  • Operating system: mac
  • Local or remote host-local andAWS

Database

  • System (MongoDB or Postgres): MongoDB
  • Database version: 7
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): local

Logs

No error showing

mrutyunjaypowerschool avatar Jul 10 '24 12:07 mrutyunjaypowerschool

Thanks for opening this issue!

  • 🚀 You can help us to fix this issue faster by opening a pull request with a failing test. See our Contribution Guide for how to make a pull request, or read our New Contributor's Guide if this is your first time contributing.

Could you add more details to the issue description please. Did you setup ever send successful pushes, and if yes, with which push adapter version?

mtrezza avatar Jul 11 '24 01:07 mtrezza

We are in the process of upgrading from parse server 2.x to 6.x, and were experiencing the same issue with Android. I narrowed it down to a schema change. We were sending push notifications in parse cloud code as follows (this is how we have been configured since 2014 or so):

        await Parse.Push.send(
          {
            channels: validChannels,
            data:     {
              alert: "welcome message",
              badge: 0,
              sound: 'default',
            },
          },
          { useMasterKey: true }
        );

Off the bat, after updating to parse server 6, the badge:0 line was getting rejected with the error: ERR! parse-server-push-adapter FCM error sending push: Error: data must only contain string values After some experimentation, I found that this goes away after installing the parse-push-adapter separately and invoking a new ParsePushAdapter() call in the parse startup config. We are running parse server 6.5.8, which to my understanding should have support for the old GCM deprecation and new FCM migration. However, the newer push adapter seems to allow this for the badge, which I believe iOS needs, or at least allows, so it was throwing us off because iOS was working.

Our client is an Ionic React app, and we are using the @capacitor/push-notifications plugin. The notifications were coming in, but the capacitor plugin was ignoring them, because they do not have the expected payload. After some research, I found that the payload schema must have changed and needs to be accounted for with the migration from legacy to v1 FCM. While there appears to be a schema change in firebase notifications, it doesn't appear related to this. I'm assuming the original parse schema of "data -> alert, badge, sound" were not consistent with GCM and were maybe a proxy?

Specifically, the capacitor plugin expects the payload to look something like this:

{
    notification: {
        title: "title",
        body: "body",
    },
    data: {
        customPayloadField1: "mustbestring",
        customPayloadField2: "anotherstring",
    }
}

So the solution is to add that to the payload. I'm not sure where the badge fits into all of this. You can likely leave it in the data payload along with the alert and sound fields if required, but just add the notification field.

I don't think this is a bug in the push adapter (maybe the bug was that the old one had a non-standard schema, but again I'm not sure), although the "string" error I mentioned above might be worth looking into on the parse server 6 line.

massivespace avatar Oct 11 '24 05:10 massivespace

Off the bat, after updating to parse server 6, the badge:0 line was getting rejected with the error: ERR! parse-server-push-adapter FCM error sending push: Error: data must only contain string values After some experimentation, I found that this goes away after installing the parse-push-adapter separately and invoking a new ParsePushAdapter() call in the parse startup config. We are running parse server 6.5.8, which to my understanding should have support for the old GCM

@mtrezza Not really familiar with how Parse Server bundles adapters. Does Parse Server 6.5.8 not bundle the latest push adapter? I believe above bug was fixed in 6.1.1 of the push adapter.

@massivespace

Our client is an Ionic React app, and we are using the @capacitor/push-notifications plugin. The notifications were coming in, but the capacitor plugin was ignoring them, because they do not have the expected payload. I'm assuming the original parse schema of "data -> alert, badge, sound" were not consistent with GCM and were maybe a proxy?

Your assumption is correct. Parse has its own payload abstraction for payloads around Android/iOS push notifications which convert to the raw payload FCM expects. Although it is somewhat loosely defined at the moment as things have evolved over the years so it can be quite confusing.

If you handle push notifications using a client SDK that is Parse-related (e.g. Parse Android SDK), notifications will pop up when you only use the data field and put alert in there.

This is not the case for non-Parse related libraries that use FCM as a provider such as @capacitor/push-notifications. These libs handle things in the "FCM-way", where you use the notification key for the alert that should pop up in the tray, and data for data payloads.

As you noticed, adding the notification key does work, since we have support for that key as well. Although documentation on the net around setting up Parse push notifications only mention the data key being the way of having a notification show up in the tray (since this is how you do things with the Parse Android/iOS SDK, historically).

There is some related discussion around improving things around this in https://github.com/parse-community/parse-server-push-adapter/issues/286.

jimnor0xF avatar Dec 12 '24 09:12 jimnor0xF

@jimnor0xF In your deployment try this to figure out what push adapter version was pulled in. For 6.x chances are that it's the old version without the fixes.

€ npm ls @parse/push-adapter
...

mman avatar Dec 12 '24 10:12 mman

Not really familiar with how Parse Server bundles adapters. Does Parse Server 6.5.8 not bundle the latest push adapter? I believe above bug was fixed in 6.1.1 of the push adapter.

Parse Server 6.5.8 comes bundled with push adapter 5.1.1, as you can see here. We don't make any particular effort to always keep Parse Server bundled with the adapter latest version, since one can easily replace the bundled adapter. The updates are automatically done by Snyk, and we can't predict when Snyk opens a PR to upgrade the adapter, but as long as there is no security issue I believe these PRs are not prioritized and can take some time.

mtrezza avatar Dec 12 '24 17:12 mtrezza