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 

NameTypeDescription
recordIdStringThe ID of the record for the Messaging session.
messageTypeStringThe message component type to place in the service rep’s text box. For example, StaticContentMessage. See Message Types and Message Format Types.
nameOrIdStringThe name or ID of the messaging component to place in the service rep’s text box.
textStringOptional. The message to the end user. For example: This is a sample message.
setAtCursorBooleanOptional. 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}