Send Broswer notification

Dear team,

 

Is there a way to send browser notifications (as seen in the image attached) through javascript? Our use case is that when our webservice receives a response from client, we use Message Channel Utilities to send message from server to client. When client receives the message, it should be able to trigger a browser notification

Like 0

Like

4 comments

Creatio does have a module named DesktopPopupNotification which you can use for this if you'd like. It can handle the request for permissions (if not yet granted by the user/browser) and create the notification and handle a click of the notification. Something like this:

// in init call:
DesktopNotification.requestPermission();
 
// to use, something like this:
var config = {
    id: someId,
    title: someTitle,
    body: someSubject,
    icon: this._getIcon(),
    onClick: this.onDesktopNotificationClick,
    ignorePageVisibility: true,
    timeout: 5000,
    scope: this
};
 
DesktopNotification.show(config);

Ryan

Ryan Farley,

 

Thank you for your response. I have implemented this and also permission to enable pop ups have been provided. yet, there is no notification. Could you please help?

 

Implementation details :

 

I have replaced communication panel and added dependency module - DesktopPopupNotification

 

In init() I have this line of code :

init() : function()

{

    DesktopPopupNotification.requestPermission();

 this.testfn();

},

 

    testfn: function()
                {
                    DesktopPopupNotification.requestPermission();
                    this.console.log("testfn");
                        var createConfig = {
                        id: "1234",
                        title: "Chat Notification",
                        body: "You have a new chat notification",
                        icon: {},
                        ignorePageVisibility: true,
                        onClick: Ext.emptyFn,
                        onClose: Ext.emptyFn,
                        onError: Ext.emptyFn,
                        onShow: "Sample",
                        timeout: 5000,
                        scope: this
                    };
                     
                    DesktopPopupNotification.showNotification(createConfig);
                    }

This doesnt seem to throw a notification

 

Thanks in advance

Shivani Lakshman,

The reason why it's not showing is likely because it doesn't have an icon defined. The DesktopPopupNotification module validates the config, if it doesn't have an icon defined, it exits out and doesn't show the notification (if you're in debug mode it shows this reason in the console, but that will only show if in debug mode)

If you want to add an icon to the images of your schema, let's say it has a name of UsrIcon, you can show it in the notification by adding this for the icon part of the config:

Terrasoft.ImageUrlBuilder.getUrl(this.get("Resources.Images.UsrIcon"))

Ryan

Shivani Lakshman,

In case you're still looking at this and having issues, I've written up the details for using the DesktopPopupNotification module here: 

https://customerfx.com/article/how-to-display-browser-popup-notificatio…

Ryan

Show all comments