UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

91 lines 3.67 kB
import { __awaiter } from "tslib"; /* Custom modules */ import { createNodeDescriptor } from "../../../createNodeDescriptor"; /** * Node name: 'checkChannelChange' * * Purpose: * Asks the user if they want to carry on the conversation from another channel */ export const CHECK_CHANNEL_CHANGE = 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: ({ cognigy, config, childConfigs, nodeId: thisNodeId }) => __awaiter(void 0, void 0, void 0, function* () { 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; } yield 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; } yield api.say(validationMessage.replace("\{lastChannel\}", lastChannel) || questionToAsk); api.setNextNode(thisNodeId); api.stopExecution(); }) }); //# sourceMappingURL=checkChannelChange.js.map