@cognigy/rest-api-client
Version:
Cognigy REST-Client
56 lines • 1.96 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.INTERVAL = void 0;
/* Custom modules */
const createNodeDescriptor_1 = require("../../../createNodeDescriptor");
exports.INTERVAL = (0, createNodeDescriptor_1.createNodeDescriptor)({
type: "interval",
defaultLabel: "Interval",
summary: "UI__NODE_EDITOR__INTERVAL__SUMMARY",
appearance: {
color: '#5c6bc0',
variant: 'hexagon',
textColor: "white",
showIcon: false
},
behavior: {
stopping: false
},
fields: [
{
key: "interval",
label: "UI__NODE_EDITOR__INTERVAL__FIELDS__INTERVAL_LABEL",
description: "UI__NODE_EDITOR__INTERVAL__FIELDS__INTERVAL_DESCRIPTION",
type: "number"
}
],
dependencies: {
children: ["onInterval", "elseInterval"],
},
constraints: {
collapsable: true,
placement: {}
},
tags: ["logic"],
function: async ({ cognigy, config, nodeId, childConfigs }) => {
const { api } = cognigy;
const { interval } = config;
const onIntervalChild = childConfigs.find(child => child.type === "onInterval");
const elseChild = childConfigs.find(child => child.type === "elseInterval");
const now = Date.now();
const lastRunAt = api.getSystemContext(`interval:${nodeId}`);
if (!lastRunAt || now > (lastRunAt + interval)) {
api.setSystemContext(`interval:${nodeId}`, now);
if (!onIntervalChild) {
throw new Error("Unable to handle interval since onInterval child node is missing");
}
api.setNextNode(onIntervalChild.id);
return;
}
if (!elseChild) {
throw new Error("Unable to handle interval since the else child node is missing");
}
api.setNextNode(elseChild.id);
}
});
//# sourceMappingURL=interval.js.map