Newer Version Available
sendMessage() for Lightning Experience
Sends a new chat message from the agent to a chat with a specific chat key. This method works only in
Lightning console apps.
Arguments
| Name | Type | Description |
|---|---|---|
| argumentObj | Object | An object containing all the arguments to be passed into this method. |
argumentObj
| Name | Type | Description |
|---|---|---|
| recordId | String | The ID of the chat that you want to end. |
| message | Object | An object containing the data to send in the message. |
message
| Name | Type | Description |
|---|---|---|
| text | String | The text to be sent in the message. |
Sample Code
This example sends a message to the visitor and logs the result.
Component Code:
1<aura:component implements="flexipage:availableForAllPageTypes" access="global" description="Conversation toolkit api sample">
2 <aura:attribute name="recordId" type="String" />
3 <lightning:conversationToolkitAPI aura:id="conversationKit" />
4 <ui:button label="sendMessage" press="{!c.sendMessage}" />
5</aura:component>Controller Code:
1({
2 sendMessage: function(cmp, evt, helper) {
3 var conversationKit = cmp.find("conversationKit");
4 var recordId = cmp.get("v.recordId");
5 conversationKit.sendMessage({
6 recordId: recordId,
7 message: {
8 text:"Hi, this was sent using the sendMessage API!"
9 }
10 })
11 .then(function(result){
12 if (result) {
13 console.log("Successfully sent message");
14 } else {
15 console.log("Failed to send message");
16 }
17 });
18 }
19})Response
Returns a Promise. Success resolves to true. The Promise is rejected if there's an error.