updating proactive agent to support both copilot and messenger front-ends
This commit is contained in:
@@ -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: {}
|
||||
});
|
||||
}
|
||||
})();
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user