Monday, May 13, 2019

FCM (Firebase Cloud Messaging) :: User not receive offline message

              FCM (Firebase Cloud Messaging) ::  User not receive offline message 
When we move from GCM (Google Cloud Messaging) to FCM (Firebase Cloud Messaging) . During Testing we find out there is an issue in FCM i.e User not receive offline message . FCM API HTTP Response code is 200 :-

{"multicast_id":********,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"******"}]}

Then , I report this issue to https://firebase.google.com/support  by filling necessary Details on there support URL :- https://support.google.com/firebase/contact/support?page=/fcm/delivery/diagnose/web/data .

During meantime I was checked by manipulating API Params . Then I find out adding time_to_live with some value for example 2419200 #four weeks its working fine . 

Same I communicate to @kat (firebase-help@google.com Support team) because it is bug from FCM . As per FCM document :- https://firebase.google.com/docs/cloud-messaging/http-server-ref#downstream-http-messages-plain-text it is optional and the default value is 4 weeks.
Below mail send by google (firebase-help@google.com) :-

Hi Saurabh, 

Thanks for the update. Happy to hear that adding time_to_live helped fix the issue.

This sounds like a bug, though. As you've noted from our documentation, requests that don't contain this field default to the maximum period of four weeks.

...
Regards, 
Kat


In Node Server we send notification by using below code :-


var request = require('request'); // npm i request                
if (TTL) {
                        TTL = 2419200; // Default TTL is four weeks.
 }      
// Before Background notificatin fix
//var postData ='{"data":{"title":"'+title+'","body":"'+body+'","icon":"'+ImageIcon+'","click_action":"'+weburl+'","requireInteraction":true,"tag":"'+Math.random()+'"},"to":"'+endpoint+'"}'; 

 var postData ='{"data":{"title":"'+title+'","body":"'+body+'","icon":"'+ImageIcon+'","click_action":"'+weburl+'","requireInteraction":true,"tag":"'+Math.random()+'"},"to":"'+endpoint+'","priority":10,"time_to_live": '+TTL+'}';
              var url = 'https://fcm.googleapis.com/fcm/send';
                var options = {
                        method: 'post',
                        body: JSON.parse(postData),
                        json: true,
                        url: url,
                        headers: {'content-type' : 'application/json',
                        'Authorization':'key=*********,'Urgency':'high'}
                }
                request(options, function (err, res, body) {
                        if (err) {
                                console.error('error posting json: ', err)
                                throw err
                        }
                                //console.log(res);
                        var headers = res.headers;
                        var statusCode = res.statusCode;


No comments: