jlcvp / fcm-node

A Node.JS simple interface to Google's Firebase Cloud Messaging (FCM) for Android & iOS & Web Notification and data push
MIT License
125 stars 46 forks source link

tag field? #19

Closed jonathan-chin closed 7 years ago

jonathan-chin commented 7 years ago

I'm new to push notifications. It seems like what I really want is collapse_key, where the user's notification tray combines or overwrites a notification. but, it only works when the receiving device is offline?

how do I get that functionality also when it's online? some documentation online mentions FCM supporting a tag key, but it's not apparent if I can use it with fcm-node

what are my options? thanks!

jlcvp commented 7 years ago

This collapse_key option is for notifications that wasnt sent yet. (i.e.: notifications of new versions available. If you release a version 1.0 and then fix a bug and relase a 1.0.1, youll want only the 1.0.1 notification to be sent to those that didn`t received the 1.0 notification yet.)

For a functionality like facebook messenger or whatsapp messenger where the number of new messages are shown, consider send data-only objects through push and build the notification on your receiver service.

jonathan-chin commented 7 years ago

Thanks @jlcvp I actually figured out the functionality I needed; it was indeed the tag key, though I don't think fcm-node properly documents it:

 let message = {
                to: token,
            notification: {
                    tag: "new_messages",
                    title: `You have ${count} new message${count == 1 ? '' : 's'}`,
                    body: `Click to read them!`
                },
                data: {
                    type: "chat"
                }
            };
            this.fcm.send(message, (error, response) => { /* etc */ })
ghost commented 7 years ago

@jonathan-chin, tag option only works for Android or Browser , any iOS idea ?