I am working on application in which notification delivery is too important, not only the delivery but also about the status of it, like it is received by the end user or not?
I do have some in my mind to do it with FCM and websockets, like i will send a notification with FCM and when the front end (Mobile App) will receive it, it will emit an event to tell us it is received, but i think it is not the most reliable way, it does not provide 100% or near 100% accuracy.
I want to ask if any one have some in mind, please let me know, really appreciated!
I am working on application in which notification delivery is too important, not only the delivery but also about the status of it, like it is received by the end user or not?
I do have some in my mind to do it with FCM and websockets, like i will send a notification with FCM and when the front end (Mobile App) will receive it, it will emit an event to tell us it is received, but i think it is not the most reliable way, it does not provide 100% or near 100% accuracy.
I want to ask if any one have some in mind, please let me know, really appreciated!
Share Improve this question asked Mar 17 at 8:01 Faraz AliFaraz Ali 931 silver badge6 bronze badges 1- Have you ever seen a "mark as read" button/link on a notification? That's the only way to guarantee that the user saw (or at least acknowledged) the notification. – Frank van Puffelen Commented Mar 17 at 11:59
1 Answer
Reset to default 1use acknowledged functionality from socket.io, where callback event emits: Acknowledgement
socket.on("sendNotification", async (data, callback) => {
try {
// Sending the notification logic
callback({ status: "ok" }); // Notification acknowledged
} catch (error) {
callback({ status: "error", error: error.message });
}
});
//logic on server
const sendWithRetry = (notification, retries = 3) => {
let attempts = 0;
const send = () => {
attempts++;
socket.emit("sendNotification", notification, (response) => {
if (response.status === "ok" || attempts >= retries) {
console.log("Notification handled:", response);
} else {
setTimeout(send, 1000);
}
});
};
send();
};