Testing firebase messaging properties.
This commit is contained in:
72
server/_test/test.js
Normal file
72
server/_test/test.js
Normal file
@@ -0,0 +1,72 @@
|
||||
const path = require("path");
|
||||
const admin = require("../firebase/firebase-handler").admin;
|
||||
|
||||
require("dotenv").config({
|
||||
path: path.resolve(
|
||||
process.cwd(),
|
||||
`.env.${process.env.NODE_ENV || "development"}`
|
||||
),
|
||||
});
|
||||
|
||||
exports.testResponse = async (req, res) => {
|
||||
console.log("Test");
|
||||
|
||||
const uniqueTokens = [
|
||||
"f7B-k-ceDNCEAIFYCfhF3M:APA91bEn-xOmUahCBMJBBDqXpVOZJnnb_qhWlo8eOPrIkvFeSc2nqaKd4D8zs3qqZ_VNgS_OhifsetJXcwtczO8N4k3xfDzCyI3i6j6YTUNK56QC-WNmVOLR2C_g-owy7hSvhGhWilZ3",
|
||||
"eNdzsUqRBBZCM8LQKvqk6e:APA91bFgL0VQLf_TooYmHKQ7_b4H--ZmUYCdgiZpT7dxHSyEkpcCHUz33K7sKqgifUk8rMAEhSsHWa0TJgLbOJxWD6lJaGEpXn8G3PbunkJsJCNCA3CprMONylBr9d6hnQ5wnjUX2Gt6",
|
||||
];
|
||||
|
||||
var message = {
|
||||
notification: {
|
||||
title: "Test Notification",
|
||||
body: "Test Body",
|
||||
//click_action: "TEST CLICK ACTION",
|
||||
},
|
||||
data: {
|
||||
jobid: "1234",
|
||||
title: "Test Notification",
|
||||
body: "Test Body",
|
||||
},
|
||||
tokens: uniqueTokens,
|
||||
android: {
|
||||
notification: {
|
||||
body: "This is an FCM notification specifically for android.",
|
||||
title: "FCM Notification for Android",
|
||||
//image: "url-to-image",
|
||||
},
|
||||
},
|
||||
webpush: {
|
||||
headers: {
|
||||
// Urgency: "high",
|
||||
},
|
||||
notification: {
|
||||
body: "This is a message from FCM to web",
|
||||
// requireInteraction: "true",
|
||||
// actions: [{ action: "the action - matched in sw", title: "title" }],
|
||||
|
||||
// renotify: true,
|
||||
//tag: "1234",
|
||||
//badge: "/badge-icon.png",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// Send a message to the device corresponding to the provided
|
||||
// registration token.
|
||||
admin
|
||||
.messaging()
|
||||
.sendMulticast(message)
|
||||
.then((response) => {
|
||||
// Response is a message ID string.
|
||||
console.log(
|
||||
"[TEST] Successfully sent FCM Broadcast.:",
|
||||
response
|
||||
//JSON.stringify(response)
|
||||
);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("Error sending message:", error);
|
||||
});
|
||||
|
||||
res.status(200).send("OK");
|
||||
};
|
||||
Reference in New Issue
Block a user