Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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

Code Block
breakoutModewide
languagejs
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
            }
          }
        }
      }
    );
  }
);

...

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

full-width
Code Block
breakoutMode
languagejs
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.id: unique message ID
        data.chatTranscripts[i].transcript.messages[z].data.content.text : the content of the message
        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;
    };
  }
}

...

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

breakoutMode
Code Block
widelanguagejs
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);
    }
  }
);

...

The attached file can also ben downloaded by simply using an HTML anchor tag that refers to the ‘downloadTranscriptDocument’ service offered by CTLive. You have to specify in the service’s URL the unique document ID and a valid CTLive authenticatd token passed by the ‘ctlivetoken’ querystring param.

full-width
Code Block
breakoutMode
languagehtml
<a inherit;" target="_blank" href="/livechat/default/downloadTranscriptDocument/ff982682-753e-44c4-bd0f-28d0337a9ad1?ctlivetoken=3393e6e9-0b31-4a5e-b101-9809fc9035f3">
  <span class="fa fa-download fa-1x" style="cursor: pointer;"></span>
</a>

...