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 ) );
        });
       
    }
   
})


4 comments:

  1. Can you please guide me on SendMessage event how to customize it in lightning?

    ReplyDelete
    Replies
    1. Check this https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_sendMessage.htm. I don't think there is event for this.

      Delete
  2. how can we use sforce_api in lightning?

    ReplyDelete
    Replies
    1. You can use it Classic button. You can use it in VF Page - https://developer.salesforce.com/docs/atlas.en-us.ajax.meta/ajax/sforce_api_ajax_vf_sample.htm?search_text=lightning

      Delete