UNPKG

lexica-dialog-core

Version:
22 lines 885 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const lodash_1 = require("lodash"); const Api_1 = require("../Api"); const intentRequiredFeaturesMiddleware = async (context, next) => { const { commands } = context; commands.toArray().forEach(command => { const { intent, features } = command; if (!lodash_1.isNil(intent)) { let hasAllRequiredKeys = true; if (lodash_1.isArray(intent.requiredFeatureKeys)) { hasAllRequiredKeys = intent.requiredFeatureKeys.every(key => features.has(key)); } if (!hasAllRequiredKeys) { throw new Api_1.BotError(Api_1.BotErrorCode.MISSING_REQUIRED_FEATURE); } } }); await next(); }; exports.default = intentRequiredFeaturesMiddleware; //# sourceMappingURL=IntentRequiredFeatureMiddleware.js.map