sendMessagingComponent() for LWC for Lightning Experience

Sends a new message with a specified messaging component on behalf of the service rep. You can also use this method to send a text message. This method works only in Lightning console apps.

Arguments 

NameTypeDescription
recordIdStringThe ID of the record for the Messaging session.
messageTypeStringThe message component type to send on behalf of the service rep. For example, StaticContentMessage. See Message Types and Message Format Types.
nameOrIdStringThe name or ID of the messaging component to send on behalf of the service rep.
textStringOptional. The message to the end user. For example: This is a sample message.

Response 

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

Sample Code 

This example sends a static content message on behalf of the service rep.

1import { LightningElement, api } from 'lwc';
2import { sendMessagingComponent } 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}