This commit is contained in:
Lukas Nowy 2019-03-18 18:08:00 +01:00
commit 5cac024767
2 changed files with 27 additions and 3 deletions

View File

@ -1,6 +1,8 @@
var admin = require('firebase-admin');
function sendPush(msgtoken, title, text){
var message = {
notification: {
title: title,
@ -9,7 +11,7 @@ function sendPush(msgtoken, title, text){
token: msgtoken
};
firebaseAdmin.messaging().send(message)
admin.messaging().send(message)
.then(function(response) {
// See the MessagingDevicesResponse reference documentation for
// the contents of response.
@ -20,6 +22,27 @@ function sendPush(msgtoken, title, text){
});
}
function sendMultiplePush(message_ids, title, text){
console.log(message_ids)
var message = {
data: {
title: title,
body: text
},
tokens: message_ids
};
admin.messaging().sendMulticast(message)
.then(function(response) {
// See the MessagingDevicesResponse reference documentation for
// the contents of response.
console.log('Successfully sent message:', response);
})
.catch(function(error) {
console.log('Error sending message:', error);
});
}
module.exports = {
sendPush
sendPush,sendMultiplePush
}

View File

@ -17,6 +17,7 @@ var firebaseAdmin = admin.initializeApp({
//Push
router.get('/push/:msgtoken/:message/:title', function (req, res, next) {
push.sendPush(req.params.msgtoken, req.params.title, req.params.message);
var sender = "Message Token: " + req.params.msgtoken + " Message: " + req.params.message + " Title: " + req.params.title;
res.status(200).send(sender);