Versions Compared

Key

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

The contactJoin API allows you to join as an a participant to an existing chat room usually started by the customer on the corporate web site. Chat room ID and a nickname must be specified as input parameters.

...

  • message : event that notifies the receiving of a text message from a participant

  • messageReceived : event that notifies that a participant has received the message

  • messageSeen : event that notifies that a participant has read/seen the message

  • multimediaMessage : a multimedia message has been received. There are two available types of multimedia message: DOCUMENT (doc, docx, ppt, pptx, xls, xlsx, pdf) or IMAGE (PNG, JPG, JPEG). The multimedia content is encoded in Base64 format.

  • link : an hyperlink has been received

  • isWriting : event that notifies that one participant started/stopped writing

  • contactEnded : the chat has just ended and all participants have been disconnected. The chat room chat ID is no longer active.

  • multimediaMessageStored : event that notifies that a large multimedia files has been resized and stored in CTLive MondoDB database.

Code Block
languagejs
LIVECHATSDK.LIVECHAT.joinContact("CHAT_eaa2e7c0-9c26-40db-b720-d777ab68078d", "John Doe").then(
  function (contact) {
    console.log("[CTLive] Contact JOINED", contact);
    
    // Store the contact instance in a custom Hashmap
    MY_ACTIVE_CHAT[contact.contact.id] = contact;
    
    // Bind 'message' event custom callback
    contact.on("message", 
      function (event) {
        var DOMObj = null;
        console.log("[CTLIVE] On [message] event");
        console.log("Nickname......" + event.content.user.nickname);
        console.log("Text.........." + event.content.text);
        console.log("Is Agent......" + event.content.user.isAgent);
        console.log("Msg ID........" + event.id);
      }
    );

    // Bind 'message' event custom callback
    contact.on("messageReceived", 
      function (event) {
        console.log("[CTLIVE] On [messageReceived] event");
        console.log("Msg ID........" + event.messageID);
      }
    );

    // Bind 'messageSeen' event custom callback
    contact.on("messageSeen", 
      function (event) {
        console.log("[CTLIVE] On [messageSeen] event");
        console.log("Msg ID........" + event.messageID);
      }
    );

    // Bind 'multimediaMessage' event custom callback
    contact.on("multimediaMessage", 
      function (event) {
        console.log("[CTLIVE] On [multimediaMessage] event");
        if ( event.messageType === "IMAGE" ) {
          console.log("Caption............" + event.content.caption);
          console.log("Is Agent..........." + event.content.user.isAgent);
          console.log("User Nickname......" + event.content.user.nickname);
          console.log("User ID............" + event.content.user.id);
          console.log("Chat ID............" + contact.contact.id);
          console.log("Msg ID............." + event.id)
          console.log("Content (Base64)..." + event.content.img);
        }

        if ( event.messageType === "DOCUMENT" ) {
          console.log("File Extension.....", event.content.documentType);
          // PDF, DOC; DOCX, PPT, PPTX, XLS, XLSX
          console.log("File Caption.......", event.content.caption);
          console.log("Is Agent..........." + event.content.user.isAgent);
          console.log("User Nickname......" + event.content.user.nickname);
          console.log("User ID............" + event.content.user.id);
          console.log("Chat ID............" + contact.contact.id);
          console.log("Msg ID............." + event.id)
          console.log("Content (Base64)..." + event.content.document);
        }
      }
    );

    // Bind 'link' event custom callback
    contact.on("link", 
      function (event) {
        console.log("[CTLIVE] On [link] event");
        console.log("URL................", event.content.url);
        console.log("Is Agent..........." + event.content.user.isAgent);
        console.log("User Nickname......" + event.content.user.nickname);
        console.log("User ID............" + event.content.user.id);
        console.log("Chat ID............" + contact.contact.id);
        console.log("Msg ID............." + event.id)
      }
    );

    // Bind 'isWriting' event custom callback
    contact.on("isWriting",
      function (event) {
        console.log("[CTLIVE] On [isWriting] event");
        console.log("Started/Stopped writing........", event.bwrite);
      }
    );

    // Bind 'contactEnded' event custom callback
    contact.on("contactEnded",
      function (event) {
        console.log("[CTLIVE] On [contactEnded] event");
      }
    );

    // Bind 'userAdded' event custom callback
    // A new participant has benn added in the chat room
    contact.on("userAdded",
      function (event) {
        console.log("[CTLIVE] On [userAdded] event");
      }
    );
  }
);

...