Skip to content

Instantly share code, notes, and snippets.

@15mgm15
Created January 24, 2019 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 15mgm15/82aeb1ef05d65317c1b3ce2a931d6289 to your computer and use it in GitHub Desktop.
Save 15mgm15/82aeb1ef05d65317c1b3ce2a931d6289 to your computer and use it in GitHub Desktop.
var functions = require('firebase-functions');
var admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.sendNotification = functions.database.ref('/promotions/{promotion}')
.onCreate((snapshot, context) => {
const promotion = snapshot.val();
//const promotionId = promotion['id'];
const title = promotion['title'];
var topic = "all";
var payload = {
notification: {
title: "Hay una nueva promocion!",
body: title,
// data: {
// id: promotionId,
// }
}
};
return admin.messaging().sendToTopic(topic, payload)
.then(function (response) {
console.log("Successfully sent message:", response);
})
.catch(function (error) {
console.log("Error sending message:", error);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment