# Advisor Desktop Widget Event APIs Advisor Desktop Widget Event APIs enable the Advisor Desktop to be used in tandem with another third-party browser-based application. The third-party application would most likely be a CRM system for an at the pane integration use case. It involves a fully client (browser) side integration. A JavaScript file served from an eGain installation is included in the third-party application. This file enables a two-way message exchange between the Advisor Desktop and the third-party application. A few lines of code in the third-party application allows it to receive various types of messages from Advisor Desktop, as well as allow for sending messages to Advisor Desktop. E.g., whenever the user selects a new activity in the Inbox in Advisor Desktop, the information about it can be broadcasted and it can be received by an interested third-party application. # What needs to be done on eGain side? In eGain Administration Console, add the origin of the third-party application URL in the CORS configuration. Refer the section Enabling Cross-Origin Resource Sharing in Administration user guide on how to add the origin. E.g., if want to use Duo with your MS Dynamics which has the URL like https://mycrm.crm.dynamics.com, you should enable CORS for https://mycrm.crm.dynamics.com. What needs to be done on third party application side? 1. Include a JavaScript file from the eGain installation from where Advisor Desktop is served. The URL to the JS file is `https://youregaindomain//web/apps/resources/js/egainremotesolve.js` For example: ``` ``` 1. If the third-party application restricts iframe insertion using content-security-policy directives like child-src and frame-src, it needs to be changed to allow for the eGain application domain e.g., https://youregaindomain. 2. Write JavaScript code to receive and send messages to Advisor Desktop. Sample code will be published. 3. Take action based on messages received. For example, load customer details locally in the third-party application when a new activity is selected in Advisor Desktop. # Events published by Advisor Desktop to Third party The following events are published by the Advisor Desktop when the eAdvisor Desktop Widget Event library is included in a third party application UI. ## All events ``` egainSolve.init(function(){ //subscribe to all events var listener = egainSolve.subscribeAll(function(message){ console.log("event name", message.type); console.log("event data",message.data ); }); //listener will get destroyed if called unsubscribeAll //listener.unsubscribeAll(); }); ``` ## activityselected This event is generated when an activity is selected in the Advisor Desktop. The event is supported for following channels: + Chat + Email + Secure message + Task + Calltrack ``` egainSolve.init(function(){ //subscribe to activity section event var listener2 = egainSolve.subscribe('activityselected', function(message){ console.log("event name", message.type); console.log("event data",message.data ); }); //listener will get destroyed if called //listener2.unsubscribe(); }); ``` ##### Payload ``` { "activity": { "type": type, "id": activity id, "subject": subject, "caseId": case id, "customerId": customer id, "subType": activity sub type, "channel": channel name in case of messaging chat }, } ``` ## chatmessage This event is generated when a chat message is received or sent ``` egainSolve.init(function(){ //subscribe to activity section event var listener2 = egainSolve.subscribe('chatmessage', function(message){ console.log("event name", message.type); console.log("event data",message.data ); }); //listener will get destroyed if called //listener2.unsubscribe(); }); ``` #### Payload ``` { author: author, authorType: type of author i.e. SYSTEM, AGENT or CUST, content: message content, originalMsgObject: original message object with all message parameters, activity: An object of all activity data } ``` ## chatcomplete This event is generated when a chat is completed. ``` egainSolve.init(function(){ //subscribe to activity section event var listener2 = egainSolve.subscribe('chatcomplete', function(message){ console.log("event name", message.type); console.log("event data",message.data ); }); //listener will get destroyed if called //listener2.unsubscribe(); }); ``` #### Payload ``` { "activity": { "type": type, "id": activity id, "subject": subject, "caseId": case id, "customerId": customer id, "subType": activity sub type, "channel": channel name in case of messaging chat } } ``` ## caseselected This event is generated when a case is selected on the Advisor Desktop. ``` egainSolve.init(function(){ //subscribe to activity section event var listener2 = egainSolve.subscribe('caseselected', function(message){ console.log("event name", message.type); console.log("event data",message.data ); }); //listener will get destroyed if called //listener2.unsubscribe(); }); ``` #### Payload ``` { case: { id: case id } } ``` ## folderchanged This event is generated when a folder is selected on the Advisor Desktop. ``` egainSolve.init(function(){ //subscribe to activity section event var listener2 = egainSolve.subscribe('folderchanged', function(message){ console.log("event name", message.type); console.log("event data",message.data ); }); //listener will get destroyed if called //listener2.unsubscribe(); }); ``` #### Payload ``` { folder: an object containing folder data like id, type , parent etc. } ``` ## nonchatactivitycomplete This event is generated when activity(s) are completed on the Advisor Desktop. The event is supported for following channels: + Chat + Email + Secure message + Task + Calltrack ``` egainSolve.init(function(){ //subscribe to activity section event var listener2 = egainSolve.subscribe('nonchatactivitycomplete', function(message){ console.log("event name", message.type); console.log("event data",message.data ); }); //listener will get destroyed if called //listener2.unsubscribe(); }); ``` #### Payload ``` { activities: an array of object containing activity data like id, type, caseId, customerId, subject } ``` ## nonchatactivitysave This event is generated when an activity is explicitly saved from reply pane on the Advisor Desktop. The event is supported for following channels: + Email + Task ``` egainSolve.init(function(){ //subscribe to activity section event var listener2 = egainSolve.subscribe('nonchatactivitysave' function(message){ console.log("event name", message.type); console.log("event data",message.data ); }); //listener will get destroyed if called //listener2.unsubscribe(); }); ``` #### Payload ``` { "activity": { "type": type, "id": activity id, "subject": subject, "caseId": case id, "customerId": customer id, "subType": activity sub type } ``` ## emailsend This event is generated when an email is sent on the Advisor Desktop. ``` egainSolve.init(function(){ //subscribe to activity section event var listener2 = egainSolve.subscribe('emailsend', function(message){ console.log("event name", message.type); console.log("event data",message.data ); }); //listener will get destroyed if called //listener2.unsubscribe(); }); ``` #### Payload ``` { "activity": { "type": type, "id": activity id, "subject": subject, "caseId": case id, "customerId": customer id, "subType": activity sub type } ``` ## emailsendandcomplete This event is generated when an email is sent and completed on the Advisor Desktop. ``` egainSolve.init(function(){ //subscribe to activity section event var listener2 = egainSolve.subscribe('emailsendandcomplete', function(message){ console.log("event name", message.type); console.log("event data",message.data ); }); //listener will get destroyed if called //listener2.unsubscribe(); }); ``` #### Payload ``` { "activity": { "type": type, "id": activity id, "subject": subject, "caseId": case id, "customerId": customer id, "subType": activity sub type } ``` ## transferactivities This event is generated when activities are transferred on the Advisor Desktop. ``` egainSolve.init(function(){ //subscribe to activity section event var listener2 = egainSolve.subscribe('transferactivities', function(message){ console.log("event name", message.type); console.log("event data",message.data ); }); //listener will get destroyed if called //listener2.unsubscribe(); }); ``` #### Payload ``` { activities: an array of object containing activity data like id, type, caseId, customerId, subject } ``` ## customerchanged This event is generated when a customer of selected activity is changed through the info pane on the Advisor Desktop. ``` egainSolve.init(function(){ //subscribe to activity section event var listener2 = egainSolve.subscribe('customerchanged', function(message){ console.log("event name", message.type); console.log("event data",message.data ); }); //listener will get destroyed if called //listener2.unsubscribe(); }); ``` #### Payload ``` {customerId: customerId} ``` ## casechanged This event is generated when a field on the case of a selected activity is changed through info pane on the Advisor Desktop. If a new case is created then new case id is sent. ``` egainSolve.init(function(){ //subscribe to activity section event var listener2 = egainSolve.subscribe('casechanged', function(message){ console.log("event name", message.type); console.log("event data",message.data ); }); //listener will get destroyed if called //listener2.unsubscribe(); }); ``` #### Payload ``` {caseId: caseid} ``` ## casecustomattributechanged This event is generated when a custom attribute field on a case of a selected activity is changed through info pane on the Advisor Desktop. ``` egainSolve.init(function(){ //subscribe to activity section event var listener2 = egainSolve.subscribe('casecustomattributechanged', function(message){ console.log("event name", message.type); console.log("event data",message.data ); }); //listener will get destroyed if called //listener2.unsubscribe(); }); ``` #### Payload ``` { caseId: caseid, customAttributed: an array of modified custom attribute name value pair } ``` ## activitychanged This event is generated when an activity field of a selected activity is changed through the info pane on the Advisor Desktop. ``` egainSolve.init(function(){ //subscribe to activity section event var listener2 = egainSolve.subscribe('activitychanged', function(message){ console.log("event name", message.type); console.log("event data",message.data ); }); //listener will get destroyed if called //listener2.unsubscribe(); }); ``` #### Payload ``` { activityId: activity id } ``` ## activitycustomattributechanged This event is generated when a custom attribute field on a selected activity is changed through the info pane on the Advisor Desktop. ``` egainSolve.init(function(){ //subscribe to activity section event var listener2 = egainSolve.subscribe('activitycustomattributechanged', function(message){ console.log("event name", message.type); console.log("event data",message.data ); }); //listener will get destroyed if called //listener2.unsubscribe(); }); ``` #### Payload ``` { activityId: activity id, customAttributed: an array of modified custom attribute name value pair } ``` ## calltrackfieldchange This event is generated when a when content or field of a call track reply pane is changed on the Advisor Desktop. ``` egainSolve.init(function(){ //subscribe to activity section event var listener2 = egainSolve.subscribe('calltrackfieldchange', function(message){ console.log("event name", message.type); console.log("event data",message.data ); }); //listener will get destroyed if called //listener2.unsubscribe(); }); ``` #### Payload ``` { activityId: activity id, subject: subject, fieldName: name of field or editor in case of content, value: new value of field value pair } ``` ## replyfieldchange This event is generated when any field except 'content' changes in reply pane on the Advisor Desktop. ``` egainSolve.init(function(){ //subscribe to activity section event var listener2 = egainSolve.subscribe('replyfieldchange', function(message){ console.log("event name", message.type); console.log("event data",message.data ); }); //listener will get destroyed if called //listener2.unsubscribe(); }); ``` #### Payload ``` { "activity": { "type": type, "id": activity id, "subject": subject, "caseId": case id, "customerId": customer id, "subType": activity sub type. "channel": channel name in case of messaging chat }, "fieldName": field name, "value": value of field, "displayValue": display value if combo or multiselect field, "custom": false } ``` ## pullchatblink This event is generated when pull chat button start or stop event for a chat is received on the Advisor Desktop. ``` egainSolve.init(function(){ //subscribe to activity section event var listener2 = egainSolve.subscribe('pullchatblink', function(message){ console.log("event name", message.type); console.log("event data",message.data ); }); //listener will get destroyed if called //listener2.unsubscribe(); }); ``` #### Payload ``` { "queueId": queue id "start": start or stop } ``` ## chatassigned This event is generated when a chat is assigned. ``` egainSolve.init(function(){ //subscribe to activity section event var listener2 = egainSolve.subscribe('chatassigned', function(message){ console.log("event name", message.type); console.log("event data",message.data ); }); //listener will get destroyed if called //listener2.unsubscribe(); }); ``` #### Payload ``` { "activity": { "type": type, "id": activity id, "subject": subject, "caseId": case id, "customerId": customer id, "subType": activity sub type, "channel": channel name in case of messaging chat }, } ``` ## nonchatassigned This event is generated when a non chat activity is assigned. ``` egainSolve.init(function(){ //subscribe to activity section event var listener2 = egainSolve.subscribe('nonchatassigned', function(message){ console.log("event name", message.type); console.log("event data",message.data ); }); //listener will get destroyed if called //listener2.unsubscribe(); }); ``` #### Payload ``` { "activity": { "type": type, "id": activity id, "subject": subject, "caseId": case id, "customerId": customer id, "subType": activity sub type }, } ``` ## channelavailabilitychanged Fires when an agent channel (chat/videochat/email/social/phone) status is changed #### Payload ``` { "activity": { "type": type, "value": true or false "status": success or fail "reasonCode": reason code id }, } ``` ## incomingCall Fires when call is coming in #### Payload ``` { callId: callId } ``` ## callPaused Fires when call is paused #### Payload ``` { callId: callId } ``` ## callResumed Fires when call is resumed #### Payload ``` { callId: callId } ``` ## callEnded Fires when call ends #### Payload ``` { activityId: activityId, callId: callId } ``` ## callHold Fires when call is put on hold #### Payload ``` { activityId: activityId, callId: callId } ``` ## callToggled Fires when toggling between calls #### Payload ``` { activityId: activityId, primaryCallInProgress: primaryCallInProgress, primaryCallId: primaryCallId, secondaryCallInProgress: secondaryCallInProgress, secondaryCallId: secondaryCallId } ``` ## callsMerged Fires when primary and secondary call are merged #### Payload ``` { activityId: activityId, primaryCallId: primaryCallId, secondaryCallId: secondaryCallId } ``` ## leaveConference Fires when leaving conference call #### Payload ``` { callId: callId } ``` ## triggerphoneavailability Trigger phone availability #### Payload ``` { name: phone, value: true or false, reasonCode: reasonCode } ``` # Events Subscribed by Solve Advisor The following events are subscribed by the Advisor Desktop. Third party UI can publish these events using the Advisor Desktop Widget Event library to build custom functionality. ## addtoeditor Publish event to add content to Advisor Desktop editor of currently selected activity. ``` egainSolve.init(function(){ egainSolve.publish('addtoeditor', { content: "Hello world" }); }); ``` #### Here is an example of a response ``` { content: content to add to editor } ``` ## showtoast Publish event to show a toast notification. ``` egainSolve.init(function(){ egainSolve.publish('showtoast', { content: "Hello world" }); }); ``` #### Response example ``` { title: title of toast, html: html content of toast, width: width of toast. Defaults to 280 px, cls: any classes to be applied to toast. Default to eg-guidance-toast, autoClose: Auto close toast or not. Applicable only if autoCloseDelay not set autoCloseDelay: delay in seconds before toast closes, align: Extjs alignment string to align toast. Defaults to 'br' meaning bottom right, stickOnClick: make toast sticky on click. Default to false, } ``` ## cleartoast Publish event to clear all previously shown toasts if still visible. ``` egainSolve.init(function(){ egainSolve.publish('cleartoast', { content: "Hello world" }); }); ``` ## refreshmaininbox Publish event to refresh main inbox on Advisor Desktop. ``` egainSolve.init(function(){ egainSolve.publish('refreshmaininbox', { content: "Hello world" }); }); ``` ## refreshchatinbox Publish event to refresh chat inbox on Advisor Desktop. ``` egainSolve.init(function(){ egainSolve.publish('refreshchatinbox', { content: "Hello world" }); }); ``` ## refreshactivitypane Publish event to refresh activity pane on Advisor Desktop. ``` egainSolve.init(function(){ egainSolve.publish('refreshactivitypane', { content: "Hello world" }); }); ``` ## refreshcasepane Publish event to refresh case pane on Advisor Desktop. ``` egainSolve.init(function(){ egainSolve.publish('refreshcasepane', { content: "Hello world" }); }); ``` ## refreshcustomerpane Publish event to refresh customer pane on Advisor Desktop. ``` egainSolve.init(function(){ egainSolve.publish('refreshcustomerpane', { content: "Hello world" }); }); ``` ## selectactivity Select an activity in the inbox ``` { "type": type of activity (email, chat, etc.), "activity": {"id":Id of activity} } ``` ## openctiwidget Launch CTI Widget ## closectiwidget Close CTI Widget ## changeavailabilitystate Change agent availability state (chat/videochat/email/phone) ``` { "type": type, (chat/videochat/email/phone) "status": true or false (enable/disable) "reasonCode": reason code id } ``` ## aftertriggerphoneavailability Event to change phone UI button from 3rd party system ``` { "type": 'phone', "value": true or false "status": true or false (enable/disable) } ``` # Callbacks Available These callbacks can be called on the object 'egainSolve' to fetch specific data actively. ## getCurrentActivityData Publish event to show a toast notification ``` egainSolve.getCurrentActivityData(function(message){ var data = message.data; }); ``` #### Returned Data Example of getCurrentActivityData callback ``` { "type": "email", "id": 1850, "subject": "sup [#1719]", "caseId": 1719, "customerId": 1007 } ``` ## getActivityReplyData Publish event to show a toast notification ``` egainSolve.getActivityReplyData(function(message){ var data = message.data; }); ``` #### Returned Data Example of getActivityReplyData callback ``` { "activity": { "type": "email", "id": 1850, "subject": "sup [#1719]", "caseId": 1719, "customerId": 1007 }, "fields": [ { "name": "from_email_address", "value": "kushal01@egain-corp.com", "dirty": true, "displayValue": "kushal01@egain-corp.com" }, { "name": "to_email_address", "value": [ "kkhandelwal@egain.com" ], "dirty": true, "displayValue": [ "kkhandelwal@egain.com" ] }, { "name": "cc_email_address", "value": [], "dirty": false }, { "name": "subject", "value": "sup [#1719]", "dirty": true }, { "name": "actcust", "value": "", "custom": true, "dirty": false }, { "name": "actmul", "value": null, "custom": true, "dirty": false }, { "name": "delay_time_in_min", "value": null, "dirty": false }, { "name": "maxlength", "value": null, "custom": true, "dirty": false }, { "name": "prasad1", "value": "", "custom": true, "dirty": false }, { "name": "prasad2", "value": "aaa", "custom": true, "dirty": false }, { "name": "testattr", "value": "testing", "custom": true, "dirty": false }, { "name": "group_name", "value": "", "custom": true, "dirty": false } ] } ``` ## getAgentAvailabilityData Event to get agent availability data ``` egainSolve.getAgentAvailabilityData(function(message){ var data = message.data; }); ``` #### Returned Data Example of getCurrentActivityData callback ``` { "chat": true, "videochat": false, "mail": false } ``` ## Test Sample showing use of the Advisor Desktop Widget Event API ```

test

This is a new page;

Click here to add to reply;

``` ## Remote Client ``` eGain Solve Advisor Desktop Messages Demo

Incoming Messages





Publish Messages

Add to Reply Editor

Show Toast Message Title
HTML
Auto close

Refresh various parts of the Desktop


} ```