Created
January 24, 2019 08:05
-
-
Save 15mgm15/82aeb1ef05d65317c1b3ce2a931d6289 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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