Use Salesforce console events


Note: This article applies to PureCloud for Salesforce.

Through the event model in the Salesforce Console Integration Toolkit, the integration broadcasts and listens for events being raised around status changes (such as Available, Busy, Away, Out of Office, and On Queue) and call activities (connected, disconnected, ACW required, ACW completed).

Note: This article is an advanced customization topic meant for developers familiar with Salesforce.

Developers can create Visualforce pages that use these events. To create an example Visualforce page that broadcasts and listens for events, use this sample code:

<apex:page >
   <apex:includeScript value="/support/console/34.0/integration.js"/>
 
   <style type="text/css">
      .statusSelection {
         position: relative;
         display: block;
         padding-top: 6px;
      }
   </style>

   <script type="text/javascript">
 
 
   //Omni Status Map Ids are org specific
   var statusMap = {Omni:{available:"0N5j00000008QNQ" , queue:"0N5j00000008QMt"}, PureCloud:{available:"AVAILABLE", queue:"ON_QUEUE"}};
 
   function OutputToConsole(message){
      console.log(message);
      if(document.getElementById("OUTPUTCONSOLE").value != ""){
         document.getElementById("OUTPUTCONSOLE").value = document.getElementById("OUTPUTCONSOLE").value + " \r\n";
      }
 
      document.getElementById("OUTPUTCONSOLE").value = document.getElementById("OUTPUTCONSOLE").value + message;
   }

   function changeStatus(status) { 
      if(status == 'available'){
         sforce.console.fireEvent('inin.salesforce.constants.consoleevent.changestatus', statusMap.PureCloud.available , function(data){console.log(data);});
         sforce.console.presence.setServicePresenceStatus(statusMap.Omni.available);
      }else if(status = 'onQueue'){
         sforce.console.fireEvent('inin.salesforce.constants.consoleevent.changestatus', statusMap.PureCloud.queue , function(data){console.log(data);});
         sforce.console.presence.setServicePresenceStatus(statusMap.Omni.queue);
      }
   }
 
   sforce.console.addEventListener('inin.salesforce.constants.consoleevent.pc.UPDATE_STATUS', function(data){
      OutputToConsole(JSON.stringify(data));
   });
 
   sforce.console.addEventListener('inin.salesforce.constants.consoleevent.pc.INTERACTION_CONNECTED', function(data){
      OutputToConsole(JSON.stringify(data));
   });
 
   sforce.console.addEventListener('inin.salesforce.constants.consoleevent.pc.INTERACTION_DISCONNECTED', function(data){
      OutputToConsole(JSON.stringify(data));
   });
	
   sforce.console.addEventListener('inin.salesforce.constants.consoleevent.pc.ACW_REQUIRED', function(data){
      OutputToConsole(JSON.stringify(data));
   });
 
   sforce.console.addEventListener('inin.salesforce.constants.consoleevent.pc.ACW_COMPLETED', function(data){
      OutputToConsole(JSON.stringify(data));
   });

   </script>
   <span class="statusSelection">
      <input type="button" onclick="changeStatus('available')" value="Change status to Available" /> |
      <input type="button" onclick="changeStatus('onQueue')" value="Change Status to On Queue" />
   </span>
   <hr/>
   <span>
       <textArea id="OUTPUTCONSOLE" rows="20" cols="100" ></textArea>
   </span>
 
</apex:page>

For information about the Salesforce console, see Customize a Console with Custom Components in Salesforce Classic in the Salesforce documentation.

For information about using the event model, see the Salesforce Console Integration Toolkit for Salesforce Classic in the Salesforce documentation.

Events the integration broadcasts

The integration can broadcast the following five events and send them to Salesforce.

Note: These event names begin with inin.salesforce.constants.consoleevent.pc., followed by the name in the table, for example, inin.salesforce.constants.consoleevent.pc.UPDATE_STATUS.
Event name Body example Description
UPDATE_STATUS

{
“reason”: “status_updated”,
“status”: “AVAILABLE”,
“id”: “44560c74-5e84-4062-94b6-5680cdeb54d5”,
“sub_status”: “Available Work At Home”
}

Status update. If using secondary statuses, the response includes secondary status information.
INTERACTION_CONNECTED {
“reason”: “connected”,
“interactionId”: “44560c74-5e84-4062-94b6-5680cdeb54d5”
}
Interaction connected
INTERACTION_DISCONNECTED {
“reason”: “disconnected”,
“interactionId”: “44560c74-5e84-4062-94b6-5680cdeb54d5”
}
Interaction disconnected
LOGGED_OUT {
“reason”: “logged_out”
}
User logged out
ACW_REQUIRED {
“reason”: “acw_required”,
“interactionId”: “44560c74-5e84-4062-94b6-5680cdeb54d5”
}
ACW required
ACW_COMPLETED {
“reason”: “acw_completed”,
“interactionId”: “44560c74-5e84-4062-94b6-5680cdeb54d5”
}
ACW completed

Event the integration listens for

The integration can listen for the following event about status changes and change an agent’s status.

Note: This event name begins with inin.salesforce.constants.consoleevent., followed by the name in the table, for example, inin.salesforce.constants.consoleevent.changestatus.
Event name Body example Description
changestatus  {Status}

Status changes. Send the status ID in the request.

Note: If you only use primary statuses, you can send high-level key values in place of the status ID: ‘AVAILABLE’, ‘AWAY’, ‘BUSY’, ‘OUT_OF_OFFICE’, ‘ON_QUEUE’, ‘BREAK’, ‘TRAINING’, ‘MEETING’, ‘MEAL’.

For more information about the integration, see About PureCloud for Salesforce.