Slide 86
Slide 86 text
var functions = require('firebase-functions');
var admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.annotateImage = functions.database.ref('/motion-logs/{id}')
.onCreate(event => {
const original = event.data.val();
var topic = "/topics/intruders";
var payload = {
data: {
title: "Intruder Alert!",
body: "An intruder has been detected"
}
};
return admin.messaging().sendToTopic(topic, payload)
.then(function (response) {
console.log("Successfully sent message:", response);
}).catch(function (error) {
console.log("Error sending message:", error);
});
}
);