[Web Notifications] Notification Users in batch

Forge Component
(10)
Published on 2017-05-18 by Henrique Batista
10 votes
Published on 2017-05-18 by Henrique Batista

Hi Henrique,

I'm trying to build an async process that notifies the users that an event will happen soon. I'm trying to use this component to accomplish this but I'm not sure if it's possible. I was using the action SendNotificationToUserId but I'm not sure if it's possible using this. I also tried to use the SendWebNotification action but I didn't know how to configure it, especially the Subscription object.

Hope to hear from you.


Solution

Hi João,


The component has 2 modules, one of them is an example, have you looked at it?

Also, you have it running here and instructions are here (a bit outdated but I think one can figure it out), are you running into any specific issue?

When you save the browsers endpoint (Id) to the BD, if the user was logged in it will be associated with that specific browser. This way you can query it and send notifications to particular users.

The SendWebNotifications is for more advanced scenarios or if you wan to fire notifications for browsers that are not associated with users.

Let me know if you need further details

Cheers,


Solution

Hi Henrique,


Yes, I did and it helped a lot although I didn't check the examples on the OML because I was reading the support posts and I found a Sample that you shared, but it was older and didn't show that last action that I was asking about. 


Right now I'm facing the following issue:


function subscribeUser() {
   
    const applicationServerKey = urlB64ToUint8Array(applicationServerPublicKey);
    navigator.serviceWorker.ready.then(function(swRegistration) {
      swRegistration.pushManager.subscribe({
        userVisibleOnly: true,
        applicationServerKey: applicationServerKey
      })
      .then(function(subscription) {
          isSubscribed = true;
          updateSubscriptionOnServer(subscription,'subscribe');        
      })
      .catch(function(err) {
        if (Notification.permission === 'denied') {
            swRegistration.pushManager.getSubscription()
              .then(function(subscription) {
                    updateSubscriptionOnServer(subscription,'denied');
              });
         
        } else {
            console.log('Error subscribing', error);
        }
      });
    });
}


in the method above the component is throwing a JS error because the var in the catch method is different from the one that you are outputting into the console, you might want to fix that :) but the real problem was that applicationServerPublicKey was empty and I didn't know why. While writing this down I figured out that I also needed to configure the Pair Private/Public Keys in the WebNotifications eSpace, even if I was only using this action. Not is working like a charm. Thanks for the support.

Hi João,

Glad you figured it out and thanks for the feedback, I'll fix it.

Cheers,