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

Name Type Description
recordId String The ID of the record for the Messaging session.
messageType String The message component type to send on behalf of the service rep. For example, StaticContentMessage. See Message Types and Message Format Types.
nameOrId String The name or ID of the messaging component to send on behalf of the service rep.
text String Optional. 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.

import { LightningElement, api } from 'lwc';
import { sendMessagingComponent } from 'lightning/conversationToolkitApi';

export default class MyComponent extends LightningElement {
    @api recordId;

    async handleButtonClick(event) {
        const result = await setMessagingComponent(
            this.recordId, {
                messageType: "StaticContentMessage",
                nameOrId: "1mdxx0000000001AAA"
            });
        console.log(result);
    }
}