@ebonydevcopy/framework
Version:
A module-based NodeJS chatbot framework.
40 lines • 1.56 kB
JavaScript
;
/**
* ebony-framework
*
* @module handlers/nlp
* @author Christos Panagiotakopoulos <chrispanag@gmail.com>
* @copyright Copyright(c) 2020 Christos Panagiotakopoulos
* @license MIT
*
*/
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @param intentRouter - An IntentRouter instance
* @returns Returns the nlpHandler function
*/
function nlpHandlerFactory(intentRouter, options) {
const MAX_LENGTH = (options === null || options === void 0 ? void 0 : options.maxMessageLength) ? options.maxMessageLength : 51;
const MIN_CONFIDENCE = (options === null || options === void 0 ? void 0 : options.confidenceThreshold) ? options.confidenceThreshold : 0.9;
function nlpHandler(user, message, nlp) {
// The NLP object doesn't exist if the user hasn't activated the built in NLP
if (nlp) {
const msg = message.text;
if (nlp.entities.intent) {
if (nlp.entities.intent[0].confidence > MIN_CONFIDENCE && msg.length < MAX_LENGTH) {
const action = intentRouter.intentRouter(user.id, msg, nlp);
if (action) {
return action(user, nlp);
}
}
}
console.log('Sending to Complex NLP');
return this.complexNlp(user, message, nlp);
}
console.log('No NLP object!');
// TODO : Add a fallback message (next release)
}
return nlpHandler;
}
exports.default = nlpHandlerFactory;
//# sourceMappingURL=nlp.js.map