2

I initialize Web firebase and I get Token:

https://github.com/MarcinMoskala/KotlinAcademyApp/blob/master/web/src/main/web/js/initFirebase.js

I get current token after it is created and I send it in simple message:

curl -X POST -H "Authorization: key=AAAA_XXXMYKEYXXXw26gv" -H "Content-Type: application/json" -d '{
    "to" : "fo3aexgjsbQ:APA91bEWh47m2cVoflhQ_E__E31jbQpoyaHZTRKmkJIG7Uaarrw0KwvCYYCnNTMmaQIcKBFrq2fGFEBj-nVB9obE-wf4FiTCKedR_gWdMPfc8bNgpK5MQ7SsLmcVRWLlert3AXXdbuzk",
    "data" : {
      "body" : "This is an FCM notification message!",
      "title" : "FCM Message",
    }
}' "https://fcm.googleapis.com/fcm/send"

I get the following success result:

{"multicast_id":8683406144829883570,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1512147661586241%2fd9afcdf9fd7ecd"}]}

The problem is that nothing is displayed or printed in the console! I am sending request, I see success and... nothing happend both when website is opened and when it is closed!

Here is my firebase-messaging-sw.js file placed in root directory:

https://github.com/MarcinMoskala/KotlinAcademyApp/blob/master/web/src/main/web/firebase-messaging-sw.js

I also tried to set configuration this way:

firebase.initializeApp({
  'messagingSenderId': '1091715558873'
});

I specified manifest:

https://github.com/MarcinMoskala/KotlinAcademyApp/blob/master/web/src/main/web/manifest.json

MarcinM
  • 428
  • 7
  • 15

1 Answers1

3

Because your payload uses the key data, you are sending a data message, not a notification. They are handled differently, as explained in the documentation.

Change data to notification

"to" : "fo3aexgjsbQ:APA91bEWh47m2cVoflhQ_E__E31jbQpoyaHZTRKmkJIG7Uaarrw0KwvCYYCnNTMmaQIcKBFrq2fGFEBj-nVB9obE-wf4FiTCKedR_gWdMPfc8bNgpK5MQ7SsLmcVRWLlert3AXXdbuzk",
"notification" : {
  "body" : "This is an FCM notification message!",
  "title" : "FCM Message",
Bob Snyder
  • 37,759
  • 6
  • 111
  • 158