UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

93 lines 4.68 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CXONE_SEND_SIGNAL = void 0; /* Custom modules */ const createNodeDescriptor_1 = require("../../../createNodeDescriptor"); const cxOneChannelUtils_1 = require("../libs/cxOneChannelUtils"); const prepareParams_1 = require("../libs/prepareParams"); /** * Node name: 'cxOneSendSignal' * * Purpose: * - Pass information from the Cognigy Session to CXone Studio Script * - Interrupts an active Studio Script with a command to do something else */ exports.CXONE_SEND_SIGNAL = (0, createNodeDescriptor_1.createNodeDescriptor)({ type: "cxOneSendSignal", defaultLabel: "Signal Interaction", summary: "UI__NODE_EDITOR__CXONE_SEND_SIGNAL__SUMMARY", preview: { key: "contactId", type: "text" }, fields: [ { key: "contactId", label: "UI__NODE_EDITOR__CXONE__SHARED__CONTACT_ID__LABEL", type: "cognigyText", description: "UI__NODE_EDITOR__CXONE__SHARED__CONTACT_ID__DESCRIPTION", params: { required: true, }, }, { key: "signalParams", label: "UI__NODE_EDITOR__CXONE_SEND_SIGNAL__FIELDS__SIGNAL_PARAMS__LABEL", type: "json", defaultValue: "[]", description: "UI__NODE_EDITOR__CXONE_SEND_SIGNAL__FIELDS__SIGNAL_PARAMS__DESCRIPTION", params: { required: true, }, }, ], form: [ { type: "field", key: "contactId" }, { type: "field", key: "signalParams" }, ], appearance: { color: "#3694FD", }, tags: ["nice", "cxone"], function: async ({ cognigy, config }) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; const { api, input } = cognigy; const { contactId, signalParams } = config; if (!contactId) { (_a = api.output) === null || _a === void 0 ? void 0 : _a.call(api, "cxOneSendSignal Error: Missing contactId", { error: "Missing contactId" }); throw new Error("cxOneSendSignal: Validation: Missing contactId"); } const finalParams = (0, prepareParams_1.prepareParams)(signalParams, api.log, "cxOneSendSignal"); (_b = api.log) === null || _b === void 0 ? void 0 : _b.call(api, "info", `cxOneSendSignal: Contact ID: ${contactId}`); try { const channel = (input === null || input === void 0 ? void 0 : input.channel) || ""; (_c = api.log) === null || _c === void 0 ? void 0 : _c.call(api, "info", `cxOneSendSignal: Interaction channel: ${channel}`); const isVoice = (0, cxOneChannelUtils_1.isVoiceChannel)(input); (_d = api.log) === null || _d === void 0 ? void 0 : _d.call(api, "info", `cxOneSendSignal: isVoice: ${isVoice}`); if (contactId && isVoice) { const apiClient = await api.getCxOneApiClient(); const status = await apiClient.sendSignal(contactId, finalParams); (_e = api.log) === null || _e === void 0 ? void 0 : _e.call(api, "info", `cxOneSendSignal: sent signal to CXone for contactId: ${contactId}; status: ${status}`); (_f = api.addToContext) === null || _f === void 0 ? void 0 : _f.call(api, "CXoneSendSignal", { success: true, contactId, params: finalParams, status }, "simple"); } else { const data = { Intent: "Signal", }; if (finalParams.length) { data.Params = finalParams.join("|"); } (_g = api.output) === null || _g === void 0 ? void 0 : _g.call(api, "", data); (_h = api.addToContext) === null || _h === void 0 ? void 0 : _h.call(api, "CXoneSendSignal", { success: true, contactId, params: finalParams, note: "chat-channel output only" }, "simple"); } } catch (error) { const errorMessage = error.message || "Unknown error"; (_j = api.log) === null || _j === void 0 ? void 0 : _j.call(api, "error", `cxOneSendSignal: Error signaling '${JSON.stringify(finalParams)}' for contactId: ${contactId}; error: ${errorMessage}`); (_k = api.addToContext) === null || _k === void 0 ? void 0 : _k.call(api, "CXoneSendSignal", { success: false, contactId, params: finalParams, error: errorMessage }, "simple"); (_l = api.output) === null || _l === void 0 ? void 0 : _l.call(api, "Something is not working. Please retry.", { error: errorMessage }); throw error; } }, }); //# sourceMappingURL=cxOneSendSignal.js.map