@cognigy/rest-api-client
Version:
Cognigy REST-Client
170 lines • 5.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GO_TO = void 0;
/* Custom modules */
const createNodeDescriptor_1 = require("../../createNodeDescriptor");
/**
* Node name: 'goTo'
*
* Purpose:
* Jumps to a given node in a given Flow
*/
exports.GO_TO = (0, createNodeDescriptor_1.createNodeDescriptor)({
type: "goTo",
defaultLabel: "Go To",
summary: "UI__NODE_EDITOR__GO_TO__SUMMARY",
appearance: {
showIcon: false,
},
behavior: {
stopping: true
},
fields: [
{
key: "flowNode",
type: "flowNode",
label: "UI__NODE_EDITOR__GO_TO__FLOW_NODE__LABEL",
params: {
required: true
}
},
{
key: "absorbContext",
type: "toggle",
description: "UI__NODE_EDITOR__GO_TO__ABSORB_CONTEXT__DESCRIPTION",
label: "UI__NODE_EDITOR__GO_TO__ABSORB_CONTEXT__LABEL",
defaultValue: false
},
{
key: "executionMode",
type: "select",
description: "UI__NODE_EDITOR__GO_TO__EXECUTION_MODE__DESCRIPTION",
label: "UI__NODE_EDITOR__GO_TO__EXECUTION_MODE__LABEL",
defaultValue: "continue",
params: {
options: [
{
label: "UI__NODE_EDITOR__GO_TO__EXECUTION_MODE__CONTINUE__LABEL",
value: "continue"
},
{
label: "UI__NODE_EDITOR__GO_TO__EXECUTION_MODE__WAIT__LABEL",
value: "wait"
},
]
}
},
{
key: "injectedText",
label: "UI__NODE_EDITOR__GO_TO__INJECTED_TEXT__LABEL",
type: "cognigyText",
description: "UI__NODE_EDITOR__GO_TO__INJECTED_TEXT__DESCRIPTION",
defaultValue: "",
condition: {
key: "executionMode",
value: "continue"
}
},
{
key: "injectedData",
label: "UI__NODE_EDITOR__GO_TO__INJECTED_DATA__LABEL",
type: "json",
description: "UI__NODE_EDITOR__GO_TO__INJECTED_DATA__DESCRIPTION",
defaultValue: "{}",
condition: {
key: "executionMode",
value: "continue"
}
},
{
key: "parseIntents",
type: "toggle",
label: "UI__NODE_EDITOR__GO_TO__PARSE_INTENTS__LABEL",
description: "UI__NODE_EDITOR__GO_TO__PARSE_INTENTS__DESCRIPTION",
defaultValue: false,
condition: {
key: "executionMode",
value: "continue"
}
},
{
key: "parseKeyphrases",
type: "toggle",
label: "UI__NODE_EDITOR__GO_TO__PARSE_KEYPHRASES__LABEL",
description: "UI__NODE_EDITOR__GO_TO__PARSE_KEYPHRASES__DESCRIPTION",
defaultValue: false,
condition: {
key: "executionMode",
value: "continue"
}
},
],
sections: [
{
key: "advanced",
label: "UI__NODE_EDITOR__GO_TO__ADVANCED__LABEL",
defaultCollapsed: true,
fields: [
"executionMode",
"injectedText",
"injectedData",
"parseIntents",
"parseKeyphrases",
"absorbContext"
]
}
],
form: [
{ type: "field", key: "flowNode" },
{ type: "section", key: "advanced" }
],
preview: {
key: "flowNode",
type: "resource",
},
tags: ["logic"],
function: async ({ cognigy, config, nodeId: thisNodeId }) => {
const { flowNode: { flow: flowId, node: nodeId }, absorbContext, executionMode, injectedText, injectedData, parseIntents, parseKeyphrases } = config;
const { api } = cognigy;
if (!flowId) {
throw new Error("flowId is required");
}
if (!nodeId) {
throw new Error("nodeId is required");
}
if (!api.checkThink(thisNodeId)) {
api.resetNextNodes();
api.setThinkMarker(config.flowNode.flow);
// Check if execution is to wait at Node for Input
if (executionMode === "wait") {
// only set the next node if the execution mode is "wait",
// otherwise input after the goto node would again go to this node, and not to the start node
await api.goToNode(config.flowNode);
return;
}
if (injectedText) {
cognigy.input.text = injectedText;
}
if (injectedData &&
typeof injectedData === 'object' &&
Object.keys(injectedData).length !== 0) {
cognigy.input.data = injectedData;
}
// If Execution is to continue, execute Flow
await api.executeFlow({
flowNode: {
flow: flowId,
node: nodeId,
isGoto: true,
},
absorbContext,
parseIntents,
parseKeyphrases
});
}
else {
throw new Error("Infinite Loop Detected");
}
},
});
//# sourceMappingURL=goTo.js.map