Newer Version Available
Integrate the Engagement Objects Into Your CTI System
Modify your CTI adapter so that when a customer service representative (CSR) accepts an
incoming call using the softphone, an engagement interaction record for the call is created.
Engagement Interaction is part of the Engagement data model, which has two other objects,
Engagement Attendee and Engagement Topic. These objects store details such as the start and
end date and time of an interaction, what an interaction is about, and attendee
details.
Modifications to the CTI Adapter
The Engagement Connect APIs (REST or Apex) provide a way to create, get, and
delete engagement attendee, engagement interaction, and engagement topic
records.
Alternatively, use the
sObject API to perform CRUD operations on the engagement objects.
The demo adapter triggers an Aura component code when an incoming call is accepted
using the softphone. The callInitiatedPanel.cmp
is displayed that contains the accept
listener.
1<button class="slds-size--1-of-2 slds-button slds-button--brand"
2onclick="{!c.accept}">Accept</button>At the same time, an event is raised, which is captured by the accept method in the callInitiatedPanelController.js
file.
1accept : function(cmp, event, helper) {
2helper.renderConnectedPanel(cmp);
3},The method brings up the Connected panel defined in the helper. The panel contains
the SoftphoneContactSearchController Apex
class, which is called from the callInitiatedPanelHelper.js
file.
1renderConnectedPanel : function(cmp){
2 var recordId = cmp.get('v.recordId');
3 var account = cmp.get('v.account');
4 var recparam=(recordId)?recordId:'UNKNOWN';
5 sforce.opencti.runApex({
6 apexClass : 'SoftphoneContactSearchController',
7 methodName : 'createEngagementInteraction',
8 methodParams : 'recordId='+recparam ,
9 callback : function(result) {
10 cmp.getEvent('editPanel').setParams({
11 label : 'Open CTI Softphone: ' + cmp.get('v.state')
12 }).fire();
13 if (result.success) {
14 sforce.opencti.screenPop({
15 type : sforce.opencti.SCREENPOP_TYPE.SOBJECT,
16 params : { recordId : result.returnValue.runApex }
17 });
18 } else {
19 throw new Error('Unable to make a call. Contact your admin.');
20 }
21 cmp.getEvent('renderPanel').setParams({
22 type : 'c:connectedPanel',
23 attributes : {
24 showDialPad : false,
25 recordId : recordId,
26 engagementId : result.returnValue.runApex,
27 callType : 'Inbound',
28 account : account,
29 recordName: cmp.get('v.recordName'),
30 presence : cmp.get('v.presence')
31 }
32 }).fire();
33 }
34 });
35}The SoftphoneContactSearchController Apex class
contains the createEngagementInteraction
method, which uses the connect API to create an engagement interaction record as
shown in this
example:
1// Create Engagement Interaction using connect API
2webService static String createEngagementInteraction(String recordId) {
3 system.debug('In create Engagement Interaction');
4 ConnectApi.EngagementInteractionCreateInput interactionInput = new
5ConnectApi.EngagementInteractionCreateInput();
6 interactionInput.communicationChannel = 'Voice Call';
7 interactionInput.attendeeVerified = false;
8 interactionInput.startDateTime =
9datetime.now().formatGMT('yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\'');
10 interactionInput.status = 'New';
11 if(recordId !='UNKNOWN' ){
12 interactionInput.initiatingAttendeeId = recordId;
13 interactionInput.attendeeAuthenticated = true;
14 }
15 ConnectApi.EngagementsCreateInput containerInput = new
16ConnectApi.EngagementsCreateInput();
17 containerInput.engagementInteraction = interactionInput;
18 ConnectApi.EngagementsCreateOutput output =
19ConnectApi.EngagementContainerConnect.createEngagementInteraction(containerInput);
20 return output.engagementInteraction.id;
21}if you want to create engagement attendee and engagement topic records along with the
engagement interaction record using the connect API, you can change the input to the
createEngagementInteraction method. . This
example shows how to create engagement attendee records using the Connect
API:
1List<ConnectApi.EngagementAttendeeCreateInput> eaList = new
2List<ConnectApi.EngagementAttendeeCreateInput>();
3ConnectApi.EngagementAttendeeCreateInput internalAttendeeInput = new
4ConnectApi.EngagementAttendeeCreateInput();
5internalAttendeeInput.startDateTime =
6datetime.now().formatGMT('yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\'');
7internalAttendeeInput.internalAttendeeId = UserInfo.getUserId();
8eaList.add(internalAttendeeInput);
9if(recordId !='UNKNOWN' ){
10 ConnectApi.EngagementAttendeeCreateInput externalAttendeeInput = new
11ConnectApi.EngagementAttendeeCreateInput();
12 externalAttendeeInput.startDateTime =
13datetime.now().formatGMT('yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\'');
14 externalAttendeeInput.externalAttendeeId = recordId;
15 eaList.add(externalAttendeeInput);
16}
17interactionInput.engagementAttendees = eaList;Engagement attendee records for internal attendees of an engagement are automatically created after an engagement interaction record is created. If necessary, stop the automatic creation of engagement attendee records by turning off the Auto-Creation of Internal Attendee Record org preference.
When the call ends, another Aura component code is
triggered.
1<button aura:id="endcall" class="slds-size--1-of-2 slds-button slds-button--destructive" onclick="{!c.endCall}">End</button>The endCall listener invokes the endCall method in the connectedPanelController.js
file.
1endCall: function(cmp, event, helper) {
2sforce.opencti.runApex({
3apexClass : 'SoftphoneContactSearchController',
4methodName : 'updateEngagementInteraction',
5methodParams : 'recordId=' + cmp.get('v.engagementId'),
6callback : function(result) {
7if (result.success) {
8} else {
9throw new Error(
10'Unable to update EI. Contact your admin.');
11}
12helper.logCall(cmp, function(response) {
13cmp.getEvent('renderPanel').setParams({
14type : 'c:phonePanel',
15toast : {'type': 'normal', 'message': 'Call was ended.'},
16attributes : { presence : cmp.get('v.presence')}
17}).fire();
18})
19var param = {callback:
20function(response) {
21if (response.success) {
22console.log('API method call executed successfully! returnValue:', response.returnValue);
23} else {
24console.error('Something went wrong! Errors:', response.errors);
25}
26}};
27sforce.opencti.refreshView(param);
28}
29});
30}If necessary, add methods to update engagement interaction, engagement attendee, and engagement topic records to the SoftphoneContactSearchController Apex class.
Alternatively, use the sObject API to perform CRUD operations on the engagement
objects. This example shows how to create or edit engagement attendee or engagement
topic records using the sObject
API:
1//Create Engagement Attendee
2List<EngagementAttendee> eaList = new List<EngagementAttendee>();
3EngagementAttendee internalAttendeeInput = new EngagementAttendee();
4internalAttendeeInput.EngagementId = output.engagementInteraction.id;
5internalAttendeeInput.StartDateTime = datetime.now();
63
7Integrate Your CTI System with the Engagement Objects
8internalAttendeeInput.InternalAttendeeId = UserInfo.getUserId();
9eaList.add(internalAttendeeInput);
10insert eaList;
11System.debug('EI Created'+eaList.get(0).id);
12//Update Engagement Attendee
13EngagementAttendee internalAttendee=[select id from EngagementAttendee where
14EngagementId=:output.engagementInteraction.id];
15internalAttendee.EndDateTime = datetime.now();
16internalAttendee.IsVerified = true;
17internalAttendee.Role='Self';
18update internalAttendee;
19System.debug('EA updated'+internalAttendee.EndDateTime);
20//Create Engagement Topic
21List<EngagementTopic> topicList = new List<EngagementTopic>();
22EngagementTopic topic = new EngagementTopic();
23topic.EngagementId = output.engagementInteraction.id;
24topic.Name = 'Address Change';
25topicList.add(topic);
26insert topicList;
27System.debug('ET Created'+topicList.get(0).id);
28//Update Engagement Topic
29EngagementTopic engagementTopic = [select id from EngagementTopic where
30EngagementId=:output.engagementInteraction.id];
31engagementTopic.ProcessFailureReason = 'Job Shift';
32update engagementTopic;