Adding 'IVA Wakeup' script used for Bot Tango example
This commit is contained in:
68
IVA-Wakeup/global/gvf_ConversationHistory.js
Normal file
68
IVA-Wakeup/global/gvf_ConversationHistory.js
Normal file
@@ -0,0 +1,68 @@
|
||||
return {
|
||||
async fetchConversationHistory(conversationId, limit) {
|
||||
|
||||
let datahistory = await db.collection("analytics_transactions").aggregate([
|
||||
{
|
||||
$match: {
|
||||
$and: [
|
||||
{ "conversationId": conversationId },
|
||||
{ "outputs.datacollect": true }
|
||||
]
|
||||
}
|
||||
}
|
||||
]).toArray();
|
||||
|
||||
console.log('10 line');
|
||||
let lastElement = datahistory[datahistory.length - 1];
|
||||
console.log(lastElement?.metadata?.actionType);
|
||||
let messages = [];
|
||||
const tx_msg = (direction, text, sentTime) => {
|
||||
return {
|
||||
conversationId: conversationId,
|
||||
direction,
|
||||
text,
|
||||
dateSent: new Date(sentTime).toISOString(),
|
||||
};
|
||||
};
|
||||
let counts = { agent: 0, ivas: 0 };
|
||||
let agentName;
|
||||
let is_async = null;
|
||||
for (let msg of datahistory) {
|
||||
if (msg?.answers.length) {
|
||||
if (msg?.input !== "") {
|
||||
messages.push(tx_msg("ToAgent", msg?.input, (msg?.metadata?.createdAt ?? Date.now())));
|
||||
}
|
||||
counts.ivas++;
|
||||
for (let i = 0; i < msg?.answers.length; i++) {
|
||||
let answer = msg.answers[i];
|
||||
if (typeof answer !== "string") {
|
||||
answer = JSON.stringify(answer ?? null);
|
||||
}
|
||||
messages.push(tx_msg("ToCustomer", answer, (msg?.metadata?.createdAt ?? Date.now()) + 50 + i));
|
||||
counts.ivas++;
|
||||
}
|
||||
}
|
||||
if (limit > 0 && messages.length >= limit) break;
|
||||
}
|
||||
|
||||
const summary = {
|
||||
conversationId: conversationId,
|
||||
steps: []
|
||||
};
|
||||
|
||||
|
||||
messages.forEach(msg => {
|
||||
summary.steps.push({
|
||||
who: msg.direction === "ToAgent" ? "Customer" : "System",
|
||||
text: msg.text,
|
||||
time: new Date(msg.dateSent).toLocaleString()
|
||||
});
|
||||
});
|
||||
let history = ``;
|
||||
summary.steps.forEach((step, index) => {
|
||||
history += `<strong>${step.who}:</strong> ${step.text}<br/>`;
|
||||
});
|
||||
history+= `<strong>ActionType:</strong> ${lastElement?.metadata?.actionType}`
|
||||
return history;
|
||||
}
|
||||
};
|
||||
39
IVA-Wakeup/global/gvf_handleIVAWakeupEvent.js
Normal file
39
IVA-Wakeup/global/gvf_handleIVAWakeupEvent.js
Normal file
@@ -0,0 +1,39 @@
|
||||
return {
|
||||
async handleIVAWakeupEvent(event, req, session, settings, redis, smStr, channel, eventPayload) {
|
||||
try {
|
||||
const ivaWakeupText = `<p><br data-mce-bogus="1"></p><p><br data-mce-bogus="1"></p><p>IVA-Wakeup</p>`;
|
||||
|
||||
if (event.text === ivaWakeupText) {
|
||||
const nluSettings = settings.nlu;
|
||||
|
||||
const result = await axios.post(
|
||||
`${nluSettings.apiBaseURL}Model/run/${req.params.workspaceId}/${req.params.branch}/${nluSettings.modelName}`,
|
||||
{
|
||||
input: "CaseSetup",
|
||||
conversationId: session.conversationId,
|
||||
settings: nluSettings.settings,
|
||||
sessionId: event.sessionId
|
||||
}
|
||||
);
|
||||
|
||||
eventPayload.options = result?.data?.options;
|
||||
eventPayload.metadata = {
|
||||
outputs: result.data?.outputs,
|
||||
channel: channel
|
||||
};
|
||||
eventPayload.input = result.data.answers[0];
|
||||
eventPayload.metadata.outputs.disableMessengerInput = true;
|
||||
eventPayload.metadata.outputs.datacollect = true;
|
||||
|
||||
await redis.hSet(smStr, {
|
||||
formFlow: "true",
|
||||
datacollect: "true",
|
||||
sentdata: "false"
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.info("Error with IVA-Wakeup");
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user