activitree / meteor-push

Meteor Push Notifications for Cordova and Web/PWA with Firebase (FCM).
MIT License
27 stars 19 forks source link

Is there a way to determine if Push.send fails? #10

Closed jamauro closed 4 years ago

jamauro commented 4 years ago

I'd like to send an email as a fallback if Push.send fails for some reason. Is there a way to determine that?

paulincai commented 4 years ago

@jamauro on IOS (with APN), once the notification is passed to the Push worker and goes "out" there are no callbacks or responses. This package sends Android notifications via Firebase Admin. In your google console (https://console.cloud.google.com/apis/api/fcm.googleapis.com/metrics) you have some graphs like the one below. This can tell you something about the whole implementation and success rate in general. I don't know if these responses can be captured at our Node end. In general Push is a one way thing. Given the billions of messages running through the servers, the tech doesn't provide responses to the sender. Perhaps this could be looked into again and re-evaluated.

I see in the API that an error is returned if the messages(in a batch) is not handed over to FCM. However, if handed over and not sent to user/not received by the user ... https://firebase.google.com/docs/reference/admin/node/admin.messaging.SendResponse

One thing you could though though, and I think I will need this too, is to add an action to the Notification. Something like, a Push listener in your listening side (client) and if a message has... 'something', mark it as ok i your DB, if however the user logged in and the ok was not updated in DB, notification was not received/opened and you can send an email. This is the way the badge numbers are being handled. It needs to happen in the client/server based on interaction with Push.

For badges you need to increment a badge number in DB (manually, you write the code for it), get the number, and send it to the client via push as a badge number update. Similarly you could check on whether a user interacted with a Push message or not. I will very soon start an implementation of payloads and perhaps this will give you some more leverage. Screen Shot 2019-10-19 at 15 51 54

jamauro commented 4 years ago

Thanks for the detailed response! Excited to hear that payloads will be worked on soon.

paulincai commented 4 years ago

@jamauro I will be moving everything over to Firebase. Still want to do some reading about IOS over firebase and so we will be getting everything Firebase has to offer (and is not limited by the Cordova Push plugin). By the way. I am doing PWA and WebPush these days so there are some more interesting features coming, pretty much what was asked in these tickets here.

paulincai commented 4 years ago

@jamauro question on your case. Let's say you send a message and the phone is out of range. The message is sent successfully but not (yet) received. How do you plan to handle this. Or the user changed phone and didn't reinstall your app. All messages will be sent successfully but there is nobody to receive them. The success rate in sending messages is very high. With the new updates, you can turn a flag for debugging On and see how many messages were sent out successfully. I added some flags such as the one that follows. So having in mind that once you correctly set your system, the success rate will be eventually close to 100%. There are not many reasons for a token in your MongoDB to become invalid.

What else could you use to determine whether you should send an email or not. I am asking this because I am personally in need of some inspiration.

And to answer your question, (with another question) would you still want to have the result from this sending returned to the client? It now exists server side in the console if the debugging is turned on.

fcmConnection.send(webNote)
    .then(response => {
      // response is a message ID string.
      if (isDebug) { console.log('Successfully sent Web push message:', response) }
    })
    .catch(error => {
      if (isDebug) { console.log('Web Push ERROR: result of sender: ', error) }
    })
paulincai commented 4 years ago

The final answer is yes.