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 ) );
});
}
July 27, 2020
How to close the Chat tab when the conversation is ended in Salesforce Chat in Lightning Experience?
lightning:conversationChatEnded Event is triggered when an active chat ends.
For the below component to work,
1. Add it to the Chat Transcript Lightning Record Page.
2. When the Chat is ended, lightning:conversationChatEnded event will be fired.
3. onChatEnded method will be called.
4. workspaceAPI.closeTab() closes the Chat Transcript record.
Sample Code:
})
Subscribe to:
Post Comments (Atom)
Can you please guide me on SendMessage event how to customize it in lightning?
ReplyDeleteCheck 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.
Deletehow can we use sforce_api in lightning?
ReplyDeleteYou 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
DeleteCan you add some details on how to fire this event
ReplyDeleteThanks for the feedback. I have added some instructions for better understanding of this component.
DeleteHello ,
ReplyDeletei used the same code , if it works for 1 chat , if we have more than 1 chat(means 5 chats) , if customer is closed chat their end , popup window will show the End Conversion or Cancel to continue the same chat, if i click End Conversion one time that window will not close and still appearing and if i click 4 times then all the chats tabs closed automatically , can someone tell me the reason , its very urgent
End user closing the chat window won't end the conversation. End user has to click End Conversation and confirm it.
DeleteHi i did the same as what you suggested , but still getting the same error, see the below
ReplyDelete1) First i click on "Close dialouge"
2) clicked Confirmed endchat
3) Clicked Close Chat button
In Console app , able to see the same screen "Cancel" & "End Conversation" , if i click "End Conversion" one time, confirmation screen is still appearing , then i start click 4 times then all the chat tabs closing and agent occupancy is updated to 0 , any suggestion please , its very urgent
I am not sure about this.
DeleteWhen the Chat is ended, lightning:conversationChatEnded event will be fired. Not sure, what is happening in this case. If the Chat is ended properly, definitely, the event will be fired. You can add some console.log statements in the component to check in the browser.