lexica-dialog-core
Version:
Core server for Lexica dialog agent.
36 lines • 1.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const lodash_1 = require("lodash");
const immutable_1 = require("immutable");
const intentPostProcessorMiddleware = async (context, next) => {
const { request, commands, postProcessors, uni, uniConfigs, messenger, issue, senderInfo } = context;
if (!lodash_1.isNil(request)) {
const { locale, senderId } = request;
const processorContext = {
issue,
locale,
messengerName: messenger.name,
senderId,
senderInfo,
uni,
uniConfigs,
};
const commandPromises = commands.toArray().map(async (command) => {
const { intent, features } = command;
let processedFeatures = lodash_1.defaultTo(features, immutable_1.Map());
if (!lodash_1.isNil(intent) && !lodash_1.isNil(intent.postProcessors)) {
const intentPostProcessors = intent.postProcessors
.filter(postProcessorName => postProcessors.has(postProcessorName))
.map(postProcessorName => postProcessors.get(postProcessorName));
for (const postProcessor of intentPostProcessors) {
processedFeatures = processedFeatures.merge(await postProcessor(processorContext, processedFeatures));
}
}
command.processedFeatures = processedFeatures;
});
await Promise.all(commandPromises);
}
await next();
};
exports.default = intentPostProcessorMiddleware;
//# sourceMappingURL=IntentPostProcessorMiddleware.js.map