UNPKG

lexica-dialog-core

Version:
51 lines 2.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const lodash_1 = require("lodash"); const immutable_1 = require("immutable"); const Intent_1 = require("lexica-dialog-model/dist/Intent"); const intentOptionMiddleware = async (context, next) => { const { sessionService, commands, request } = context; if (!lodash_1.isNil(sessionService) && !lodash_1.isNil(request) && !lodash_1.isNil(request.message) && sessionService.hasOptions() && commands.isEmpty()) { const options = immutable_1.List(sessionService .getOptions() .filter(option => !lodash_1.isNil(request.message) && option.textOnlyIndicator.toLowerCase().trim() === request.message.toLowerCase().trim())); if (!options.isEmpty() && options.size === 1) { const option = options.first(); context.commands = immutable_1.List([ { attributes: immutable_1.Map(), botResponses: immutable_1.List(), features: immutable_1.Map(option.features), name: option.command, processedFeatures: immutable_1.Map(), }, ]); sessionService.removeOptions(); } } await next(); const responses = immutable_1.List(context.responses.toArray().filter(response => response.type === Intent_1.ResponseType.OPTIONS)); if (!lodash_1.isNil(sessionService) && !responses.isEmpty() && responses.size === 1) { const response = responses.first(); if (response.type === Intent_1.ResponseType.OPTIONS) { const options = !lodash_1.isNil(response.options) ? response.options.map(option => ({ command: option.command, features: option.features, liveCount: 0, textOnlyIndicator: option.textOnlyIndicator, })) : undefined; if (!lodash_1.isNil(options)) { sessionService.setOptions(options); } } } }; exports.default = intentOptionMiddleware; //# sourceMappingURL=IntentOptionMiddleware.js.map