-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathindex.js
More file actions
27 lines (25 loc) · 673 Bytes
/
Copy pathindex.js
File metadata and controls
27 lines (25 loc) · 673 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);
exports.sendPushNotification = functions.https.onCall((data, context) => {
var message = {
notification: {
title: data.title,
body: data.body
},
token: data.token
};
// Send a message to the device corresponding to the provided
// registration token.
admin
.messaging()
.send(message)
.then(response => {
console.log("Successfully sent message:", response);
return;
})
.catch(error => {
console.log("Error sending message:", error);
return;
});
});