Newer Version Available

This content describes an older version of this product. View Latest

lightning__conversationEnded

Messaging event triggered when an active chat ends or an agent leaves a chat conference. This event is also triggered when using Enhanced Messaging channels. To work with Enhanced Messaging channels, the session must be active and the Enhanced Conversation Component must be visible on the page.

Response

Name Type Description
recordId String The ID of the work record that’s associated with the current chat.

LWC Sample Code

To listen to the lightning__conversationEnded event, import the Lightning Message Service features from lightning/messageService and pass the event to the subscribe() method.

1import { LightningElement, wire } from 'lwc';
2
3import {
4    subscribe,
5    unsubscribe,
6    APPLICATION_SCOPE,
7    MessageContext
8} from 'lightning/messageService';
9
10import ConversationEndedChannel from '@salesforce/messageChannel/lightning__conversationEnded';
11
12export default class ConversationEndedExample extends LightningElement {
13    subscription = null;
14    recordId;
15
16    // To pass scope, you must get a message context.
17    @wire(MessageContext)
18    messageContext;
19
20    // Standard lifecycle hook used to subscribe to the message channel
21    connectedCallback() {
22        this.subscribeToMessageChannel();
23    }
24
25    // Pass scope to the subscribe() method.
26    subscribeToMessageChannel() {
27        if (!this.subscription) {
28            this.subscription = subscribe(
29                this.messageContext,
30                ConversationEndedChannel,
31                (message) => this.handleMessage(message),
32                { scope: APPLICATION_SCOPE }
33            );
34        }
35    }
36
37    // Handler for message received by component
38    handleMessage(message) {
39        this.recordId = message.recordId;
40    }
41}

Aura Components Sample Code

Component code:

1<lightning:messageChannel type="lightning__conversationEnded" scope="APPLICATION" 
2                          onMessage="{!c.onConversationEndedEvent}" />

Controller code:

1({
2    onConversationEndedEvent: function(cmp, evt, helper) {
3        var conversation = cmp.find("conversationKit");
4        var recordId = evt.getParam("recordId");
5
6        console.log("recordId:" + recordId);
7    }
8})