ToothlessGear / node-gcm

A NodeJS wrapper library port to send data to Android devices via Google Cloud Messaging
https://github.com/ToothlessGear/node-gcm
Other
1.3k stars 208 forks source link

Only last push notification show upon sending multiple notifications #215

Closed manojbadam closed 8 years ago

manojbadam commented 8 years ago

Hi Team,

We have a cron job running on and sending the push notifications frequently. If i have multiple push messages to the same device, I'm able to see only the last one (overwriting the previous messages). I found a similar Issue #164 and added NotificationId and value(simple counter) to the message payload. But still facing the issue.

I'm sending the notification Id as below. Do i need to make any changes at the client side ? We are using the Ionic framework at client side.

    var message = new gcm.Message();
    message.addData('message',msg.details.message);
    message.addData('title',msg.details.appId);
    message.addData('msgcnt','1');
    message.addData('NOTIFICATION_ID',this.androidcount++);
    sender.send(message, registrationIds, function (err, result) {
    });

Thanks in advance

MB

eladnava commented 8 years ago

@manojbadam how are you sending multiple push notifications to the same device? I see that you send a registrationIds array, did you purposefully insert a specific device registration ID twice to that array?

manojbadam commented 8 years ago

@eladnava No, i will be calling by API twice. Example scenario: at 12.00 PM - Notification was sent to DeviceID/registrationID xxxx (NoticificationId is 1) at 12.05 PM - Notification was sent to DeviceID/registrationID xxxx (NoticificationId is 2)

when i check my the mobile at 12.10 PM, i can see only the message received at 12.05 PM. I cant see the message received at 12.00 PM.

Thanks Manoj Badam

eladnava commented 8 years ago

@manojbadam are you by any chance supplying a collapseKey in the gcm.Message?

This parameter identifies a group of messages that can be collapsed, so that only the last message gets sent when delivery can be resumed. This is intended to avoid sending too many of the same messages when the device comes back online or becomes active (see delay_while_idle).

https://developers.google.com/cloud-messaging/http-server-ref

hypesystem commented 8 years ago

@manojbadam what does the GCM service return? In the code you have shared it doesn't seem like you are looking at the err and result variables returned from the callback. Knowing what these are might help us :-)

eladnava commented 8 years ago

Closing the issue due to lack of response. Let us know if you still need help! :+1:

tmoubarak commented 5 years ago

Hi There!

Im having the same issue, especially when I put it in a for loop:

 for (var i = 0; i < extIds.length; i++) {

       var newBody = body;
       newBody.index = i ;

      var sender = new FCM.Sender('..........');

       var message = new FCM.Message({
             priority:"high",
             data: newBody
         });

         console.log(message);

         var regToken = extIds[i].device;
         var sendResult =  await sender.send(message, { to: regToken }, async function (err, response) {
             if (err) {
             console.log("ERROR!")
            //  return err;
                console.log(err);
             }
             else{
               console.log(response);
              // return response;
             }
         });
}

can you please advise, let me know if you require anymore informtion.

hypesystem commented 5 years ago

Hi @nervouscat I think it would be more appropriate to start a new issue where we can discuss this :smile: I'm not sure it's the same as the original one, which has been closed.

tmoubarak commented 5 years ago

alright no Problem :)