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 that needs to send a notification to a certain group of devices at a certain time, would I be able to do that easily? Is this something I could do on Google App Engine?
Example:
I have a list of records with different time values in them. When the time value of that record is equal to that of the server machine, send the message.
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:
- How can I send a Firebase Cloud Messaging notification without use the Firebase Console?
- Firebase, send message to specific platform (Android)