45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
var admin = require("firebase-admin");
|
|
const path = require("path");
|
|
require("dotenv").config({
|
|
path: path.resolve(
|
|
process.cwd(),
|
|
`.env.${process.env.NODE_ENV || "development"}`
|
|
),
|
|
});
|
|
|
|
var serviceAccount = require(process.env.FIREBASE_ADMINSDK_JSON);
|
|
|
|
admin.initializeApp({
|
|
credential: admin.credential.cert(serviceAccount),
|
|
databaseURL: process.env.FIREBASE_DATABASE_URL,
|
|
});
|
|
|
|
exports.admin = admin;
|
|
|
|
exports.sendNotification = (req, res) => {
|
|
var registrationToken =
|
|
"fqIWg8ENDFyrRrMWJ1sItR:APA91bHirdZ05Zo66flMlvala97SMXoiQGwP4oCvMwd-vVrSauD_WoNim3kXHGqyP-bzENjkXwA5icyUAReFbeHn6dIaPcbpcsXuY73-eJAXvZiu1gIsrd1BOsnj3dEMT7Q4F6mTPth1";
|
|
var message = {
|
|
notification: { title: "The Title", body: "The Body" },
|
|
data: {
|
|
jobid: "1234",
|
|
},
|
|
token: registrationToken,
|
|
};
|
|
|
|
// Send a message to the device corresponding to the provided
|
|
// registration token.
|
|
admin
|
|
.messaging()
|
|
.send(message)
|
|
.then((response) => {
|
|
// Response is a message ID string.
|
|
console.log("Successfully sent message:", response);
|
|
})
|
|
.catch((error) => {
|
|
console.log("Error sending message:", error);
|
|
});
|
|
|
|
res.sendStatus(200);
|
|
};
|