Your IP : 216.73.216.91


Current Path : /var/node/inatote/Inatote-Backend/helpers/
Upload File :
Current File : //var/node/inatote/Inatote-Backend/helpers/fcm_helper.js

import FCM from 'fcm-node'
import config from '../config.js';


var FCM_Send = ({ notificationTitle, notificationBody, token, payload, type }) => {
    try{
        var serverKey = ""
    if (type.toLowerCase() === "client") {
        serverKey = config.app.serverKey.customerApp;
    } else if (type.toLowerCase() === "rider") {
        serverKey = config.app.serverKey.riderApp;
    }
    //console.log("serverKey" , type, serverKey);
    // var serverKey = type.toLowerCase() === "client" ? config.app.serverKey.customerApp : config.app.serverKey.riderApp; //put your server key here
    var fcm = new FCM(serverKey);

    var message = { //this may vary according to the message type (single recipient, multicast, topic, et cetera)
        to: token,

        notification: {
            title: notificationTitle,
            body: notificationBody
        },

        // data: {  //you can send only notification or only data(or include both)
        //     payloadType: payload.payloadType,
        // }
    };
    if (payload) {
        message['data'] = payload;
    }
    //console.log("MESSAGE" , message);

    fcm.send(message, function (err, response) {
        if (err) {
            console.log("Something has gone wrong!" , err);
        } else {
            console.log("Successfully sent with response: ", response);
        }
    });
    }
    catch(err){
        console.log("err" , err);
    }
}
export default FCM_Send;