Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

In CTLive, it is possible to request the transcript of the current chat or a chat already archived in the system.

Depending on the scenario you want to implement, the CTLive Agent SDK provides specific APIs/WS to retrieve the chat transcript.

Transcript of an active chat

During the engagement phase (joinContact) of a chat can ben useful to retreive all messages that were previously sent into the chat, before the agent start to writing. This includes interactions with automated systems such as BOTs and IVR logic.

The best moment to retreive the messages transcript is when the agent is joining a new chat, on the joinContact callback event.

LIVECHATSDK.LIVECHAT.joinContact(<chat_id>, <nickname>).then(
  function (contact) {
    LIVECHATSDK.LIVECHAT.getChatHistory(contact.contact.id, true).then(
      function(data) {
        if (data.messages.length > 0) {
          for (var i = 0; i < data.messages.length; i++) {
            // The data.messages[i].data.messageType can be:
            // TEXT, IMAGE, LINK, MENU, MENU_RESPONSE,
            // DOCUMENT, AUDIO, VIDEO, LOCATION, REPLY_TO_STORY,
            // STORY_MENTION, QUICK_REPLY, QUICK_REPLY_RESPONSE
            // (some message types are related to specific features offered
            // by some media channels like Meta, Istagram o DialogFlow)
            if ( data.messages[i].data.messageType === "TEXT" ) {
              /* Text Message...call your custom function that render the message
              using the following properties:
              data.messages[i].data.content.user.nickname: agent/customer nickname
              data.messages[i].data.content.text: the text of the message
              data.messages[i].data.content.user.isAgent: boolean to identify agent or customer
              data.messages[i].data.id: unique ID of the message
              data.messages[i].data.ts: timestamp
            }
          }
        }
      }
    );
  }
);

Transcript of an archived chat

For better customer management, it might be useful to access all interactions that a specific UserID has carried out across multiple chat sessions on different agents.

To this purpose, CTLive provides a service that allows retrieving all archived chats for a specific customer with an unique user ID.

The service can be called with a simple Ajax GET request. An authenticated token session must be provided.

jQuery.ajax(
  {
    type: "GET",
    async: true,
    url: "/livechat/" + <TENANT_NAME> + "/getChatTranscriptByUserID/" + <USER_ID>,
    dataType: "json",
    headers: {
      "ctlivetoken": <CTLIVE_VALID_SESSION_TOKEN>
  }
}

The response contains an array object with all the archived chat and messages.

for (var i = 0; i < data.chatTranscripts.length; i++ ) {
  // data.chatTranscripts[i] is an object that contains the following information:
  // data.chatTranscripts[i].transcript.messages: all the messages sent on a single archived chat
  // data.chatTranscripts[i].transcript.room: CTLive chat room ID

  // Get all messages:
  for (z = 0; z < data.chatTranscripts[i].transcript.messages.length; z++) {
    switch (data.chatTranscripts[i].transcript.messages[z].data.messageType) {
      case "TEXT":
        /* Text Message...call your custom function that render the message
        using the following properties:
        data.chatTranscripts[i].transcript.messages[z].data.content.text : all messages of the chat
        data.chatTranscripts[i].transcript.messages[z].data.content.user.isAgent: boolean to identify agent or customer
        data.chatTranscripts[i].transcript.messages[z].data.content.user.id : unique ID of the user
        data.chatTranscripts[i].transcript.messages[z].data.ts: timestamp of the message
        data.chatTranscripts[i].transcript.messages[z].data.deliveryErrorReason: if 'deliverySuccess' is false this propert contains the delivery error reason
        data.chatTranscripts[i].transcript.messages[z].data.deliverySuccess: boolean used to identify if the message war delivered successfully
        */
        break;
    };
  }
}

In the case of an attachment (image, document, audio and video message types) the message will not contain the binary content of the sent file but a reference to it. An additional web service provided by CTLive must be used to retrieve the file's content.

A two-step process can be useful for retrieving the binary content of an attachment to avoid overloading the page rendering time due to multiple requests to CTLive for large file content.

First of all you may display only a reference to the file based on an icon:

image-20241128-114039.png

When the user clicks on the icon the file content can ben request using the 'getMultimediaMessageByMessageID' web service and specifying the original document ID that is stored into the transcript message:

jQuery.ajax(
  {
    type: "GET",
    async: true,
    url: "/livechat/" + <TENANT_NAME> + "/getMultimediaMessageByMessageID/" + <IMAGE_ID>,
    dataType: "json",
    headers: {
      "ctlivetoken": <CTLIVE_VALID_SESSION_TOKEN>
    }
  }
).done(
  function (data) {
    if (data.result == true) {
      // File binary content is stored in Base64 format
      jQuery( "#imgChatHistory").attr("src", "data:image/jpeg;base64, " + data.message.messages[0].content.img);
    }
  }
);

  • No labels