Skip to content

Commit

Permalink
Merge pull request #398 from chughts/discover
Browse files Browse the repository at this point in the history
Discover
  • Loading branch information
chughts committed Apr 22, 2018
2 parents 24ce5a0 + 7f2d26c commit a3cd49a
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 40 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ Node-RED Watson Nodes for IBM Cloud

<a href="https://cla-assistant.io/watson-developer-cloud/node-red-node-watson"><img src="https://cla-assistant.io/readme/badge/watson-developer-cloud/node-red-node-watson" alt="CLA assistant" /></a>

### 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.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions services/conversation/v1-workspace-manager.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</div>
<div class="form-row">
<label for="node-input-cwm-service-endpoint"><i class="fa fa-tag"></i> Service Endpoint</label>
<input type="text" id="node-input-cwm-service-endpoint" placeholder="https://gateway.watsonplatform.net/conversation/api">
<input type="text" id="node-input-cwm-service-endpoint" placeholder="https://gateway.watsonplatform.net/assistant/api">
</div>

<div class="form-row">
Expand Down Expand Up @@ -351,7 +351,7 @@
</li>
<li>
<code>msg.params.password</code>
</li>
</li>
<li>
<code>msg.params.workspace_id</code>
</li>
Expand Down Expand Up @@ -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'},
Expand All @@ -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' : '';
Expand Down
35 changes: 21 additions & 14 deletions services/conversation/v1-workspace-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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'});

Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions services/conversation/v1.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</div>
<div class="form-row">
<label for="node-input-service-endpoint"><i class="fa fa-tag"></i> Service Endpoint</label>
<input type="text" id="node-input-service-endpoint" placeholder="https://gateway.watsonplatform.net/conversation/api">
<input type="text" id="node-input-service-endpoint" placeholder="https://gateway.watsonplatform.net/assistant/api">
</div>

<div class="form-row">
Expand Down Expand Up @@ -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}
},
Expand All @@ -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' : '';
Expand Down
14 changes: 10 additions & 4 deletions services/conversation/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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;
}

Expand Down
34 changes: 33 additions & 1 deletion services/discovery/discovery-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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);
});
Expand Down
15 changes: 8 additions & 7 deletions services/discovery/v1-document-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion services/discovery/v1-query-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ module.exports = function(RED) {
}
});

discovery.getCollections({
discovery.listCollections({
environment_id: req.query.environment_id
},
function(err, response) {
Expand Down
2 changes: 1 addition & 1 deletion services/discovery/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions services/visual_recognition/v3.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<option selected="selected" value="en">English</option>
<option value="es">Spanish</option>
<option value="de">German</option>
<option value="fr">French</option>
<option value="it">Italian</option>
<option value="ar">Arabic</option>
<option value="ja">Japanese</option>
Expand Down
2 changes: 1 addition & 1 deletion services/visual_recognition/v3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit a3cd49a

Please sign in to comment.