UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

167 lines 6.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EXECUTE_COGNIGY_NLU = void 0; /* Custom modules */ const createNodeDescriptor_1 = require("../../createNodeDescriptor"); const errors_1 = require("../../../errors"); const logger_1 = require("../../../helper/logger"); /** * Node name: 'executeCognigyNLU' * * Purpose: * Runs Cognigy NLU */ exports.EXECUTE_COGNIGY_NLU = (0, createNodeDescriptor_1.createNodeDescriptor)({ type: "executeCognigyNLU", defaultLabel: "Execute Cognigy NLU", summary: "UI__NODE_EDITOR__NLU__EXECUTE_COGNIGY_NLU__DEFAULT_SUMMARY", appearance: { showIcon: false }, fields: [ { key: "text", type: "cognigyText", label: "UI__NODE_EDITOR__NLU__EXECUTE_COGNIGY_NLU__FIELDS__TEXT__LABEL", params: { required: true } }, { key: "data", type: "json", label: "UI__NODE_EDITOR__NLU__EXECUTE_COGNIGY_NLU__FIELDS__DATA__LABEL", defaultValue: "{}" }, { key: "mode", type: "select", label: "UI__NODE_EDITOR__NLU__EXECUTE_COGNIGY_NLU__FIELDS__MODE__LABEL", defaultValue: "context", params: { required: true, options: [ { label: "UI__NODE_EDITOR__NLU__EXECUTE_COGNIGY_NLU__FIELDS__MODE__OPTIONS__CONTEXT__LABEL", value: "context", }, { label: "UI__NODE_EDITOR__NLU__EXECUTE_COGNIGY_NLU__FIELDS__MODE__OPTIONS__INPUT__LABEL", value: "input", }, { label: "UI__NODE_EDITOR__NLU__EXECUTE_COGNIGY_NLU__FIELDS__MODE__OPTIONS__OVERWRITE__LABEL", value: "overwrite" } ], }, }, { key: "contextKey", type: "cognigyText", label: "UI__NODE_EDITOR__NLU__EXECUTE_COGNIGY_NLU__FIELDS__CONTEXT_KEY__LABEL", condition: { key: "mode", value: "context" } }, { key: "inputKey", type: "cognigyText", label: "UI__NODE_EDITOR__NLU__EXECUTE_COGNIGY_NLU__FIELDS__INPUT_KEY__LABEL", condition: { key: "mode", value: "input" } }, { key: "parseIntents", type: "toggle", label: "UI__NODE_EDITOR__NLU__EXECUTE_COGNIGY_NLU__FIELDS__PARSE_INTENTS__LABEL", defaultValue: true }, { key: "parseSlots", type: "toggle", label: "UI__NODE_EDITOR__NLU__EXECUTE_COGNIGY_NLU__FIELDS__PARSE_SLOTS__LABEL", defaultValue: true }, { key: "parseSystemSlots", type: "toggle", label: "UI__NODE_EDITOR__NLU__EXECUTE_COGNIGY_NLU__FIELDS__PARSE_SYSTEM_SLOTS__LABEL", defaultValue: true }, { key: "findType", type: "toggle", label: "UI__NODE_EDITOR__NLU__EXECUTE_COGNIGY_NLU__FIELDS__FIND_TYPE__LABEL", defaultValue: true }, { key: "processDefaultReply", type: "toggle", label: "UI__NODE_EDITOR__NLU__EXECUTE_COGNIGY_NLU__FIELDS__PARSE_DEFAULT_REPLAY__LABEL", defaultValue: false } ], sections: [ { key: "advanced", label: "UI__NODE_EDITOR__NLU__EXECUTE_COGNIGY_NLU__SECTIONS__ADVANCED__LABEL", defaultCollapsed: true, fields: [ "parseIntents", "parseSystemSlots", "parseSlots", "findType", "processDefaultReply" ] } ], form: [ { type: "field", key: "text" }, { type: "field", key: "data" }, { type: "field", key: "mode" }, { type: "field", key: "contextKey" }, { type: "field", key: "inputKey" }, { type: "section", key: "advanced" } ], tags: ["ai", "nlu"], function: async ({ cognigy, config }) => { const { api, input } = cognigy; const { text, data, mode, contextKey, inputKey, parseIntents, parseSlots, parseSystemSlots, findType, processDefaultReply } = config; if (mode === "context" && !contextKey) { logger_1.default.log("error", { traceId: input.traceId, disableSensitiveLogging: false }, "No context key provided in addLexiconKeyphrse with context mode"); return; } if ((input === null || input === void 0 ? void 0 : input.channel) === "nonConversational") { logger_1.default.log("error", { traceId: input.traceId, disableSensitiveLogging: false }, "Execute Cognigy NLU is not allowed with nonConversational endpoint"); throw new errors_1.InvalidArgumentError("Execute Cognigy NLU is not allowed with nonConversational endpoint", { traceId: input.traceId, disableSensitiveLogging: false }); } const result = await api.executeCognigyNLU(text, data, input.inputId, { parseIntents, parseSlots, parseSystemSlots, findType }); // Handle intent default reply if an intent was triggered, and the // "Process Intent Default Reply" toggle was enabled if (result.intent && processDefaultReply) { const defaultReplyResult = await api.handleIntentDefaultReply(result); if (defaultReplyResult.pendingDefaultReply) { result.nlu.intentMapperResults.finalIntentDefaultReply = defaultReplyResult.pendingDefaultReply; } } if (result.tokens) { delete result.tokens; } switch (mode) { case "overwrite": Object.assign(input, result); break; case "input": input[inputKey] = result; break; case "context": api.addToContext(contextKey, result, "simple"); break; } } }); //# sourceMappingURL=executeCognigyNLU.js.map