最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - How to ensure the notification delivery and know if the notification was recieved by the end user? - Stack Overflow

programmeradmin3浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 1

use 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();
    };

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论