Krishna Agrawal
Krishna Agrawal

Reputation: 44

How to handle FCM upstream message in Node server?

I am using node-xcs module to create XMPP CCS server in NodeJs, But in that module there is no method to send ACK message which is required to send back to FCM.

Upvotes: 2

Views: 991

Answers (1)

Alex
Alex

Reputation: 838

do you use fcm-node package for get FCM token . using that we can register device look at my full coding i have use it for send notification to mobile

var FCM = require('fcm-node');
exports.SendNotification = function(msg,title,type,id,user_id,api_token)
{

                        var fcm = new FCM(constants.serverKey);

                            var message = {
                                        registration_ids :  api_token,
                                      notification: {
                                        title: title,
                                        body:msg
                                        },
                                    data: {
                                        type: type,
                                                id:id,
                                                user_id:user_id
                                    }
                                };

                                fcm.send(message, function(err, response){
                                    if (err)
                                        {
                                        console.log("Error for Send Notification",err);
                                                return;
                                    }
                                        else
                                        {
                                        console.log("Successfully sent Notification", response);
                                                return;
                                        }
                                    });
}

and than call this function like this

msg='new notification for you'
title='Hello'
id='34'
user_id='34'
result='api_token'//save this token in database and retrive using user_id
SendNotification(msg,title,'START_APPOINTMENT',id,user_id,result);

Upvotes: 1

Related Questions