lightning__conversationEndUserMessage

Messaging event triggered when the customer sends a new message. In Enhanced Messaging channels, this event is triggered only for text messages. This event is not triggered for messages with files or rich content. To work with Enhanced Messaging channels, the session must be active and the Enhanced Conversation Component must be visible on the page.

Response 

NameTypeDescription
recordIdStringThe ID of the work record that’s associated with the current conversation.
contentStringThe message sent by the customer.
nameStringThe name of the user who sent the message. This name matches the username displayed in the conversation log.
timestampDate/TimeThe date and time the message was received.

LWC Sample Code 

To listen to the lightning__conversationEndUserMessage 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 ConversationEndUserChannel from '@salesforce/messageChannel/lightning__conversationEndUserMessage';
11
12export default class ConversationEndUserExample 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                ConversationEndUserChannel,
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__conversationEndUserMessage" scope="APPLICATION" 
2                          onMessage="{!c.onConversationEndUserMessage}" />

Controller code:

1({
2    onConversationEndUserMessage: function(cmp, evt, helper) {
3        var recordId = evt.getParam('recordId');
4        var content = evt.getParam('content');
5        var name = evt.getParam('name');
6        var timestamp = evt.getParam('timestamp');
7
8        console.log("recordId:" + recordId + " content:" + content + " name:" + name + " timestamp:" + timestamp);
9    }
10})