2013-09-05 16:02:48 +02:00
|
|
|
|
2014-05-04 00:32:04 +02:00
|
|
|
module.exports = function(RED) {
|
2014-05-29 23:13:21 +02:00
|
|
|
"use strict";
|
2014-05-04 00:32:04 +02:00
|
|
|
var sentiment = require('sentiment');
|
2014-05-29 23:13:21 +02:00
|
|
|
|
2014-05-04 00:32:04 +02:00
|
|
|
function SentimentNode(n) {
|
|
|
|
RED.nodes.createNode(this,n);
|
2018-01-16 22:43:37 +01:00
|
|
|
this.property = n.property||"payload";
|
2014-05-04 00:32:04 +02:00
|
|
|
var node = this;
|
2014-05-29 23:13:21 +02:00
|
|
|
|
2014-05-04 00:32:04 +02:00
|
|
|
this.on("input", function(msg) {
|
2018-01-16 22:43:37 +01:00
|
|
|
var value = RED.util.getMessageProperty(msg,node.property);
|
|
|
|
if (value !== undefined) {
|
|
|
|
sentiment(value, msg.overrides || null, function (err, result) {
|
2015-03-31 09:35:56 +02:00
|
|
|
msg.sentiment = result;
|
|
|
|
node.send(msg);
|
|
|
|
});
|
|
|
|
}
|
2018-01-16 22:43:37 +01:00
|
|
|
else { node.send(msg); } // If no matching property - just pass it on.
|
2013-11-21 09:47:34 +01:00
|
|
|
});
|
2014-05-04 00:32:04 +02:00
|
|
|
}
|
|
|
|
RED.nodes.registerType("sentiment",SentimentNode);
|
2013-09-05 16:02:48 +02:00
|
|
|
}
|