UNPKG

@botonic/plugin-flow-builder

Version:

Use Flow Builder to show your contents

52 lines 2.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getArgumentsByLocale = exports.CustomFunction = exports.DEFAULT_FUNCTION_NAMES = void 0; const tslib_1 = require("tslib"); exports.DEFAULT_FUNCTION_NAMES = [ 'check-queue-status', 'get-channel-type', 'check-country', 'check-bot-variable', ]; class CustomFunction { constructor(functions, currentRequest, locale) { this.functions = functions; this.currentRequest = currentRequest; this.locale = locale; } call(functionNode) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const functionNodeId = functionNode.id; const functionArguments = getArgumentsByLocale(functionNode.content.arguments, this.locale); const nameValues = functionArguments.map(arg => { return { [arg.name]: arg.value }; }); const args = Object.assign({ request: this.currentRequest, results: functionNode.content.result_mapping.map(r => r.result), }, ...nameValues); const functionResult = yield this.functions[functionNode.content.action](args); // TODO define result_mapping per locale?? const result = functionNode.content.result_mapping.find(r => r.result === functionResult); if (!(result === null || result === void 0 ? void 0 : result.target)) { throw new Error(`No result found for result_mapping for node with id: ${functionNodeId}`); } return result.target.id; }); } } exports.CustomFunction = CustomFunction; function getArgumentsByLocale(args, locale) { let resultArguments = []; for (const arg of args) { if ('locale' in arg && arg.locale === locale) { resultArguments = [...resultArguments, ...arg.values]; } if ('type' in arg) { resultArguments = [...resultArguments, arg]; } } return resultArguments; } exports.getArgumentsByLocale = getArgumentsByLocale; //# sourceMappingURL=index.js.map