UNPKG

@cognigy/rest-api-client

Version:

Cognigy REST-Client

173 lines 6.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setxAppResult = exports.SET_ADAPTIVE_CARD_APP_STATE = void 0; /* Custom modules */ const createNodeDescriptor_1 = require("../../createNodeDescriptor"); const BaseContext_1 = require("../../../helper/BaseContext"); const getXAppsOverlaySettings_1 = require("./utils/getXAppsOverlaySettings"); /** * Node name: 'setAdaptiveCardAppState' * * Purpose: * Set the state of an AdaptiveCard App */ exports.SET_ADAPTIVE_CARD_APP_STATE = (0, createNodeDescriptor_1.createNodeDescriptor)({ type: "setAdaptiveCardAppState", defaultLabel: "xApp: Show Adaptive Card", summary: "UI__NODE_EDITOR__SET_ADAPTIVE_CARD_APP_STATE__SUMMARY", appearance: { showIcon: false, }, fields: [ { key: "card", type: "json", label: "UI__NODE_EDITOR__SET_ADAPTIVE_CARD_APP_STATE__CARD__LABEL", description: "UI__NODE_EDITOR__SET_ADAPTIVE_CARD_APP_STATE__CARD__DESCRIPTION", defaultValue: {}, }, { key: "primaryColor", type: "cognigyText", label: "UI__NODE_EDITOR__SET_ADAPTIVE_CARD_APP_STATE__PRIMARY_COLOR__LABEL", description: "UI__NODE_EDITOR__SET_ADAPTIVE_CARD_APP_STATE__PRIMARY_COLOR__DESCRIPTION", defaultValue: "", }, { key: "primaryContrastColor", type: "cognigyText", label: "UI__NODE_EDITOR__SET_ADAPTIVE_CARD_APP_STATE__PRIMARY_CONTRAST_COLOR__LABEL", description: "UI__NODE_EDITOR__SET_ADAPTIVE_CARD_APP_STATE__PRIMARY_CONTRAST_COLOR__DESCRIPTION", defaultValue: "", }, { key: "waitForInput", type: "toggle", label: "UI__NODE_EDITOR__SET_ADAPTIVE_CARD_APP_STATE__WAIT_FOR_INPUT__LABEL", defaultValue: false, }, { key: "storeResultInContext", type: "toggle", label: "UI__NODE_EDITOR__SET_ADAPTIVE_CARD_APP_STATE__STORE_RESULT_IN_CONTEXT__LABEL", condition: { key: "waitForInput", value: true, }, }, { key: "contextKey", type: "cognigyText", label: "UI__NODE_EDITOR__SET_ADAPTIVE_CARD_APP_STATE__CONTEXT_KEY__LABEL", defaultValue: "result", condition: { and: [ { key: "waitForInput", value: true, }, { key: "storeResultInContext", value: true, }, ], }, }, ...(0, getXAppsOverlaySettings_1.getXAppsOverlaySettingsFields)(), ], sections: [ { key: "overrideSection", defaultCollapsed: true, fields: ["primaryColor", "primaryContrastColor"], label: "UI__NODE_EDITOR__SET_ADAPTIVE_CARD_APP_STATE__OVERRIDE_SECTIONS__LABEL", }, { key: "waitingBehavior", defaultCollapsed: true, fields: ["waitForInput", "storeResultInContext", "contextKey"], label: "UI__NODE_EDITOR__SET_ADAPTIVE_CARD_APP_STATE__WAITING_BEHAVIOR__LABEL", }, (0, getXAppsOverlaySettings_1.getXAppsOverlaySettingsSection)(), ], form: [ { type: "field", key: "card" }, { type: "section", key: "overrideSection" }, { type: "section", key: "waitingBehavior" }, { type: "section", key: (0, getXAppsOverlaySettings_1.getXAppsOverlaySettingsSection)().key }, ], tags: ["basic", "apps", "xApps"], function: async ({ cognigy, config, nodeId }) => { var _a, _b; const { api, input, context } = cognigy; const { card, primaryColor, primaryContrastColor, waitForInput, storeResultInContext, contextKey, } = config; const overlaySettings = { autoOpen: config.autoOpen, closeOnSubmit: config.closeOnSubmit, feedbackMessage: config.feedbackMessage, screenTitle: config.screenTitle, sendEventOnCloseIconClick: config.sendEventOnCloseIconClick, showCloseIcon: config.showCloseIcon, }; const systemContextWaitingKey = `adaptiveCardAPPWaiting-${nodeId}`; const appTemplateURL = `${input.apps.baseUrl}/apps/adaptivecards/`; // only set the app state once if (!api.getSystemContext(systemContextWaitingKey)) { api.setAppState(appTemplateURL, { card, primaryColor: primaryColor || undefined, primaryContrastColor: primaryContrastColor || undefined }, { webchat3: { overlaySettingsMetaData: { overlaySettings, endpointType: input.endpointType, url: input.apps.url, URLToken: input.URLToken } } }); api.logDebugMessage(`UI__DEBUG_MODE__SET_ADAPTIVE_CARD_APP_STATE__MESSAGE`); } if (api.getSystemContext(systemContextWaitingKey) && contextKey && ((_b = (_a = input.data) === null || _a === void 0 ? void 0 : _a._cognigy) === null || _b === void 0 ? void 0 : _b._app)) { api.deleteSystemContext(systemContextWaitingKey); (0, exports.setxAppResult)({ input, storeResultInContext, contextKey, context, }); return; } if (waitForInput) { api.setSystemContext(systemContextWaitingKey, true); api.setNextNode(nodeId); api.stopExecution(); } }, }); /** * Sets the result of an xApp in the context */ const setxAppResult = (params) => { var _a, _b, _c; const { input, storeResultInContext, contextKey, context } = params; const result = (_c = (_b = (_a = input === null || input === void 0 ? void 0 : input.data) === null || _a === void 0 ? void 0 : _a._cognigy) === null || _b === void 0 ? void 0 : _b._app) === null || _c === void 0 ? void 0 : _c.payload; if (storeResultInContext) { // check whether contextKey or inputKey is a deep query and set // storage location accordingly let location = context; let target = contextKey; // deep query if (target.indexOf(".") > -1) { const splits = target.split("."); location = BaseContext_1.BaseContext.findLocationPathStateless(splits, true, location); target = splits[splits.length - 1]; } location[target] = result; } }; exports.setxAppResult = setxAppResult; //# sourceMappingURL=setAdaptiveCardAppState.js.map