Updating Context Service example
This commit is contained in:
parent
0650f12bd5
commit
440b84edfc
15
CA_ContextService/README.md
Normal file
15
CA_ContextService/README.md
Normal file
@ -0,0 +1,15 @@
|
||||
# Interaction Notification API
|
||||
|
||||
Interaction Notification API is used to push Call Pops into Channel Automation.
|
||||
|
||||
## Prerequisits
|
||||
|
||||
1. Install and configure the _Channel Automation Interface_ Package from Resource Center -> Hub.
|
||||
|
||||
## Studio Dependencies
|
||||
|
||||
[CA_ContextService](./_studio_dependencies/Global%20Variable/CA_ContextService.js) Global Variable Function
|
||||
|
||||
## Example Usage
|
||||
|
||||
Conversation Flow Code Block [postContextHistory](./snippets/postContactHistory.js)
|
||||
@ -0,0 +1,60 @@
|
||||
function toCustomISOString(date) {
|
||||
// Ensure input is a Date object
|
||||
if (!(date instanceof Date)) throw new Error("Input must be a Date object");
|
||||
// Get ISO string, then trim to 3 ms digits and add 'Z'
|
||||
return date.toISOString().replace(/\d{3}Z$/, match => match.slice(0, 3) + 'Z');
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
/**
|
||||
*
|
||||
* @param {String} customerId Customer identifier (i.e. 10000050)
|
||||
* @param {[String]} notes Array on notes
|
||||
* @param {Date} startTime Start time of the interaction
|
||||
* @param {Date} endTime End time of the interaction
|
||||
* @param {String} external URL
|
||||
*/
|
||||
post(customerId, notes, startTime, endTime, url) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
const OIDC = await CAInterface().getOIDC();
|
||||
let config = CAInterface().settings().url.CA;
|
||||
const contextServiceURL = `https://${config.base}/context-service/${config.tenant}/contexts`;
|
||||
|
||||
const { data } = await CAInterface().axios("contextService", {
|
||||
method: "post",
|
||||
url: contextServiceURL,
|
||||
headers: {
|
||||
"Content-Type": "application/ld+json",
|
||||
Authorization: `OIDC_id_token ${OIDC.access_token}`,
|
||||
},
|
||||
data: {
|
||||
"@type": "vctx:Context",
|
||||
"vctx:contacts": [
|
||||
{
|
||||
"@type": "vctc:ExternalContact",
|
||||
"vctc:subtype": "iva",
|
||||
"vctc:direction": "vctc:inbound",
|
||||
"vctc:startTime": toCustomISOString(startTime),
|
||||
"vctc:endTime": toCustomISOString(endTime),
|
||||
"vctc:externalUrl": url,
|
||||
"vctc:notes": notes,
|
||||
},
|
||||
],
|
||||
"vctx:customer": {
|
||||
"@type": "vcust:Customer",
|
||||
"vcust:identifier": `${customerId}`,
|
||||
},
|
||||
},
|
||||
});
|
||||
console.log({
|
||||
contextServiceData: data,
|
||||
});
|
||||
resolve();
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
32
CA_ContextService/snippets/postContactHistory.js
Normal file
32
CA_ContextService/snippets/postContactHistory.js
Normal file
@ -0,0 +1,32 @@
|
||||
(async () => {
|
||||
const customerId = conversationData.customer?.customerId ?? "CC1000778";
|
||||
const history = await CAInterface().getConversationHistory(
|
||||
conversationData.id,
|
||||
50
|
||||
);
|
||||
let notes = ["No History Found"];
|
||||
let startTime = new Date();
|
||||
if (history.messages.length > 0) {
|
||||
notes = history.messages
|
||||
.map((message) => `[${message.dateSent}] ${message.direction} : ${message.text}`)
|
||||
.filter((text) => text.trim() !== "");
|
||||
startTime = new Date(history.messages[0]?.dateSent || startTime);
|
||||
}
|
||||
const endTime = new Date();
|
||||
const url = `https://ivastudio.verint.live/organizations/${recognizedObject.classificationResults.organizationId}/workspaces/${conversationData.workspaceId}/conversation/${conversationData.id}`;
|
||||
CA_ContextService().post(customerId, notes, startTime, endTime, url);
|
||||
})()
|
||||
.catch((error) => {
|
||||
console.log(error.message);
|
||||
recognizedObject.answers.push("");
|
||||
recognizedObject.errorInfo = {
|
||||
...recognizedObject.errorInfo,
|
||||
label: {
|
||||
data: error.toJSON ? error.toJSON() : {},
|
||||
message: error.message,
|
||||
},
|
||||
};
|
||||
})
|
||||
.finally(() => {
|
||||
next();
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user