UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

135 lines 5.03 kB
import { __awaiter } from "tslib"; /** Custom Modules */ import { createNodeDescriptor } from "../../../createNodeDescriptor"; /** Helper Modules */ import { msTeamsTransfer } from "../../voice/mappers/msTeamsTransfer.mapper"; import { nodeColor } from "../utils/design"; const customHeaderDefaultValue = "X-Custom-Header"; const isMSTeamsTransferNodeAllowed = (organisationId) => { const allowlist = process.env.FEATURE_ENABLE_MS_TEAMS_TRANSFER_NODE_ALLOWLIST; if (!allowlist || !organisationId) { return false; } const entries = allowlist.split(",").map((entry) => entry.trim()); return entries.includes("*") || entries.includes(organisationId); }; export const msTeamsTransferNode = createNodeDescriptor({ type: "msTeamsTransfer", defaultLabel: "MS Teams Transfer", preview: { key: "transferTarget", type: "text", }, appearance: { color: nodeColor, }, tags: ["voice"], fields: [ { key: "transferTarget", label: "UI__NODE_EDITOR__VOICEGATEWAY2__TRANSFER__FIELDS__TRANSFER_TARGET__LABEL", type: "cognigyText", params: { required: true, }, description: "UI__NODE_EDITOR__VOICEGATEWAY2__TRANSFER__FIELDS__TRANSFER_TARGET__DESCRIPTION", defaultValue: "+49123456789", }, { key: "callerName", label: "UI__NODE_EDITOR__VOICEGATEWAY2__MSTEAMS_TRANSFER__FIELDS__CALLER_NAME__LABEL", type: "cognigyText", description: "UI__NODE_EDITOR__VOICEGATEWAY2__MSTEAMS_TRANSFER__FIELDS__CALLER_NAME__DESCRIPTION", defaultValue: "", }, { key: "topic", label: "UI__NODE_EDITOR__VOICEGATEWAY2__MSTEAMS_TRANSFER__FIELDS__TOPIC__LABEL", type: "cognigyText", description: "UI__NODE_EDITOR__VOICEGATEWAY2__MSTEAMS_TRANSFER__FIELDS__TOPIC__DESCRIPTION", defaultValue: "", }, { key: "context", label: "UI__NODE_EDITOR__VOICEGATEWAY2__MSTEAMS_TRANSFER__FIELDS__CONTEXT__LABEL", type: "cognigyText", description: "UI__NODE_EDITOR__VOICEGATEWAY2__MSTEAMS_TRANSFER__FIELDS__CONTEXT__DESCRIPTION", defaultValue: "My context", params: { required: true, }, }, { key: "callSentiment", label: "UI__NODE_EDITOR__VOICEGATEWAY2__MSTEAMS_TRANSFER__FIELDS__CALL_SENTIMENT__LABEL", type: "cognigyText", description: "UI__NODE_EDITOR__VOICEGATEWAY2__MSTEAMS_TRANSFER__FIELDS__CALL_SENTIMENT__DESCRIPTION", defaultValue: "", }, { key: "suggestedActions", label: "UI__NODE_EDITOR__VOICEGATEWAY2__MSTEAMS_TRANSFER__FIELDS__SUGGESTED_ACTIONS__LABEL", type: "cognigyText", description: "UI__NODE_EDITOR__VOICEGATEWAY2__MSTEAMS_TRANSFER__FIELDS__SUGGESTED_ACTIONS__DESCRIPTION", defaultValue: "", }, ], form: [ { type: "field", key: "transferTarget" }, { type: "field", key: "callerName" }, { type: "field", key: "topic" }, { type: "field", key: "context" }, { type: "field", key: "callSentiment" }, { type: "field", key: "suggestedActions" }, ], summary: "UI__NODE_EDITOR__VOICEGATEWAY2__TRANSFER__SUMMARY", function: ({ cognigy, config, organisationId, }) => __awaiter(void 0, void 0, void 0, function* () { const { api, input } = cognigy; if (!isMSTeamsTransferNodeAllowed(organisationId)) { throw new Error("MS Teams Transfer node is not enabled for this organisation."); } const { transferTarget, callerName, topic, context, callSentiment, suggestedActions, } = config; const transferParams = { transferTarget, callerName, topic, context, callSentiment, suggestedActions, }; try { if (input.channel === "adminconsole") { let textWarningAdminChannel = "Transferring a call is not supported in the Interaction Panel, please use the VoiceGateway endpoint."; yield api.say(textWarningAdminChannel, null); return; } const payload = msTeamsTransfer.handleInput("voiceGateway2", transferParams); yield api.say(null, { _cognigy: payload, }); api.logDebugMessage(`UI__DEBUG_MODE__MS_TEAMS__TRANSFER__MESSAGE ${transferTarget}`); } catch (error) { throw new Error(`Error on Transfer node type:. Error message: ${error.message}`); } }), }); //# sourceMappingURL=msTeamsTransfer.js.map