diff --git a/README.md b/README.md index 3f2ae4e5..87abef31 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,17 @@ Node-RED Watson Nodes for IBM Cloud CLA assistant +### New in version 0.6.8 +- Move all Discovery calls to latest API version - 2017-11-07 +- Updated calls to deprecated discovery methods addJsonDocument and getCollections +- Correct implemetation of passages related options +- Allow highlight option to be specified in Discovery overrides - msg.discoveryparams +- Rename Conversation Nodes to Assistant +- Use Assistant endpoint +- Move all Assistant calls to latest API version - 2018-02-16 +- Move all Visual Recognition calls to lates API version - 2018-03-19 +- Add French as a Visual Recognition classification response language + ### New in version 0.6.7 - Enable Opt-out option for Conversation Node. - Implement time out option for response from Conversation Node. diff --git a/package.json b/package.json index e49abf0d..ae188ce4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-red-node-watson", - "version": "0.6.7", + "version": "0.6.8", "description": "A collection of Node-RED nodes for IBM Watson services", "dependencies": { "async": "^1.5.2", @@ -10,7 +10,7 @@ "temp": "^0.8.3", "qs": "6.x", "image-type": "^2.0.2", - "watson-developer-cloud": "^3.2.1", + "watson-developer-cloud": "^3.3.0", "kuromoji": "^0.1.1", "word-count": "^0.2.2", "is-docx": "^0.0.3", diff --git a/services/conversation/v1-workspace-manager.html b/services/conversation/v1-workspace-manager.html index 33b31e71..973db218 100644 --- a/services/conversation/v1-workspace-manager.html +++ b/services/conversation/v1-workspace-manager.html @@ -45,7 +45,7 @@
- +
@@ -351,7 +351,7 @@
  • msg.params.password -
  • +
  • msg.params.workspace_id
  • @@ -592,7 +592,7 @@ 'cwm-dialog-node': {value:""}, 'cwm-export-content': {value:false}, 'cwm-default-endpoint' :{value: true}, - 'cwm-service-endpoint' :{value: 'https://gateway.watsonplatform.net/conversation/api'} + 'cwm-service-endpoint' :{value: 'https://gateway.watsonplatform.net/assistant/api'} }, credentials: { username: {type:'text'}, @@ -602,9 +602,9 @@ inputs: 1, outputs: 1, icon: 'conversation-v1-25x25.png', - paletteLabel: 'conversation workspace manager', + paletteLabel: 'assistant workspace manager', label: function() { - return this.name || 'conversation workspace manager'; + return this.name || 'assistant workspace manager'; }, labelStyle: function() { return this.name ? 'node_label_italic' : ''; diff --git a/services/conversation/v1-workspace-manager.js b/services/conversation/v1-workspace-manager.js index c1fe056a..5d4279dd 100644 --- a/services/conversation/v1-workspace-manager.js +++ b/services/conversation/v1-workspace-manager.js @@ -15,17 +15,23 @@ **/ module.exports = function (RED) { - const SERVICE_IDENTIFIER = 'conversation'; + const SERVICE_IDENTIFIER = 'assistant', + OLD_SERVICE_IDENTIFIER = 'conversation'; + var pkg = require('../../package.json'), temp = require('temp'), fs = require('fs'), serviceutils = require('../../utilities/service-utils'), payloadutils = require('../../utilities/payload-utils'), - ConversationV1 = require('watson-developer-cloud/conversation/v1'), + AssistantV1 = require('watson-developer-cloud/assistant/v1'), service = serviceutils.getServiceCreds(SERVICE_IDENTIFIER), username = '', password = '', sUsername = '', sPassword = '', endpoint = '', sEndpoint = ''; + if (!service) { + service = serviceutils.getServiceCreds(OLD_SERVICE_IDENTIFIER); + } + temp.track(); // Require the Cloud Foundry Module to pull credentials from bound service @@ -117,7 +123,7 @@ module.exports = function (RED) { function executeListIntents(node, conv, params, msg) { var p = new Promise(function resolver(resolve, reject){ - conv.getIntents(params, function (err, response) { + conv.listIntents(params, function (err, response) { if (err) { reject(err); } else { @@ -193,7 +199,7 @@ module.exports = function (RED) { // response function executeListExamples(node, conv, params, msg) { var p = new Promise(function resolver(resolve, reject){ - conv.getExamples(params, function (err, response) { + conv.listExamples(params, function (err, response) { if (err) { reject(err); } else { @@ -236,7 +242,7 @@ module.exports = function (RED) { function executeListCounterExamples(node, conv, params, msg) { var p = new Promise(function resolver(resolve, reject){ - conv.getCounterExamples(params, function (err, response) { + conv.listCounterexamples(params, function (err, response) { if (err) { reject(err); } else { @@ -251,7 +257,7 @@ module.exports = function (RED) { function executeCreateCounterExample(node, conv, params, msg) { var p = new Promise(function resolver(resolve, reject){ - conv.createCounterExample(params, function (err, response) { + conv.createCounterexample(params, function (err, response) { if (err) { reject(err); } else { @@ -265,7 +271,7 @@ module.exports = function (RED) { function executeDeleteCounterExample(node, conv, params, msg) { var p = new Promise(function resolver(resolve, reject){ - conv.deleteCounterExample(params, function (err, response) { + conv.deleteCounterexample(params, function (err, response) { if (err) { reject(err); } else { @@ -279,7 +285,7 @@ module.exports = function (RED) { function executeListEntities(node, conv, params, msg) { var p = new Promise(function resolver(resolve, reject){ - conv.getEntities(params, function (err, response) { + conv.listEntities(params, function (err, response) { if (err) { reject(err); } else { @@ -352,7 +358,7 @@ module.exports = function (RED) { function executeListEntityValues(node, conv, params, msg) { var p = new Promise(function resolver(resolve, reject){ - conv.getValues(params, function (err, response) { + conv.listValues(params, function (err, response) { if (err) { reject(err); } else { @@ -422,7 +428,7 @@ module.exports = function (RED) { function executeListDialogNodes(node, conv, params, msg) { var p = new Promise(function resolver(resolve, reject){ - conv.getDialogNodes(params, function (err, response) { + conv.listDialogNodes(params, function (err, response) { if (err) { reject(err); } else { @@ -499,7 +505,8 @@ module.exports = function (RED) { serviceSettings = { username: username, password: password, - version_date: '2017-05-26', + version_date: '2018-02-16', + version: '2018-02-16', headers: { 'User-Agent': pkg.name + '-' + pkg.version } @@ -509,7 +516,7 @@ module.exports = function (RED) { serviceSettings.url = endpoint; } - conv = new ConversationV1(serviceSettings); + conv = new AssistantV1(serviceSettings); node.status({fill:'blue', shape:'dot', text:'executing'}); @@ -1068,12 +1075,12 @@ module.exports = function (RED) { params = {}; username = sUsername || this.credentials.username; - password = sPassword || this.credentials.password || config.password; + password = sPassword || this.credentials.password || config.password; // All method to be overridden if (msg.params) { if (msg.params.method) { - method = msg.params.method; + method = msg.params.method; } if (msg.params.username) { username = msg.params.username; diff --git a/services/conversation/v1.html b/services/conversation/v1.html index f3079616..fbaa10c6 100644 --- a/services/conversation/v1.html +++ b/services/conversation/v1.html @@ -42,7 +42,7 @@
    - +
    @@ -159,7 +159,7 @@ context: {value: true}, 'empty-payload': {value: false}, 'default-endpoint' : {value: true}, - 'service-endpoint' : {value: 'https://gateway.watsonplatform.net/conversation/api'}, + 'service-endpoint' : {value: 'https://gateway.watsonplatform.net/assistant/api'}, timeout: {value: '', validate: RED.validators.number(true)}, 'optout-learning': {value: false} }, @@ -171,9 +171,9 @@ inputs: 1, outputs: 1, icon: 'conversation-v1-25x25.png', - paletteLabel: 'conversation', + paletteLabel: 'assistant', label: function() { - return this.name || 'conversation'; + return this.name || 'assistant'; }, labelStyle: function() { return this.name ? 'node_label_italic' : ''; diff --git a/services/conversation/v1.js b/services/conversation/v1.js index c5a97811..bc829884 100644 --- a/services/conversation/v1.js +++ b/services/conversation/v1.js @@ -15,15 +15,20 @@ **/ module.exports = function(RED) { - const SERVICE_IDENTIFIER = 'conversation'; + const SERVICE_IDENTIFIER = 'assistant', + OLD_SERVICE_IDENTIFIER = 'conversation'; + var pkg = require('../../package.json'), - ConversationV1 = require('watson-developer-cloud/conversation/v1'), + AssistantV1 = require('watson-developer-cloud/assistant/v1'), serviceutils = require('../../utilities/service-utils'), service = null, sUsername = null, sPassword = null; service = serviceutils.getServiceCreds(SERVICE_IDENTIFIER); + if (!service) { + service = serviceutils.getServiceCreds(OLD_SERVICE_IDENTIFIER); + } if (service) { sUsername = service.username; @@ -136,7 +141,8 @@ module.exports = function(RED) { // If msg.params contain credentials then these will Overridde // the bound or configured credentials. const serviceSettings = { - version_date: '2017-05-26', + version_date: '2018-02-16', + version: '2018-02-16', headers: { 'User-Agent': pkg.name + '-' + pkg.version } @@ -203,7 +209,7 @@ module.exports = function(RED) { serviceSettings.timeout = parseInt(msg.params.timeout); } - node.service = new ConversationV1(serviceSettings); + node.service = new AssistantV1(serviceSettings); return true; } diff --git a/services/discovery/discovery-utils.js b/services/discovery/discovery-utils.js index 29de768d..ff235139 100644 --- a/services/discovery/discovery-utils.js +++ b/services/discovery/discovery-utils.js @@ -71,6 +71,35 @@ DiscoveryUtils.prototype = { return params; }, + buildParamsForPassages: function (me, msg, config, params) { + let passagesFound = false; + + // Allow the passages parameters to be passed in two ways + // 1. As the API is expecting + ['passages.fields', 'passages.count', 'passages.characters' + ].forEach(function(f) { + params = me.buildParamsFor(msg, config, params, f); + passagesFound = true; + }); + + // 2. As anyone misreading the documentation might do it. + if (msg.discoveryparams && msg.discoveryparams.passages) { + passagesFound = true; + ['fields', 'count', 'characters' + ].forEach(function(f) { + if (msg.discoveryparams.passages[f]) { + params['passages.' + f] = msg.discoveryparams.passages[f]; + } + }); + } + + if (passagesFound) { + params.passages = true; + } + + return params; + }, + buildParamsFromConfig: function(config, params, field) { if (config[field]) { params[field] = config[field]; @@ -96,11 +125,14 @@ DiscoveryUtils.prototype = { ['environment_id', 'collection_id', 'configuration_id', 'collection_name', 'language_code', - 'passages', 'description', 'size', 'filename' + 'passages', 'description', 'size', 'filename', + 'highlight' ].forEach(function(f) { params = me.buildParamsFor(msg, config, params, f); }); + params = me.buildParamsForPassages(me, msg, config, params); + ['count', 'filter', 'aggregation', 'return'].forEach(function(f) { params = me.buildParamsFromConfig(config, params, f); }); diff --git a/services/discovery/v1-document-loader.js b/services/discovery/v1-document-loader.js index b58b0661..72a62bb4 100644 --- a/services/discovery/v1-document-loader.js +++ b/services/discovery/v1-document-loader.js @@ -130,7 +130,7 @@ module.exports = function (RED) { serviceSettings = { username: username, password: password, - version_date: '2017-09-01', + version_date: '2017-11-07', headers: { 'User-Agent': pkg.name + '-' + pkg.version } @@ -141,12 +141,13 @@ module.exports = function (RED) { } discovery = new DiscoveryV1(serviceSettings); - - if ('.json' === suffix) { - method = 'addJsonDocument'; - } else { - method = 'addDocument'; - } + // addJsonDocument is deprecated + //if ('.json' === suffix) { + // method = 'addJsonDocument'; + //} else { + // method = 'addDocument'; + //} + method = 'addDocument'; discovery[method](params, function (err, response) { if (err) { diff --git a/services/discovery/v1-query-builder.js b/services/discovery/v1-query-builder.js index 38e72619..fe44210e 100644 --- a/services/discovery/v1-query-builder.js +++ b/services/discovery/v1-query-builder.js @@ -70,7 +70,7 @@ module.exports = function(RED) { } }); - discovery.getCollections({ + discovery.listCollections({ environment_id: req.query.environment_id }, function(err, response) { diff --git a/services/discovery/v1.js b/services/discovery/v1.js index e598917e..6df6a25a 100644 --- a/services/discovery/v1.js +++ b/services/discovery/v1.js @@ -251,7 +251,7 @@ module.exports = function (RED) { serviceSettings = { username: username, password: password, - version_date: '2017-09-01', + version_date: '2017-11-07', headers: { 'User-Agent': pkg.name + '-' + pkg.version } diff --git a/services/visual_recognition/v3.html b/services/visual_recognition/v3.html index f3072be2..ce8f70bf 100644 --- a/services/visual_recognition/v3.html +++ b/services/visual_recognition/v3.html @@ -41,6 +41,7 @@ + diff --git a/services/visual_recognition/v3.js b/services/visual_recognition/v3.js index 694bd52e..be982bfb 100644 --- a/services/visual_recognition/v3.js +++ b/services/visual_recognition/v3.js @@ -144,7 +144,7 @@ module.exports = function(RED) { var serviceSettings = { api_key: node.apikey, - version_date: VisualRecognitionV3.VERSION_DATE_2016_05_20, + version_date: '2018-03-19', headers: { 'User-Agent': pkg.name + '-' + pkg.version }