@cognigy/rest-api-client
Version:
Cognigy REST-Client
87 lines • 3.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CXONE_SEND_COPILOT_STATUS = void 0;
/* Custom modules */
const createNodeDescriptor_1 = require("../../../createNodeDescriptor");
/**
* Node name: 'cxOneSendCopilotStatus'
*
* Purpose:
* - Sends workflow completion status (success or failure) to CXone Copilot
*/
exports.CXONE_SEND_COPILOT_STATUS = (0, createNodeDescriptor_1.createNodeDescriptor)({
type: "cxOneSendCopilotStatus",
defaultLabel: "Send Status to CXone Copilot",
summary: "UI__NODE_EDITOR__CXONE_SEND_COPILOT_STATUS__SUMMARY",
preview: {
key: "status",
type: "text"
},
fields: [
{
key: "status",
label: "UI__NODE_EDITOR__CXONE_SEND_COPILOT_STATUS__FIELDS__STATUS__LABEL",
type: "select",
description: "UI__NODE_EDITOR__CXONE_SEND_COPILOT_STATUS__FIELDS__STATUS__DESCRIPTION",
params: {
options: [
{
label: "UI__NODE_EDITOR__CXONE_SEND_COPILOT_STATUS__FIELDS__STATUS__OPTIONS__COMPLETE__LABEL",
value: "Complete"
},
{
label: "UI__NODE_EDITOR__CXONE_SEND_COPILOT_STATUS__FIELDS__STATUS__OPTIONS__FAILED__LABEL",
value: "Failed"
},
],
required: true,
},
defaultValue: "Complete",
},
{
key: "data",
label: "UI__NODE_EDITOR__CXONE_SEND_COPILOT_STATUS__FIELDS__DATA__LABEL",
type: "json",
description: "UI__NODE_EDITOR__CXONE_SEND_COPILOT_STATUS__FIELDS__DATA__DESCRIPTION",
},
],
form: [
{ type: "field", key: "status" },
{ type: "field", key: "data" },
],
appearance: {
color: "#3694FD",
},
tags: ["nice", "cxone"],
function: async ({ cognigy, config }) => {
var _a, _b, _c, _d, _e, _f, _g;
const { api, input } = cognigy;
const { status, data } = config;
if (!status || (status !== "Complete" && status !== "Failed")) {
(_a = api.output) === null || _a === void 0 ? void 0 : _a.call(api, "cxOneSendCopilotStatus Error: Missing or invalid status", { error: "Missing or invalid status" });
throw new Error("cxOneSendCopilotStatus: Validation: Missing or invalid status");
}
try {
const metrics = {
sessionId: input.sessionId,
channel: input.channel,
language: input.language,
completionTimestamp: Date.now()
};
const outputData = Object.assign({ status,
metrics }, (data != null &&
Object.keys(data).length > 0 && { data }));
(_b = api.output) === null || _b === void 0 ? void 0 : _b.call(api, "", outputData);
(_c = api.addToContext) === null || _c === void 0 ? void 0 : _c.call(api, "CXoneSendCopilotStatus", outputData, "simple");
(_d = api.log) === null || _d === void 0 ? void 0 : _d.call(api, "debug", `cxOneSendCopilotStatus: Status sent to CXone Copilot: ${status}`);
}
catch (error) {
const errorMessage = error.message || "Unknown error";
(_e = api.log) === null || _e === void 0 ? void 0 : _e.call(api, "error", `cxOneSendCopilotStatus: Error sending status '${status}'; error: ${errorMessage}`);
(_f = api.addToContext) === null || _f === void 0 ? void 0 : _f.call(api, "CXoneSendCopilotStatus", { status: "error", error: errorMessage }, "simple");
(_g = api.output) === null || _g === void 0 ? void 0 : _g.call(api, "Something is not working. Please retry.", { error: errorMessage });
throw error;
}
},
});
//# sourceMappingURL=cxOneSendCopilotStatus.js.map