I am positive that I can send a Firebase Cloud Message when a record is added to the database or when some other database event occurs. My question is, if I have a record t
There is no hidden magic here. You'll have to write code that listens for the changes in the database and then calls Firebase Cloud Messaging.
ref.on('child_added', function(snapshot) {
request({
url: 'https://fcm.googleapis.com/fcm/send',
method: 'POST',
headers: {
'Content-Type' :' application/json',
'Authorization': 'key=AI...8o'
},
body: JSON.stringify(
{ data: {
message: "your message"
},
to : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1..."
}
)
}, function(error, response, body) {
if (error) {
console.error(error);
}
else if (response.statusCode >= 400) {
console.error('HTTP Error: '+response.statusCode+' - '+response.statusMessage);
}
else {
console.log('Message sent');
}
});
})
The above snippet of JavaScript would run in code and calls the Firebase Cloud Messaging HTTP endpoint to send a message.
Also see: