updating proactive agent to support both copilot and messenger front-ends

This commit is contained in:
2025-08-21 22:22:47 -05:00
parent 403c73fc83
commit 39d03d4b3a
6 changed files with 655 additions and 37 deletions

View File

@@ -1,10 +1,52 @@
/*
Proxy Script for CoPilot integration with IVAS
*/
console.log({ script: "copilot", body: req.body});
console.log({ script: "copilot", body: req.body });
let copilot_settings = copilot_settings;
if (req.headers.authorization) {
try {
console.log("decoding authorization ...");
let bearer = req.headers.authorization.replace("Bearer ", "");
req.body.event.metadata = {
...req.body.event.metadata,
...{
bearer: jwt.decode(bearer),
},
};
console.log("applying copilot overrides ...");
const found = copilot_overrides.find(
(element) =>
element.v_username === req.body.event.metadata.bearer.v_username
);
if (found) {
console.log("found copilot overrides for user: " + found.v_username);
copilot_settings = {
...copilot_settings,
...found.copilot_settings,
};
req.params = { ...req.params, ...found.req.params };
req.body.event.params = {
...req.body.event.params,
...found.event.params,
};
} else {
console.log(
"no copilot overrides found for user: " +
req.body.event.metadata.bearer.v_username
);
}
} catch (e) {
console.log("Error decoding authorization:");
console.log(e);
}
}
req.body.event.metadata = _.merge(req.body.event.metadata, {
channel: copilot_settings.channel
channel: copilot_settings.channel,
});
const messengerUrl = `${copilot_settings.nlu.apiBaseURL}ProxyScript/run/${req.params.workspaceId}/${req.params.branch}/${copilot_settings.messengerRouteName}`;
@@ -14,44 +56,16 @@ const messengerUrl = `${copilot_settings.nlu.apiBaseURL}ProxyScript/run/${req.pa
url: messengerUrl,
method: "post",
data: req.body,
// headers: {
// Authorization: `Bearer ${copilot_settings.ops.token}`
// }
// headers: {
// Authorization: `Bearer ${copilot_settings.ops.token}`
// }
});
res.send(recognizedData);
} catch (error) {
console.log(error.message);
res.send({
answers: ['Something went wrong. Please try again.'],
outputs: {}
answers: ["Something went wrong. Please try again."],
outputs: {},
});
}
})();/*
Proxy Script for CoPilot integration with IVAS
*/
console.log({ script: "copilot", body: req.body});
req.body.event.metadata = _.merge(req.body.event.metadata, {
channel: copilot_settings.channel
});
const messengerUrl = `${copilot_settings.nlu.apiBaseURL}ProxyScript/run/${req.params.workspaceId}/${req.params.branch}/${copilot_settings.messengerRouteName}`;
(async () => {
try {
const { data: recognizedData } = await axios({
url: messengerUrl,
method: "post",
data: req.body,
// headers: {
// Authorization: `Bearer ${copilot_settings.ops.token}`
// }
});
res.send(recognizedData);
} catch (error) {
console.log(error.message);
res.send({
answers: ['Something went wrong. Please try again.'],
outputs: {}
});
}
})();
})();