UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

93 lines 3.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CHECK_CHANNEL_CHANGE = void 0; /* Custom modules */ const createNodeDescriptor_1 = require("../../../createNodeDescriptor"); /** * Node name: 'checkChannelChange' * * Purpose: * Asks the user if they want to carry on the conversation from another channel */ exports.CHECK_CHANNEL_CHANGE = (0, createNodeDescriptor_1.createNodeDescriptor)({ type: "checkChannelChange", defaultLabel: "Check Channel Change", summary: "UI__NODE_EDITOR__MESSAGE__CHECK_CHANNEL_CHANGE__SUMMARY", appearance: { color: "#90caf9", textColor: "white", contrastTextColor: "black", variant: "hexagon", showIcon: false }, fields: [ { key: "includedChannels", type: "textArray", label: "UI__NODE_EDITOR__MESSAGE__CHECK_CHANNEL_CHANGE__INCLUDED_CHANELS__LABEL", }, { key: "question", type: "cognigyText", label: "UI__NODE_EDITOR__MESSAGE__CHECK_CHANNEL_CHANGE__QUESTION__LABEL" }, { key: "validationMessage", type: "cognigyText", label: "UI__NODE_EDITOR__MESSAGE__CHECK_CHANNEL_CHANGE__VALIDATION_MESSAGE__LABEL" } ], dependencies: { children: ["onYes", "onNo", "unchanged"], }, constraints: { collapsable: true, placement: {}, }, tags: ["logic", "message"], function: async ({ cognigy, config, childConfigs, nodeId: thisNodeId }) => { const { includedChannels, validationMessage, question } = config; const { input, api } = cognigy; const { channel } = input; const lastChannel = api.getSystemContext("lastChannel"); const questionToAsk = question.replace("\{lastChannel\}", lastChannel); const unchangedChild = childConfigs.find(child => child.type === "unchanged"); const executionAmount = api.getExecutionAmount(thisNodeId); const isFirstExecution = executionAmount === 1; if (isFirstExecution) { const isChannelNotIncluded = includedChannels && includedChannels.filter(channel => !!channel) .length > 0 && includedChannels.indexOf(channel) === -1; if (isChannelNotIncluded || !lastChannel || lastChannel === channel) { if (!unchangedChild) { throw new Error("Unable to process checkChannelChange node since the 'unchanged' child node doesn't exist"); } api.setNextNode(unchangedChild.id); api.resetExecutionAmount(thisNodeId); if (!isChannelNotIncluded) { api.setSystemContext("lastChannel", channel); } return; } await api.say(questionToAsk); api.setNextNode(thisNodeId); api.stopExecution(); return; } if (input.type === "pAnswer" || input.type === "nAnswer") { const child = childConfigs.find(child => input.type === "pAnswer" ? child.type === "onYes" : child.type === "onNo"); if (!child) { throw new Error("Unable to process answer since the child node doesn't exist"); } api.setSystemContext("lastChannel", channel); api.setNextNode(child.id); api.resetExecutionAmount(thisNodeId); return; } await api.say(validationMessage.replace("\{lastChannel\}", lastChannel) || questionToAsk); api.setNextNode(thisNodeId); api.stopExecution(); } }); //# sourceMappingURL=checkChannelChange.js.map