IO-1551 Refactor messaging.
This commit is contained in:
@@ -74,31 +74,48 @@ exports.updateUser = (req, res) => {
|
||||
});
|
||||
};
|
||||
|
||||
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,
|
||||
};
|
||||
exports.sendNotification = async (req, res) => {
|
||||
setTimeout(() => {
|
||||
// Send a message to the device corresponding to the provided
|
||||
// registration token.
|
||||
admin
|
||||
.messaging()
|
||||
.send({
|
||||
topic: "PRD_PATRICK-messaging",
|
||||
notification: {
|
||||
title: `ImEX Online Message - +16049992002"`,
|
||||
body: "Test Noti.",
|
||||
imageUrl: "https://thinkimex.com/img/logo512.png",
|
||||
},
|
||||
data: {
|
||||
type: "messaging-inbound",
|
||||
conversationid: "e0eb17c3-3a78-4e3f-b932-55ef35aa2297",
|
||||
text: "Hello. ",
|
||||
image_path: "",
|
||||
phone_num: "+16049992002",
|
||||
},
|
||||
})
|
||||
.then((response) => {
|
||||
// Response is a message ID string.
|
||||
console.log("Successfully sent message:", response);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log("Error sending message:", error);
|
||||
});
|
||||
|
||||
// Send a message to the device corresponding to the provided
|
||||
// registration token.
|
||||
admin
|
||||
res.sendStatus(200);
|
||||
}, 500);
|
||||
};
|
||||
|
||||
exports.subscribe = async (req, res) => {
|
||||
const result = await 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);
|
||||
});
|
||||
.subscribeToTopic(
|
||||
req.body.fcm_tokens,
|
||||
`${req.body.imexshopid}-${req.body.type}`
|
||||
);
|
||||
|
||||
res.sendStatus(200);
|
||||
res.json(result);
|
||||
};
|
||||
|
||||
exports.validateFirebaseIdToken = async (req, res, next) => {
|
||||
|
||||
Reference in New Issue
Block a user