Skip to content

FCM adapter #32

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

Closed
thailey01 opened this issue Sep 4, 2016 · 50 comments
Closed

FCM adapter #32

thailey01 opened this issue Sep 4, 2016 · 50 comments

Comments

@thailey01
Copy link

How would we go about developing a push adapter for FCM. Projects created in Google Console seem to now be required to use Firebase Cloud Messaging instead of GCM. I've tried to start an FCM adapter by copying the GCM adapter where I could but I'm changing certain parts when needed based on fcm-node documentation.

@flovilmart
Copy link
Contributor

We could add a new handler here for fcm, so it processes properly fcm based push alongside GCM. The FCM compatible installations will have pushType set to fcm instead of gcm. What do you think?

@thailey01
Copy link
Author

That'd be perfect! Wish I could help in some way.

@flovilmart
Copy link
Contributor

No need for the FCM adapter, just initialize with the right key and the GCM adapter pushes will automagically send everything correctly!

@thailey01
Copy link
Author

Don't you need a serverapi key and a project number? I don't think firebase supplies the project number or key.

@thailey01
Copy link
Author

Nevermind, Firebase creates a senderId and Server Api Key which can be found in the project settings.

@thailey01
Copy link
Author

Do we still have to add firebase to our projects? I set the senderId and apiKey found in Firebase but the message wasn't pushed.

@flovilmart
Copy link
Contributor

Does the token was acquired with the firebase SDK? Not sure about the compatibility here

@thailey01
Copy link
Author

When setting up fcm, the Firebase console automatically creates a senderId and a serverApiKey.

@flovilmart
Copy link
Contributor

I means the android device tokens. Maybe we should still let gcm and fcm token live separately.

@thailey01
Copy link
Author

Oh, I haven't added the Firebase sdk to my app so the token must be generated by parse. Basically, I'm running parse-server as usual but have setup fcm (which created a serverkey and senderId). I'm then placing that key and id in parse-server just like I would with gcm key and id. Sorry for the confusion.

@flovilmart
Copy link
Contributor

All device tokens acquired with GCM should work with FCM. But if you changed your senderID and serverKey, that's likely to be problematic IMHO yet I'm not sure

@thailey01
Copy link
Author

The thing is I haven't setup gcm with parse-server. I was using push through hosted parse but it didn't require me to create an app for gcm. Now the only option we have is to add fcm instead of gcm and it doesn't seem to be working. I setup my parse app (and server side) just like how you would with gcm and added the fcm credentials to it, which is really only the server key but that shouldn't be any different.

@flovilmart
Copy link
Contributor

@inlined may have more input on that.

@flovilmart flovilmart reopened this Sep 8, 2016
@thailey01
Copy link
Author

Ok, I think I've figured it out finally. There is a little more setup, however when adding fcm to your android project (if you haven't already setup gcm) you can keep your parse push configuration the same in the androidmanifest.xml but you have to add the firebase library to your project. This allows receiving message and customizing receiver service because fcm message doesn't show up when app is in foreground. I followed this page and got it working https://firebase.google.com/docs/notifications/android/console-audience

@thailey01
Copy link
Author

I seem to be able to receive notifications but sending them doesn't work.

@thailey01
Copy link
Author

Nevermind, I had forgotten the meta-data for gcm_sender_id at the bottom of manifest. Everything has remained the same as far as parse push.

@Onwa1kenobi
Copy link

@thailey01 by "Adding Firebase your project", do you mean just adding the import in gradle or did you also implement the FirebaseMessagingService? Also, what library did you import, the core, messaging or both?

@thailey01
Copy link
Author

In the end, I found out that you don't even need to import any library while using parse-server. I was missing the meta-data tag in my manifest and everything worked fine.

@kiis
Copy link

kiis commented Sep 13, 2016

Thailey were you using device->device pushes or device->parse-server->device pushes ? This solution here does not make any sense based on current adapter. Seems you were not using adapter at all to send and recieve pushes. So changing adapter to support FCM is still valid issue, because it uses npm-gcm, but should use npm-fcm library for new users.

@thailey01
Copy link
Author

As I'm using parse-server I am calling a cloud function from my native app to send push notifications. The adapter as it is now seems to support fcm just the same as gcm. I changed absolutely nothing from the current documentation for setting up parse-server push.

@kiis
Copy link

kiis commented Sep 13, 2016

What values do you use in parse-server config file ?

I have these fields and it seems not to work with default adapter.

{"android": {
"senderId": "FCM senderId",
"apiKey": "FCM server API key"
},

@thailey01
Copy link
Author

Those are the same I use, found from the firebase console settings page. Be
sure you have added the meta tag in your manifest to set the gcm key just
as you normally would. That was my problem.

On Sep 13, 2016 5:34 PM, "kiis" notifications@github.com wrote:

What values do you use in parse-server config file ?

I have these fields and it seems not to work with default adapter.

{"android": {
"senderId": "FCM senderId",
"apiKey": "FCM server API key"
},


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#32 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFkyEhjynFy2rMC7BBWtrMlBrTZtk25Uks5qpyUIgaJpZM4J0i1o
.

@kiis
Copy link

kiis commented Sep 13, 2016

ok, server side seems the same, manifest has meta tag. Still shows that android pushes are not delivered. In database installation table do you have deviceToken or GCMSenderId for android users ?

@thailey01
Copy link
Author

Device token

@thailey01
Copy link
Author

could you show your index.js and manifest file?

@thailey01
Copy link
Author

thailey01 commented Sep 14, 2016

In addition, I don't know if you actually have it that way, but I don't put quotes around my keys in my config. Such as:
{android: {
senderId: "FCM senderId",
apiKey: "FCM server API key"
},

@kiis
Copy link

kiis commented Sep 14, 2016

Manifest: http://pastebin.com/FAcCrAkC
Server config: http://pastebin.com/j3VmTBJ2

Server is using pm2 and it has config differently listed, but it works and ios pushes also.

@thailey01
Copy link
Author

The only difference I see between your manifest and mine is that I specify ParseBroadcastReceiver
<receiver android:name="com.parse.ParseBroadcastReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.USER_PRESENT" /> </intent-filter> </receiver>

@kristokiis
Copy link

added it, but there is still null value in isntallation table for field deviceToken

@Onwa1kenobi
Copy link

I was also getting null value returned for the deviceToken. My case was terrible, sometimes, it returns null, sometimes, it returns a value. what i did was to clean the project as instant run in android studio is quite buggy.

@thailey01
Copy link
Author

Are you calling ParseInstallation.getCurrentInstallation().saveInBackground() when you setup parse-server config In your app? I do mine in a class that extends Application.

@kiis
Copy link

kiis commented Sep 15, 2016

Found the issue. Adapter works perfectly. The issue is java.lang.Exception: GCM registration error: INVALID_SENDER . Seems FCM SenderId is not accepted in GCM server by Android SDK. Now im manually copying GCMSenderId to deviceToken field afterSave in cloud code.

@thailey01
Copy link
Author

That a little bit of a hassle, but I'm glad you figured out the problem. I don't know why I didn't have it though.

@mmazzarolo
Copy link
Contributor

mmazzarolo commented Oct 25, 2016

Disclaimer: This is the first time I'm implementing push notifications.

Hey there!
Is there any way to use FCM in parse-server-push-adapter for sending notifications on both android and iOS devices?
I'm still trying to grok the concept, but from my understanding it should be possible to use parse-server for sending a push through FCM independently from the device type, am I right?

Thanks guys :)

edit: I just tried using the master branch.
It works fine on Android, but not on iOS. Setting the pushType to android on an iOS device redirect correctly to the GCM and I get a successful response:

verb parse-server-push-adapter GCM GCM Response: {
verb parse-server-push-adapter GCM     "multicast_id": 6094255852378874000,
verb parse-server-push-adapter GCM     "success": 2,
verb parse-server-push-adapter GCM     "failure": 0,
verb parse-server-push-adapter GCM     "canonical_ids": 0,
verb parse-server-push-adapter GCM     "results": [
verb parse-server-push-adapter GCM         {
verb parse-server-push-adapter GCM             "message_id": "0:1477468345295055%99573f33f9fd7ecd"
verb parse-server-push-adapter GCM         },
verb parse-server-push-adapter GCM         {
verb parse-server-push-adapter GCM             "message_id": "0:1477468345198750%99573f33f9fd7ecd"
verb parse-server-push-adapter GCM         }
verb parse-server-push-adapter GCM     ]
verb parse-server-push-adapter GCM }

Still, on the device I don't receive any notification (sending the push through the firebase console works though).
I'd like to help on this feature but as I already said I have no experience on push notifications... do you have any suggestions?
@flovilmart @thailey01 @jeffjen

Thank you guys, let me know if I can help in any way :)

@felimartina
Copy link

We are creating an application using parse-server.
We created a firebase account in order to send push notifications to our android devices. However, everytime we send a Push Notification to an Android device the device does not display the notification. It does arrive, though. The Android dev states that the notification is missing the notification field which Android uses in order to SHOW the notification in the screen.
Are we missing anything? Again, notification arrive and can be handled, however, it is not automatically shown by Android on the screen.

This is the body of the notification we are sending:

{
    "where" : {
        "user" : {
            "__type" : "Pointer",
            "className" : "_User",
            "objectId" : "RKGGWkXaIh"
        }
    },
    "data" : {
        "body" : "great match!",
        "title" : "Portugal vs. Denmark"
    }
}

I read about it in multiple places but seems like we need to have a FCM adapter that knows how to handle FCM push notifications. I debugged the GCM push adapter and does not have any clue or whatsoever of what a notification field is. I checked the fcm-adapter branch in this repo (the only open branch other than master) and that one seems to have an FCM adapter which DOES TAKE INTO ACCOUNT notification field. I believe I should be able to request a notification with the following body and would work using the fcm-adapter branch.

{
    "where" : {
        "user" : {
            "__type" : "Pointer",
            "className" : "_User",
            "objectId" : "RKGGWkXaIh"
        }
    },
    "data" : {
        "body" : "great match!",
        "title" : "Portugal vs. Denmark",
        "notification":{
          "body" : "great match!",
          "title" : "Portugal vs. Denmark"
        }
    }
}

any thoughts? what shall we do? Is there a way to continue to use parse-server and get notifications sent AND DISPLAYED to Android devices? Do I need to tell the Android dev to change something in the app settings??? where? what?

Any help would be appreciated.

Thanks in advance

@flovilmart
Copy link
Contributor

As you mention, the current adapter works with FCM, just the notification field is missing.
Do you want to make a pull request to support that?

@felimartina
Copy link

But without notification field nothing is displayed on the Android device. What's the point of having notifications working but not having them displayed on the screen?
I pulled and compiled fcm-adapter branch and seems to be working fine if you set the device's pushType equal to fcm (also need to add fcm to parse push notifications). Not sure how stable the fcm-adapter branch is though.

@flovilmart
Copy link
Contributor

There is no need to use the fcm branch, the master branch should work correctly with fcm

@felimartina
Copy link

Mhhh...could you explain me a bit further? If I use master branch, what do I need to change on the Android App (or in my server when requesting a push notification) in order to get Push Notifications DISPLAYED on the phone screen?
This is how I am requesting the push notification and it is not being displayed on the Android screen. Am I missing something?:

curl -X POST \
  -H "X-Parse-Application-Id: ${APPLICATION_ID}" \
  -H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
        "where" : {
        "user" : {
            "__type" : "Pointer",
            "className" : "_User",
            "objectId" : "RKGGWkXaIh"
        }
    },
        "data" : {
        "body" : "great match!",
        "title" : "Portugal vs. Denmark",
        "alert": "something to say"
    }
      }' \
  http://localhost:4040/parse/push

FYI...I am using parse-server-push-adapter from npm (1.1.0). Is that the very same version that holds the master branch?

@flovilmart
Copy link
Contributor

@felimartina
Copy link

That is what I mean.
Let me re-phrase. How do I do in order to DISPLAY a notification on an Android phone?

@flovilmart
Copy link
Contributor

One need to open a pull request, follow the examples from the node-gcm package and implement the notification key inside the GCM payload.

@felimartina
Copy link

Okay, Just like someone did in the fcm-adapter. The thing is that there is no such feature in parse then, correct? There is no way, currently, to display android notifications in the phone screen using parse-server.

BTW...thank you so much for your quick responses @flovilmart and for helping me to troubleshoot this

@flovilmart
Copy link
Contributor

I believe this is a change in the google API's and we didn't catch it up. Because you caught it, that would be nice if you provide the fix too.

@felimartina
Copy link

Awesome! It just feels weird I am the only one seeing this issue (thought multiple people are using parse for sending push notifications).
I will try to put something together to overcome this problem. But I am only seeing this problem when using fcm setttigs and the gcm sender from parse.
I will try to create a pull request (need to catch up on the repo rules first)...
I see the fcm-adapter is doing kind of the same here. Any other thought on your side @flovilmart ?

Again, thanks for everything

@flovilmart
Copy link
Contributor

The fcm branch is abandoned and should be deleted, as I thought that fcm was not compatible with the node-gcm package. You can get some inspiration from there definitely.

@mmazzarolo
Copy link
Contributor

thought multiple people are using parse for sending push notifications

@felimartina I had the same issue but I thought it was just a mis-configuration on my side

@felimartina
Copy link

@mmazzarolo will see if I grab some spare time these days and create a pull request...should be as simple as taking into account notification field when sending the GCM in the GCM.js file. Let me know if you are experiencing some other issue we can see if we can add support for other options that can be sent to Android phones.
These are the fields supported in the gmc/fmc payload:

https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support

@mmazzarolo
Copy link
Contributor

@felimartina #41

@jamlfy
Copy link

jamlfy commented May 18, 2017

Well 'GCM', is oldddd.....

https://developers.google.com/cloud-messaging/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants