UNPKG

lexica-dialog-core

Version:
29 lines 1.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const lodash_1 = require("lodash"); const immutable_1 = require("immutable"); const nlpMiddleware = async (context, next) => { const { uni, nlpService, request, sessionService, requestMessage, messageRepository } = context; let features; if (!lodash_1.isNil(sessionService)) { features = sessionService.getIntentMemoryFeatures(); } if (!lodash_1.isNil(request) && !lodash_1.isNil(request.message) && context.commands.isEmpty()) { const commands = await nlpService.analyse(request.message, uni, features); context.commands = immutable_1.List(commands.toArray().map(command => ({ attributes: immutable_1.Map(), botResponses: immutable_1.List(), features: command.features, name: command.name, processedFeatures: immutable_1.Map(), }))); if (!lodash_1.isNil(requestMessage)) { const commandNames = commands.toArray().map(command => command.name); requestMessage.commands = commandNames; context.requestMessage = (await messageRepository.save(requestMessage)); } } await next(); }; exports.default = nlpMiddleware; //# sourceMappingURL=NlpMiddleware.js.map