July 27, 2020

How to close the Chat tab when the conversation is ended in Salesforce Chat in Lightning Experience?

Sample Code:

ChatEnd.cmp:


<aura:component implements="flexipage:availableForAllPageTypes" access="global">
   
    <lightning:conversationToolkitAPI aura:id="conversationKit" />
    <lightning:workspaceAPI aura:id="workspace"/>
   
    <aura:handler event="lightning:conversationChatEnded" action="{!c.onChatEnded}" />
   
</aura:component>

ChatEndController.js:

({
   
    onChatEnded: function(cmp, evt, helper) {
       
        /*var conversation = cmp.find( "conversationKit" );
        var recordId = evt.getParam( "recordId" );
        console.log( "recordId:" + recordId );*/
        var workspaceAPI = cmp.find( "workspace" );
        workspaceAPI.getFocusedTabInfo().then( function( response ) {
            var focusedTabId = response.tabId;
            console.log( 'Focused Tab is ' + focusedTabId );
            workspaceAPI.closeTab( { tabId: focusedTabId } );
        })
        .catch(function( error ) {
            console.log( 'Error is' + JSON.stringify( error ) );
        });
       
    }
   
})


No comments:

Post a Comment