From 75f25665331050a01e4386cbfce838e734016e27 Mon Sep 17 00:00:00 2001 From: Bhaskar Date: Thu, 22 Aug 2024 12:33:59 +0530 Subject: [PATCH] notification --- src/controllers/tanksController.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/controllers/tanksController.js b/src/controllers/tanksController.js index f4b5e9e9..20db95ff 100644 --- a/src/controllers/tanksController.js +++ b/src/controllers/tanksController.js @@ -1307,6 +1307,33 @@ admin.initializeApp({ credential: admin.credential.cert(serviceAccount), }); +const sendPushNotification = async (registrationToken, title, body) => { + const message = { + notification: { + title: title, + body: body, + }, + data: { + title: title, + body: body, + }, + }; + + const options = { + priority: "high", + timeToLive: 60 * 60 * 24, + }; + + try { + const response = await admin.messaging().sendToDevice(registrationToken, message, options); + console.log('FCM response:', response); // Log the FCM response + return response; // Return the FCM response object + } catch (error) { + console.error('FCM error:', error); + throw error; // Throw the error to handle it further up the call stack + } +}; + exports.motorAction = async (req, reply) => { try { const customerId = req.params.customerId;