Newer Version Available
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.
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}