lightning__conversationAgentSend

Messaging event triggered when an agent sends a message through the Salesforce console. This method intercepts the message before it’s sent to the chat visitor. 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 

NameTypeDescription
recordIdStringThe ID of the work record that’s associated with the current conversation.
contentStringThe text of the message in the conversation log.
nameStringThe name of the agent who is attempting to send the message. This name matches the agent name displayed in the conversation log.
timestampDate/TimeThe date and time that the agent attempted to send the message.

LWC Sample Code 

To listen to the lightning__conversationAgentSend 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 ConversationAgentSendChannel from '@salesforce/messageChannel/lightning__conversationAgentSend';
11
12export default class ConversationAgentSendExample 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                ConversationAgentSendChannel,
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__conversationAgentSend" scope="APPLICATION" 
2                          onMessage="{!c.onConversationAgentSend}" />

Controller code:

1({
2    onConversationAgentSend: 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})