diff --git a/README.md b/README.md index 261cfd33..b963d62c 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,10 @@ Node-RED Watson Nodes for IBM Bluemix +### New in version 0.5.8 +- Visual Reconition Node, now accepts readstream on msg.payload +- Add passages parameter to Discovery Node + ### New in version 0.5.7 - Fix to Tone Analyzer to allow JSON as input - Enabled Conversation Tone method to Tone Analyzer Node diff --git a/package.json b/package.json index aa654ebe..82cdfef6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-node-watson", - "version": "0.5.7", + "version": "0.5.8", "description": "A collection of Node-RED nodes for IBM Watson services", "dependencies": { "alchemy-api": "^1.3.0", @@ -11,9 +11,10 @@ "temp": "^0.8.3", "qs": "6.x", "image-type": "^2.0.2", - "watson-developer-cloud": "^2.31.2", + "watson-developer-cloud": "^2.32.1", "kuromoji": "^0.0.5", - "is-docx": "^0.0.3" + "is-docx": "^0.0.3", + "stream-to-array" : "^2.3.0" }, "repository": { "type": "git", diff --git a/services/conversation/v1.js b/services/conversation/v1.js index 1c298f60..73cc5e99 100644 --- a/services/conversation/v1.js +++ b/services/conversation/v1.js @@ -14,12 +14,14 @@ * limitations under the License. **/ -module.exports = function (RED) { +module.exports = function(RED) { const SERVICE_IDENTIFIER = 'conversation'; var pkg = require('../../package.json'), ConversationV1 = require('watson-developer-cloud/conversation/v1'), serviceutils = require('../../utilities/service-utils'), - service = null, sUsername = null, sPassword = null; + service = null, + sUsername = null, + sPassword = null; service = serviceutils.getServiceCreds(SERVICE_IDENTIFIER); @@ -28,13 +30,19 @@ module.exports = function (RED) { sPassword = service.password; } - RED.httpAdmin.get('/watson-conversation/vcap', function (req, res) { - res.json(service ? {bound_service: true} : null); + RED.httpAdmin.get('/watson-conversation/vcap', function(req, res) { + res.json(service ? { + bound_service: true + } : null); }); function verifyPayload(node, msg) { if (!msg.payload) { - node.status({fill:'red', shape:'ring', text:'missing payload'}); + node.status({ + fill: 'red', + shape: 'ring', + text: 'missing payload' + }); node.error('Missing property: msg.payload', msg); return false; } @@ -57,11 +65,13 @@ module.exports = function (RED) { function verifyInputs(node, msg, config, params) { if (!config.workspaceid && !msg.params.workspace_id) { - node.error('Missing workspace_id. check node documentation.',msg); + node.error('Missing workspace_id. check node documentation.', msg); return false; } // mandatory message - params.input = {text:msg.payload}; + params.input = { + text: msg.payload + }; var prop = null; if (config.context) { @@ -127,9 +137,13 @@ module.exports = function (RED) { var userName = sUsername || node.credentials.username, passWord = sPassword || node.credentials.password; - if ( !(userName || msg.params.username) || - !(passWord || msg.params.password) ) { - node.status({fill:'red', shape:'ring', text:'missing credentials'}); + if (!(userName || msg.params.username) || + !(passWord || msg.params.password)) { + node.status({ + fill: 'red', + shape: 'ring', + text: 'missing credentials' + }); node.error('Missing Watson Conversation API service credentials', msg); return false; } @@ -157,8 +171,11 @@ module.exports = function (RED) { function processResponse(err, body, node, msg, config) { if (err !== null && body === null) { node.error(err); - node.status({fill:'red', shape:'ring', - text:'call to watson conversation service failed'}); + node.status({ + fill: 'red', + shape: 'ring', + text: 'call to watson conversation service failed' + }); return; } msg.payload = body; @@ -179,7 +196,11 @@ module.exports = function (RED) { } function execute(params, node, msg, config) { - node.status({fill:'blue', shape:'dot' , text:'Calling Conversation service ...'}); + node.status({ + fill: 'blue', + shape: 'dot', + text: 'Calling Conversation service ...' + }); // call POST /message through SDK node.service.message(params, function(err, body) { processResponse(err, body, node, msg, config); @@ -187,12 +208,13 @@ module.exports = function (RED) { } // This is the Watson Conversation V1 (GA) Node - function WatsonConversationV1Node (config) { - var node = this, b = false; + function WatsonConversationV1Node(config) { + var node = this, + b = false; RED.nodes.createNode(this, config); - node.on('input', function (msg) { + node.on('input', function(msg) { var params = {}; node.status({}); @@ -215,8 +237,12 @@ module.exports = function (RED) { RED.nodes.registerType('watson-conversation-v1', WatsonConversationV1Node, { credentials: { - username: {type:'text'}, - password: {type:'password'} + username: { + type: 'text' + }, + password: { + type: 'password' + } } }); }; diff --git a/services/discovery/discovery-utils.js b/services/discovery/discovery-utils.js index 8154396b..28447ff3 100644 --- a/services/discovery/discovery-utils.js +++ b/services/discovery/discovery-utils.js @@ -36,13 +36,13 @@ DiscoveryUtils.prototype = { buildParamsForPayload: function(msg, config, params) { var isJSON = this.isJsonString(msg.payload) || - this.isJsonObject(msg.payload); + this.isJsonObject(msg.payload); // Payload (text to be analysed) must be a string (content is either raw string or Buffer) if (typeof msg.payload === 'string' || isJSON) { params.file = this.isJsonObject(msg.payload) ? - JSON.stringify(msg.payload) : - msg.payload; + JSON.stringify(msg.payload) : + msg.payload; } return params; }, @@ -69,13 +69,14 @@ DiscoveryUtils.prototype = { params = this.buildParamsForName(msg, config, params); - ['environment_id','collection_id','configuration_id', + ['environment_id', 'collection_id', 'configuration_id', 'collection_name', - 'query','description','size'].forEach(function(f) { + 'query', 'passages', 'description', 'size' + ].forEach(function(f) { params = me.buildParamsFor(msg, config, params, f); }); - ['count','filter','aggregation','return'].forEach(function(f) { + ['count', 'filter', 'aggregation', 'return'].forEach(function(f) { params = me.buildParamsFromConfig(config, params, f); }); @@ -107,11 +108,14 @@ DiscoveryUtils.prototype = { } params.query += config.query3 + ':"' + config.queryvalue3 + '"'; } + if (config.passages) { + params.passages = config.passages; + } return params; }, - paramEnvCheck: function (params) { + paramEnvCheck: function(params) { var response = ''; if (!params.environment_id) { response = 'Missing Environment ID '; @@ -119,7 +123,7 @@ DiscoveryUtils.prototype = { return response; }, - paramJSONCheck: function (params) { + paramJSONCheck: function(params) { var response = ''; if (!params.file) { response = 'Missing JSON file on payload'; @@ -127,7 +131,7 @@ DiscoveryUtils.prototype = { return response; }, - paramNameCheck: function (params) { + paramNameCheck: function(params) { var response = ''; if (!params.name) { response = 'Missing Name '; @@ -135,7 +139,7 @@ DiscoveryUtils.prototype = { return response; }, - paramDescriptionCheck: function (params) { + paramDescriptionCheck: function(params) { var response = ''; if (!params.description) { response = 'Missing Description '; @@ -143,7 +147,7 @@ DiscoveryUtils.prototype = { return response; }, - paramCollectionCheck: function (params) { + paramCollectionCheck: function(params) { var response = ''; if (!params.collection_id) { response = 'Missing Collection ID '; @@ -151,7 +155,7 @@ DiscoveryUtils.prototype = { return response; }, - paramConfigurationCheck: function (params) { + paramConfigurationCheck: function(params) { var response = ''; if (!params.configuration_id) { response = 'Missing Configuration ID '; @@ -184,7 +188,7 @@ DiscoveryUtils.prototype = { }, // sorting functions - uniqueFilter: function (value, index, self) { + uniqueFilter: function(value, index, self) { return self.indexOf(value) === index; }, @@ -194,8 +198,8 @@ DiscoveryUtils.prototype = { if ('object' === typeof schemaData) { for (var k in schemaData) { if ('results' === k && - 'object' === typeof schemaData[k] && - 'object' === typeof schemaData[k][0]) { + 'object' === typeof schemaData[k] && + 'object' === typeof schemaData[k][0]) { fields = this.buildFieldByStep(schemaData[k][0], fields, ''); } } @@ -206,11 +210,11 @@ DiscoveryUtils.prototype = { return fields; }, -// reportError: function (node, msg, message) { -// var messageTxt = message.error ? message.error : message; -// node.status({fill:'red', shape:'dot', text: messageTxt}); -// node.error(message, msg); -// } , + // reportError: function (node, msg, message) { + // var messageTxt = message.error ? message.error : message; + // node.status({fill:'red', shape:'dot', text: messageTxt}); + // node.error(message, msg); + // } , isJsonString: function(str) { try { diff --git a/services/discovery/v1-query-builder.html b/services/discovery/v1-query-builder.html index 089a8a75..0d3a5773 100644 --- a/services/discovery/v1-query-builder.html +++ b/services/discovery/v1-query-builder.html @@ -100,6 +100,15 @@ +