improved defensive coding and added proper dates to Notes
This commit is contained in:
parent
e50064a781
commit
74f6c2d471
@ -1,27 +1,34 @@
|
||||
// Test update
|
||||
(async () => {
|
||||
|
||||
try {
|
||||
console.log("Request: [" + JSON.stringify(req.body) + "]")
|
||||
console.log("Request: [" + JSON.stringify(req.body) + "]");
|
||||
|
||||
const conversationId = req.body.conversationId;
|
||||
const caseId = req.body.caseId;
|
||||
const conversationId = req.body.conversationId;
|
||||
const externalSettings = req.body.settings;
|
||||
const externalModelName = req.body.modelName;
|
||||
const modelName = externalModelName ? externalModelName : inferenceSettings_64f77978cbc0b66fc62838e4.nlu.modelName;
|
||||
|
||||
// with Email to Case - the 1st/recent note is the body of the email
|
||||
var caseInstance = await CACaseInterface().getCase(caseId);
|
||||
console.log(`Case Note: [" + ${caseInstance.recentNotes[0].content}]`);
|
||||
var inboundEmailBody = ""
|
||||
if (caseInstance?.recentNotes?.length === 0)
|
||||
console.log(`No body found in case notes`);
|
||||
else
|
||||
inboundEmailBody = caseInstance.recentNotes[0].content;
|
||||
|
||||
const modelResponse = await axios({
|
||||
url: `${inferenceSettings_64f77978cbc0b66fc62838e4.nlu.apiBaseURL}Model/run/${req.params.workspaceId}/${req.params.branch}/${modelName}`,
|
||||
method: "post",
|
||||
data: {
|
||||
input: caseInstance.recentNotes[0].content,
|
||||
input: inboundEmailBody,
|
||||
conversationId: conversationId ? conversationId : undefined,
|
||||
settings: externalSettings ? externalSettings : inferenceSettings_64f77978cbc0b66fc62838e4.nlu.settings
|
||||
}
|
||||
});
|
||||
console.log("modelResponse.data: [" + JSON.stringify(modelResponse.data) + "]")
|
||||
|
||||
await redis.set(`${req.body?.conversationId}`, `${modelResponse?.data?.conversationId}`, {
|
||||
EX: 3600
|
||||
});
|
||||
@ -60,8 +67,8 @@
|
||||
// Create the ACK against the Notifying Case
|
||||
var notes = [
|
||||
{
|
||||
"createdBy": "IVA Studio conversationId:" + conversationId,
|
||||
"createdOn": "2022-06-21T13:38:12Z", // TODO: create timestamp
|
||||
"createdBy": "IVA conversationId:" + modelResponse?.data?.conversationId,
|
||||
"createdOn": `${(new Date().toISOString())}`,
|
||||
"content": "IVA Acknowledging receipt of email"
|
||||
|
||||
}
|
||||
@ -76,20 +83,31 @@
|
||||
|
||||
}
|
||||
];
|
||||
var body = response.answers[0];
|
||||
|
||||
var body;
|
||||
if (response.answers?.length === 0) {
|
||||
body = "Answer not available";
|
||||
} else {
|
||||
body = "";
|
||||
response.answers.forEach(answer => {
|
||||
body += "\n" + answer;
|
||||
})
|
||||
}
|
||||
|
||||
var entities = {
|
||||
"InboundEmail": {
|
||||
"@type": "vde:InboundEmail",
|
||||
"subject": "TODO: get this from the case",
|
||||
"subject": req.body.subject,
|
||||
"body": caseInstance.recentNotes[0].content
|
||||
},
|
||||
"EmailResponse": {
|
||||
"@type": "vde:EmailResponse",
|
||||
"subject": "LIMITATION: CA Case Send Email does not allow setting of subject by dynamic entities",
|
||||
"body": body
|
||||
"subject": "RE:" + req.body.subject,
|
||||
"bodyRichText": body,
|
||||
"conversationId" : `${modelResponse?.data?.conversationId}`
|
||||
}
|
||||
};
|
||||
// TODO: Replace Hardcoded Customer Reference when search API is working again
|
||||
var createCase = await CACaseInterface().createCase("vcs:IVAEmailAutoReply", "CC1000050", "IVA requesting send of email", notes, entities);
|
||||
|
||||
response.caseData = createCase;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user