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
Code Block | ||
---|---|---|
| ||
ctlive_contact.sendMessage("Hello world!").then( function (msgid) { console.log("Message sent", msgid); } ); |
Send a Multimedia message
Code Block | ||
---|---|---|
| ||
//* Send a DOCUMENTmultimedia type message 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), (doc/docx/xls/xlsx/ppt/pptx/pdf)PPT(X), XLS(X).) } */ ctlive_contact.SendMultimediaMessage( "CHAT_eaa2e7c0-9c26-40db-b720-d777ab68078d", "DOCUMENT", Base64Contentcontent).then ( function (msgiddata) { console.log("Document message sent", msgiddata); } ); // Send an IMAGE type message (png/jpg/jpeg) ctlive_contact.SendMultimediaMessage( "IMAGE", content).then( function (data) { console.log("CHAT_eaa2e7c0-9c26-40db-b720-d777ab68078d", "IMAGE", Base64ContentImage message sent", data); } ); |
Get a Multimedia message
Code Block | ||
---|---|---|
| ||
ctlive_contact.on("multimediaMessage",
function (event) {
// Get multiemdia message content: call contact API GetMultimediaMessageInActiveChat(<chat_id>,<message_id>)
ctlive_contact.GetMultimediaMessageInActiveChat( ctlive_contact.contact.id, event.id).then(
function (multimediaMessageObj) {
console.log("multimedia message retrieved", multimediaMessageObj);
/*
Example of multimedia object retrieved:
{
"result": true,
"data": {
"chatID": "CHAT_DEFAULT_96387da2-3a5f-4d60-a30d-729e0e5706d8",
"messageID": "a0458869-9747-4ab1-bd76-8727cf483685",
"messageType": "IMAGE",
"domain": "DEFAULT",
"format": "fullsize",
"content": {
"img": "/9j/4AAQSkZJRgABA....",
"caption": "myImage",
"fileName": "45971097-illustrazione-di-happy-emoticon-dà-pollice-in-su-isolato-su-sfondo-bianco.jpg",
"documentType": "jpg",
"user": {
"id": "USER_gverde1@acd.enghouse.com",
"nickname": "Gabriele Verde",
"isAgent": true,
"beginTime": 1584722203945,
"endTime": "",
"isOnline": true,
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36",
"firstUri": "http://localhost:3003/AD/AD.html",
"firstTitle": "AgentDesktop - Enghouse Interactive",
"channel": "web",
"firstIP": "::ffff:127.0.0.1"
}
}
},
"error": null
}
{
"result": true,
"data": {
"chatID": "CHAT_DEFAULT_96387da2-3a5f-4d60-a30d-729e0e5706d8",
"messageID": "9c45e6ce-e48f-4d55-beb3-6141ee2b1339",
"messageType": "DOCUMENT",
"domain": "DEFAULT",
"format": "fullsize",
"content": {
"document": "JVBERi0xLjMNJeL.....",
"caption": "myDoc",
"fileName": "WhatsApp - omnichannel API quick guide.pdf",
"documentType": "pdf",
"user": {
"id": "USER_gverde1@acd.enghouse.com",
"nickname": "Gabriele Verde",
"isAgent": true,
"beginTime": 1584722203945,
"endTime": "",
"isOnline": true,
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36",
"firstUri": "http://localhost:3003/AD/AD.html",
"firstTitle": "AgentDesktop - Enghouse Interactive",
"channel": "web",
"firstIP": "::ffff:127.0.0.1"
}
}
},
"error": null
}
*/
}
);
}); |
Send an Hyperlink message
Code Block | ||
---|---|---|
| ||
ctlive_contact.SendLink("https://www.enghouseinteractive.it/").then ( function (msgid) { console.log("ImageHyperlink message sent", msgid); } ); |
Notifies “is writing” agent status
Code Block | ||
---|---|---|
| ||
// The agent has started writing
ctlive_contact.isWriting(true);
// The agent has stopped writing
ctlive_contact.isWriting(false); |
Terminate an active chat
Code Block | ||
---|---|---|
| ||
// 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
Code Block | ||
---|---|---|
| ||
LIVECHATSDK.LIVECHAT.leave("CHAT_eaa2e7c0-9c26-40db-b720-d777ab68078d"); |