Author Topic: Trigger an event from Toaster popup - GWS API  (Read 4045 times)

Offline genesys_kumar

  • Newbie
  • *
  • Posts: 28
  • Karma: 0
Trigger an event from Toaster popup - GWS API
« on: February 25, 2022, 01:55:41 PM »
Hi,

I'm trying to customize the toaster popup in WWE with custom buttons.  I'm able to replace the "Show/Dismiss" buttons to "Yes/No".  Now I need to execute functionality when agents click "Yes" or "No".  The document shows not much info or I'm looking at the wrong doc.

Can someone please help with this question?

Here is my code.

const buttonName = ["Yes", "No"];
genesys.wwe.service.system.popupToast({
                        title: "Alert Message",
                        iconUrl: msgURL,
                        subject: "Testing",
                        message: "Click Yes/No",
                        buttons: buttonName,
                        buttonShowDismiss: false
                    }, succeeded, failed);

Thanks,
Kumar

Marked as best answer by genesys_kumar on March 15, 2022, 02:08:57 AM

Offline hsujdik

  • Hero Member
  • *****
  • Posts: 541
  • Karma: 30
Re: Trigger an event from Toaster popup - GWS API
« Reply #1 on: February 26, 2022, 04:06:11 AM »
have you tried subscribing to "system" notifications and validating the message object if the event.data.eventType property is "CUSTOM_TOAST_BUTTON_CLICK" and then getting event.data.buttonIndex = 0 (Yes) or 1 (No)?

Also, you probably should assign the result of your popupToast method call to a variable so you can compare against event.data.customToastId when performing the event handling.

Check if the "Notifications" chapter of the following link helps:
https://docs.genesys.com/Documentation/HTCC/9.0.0/Dev/ServiceClientAPI

roughly, I believe that could be something like this:
[code]
const buttonName = ["Yes", "No"];
var myCustomToastId;

// Event Handler for system notifications
function myEventHandler(message)
{
    if (!message.hasOwnProperty("event")) return; // Missing property "event" on notification event
    if (!message.hasOwnProperty("data")) return;  // Missing property "data" on notification event
    if (!message.data.hasOwnProperty("eventType")) return; // Missing property "data.eventType" on notification event

    // Using switch clause in case you want to add a handler for other events
    switch(message.data.eventType) {
        case "CUSTOM_TOAST_BUTTON_CLICK":
            if (!message.data.hasOwnProperty("customToastId")) return;
            if (message.data.customToastId !== myCustomToastId) return; // These aren't the toasts you are looking for
            alert("I clicked on " + buttonName[message.data.buttonIndex] + " button!!!"); // Show an alert saying which button you clicked on
            break;
    }
}

// Subscribe for system events here
genesys.wwe.service.subscribe([ "system" ], myEventHandler, this);

// Add a reference id for your toast so you can compare later
myCustomToastId = genesys.wwe.service.system.popupToast({
                        title: "Alert Message",
                        iconUrl: msgURL,
                        subject: "Testing",
                        message: "Click Yes/No",
                        buttons: buttonName,
                        buttonShowDismiss: false
                    }); // I removed the callbacks. I don't think they are present on popupToast method call

[/code]
« Last Edit: February 26, 2022, 04:23:42 AM by hsujdik »

Offline genesys_kumar

  • Newbie
  • *
  • Posts: 28
  • Karma: 0
Re: Trigger an event from Toaster popup - GWS API
« Reply #2 on: March 14, 2022, 01:12:50 PM »
Thanks hsujdik,

It worked perfectly.

I have another question.  Is it possible to wordwrap (display messages on 2 lines) message.

const buttonName = ["Yes", "No"];
genesys.wwe.service.system.popupToast({
                        title: "Alert Message",
                        iconUrl: msgURL,
                        subject: "Testing",
                        [b]message: "Click Yes/No",[/b]
                        buttons: buttonName,
                        buttonShowDismiss: false
                    }, succeeded, failed);


Thanks,
Kumar

Offline hsujdik

  • Hero Member
  • *****
  • Posts: 541
  • Karma: 30
Re: Trigger an event from Toaster popup - GWS API
« Reply #3 on: March 14, 2022, 01:17:52 PM »
Hi, Kumar.

That I don't know. Try something like this to see if it works:

message: "Click \nYes/No"

or

message: "Click <br />Yes/No"


Regards,
H. Sujdik

Offline genesys_kumar

  • Newbie
  • *
  • Posts: 28
  • Karma: 0
Re: Trigger an event from Toaster popup - GWS API
« Reply #4 on: March 14, 2022, 02:09:23 PM »
Hi Sujdik,

Thanks for the response. 
I actually reading message text from CME so \n is considered as text and displayed like "Click \nYes/No".  Tried <br/>, displayed "Click Yes/No" like this but no line break.  Also tried some custom CSS but not helped

Finally, tried with &nbsp; - it worked (&emsp; we use this one also).

Thanks,
Kumar