简体   繁体   中英

FCM Message Notification Message and Data Message (Push Notification FOR WEB DESKTOP)

ead up about Data Payload Message and Notification Payload Message in FCM Website. It was in the main FCM messaging page and the only things they emphasized about are IOS and Android.

I am working on web push notification and wouldn't be using this for google app and plugin. So the only way to implement is through service worker and manifest. Can I only use current (Notification message) json message in sw.js file such as this?

self.addEventListener('push', function(event) {
 console.log('Push message received', event);
 var title = 'Push message';
 event.waitUntil(
   self.registration.showNotification(title, {
     body: 'Please choose to like or reply',      
     icon: 'images/icon.png',
     tag: 'my-tag',
     actions:[
       {action:"like", title: "Like"},
       {action:"reply", title: "⤻ Reply"}]
   })
 );
});

What if I would like to have different types of messages for different groups? I do not really have the clue on how to do it in the back end.. It seems like the code above could only show one Notification title?

Extra Note: (There are three ways of app server request such as topic name, device registration token or device group name as I suspect that those are only used for ANDROID and IOS. Please do correct me if I am wrong if I could use these for Web as well as for the data payload message.

you asked multiple questions in one, Well i am tring to answer your all question one by one.

1). Can I only use current (Notification message) json message in sw.js file such as this?

the code of service worker seem like you have made this based on old implementation(GCM) which will still work even with FCM too but if you want to use FCM's payload then you have to upgrade this service worker code to handle payload to show in notifications see sample code on link https://firebase.google.com/docs/cloud-messaging/js/receive .

2). What if I would like to have different types of messages for different groups? I do not really have the clue on how to do it in the back end.. It seems like the code above could only show one Notification title?

Service store on client end to handle payload messages and will be same for all clients. you have to differentiate receiving title while you sending notification. for that you have to segregate FCM registration ids and then have to send different- 2 messages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM