Tips for sending personalized notifications through Web push technology

I've successfully implemented web push on Chrome, but I'm facing an issue where all users receive the same notification from the server. Is there a way to include user-specific data or endpoint ID in the latest notification request sent by the service worker? Any suggestions on how to achieve this would be greatly appreciated.

Thank you!

Answer №1

To enhance communication, it is recommended to have a data storage system in place for all subscribed clients on the server, stored in a file named endpoint.txt. This allows for messages to be efficiently delivered to specific users.

For more information on this topic, refer to: developer.mozilla.org/en/docs/Web/API/Push_API

To customize the function that sends broadcast messages and select individual clients instead of broadcasting to all in a loop, you can modify the code found here: https://github.com/chrisdavidmills/push-api-demo/blob/gh-pages/server.js


if(obj.statusType === 'chatMsg') {
        fs.readFile("endpoint.txt", function (err, buffer) {
          var string = buffer.toString();
          var array = string.split('\n');
          for(i = 0; i < (array.length-1); i++) {
            var subscriber = array[i].split(',');
            webPush.sendNotification(subscriber[2], 200, obj.key, JSON.stringify({
              action: 'chatMsg',
              name: obj.name,
              msg: obj.msg
            }));
          };
        });

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide to concealing a language path within a url using an exception

I currently have a website with various language versions, with English set as the default. Is there a way to conceal the /en/ path from the URL? (making an exception for just en) I want to maintain the other languages unchanged. www.website.com/en/ (wa ...

JQuery unable to retrieve the value from a radio button

Currently, I'm facing an issue with a form featuring image-based radio buttons. The problem arises when attempting to initiate an AJAX call based on the chosen value (either 10, 30, or 100). Despite selecting a value other than 10, it keeps defaulting ...

Automatically conceal a div or flash message after a short period of time by utilizing CSS3 in a React

I am relatively new to the React environment and recently created a basic component for a bookmarking feature. Essentially, when the favourite icon is clicked, an ajax call is sent > a record is created in the database > on ajax success, a flash me ...

Is there a way to disable or deactivate all jQuery functions at once?

I have developed an application with push state functionality and it is running smoothly. However, I am facing an issue where my jQuery functions are being triggered multiple times in certain cases. This happens because every time I call push state, the sp ...

Class variable remains unchanged following AJAX request

Upon completion of the ajax request, two integers are received - this.N and this.M. However, these values are not being set by the storeDims() function even though the correct decoding is done on the dims variable. This implies that I am unable to access ...

Utilizing componentWillMount() with React Hooks: A step-by-step guide

According to the React official documentation, useEffect Hook can be compared to componentDidMount, componentDidUpdate, and componentWillUnmount combined for those familiar with React class lifecycle methods. If you’re familiar with React class lifecy ...

Is there a way to retrieve information from an external URL in JSON format and display it using JavaScript on a separate HTML webpage?

I'm trying to display the value TotalPostNotificationCount from a JSON file in an external HTML using either JavaScript or PHP. The JSON data is as follows: { "DayPostCount": 1, "TotalPostNotificationCount": 7381 } This data can be found at t ...

Integrating external CSS styles into your Firebase function developed in index.js

My style.css file is not being applied after deploying the website on the server. The index.js and styles.css are located in the same directory. index.js const functions = require('firebase-functions'); exports.helloWorld = functions.https.on ...

Design the header and body of the table in a visually appealing format

$("input:checkbox:not(:checked)").each(function() { var column = "table ." + $(this).attr("name"); $(column).hide(); }); $("input:checkbox").click(function() { var column = "table ." + $(this).attr("name"); $(column).toggle(); }) <script src="h ...

What is the best way to use System.Text.Json for converting objects back into their original type during deserialization?

I am currently working on a POCO class within .NET 5.0 that requires serialization and deserialization to and from the browser. This is part of a library where I aim to provide flexibility by allowing users to choose their preferred serializers without any ...

Can you confirm if this is the most efficient method for loading google-analytics and jQuery?

It's not necessary for jQuery to be loaded immediately on page load: Here is what I currently have: <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', '...']); _gaq.pus ...

Removing consecutive pipe symbols in JavaScript

Looking for a way to remove excess pipe characters before a certain pattern in JavaScript. var testString="||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||f_test!!3!!||f_test!!4!!||f_test!!5!!||"; output ="||f_test!!3!!| ...

Counting each item with jQuery and assigning them numbers 02, 03, 04, etc., with the exception of the first item which will display as "Up Next

I'm still learning jQuery and here's the code I've put together after researching on stackoverflow and other platforms: var counter = 1; $('.next-page .nav-item').each(function () { if ($(this, ':gt(0)')) { $(this ...

Printing feature causing conflicts with other jQuery event listeners

After successfully printing the content of a div on click, I encounter the issue that none of my jQuery events work after canceling the print preview. This seems to happen without requiring a page refresh. I'm puzzled as to why this occurs and would ...

Learn how to showcase a predetermined option in an HTML select element using Vue.js and Minimalect

I am currently utilizing Vue.js along with the Mininmalect HTML select plugin to showcase a list of countries by their names and values, where the value represents the 2 digit country code. Successfully, I have managed to implement the plugin for selectin ...

utilizing window.location.href to direct to a page with javascript capabilities

I am currently developing my own personal website. It is designed to be very light in terms of loading and content. This website relies heavily on the use of jquery, so if a user's browser does not have JavaScript enabled, the site will not function ...

Tips for updating a React state while using the history API

In an effort to simplify and stay focused on the problem, I recently wrote a brief piece of code. Within this code, there is a component containing a Dialog that plays a role in a commercial process. This Dialog allows users to input information such as no ...

Fancybox displaying error message: "Sorry, we are unable to load the requested content at this time. Please try again later."

Utilizing Fancybox for the purpose of displaying YouTube videos in a modal box. I am encountering an issue where I consistently receive the error message "The requested content cannot be loaded. Please try again later." The fact that the modal box is app ...

`Setting the response as an ArrayBuffer can be achieved on the client side, but it cannot be

I am working on a client-side form where I use XMLHTTPResponse to save response data as a file. In order to achieve this, the response type is set to arraybuffer using the following code: xhr.responseType = "arraybuffer"; While researching various method ...

Updating the background image with Jquery is resulting in a distracting flicker effect

Here is a snippet of the script I'm using to create a slider that changes the background image for each image object in a specified time cycle. #Sliderimg - height set to 500px, $("#Sliderimg").css({ "background-image": "url(../Images/" + SliderIma ...