@cognigy/rest-api-client
Version:
Cognigy REST-Client
54 lines • 1.9 kB
JavaScript
import { __awaiter } from "tslib";
/* Custom modules */
import { createNodeDescriptor } from "../../../createNodeDescriptor";
export const INTERVAL = 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: ({ cognigy, config, nodeId, childConfigs }) => __awaiter(void 0, void 0, void 0, function* () {
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