Through the API methods any CTLive integrator can send text messages, link or multimedia content, leave an active chat, terminate a chat for all participant.
Below we list all the available APIs related with a code example. The APIs are related to an istance of active chat, for example the same object returned by calling the joinContact method.
Send a Text message
ctlive_contact.sendMessage("Hello world!").then( function (msgid) { console.log("Message sent", msgid); } );
Send a Multimedia message
/* Send a DOCUMENT type message (doc/docx/xls/xlsx/ppt/pptx/pdf) content object can be one of the following type: { "img":"<base64_img>", "caption":"<captionToSend>", "fileName": "<file_name>", "documentType":"<document_type>" (file extension JPG, JPEG, PNG.) } { "document":"<base64_doc>", "caption":"<captionToSend>", "fileName": "<file_name>", "documentType":"<document_type>" (file extension PDF, DOC(X), PPT(X), XLS(X).) } */ ctlive_contact.SendMultimediaMessage( "DOCUMENT", content).then( function (data) { console.log("Document message sent", data); } ); // Send an IMAGE type message (png/jpg/jpeg) ctlive_contact.SendMultimediaMessage( "IMAGE", content).then( function (data) { console.log("Image message sent", data); } );
Get a Multimedia message
ctlive_contact.on("multimediaMessage", function (event) { // Get multiemdia message content ctlive_contact.GetMultimediaMessageInActiveChat( ctlive_contact.contact.id, event.id).then( function (data) { console.log("multimedia message retrieved", data); } ); });
Send an Hyperlink message
ctlive_contact.SendLink("https://www.enghouseinteractive.it/").then ( function (msgid) { console.log("Hyperlink message sent", msgid); } );
Notifies “is writing” agent status
// The agent has started writing ctlive_contact.isWriting(true); // The agent has stopped writing ctlive_contact.isWriting(false);
Terminate an active chat
// End a chat and disconnect all participant. // The instance of a CTLive active chat is specified as input parameter LIVECHATSDK.LIVECHAT.endContact(ctlive_contact);
Leave an active chat
LIVECHATSDK.LIVECHAT.leave("CHAT_eaa2e7c0-9c26-40db-b720-d777ab68078d");