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) {
/*let conversation = cmp.find( “conversationKit” );
let recordId = evt.getParam( “recordId” );
console.log( “recordId:” + recordId );*/
let workspaceAPI = cmp.find( “workspace” );
workspaceAPI.getFocusedTabInfo().then( function( response ) {
let focusedTabId = response.tabId;
console.log( ‘Focused Tab is ‘ + focusedTabId );
workspaceAPI.closeTab( { tabId: focusedTabId } );
})
.catch(function( error ) {
console.log( ‘Error is’ + JSON.stringify( error ) );
});
}
Can you please guide me on SendMessage event how to customize it in lightning?
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.
how can we use sforce_api in lightning?
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
Can you add some details on how to fire this event
Thanks for the feedback. I have added some instructions for better understanding of this component.
Hello ,
i 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.
Hi i did the same as what you suggested , but still getting the same error, see the below
1) 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.
When 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.
I'm facing the same issue.
Test it by ending the conversation. visitor closing their browser window doesn't end the chat. They have to click End Conversation button to end the Chat.
Thank you for the response!
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.
Interesting. I never faced this issue. I have used the same code.
When there is only one chat open, it works fine. But when there is multiple chat tab open, I face the issue which I mentioned at the previous comment, that is it will pop up the confirmation message again and again.
I am getting "Closing this tab will also end the conversation. Click 'Cancel' to continue your conversation." only when I close the Chat window instead of clicking End Chat button.
Hi! I have implemented this feature but it doesn't work with messaging session conversation.
Do you know why it doesn't work appropriately?
Currently, it is not available for messaging.
https://trailblazer.salesforce.com/ideaView?id=0873A000000Lrc8QAC
Hi guys! @hanu and @sow this occurs with you guys because you need to get the TAB ID correctly.
This function workspaceAPI.getFocusedTabInfo just get de tab that is open on the console.
So you need store RECORDID and TABID in a hashMap.
When the chat was ending by you or by customer you need get recordId and retrieve the related TabId that was stored in the HashMap.
example:
CONTROLLER.js
init : function(component, event, helper){
var myMap = new Map();
workspaceAPI.getAllTabInfo().then(function(response) {
response.forEach(function(item){
myMap.set( item.recordId.substring(0,15), item.tabId);
});
}
component.set('c.var_map', myMap );
},
onChatEnded: function(cmp, evt, helper) {
let myMap = cmp.get('c.var_map');
var recordId = evt.getParam( "recordId" );
console.log( "recordId:" + recordId );
let idTab = myMap.get( recordId );
var workspaceAPI = cmp.find( "workspace" );
workspaceAPI.closeTab( { tabId: idTab} );
}
BUT REMEMBER you need repopulate your VAR_MAP when a new tab was open.
Can you give an example of how to work this into the current controller. I am having the same issue as above. It is grabbing the wrong tab when multiple are open.