Created
January 31, 2019 02:16
-
-
Save 15mgm15/1a9ffdbf7149915200be2d43500d17be 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