Newer Version Available

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

setMessagingComponent() for LWC for Lightning Experience

Inserts a specified messaging component into the service rep’s text box. You can also use this method to insert text into the service rep’s text box. This method works only in Lightning console apps.

Arguments

Name Type Description
recordId String The ID of the record for the Messaging session.
messageType String The message component type to place in the service rep’s text box. For example, StaticContentMessage. See Message Types and Message Format Types.
nameOrId String The name or ID of the messaging component to place in the service rep’s text box.
text String Optional. The message to the end user. For example: This is a sample message.
setAtCursor Boolean Optional. Indicates whether to insert the message at the current cursor location. If false, the message overwrites any existing text. Default value is false.

Response

Returns a Promise. Success resolves to true. The Promise is rejected if there's an error.

Sample Code

This example inserts a static content message into the service rep’s text box.

1import { LightningElement, api } from 'lwc';
2import { setMessagingComponent } from 'lightning/conversationToolkitApi';
3
4export default class MyComponent extends LightningElement {
5    @api recordId;
6
7    async handleButtonClick(event) {
8        const result = await setMessagingComponent(
9            this.recordId, {
10                messageType: "StaticContentMessage",
11                nameOrId: "1mdxx0000000001AAA"
12            });
13        console.log(result);
14    }
15}