UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

88 lines 2.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ADD_TO_CONTEXT = void 0; /* Custom modules */ const createNodeDescriptor_1 = require("../../createNodeDescriptor"); /** * Node name: 'addToContext' * * Purpose: * Adds a new value to the Cognigy context object. */ exports.ADD_TO_CONTEXT = (0, createNodeDescriptor_1.createNodeDescriptor)({ type: "addToContext", defaultLabel: "Add To Context", summary: "UI__NODE_EDITOR__ADD_TO_CONTEXT__SUMMARY", appearance: { showIcon: false }, fields: [ { key: "key", type: "cognigyText", label: "UI__NODE_EDITOR__ADD_TO_CONTEXT__FIELDS__KEY__LABEL", params: { required: true } }, { key: "value", type: "cognigyText", label: "UI__NODE_EDITOR__ADD_TO_CONTEXT__FIELDS__VALUE__LABEL", params: { required: true } }, { key: "mode", type: "select", label: "UI__NODE_EDITOR__ADD_TO_CONTEXT__FIELDS__MODE__LABEL", defaultValue: "simple", description: "UI__NODE_EDITOR__ADD_TO_CONTEXT__FIELDS__MODE__DESCRIPTION", params: { required: true, options: [ { label: "UI__NODE_EDITOR__ADD_TO_CONTEXT__FIELDS__MODE__OPTIONS__SIMPLE__LABEL", value: "simple", }, { label: "UI__NODE_EDITOR__ADD_TO_CONTEXT__FIELDS__MODE__OPTIONS__ARRAY__LABEL", value: "array", } ] } } ], preview: { key: "key", type: "text", }, tags: ["basic", "data", "store"], function: async ({ cognigy, config }) => { const { api } = cognigy; const { key, mode } = config; if (!key) { throw new Error("Unable to add value to context. No context key was defined."); } if (!mode || !["simple", "array"].includes(mode)) { throw new Error("Unable to add value to context. The 'mode' is missing or neither 'simple' nor 'array'."); } let value; try { value = JSON.parse(config.value); } catch (e) { value = config.value; } api.addToContext(key, value, mode); let stringValue = value; try { stringValue = JSON.stringify(value, undefined, 2); } catch (err) { } api.logDebugMessage(`context.${key} = ${stringValue}`); } }); //# sourceMappingURL=addToContext.js.map