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

How to perform multicast ? #31

Closed nilaybrahmbhatt closed 6 years ago

jlcvp commented 6 years ago

you can send messages to multiple subjects by passing an array of registration tokens or sending a message to a topic, a example of sending to multiple clients follows

var message = { 
        registration_ids: ["k3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDME", "IpoDKCIZvvD:NwT_e3H3wgIpo", "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUd"],
        collapse_key: 'your_collapse_key',

        notification: {
            title: 'Title of your push notification', 
            body: 'Body of your push notification' 
        },

        data: {  //you can send only notification or only data(or include both)
            my_key: 'my value',
            my_another_key: 'my another value'
        }
    }

fcm.send(message, function(err, response){
        if (err) {
            console.log("Something has gone wrong!")
        } else {
            console.log("Successfully sent with response: ", response)
        }
    })

you can always refer to Firebase Cloud Messaging Reference to learn more about the supported message types