getChatLog() for Lightning Experience

Returns the chat log of an Enhanced Messaging chat associated with a specific recordId. 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 work associated with the current chat.

Sample Code

This example retrieves the chat log for the given chat, logs the result, and if successful, saves the result to a variable.

Component Code:

<aura:component implements="flexipage:availableForAllPageTypes" access="global" description="Conversation toolkit api sample">
  <aura:attribute name="recordId" type="String" />
  <aura:attribute name="chatLog" type="Object" />
  <lightning:conversationToolkitAPI aura:id="conversationKit" />
  <ui:button label="getChatLog" press="{!c.getChatLog}" />
</aura:component>
Controller Code:
({
    getChatLog: function(cmp, evt, helper) {
        var conversationKit = cmp.find("conversationKit");
        var recordId = cmp.get("v.recordId");
        conversationKit.getChatLog({
            recordId: recordId
        })
        .then(function(result){
            if (result) {
                    console.log("Successfully retrieved chat log");
                    cmp.set("v.chatLog", result);
                } else {
                    console.log("Failed to retrieve chat log");
                }
        });
    }
})

Response

Returns a Promise. Success resolves to a response object containing the messages. The Promise is rejected if there's an error.

Name Type Description
messages Array of message objects. An array of chat message objects containing all of the chat messages from the chat log.

message

The message object contains a single chat message from the chat log and the following properties:

Property Type Description
content String The text content of a message in the chat log.
name String The name of the user who sent the message in the chat log. This name appears exactly as it is displayed in the chat log.
type String The type of message that was received, such as Agent or Visitor.
timestamp Date/Time The date and time the chat message was received.