forked from guidone/node-red-contrib-chatbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatbot-analyze.js
More file actions
28 lines (22 loc) · 845 Bytes
/
chatbot-analyze.js
File metadata and controls
28 lines (22 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
var speak = require("speakeasy-nlp");
var levenshtein = require('fast-levenshtein');
var _ = require('underscore');
var lngDetector = new (require('languagedetect'));
module.exports = function(RED) {
function ChatBotAnalyze(config) {
RED.nodes.createNode(this, config);
var node = this;
this.message = config.message;
this.messageType = config.messageType;
this.on('input', function(msg) {
// exit if not string
if (_.isString(msg.payload.content)) {
msg.analysis = speak.classify(msg.payload.content);
var matchLanguage = lngDetector.detect(msg.payload.content, 2);
msg.analysis.language = _.isArray(matchLanguage) && !_.isEmpty(matchLanguage) ? matchLanguage[0][0] : null;
}
node.send(msg);
});
}
RED.nodes.registerType('chatbot-analyze', ChatBotAnalyze);
};