@cognigy/rest-api-client
Version:
Cognigy REST-Client
73 lines • 2.15 kB
JavaScript
import { __awaiter } from "tslib";
/* Custom modules */
import { createNodeDescriptor } from "../../../createNodeDescriptor";
export const IF = createNodeDescriptor({
type: "if",
defaultLabel: "If",
summary: "UI__NODE_EDITOR__IF__SUMMARY",
appearance: {
color: '#9483D4',
textColor: 'white',
contrastTextColor: 'black',
variant: 'hexagon',
showIcon: false
},
dependencies: {
children: ["then", "else"],
},
constraints: {
collapsable: true,
placement: {
children: {
whitelist: ["then", "else"],
},
},
},
fields: [
{
key: "condition",
type: "condition",
label: "UI__NODE_EDITOR__IF__CONDITION__FIELDS__LABEL",
defaultValue: {
condition: "",
type: "rule",
rule: {
left: "1",
operand: "eq",
right: "1"
}
}
},
],
preview: {
key: "condition",
type: "custom",
},
tags: ["basic", "logic", "condition"],
function: ({ cognigy, config, childConfigs }) => __awaiter(void 0, void 0, void 0, function* () {
const { api } = cognigy;
const { condition: conditionObject } = config;
const { condition, rule, type } = conditionObject;
let isConditionTrue;
/** normal CS condition */
switch (type) {
case "rule":
{
isConditionTrue = api.evaluateRule(rule);
}
break;
case "condition":
default:
{
isConditionTrue = api.parseCognigyScriptCondition(condition);
}
break;
}
const child = childConfigs.find(child => isConditionTrue ? child.type === "then" : child.type === "else");
if (!child) {
throw new Error("Unable to find child to execute");
}
api.setNextNode(child.id);
})
});
//# sourceMappingURL=if.js.map