Skip to content

Commit e98a06d

Browse files
authored
Merge pull request #142 from watson-developer-cloud/master
Rebasing
2 parents 182ca0e + a3cd49a commit e98a06d

File tree

12 files changed

+98
-40
lines changed

12 files changed

+98
-40
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ Node-RED Watson Nodes for IBM Cloud
77

88
<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>
99

10+
### New in version 0.6.8
11+
- Move all Discovery calls to latest API version - 2017-11-07
12+
- Updated calls to deprecated discovery methods addJsonDocument and getCollections
13+
- Correct implemetation of passages related options
14+
- Allow highlight option to be specified in Discovery overrides - msg.discoveryparams
15+
- Rename Conversation Nodes to Assistant
16+
- Use Assistant endpoint
17+
- Move all Assistant calls to latest API version - 2018-02-16
18+
- Move all Visual Recognition calls to lates API version - 2018-03-19
19+
- Add French as a Visual Recognition classification response language
20+
1021
### New in version 0.6.7
1122
- Enable Opt-out option for Conversation Node.
1223
- Implement time out option for response from Conversation Node.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-node-watson",
3-
"version": "0.6.7",
3+
"version": "0.6.8",
44
"description": "A collection of Node-RED nodes for IBM Watson services",
55
"dependencies": {
66
"async": "^1.5.2",
@@ -10,7 +10,7 @@
1010
"temp": "^0.8.3",
1111
"qs": "6.x",
1212
"image-type": "^2.0.2",
13-
"watson-developer-cloud": "^3.2.1",
13+
"watson-developer-cloud": "^3.3.0",
1414
"kuromoji": "^0.1.1",
1515
"word-count": "^0.2.2",
1616
"is-docx": "^0.0.3",

services/conversation/v1-workspace-manager.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
</div>
4646
<div class="form-row">
4747
<label for="node-input-cwm-service-endpoint"><i class="fa fa-tag"></i> Service Endpoint</label>
48-
<input type="text" id="node-input-cwm-service-endpoint" placeholder="https://gateway.watsonplatform.net/conversation/api">
48+
<input type="text" id="node-input-cwm-service-endpoint" placeholder="https://gateway.watsonplatform.net/assistant/api">
4949
</div>
5050

5151
<div class="form-row">
@@ -351,7 +351,7 @@
351351
</li>
352352
<li>
353353
<code>msg.params.password</code>
354-
</li>
354+
</li>
355355
<li>
356356
<code>msg.params.workspace_id</code>
357357
</li>
@@ -592,7 +592,7 @@
592592
'cwm-dialog-node': {value:""},
593593
'cwm-export-content': {value:false},
594594
'cwm-default-endpoint' :{value: true},
595-
'cwm-service-endpoint' :{value: 'https://gateway.watsonplatform.net/conversation/api'}
595+
'cwm-service-endpoint' :{value: 'https://gateway.watsonplatform.net/assistant/api'}
596596
},
597597
credentials: {
598598
username: {type:'text'},
@@ -602,9 +602,9 @@
602602
inputs: 1,
603603
outputs: 1,
604604
icon: 'conversation-v1-25x25.png',
605-
paletteLabel: 'conversation workspace manager',
605+
paletteLabel: 'assistant workspace manager',
606606
label: function() {
607-
return this.name || 'conversation workspace manager';
607+
return this.name || 'assistant workspace manager';
608608
},
609609
labelStyle: function() {
610610
return this.name ? 'node_label_italic' : '';

services/conversation/v1-workspace-manager.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,23 @@
1515
**/
1616

1717
module.exports = function (RED) {
18-
const SERVICE_IDENTIFIER = 'conversation';
18+
const SERVICE_IDENTIFIER = 'assistant',
19+
OLD_SERVICE_IDENTIFIER = 'conversation';
20+
1921
var pkg = require('../../package.json'),
2022
temp = require('temp'),
2123
fs = require('fs'),
2224
serviceutils = require('../../utilities/service-utils'),
2325
payloadutils = require('../../utilities/payload-utils'),
24-
ConversationV1 = require('watson-developer-cloud/conversation/v1'),
26+
AssistantV1 = require('watson-developer-cloud/assistant/v1'),
2527
service = serviceutils.getServiceCreds(SERVICE_IDENTIFIER),
2628
username = '', password = '', sUsername = '', sPassword = '',
2729
endpoint = '', sEndpoint = '';
2830

31+
if (!service) {
32+
service = serviceutils.getServiceCreds(OLD_SERVICE_IDENTIFIER);
33+
}
34+
2935
temp.track();
3036

3137
// Require the Cloud Foundry Module to pull credentials from bound service
@@ -117,7 +123,7 @@ module.exports = function (RED) {
117123

118124
function executeListIntents(node, conv, params, msg) {
119125
var p = new Promise(function resolver(resolve, reject){
120-
conv.getIntents(params, function (err, response) {
126+
conv.listIntents(params, function (err, response) {
121127
if (err) {
122128
reject(err);
123129
} else {
@@ -193,7 +199,7 @@ module.exports = function (RED) {
193199
// response
194200
function executeListExamples(node, conv, params, msg) {
195201
var p = new Promise(function resolver(resolve, reject){
196-
conv.getExamples(params, function (err, response) {
202+
conv.listExamples(params, function (err, response) {
197203
if (err) {
198204
reject(err);
199205
} else {
@@ -236,7 +242,7 @@ module.exports = function (RED) {
236242

237243
function executeListCounterExamples(node, conv, params, msg) {
238244
var p = new Promise(function resolver(resolve, reject){
239-
conv.getCounterExamples(params, function (err, response) {
245+
conv.listCounterexamples(params, function (err, response) {
240246
if (err) {
241247
reject(err);
242248
} else {
@@ -251,7 +257,7 @@ module.exports = function (RED) {
251257

252258
function executeCreateCounterExample(node, conv, params, msg) {
253259
var p = new Promise(function resolver(resolve, reject){
254-
conv.createCounterExample(params, function (err, response) {
260+
conv.createCounterexample(params, function (err, response) {
255261
if (err) {
256262
reject(err);
257263
} else {
@@ -265,7 +271,7 @@ module.exports = function (RED) {
265271

266272
function executeDeleteCounterExample(node, conv, params, msg) {
267273
var p = new Promise(function resolver(resolve, reject){
268-
conv.deleteCounterExample(params, function (err, response) {
274+
conv.deleteCounterexample(params, function (err, response) {
269275
if (err) {
270276
reject(err);
271277
} else {
@@ -279,7 +285,7 @@ module.exports = function (RED) {
279285

280286
function executeListEntities(node, conv, params, msg) {
281287
var p = new Promise(function resolver(resolve, reject){
282-
conv.getEntities(params, function (err, response) {
288+
conv.listEntities(params, function (err, response) {
283289
if (err) {
284290
reject(err);
285291
} else {
@@ -352,7 +358,7 @@ module.exports = function (RED) {
352358

353359
function executeListEntityValues(node, conv, params, msg) {
354360
var p = new Promise(function resolver(resolve, reject){
355-
conv.getValues(params, function (err, response) {
361+
conv.listValues(params, function (err, response) {
356362
if (err) {
357363
reject(err);
358364
} else {
@@ -422,7 +428,7 @@ module.exports = function (RED) {
422428

423429
function executeListDialogNodes(node, conv, params, msg) {
424430
var p = new Promise(function resolver(resolve, reject){
425-
conv.getDialogNodes(params, function (err, response) {
431+
conv.listDialogNodes(params, function (err, response) {
426432
if (err) {
427433
reject(err);
428434
} else {
@@ -499,7 +505,8 @@ module.exports = function (RED) {
499505
serviceSettings = {
500506
username: username,
501507
password: password,
502-
version_date: '2017-05-26',
508+
version_date: '2018-02-16',
509+
version: '2018-02-16',
503510
headers: {
504511
'User-Agent': pkg.name + '-' + pkg.version
505512
}
@@ -509,7 +516,7 @@ module.exports = function (RED) {
509516
serviceSettings.url = endpoint;
510517
}
511518

512-
conv = new ConversationV1(serviceSettings);
519+
conv = new AssistantV1(serviceSettings);
513520

514521
node.status({fill:'blue', shape:'dot', text:'executing'});
515522

@@ -1068,12 +1075,12 @@ module.exports = function (RED) {
10681075
params = {};
10691076

10701077
username = sUsername || this.credentials.username;
1071-
password = sPassword || this.credentials.password || config.password;
1078+
password = sPassword || this.credentials.password || config.password;
10721079

10731080
// All method to be overridden
10741081
if (msg.params) {
10751082
if (msg.params.method) {
1076-
method = msg.params.method;
1083+
method = msg.params.method;
10771084
}
10781085
if (msg.params.username) {
10791086
username = msg.params.username;

services/conversation/v1.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</div>
4343
<div class="form-row">
4444
<label for="node-input-service-endpoint"><i class="fa fa-tag"></i> Service Endpoint</label>
45-
<input type="text" id="node-input-service-endpoint" placeholder="https://gateway.watsonplatform.net/conversation/api">
45+
<input type="text" id="node-input-service-endpoint" placeholder="https://gateway.watsonplatform.net/assistant/api">
4646
</div>
4747

4848
<div class="form-row">
@@ -159,7 +159,7 @@
159159
context: {value: true},
160160
'empty-payload': {value: false},
161161
'default-endpoint' : {value: true},
162-
'service-endpoint' : {value: 'https://gateway.watsonplatform.net/conversation/api'},
162+
'service-endpoint' : {value: 'https://gateway.watsonplatform.net/assistant/api'},
163163
timeout: {value: '', validate: RED.validators.number(true)},
164164
'optout-learning': {value: false}
165165
},
@@ -171,9 +171,9 @@
171171
inputs: 1,
172172
outputs: 1,
173173
icon: 'conversation-v1-25x25.png',
174-
paletteLabel: 'conversation',
174+
paletteLabel: 'assistant',
175175
label: function() {
176-
return this.name || 'conversation';
176+
return this.name || 'assistant';
177177
},
178178
labelStyle: function() {
179179
return this.name ? 'node_label_italic' : '';

services/conversation/v1.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,20 @@
1515
**/
1616

1717
module.exports = function(RED) {
18-
const SERVICE_IDENTIFIER = 'conversation';
18+
const SERVICE_IDENTIFIER = 'assistant',
19+
OLD_SERVICE_IDENTIFIER = 'conversation';
20+
1921
var pkg = require('../../package.json'),
20-
ConversationV1 = require('watson-developer-cloud/conversation/v1'),
22+
AssistantV1 = require('watson-developer-cloud/assistant/v1'),
2123
serviceutils = require('../../utilities/service-utils'),
2224
service = null,
2325
sUsername = null,
2426
sPassword = null;
2527

2628
service = serviceutils.getServiceCreds(SERVICE_IDENTIFIER);
29+
if (!service) {
30+
service = serviceutils.getServiceCreds(OLD_SERVICE_IDENTIFIER);
31+
}
2732

2833
if (service) {
2934
sUsername = service.username;
@@ -136,7 +141,8 @@ module.exports = function(RED) {
136141
// If msg.params contain credentials then these will Overridde
137142
// the bound or configured credentials.
138143
const serviceSettings = {
139-
version_date: '2017-05-26',
144+
version_date: '2018-02-16',
145+
version: '2018-02-16',
140146
headers: {
141147
'User-Agent': pkg.name + '-' + pkg.version
142148
}
@@ -203,7 +209,7 @@ module.exports = function(RED) {
203209
serviceSettings.timeout = parseInt(msg.params.timeout);
204210
}
205211

206-
node.service = new ConversationV1(serviceSettings);
212+
node.service = new AssistantV1(serviceSettings);
207213
return true;
208214
}
209215

services/discovery/discovery-utils.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,35 @@ DiscoveryUtils.prototype = {
7171
return params;
7272
},
7373

74+
buildParamsForPassages: function (me, msg, config, params) {
75+
let passagesFound = false;
76+
77+
// Allow the passages parameters to be passed in two ways
78+
// 1. As the API is expecting
79+
['passages.fields', 'passages.count', 'passages.characters'
80+
].forEach(function(f) {
81+
params = me.buildParamsFor(msg, config, params, f);
82+
passagesFound = true;
83+
});
84+
85+
// 2. As anyone misreading the documentation might do it.
86+
if (msg.discoveryparams && msg.discoveryparams.passages) {
87+
passagesFound = true;
88+
['fields', 'count', 'characters'
89+
].forEach(function(f) {
90+
if (msg.discoveryparams.passages[f]) {
91+
params['passages.' + f] = msg.discoveryparams.passages[f];
92+
}
93+
});
94+
}
95+
96+
if (passagesFound) {
97+
params.passages = true;
98+
}
99+
100+
return params;
101+
},
102+
74103
buildParamsFromConfig: function(config, params, field) {
75104
if (config[field]) {
76105
params[field] = config[field];
@@ -96,11 +125,14 @@ DiscoveryUtils.prototype = {
96125

97126
['environment_id', 'collection_id', 'configuration_id',
98127
'collection_name', 'language_code',
99-
'passages', 'description', 'size', 'filename'
128+
'passages', 'description', 'size', 'filename',
129+
'highlight'
100130
].forEach(function(f) {
101131
params = me.buildParamsFor(msg, config, params, f);
102132
});
103133

134+
params = me.buildParamsForPassages(me, msg, config, params);
135+
104136
['count', 'filter', 'aggregation', 'return'].forEach(function(f) {
105137
params = me.buildParamsFromConfig(config, params, f);
106138
});

services/discovery/v1-document-loader.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ module.exports = function (RED) {
130130
serviceSettings = {
131131
username: username,
132132
password: password,
133-
version_date: '2017-09-01',
133+
version_date: '2017-11-07',
134134
headers: {
135135
'User-Agent': pkg.name + '-' + pkg.version
136136
}
@@ -141,12 +141,13 @@ module.exports = function (RED) {
141141
}
142142

143143
discovery = new DiscoveryV1(serviceSettings);
144-
145-
if ('.json' === suffix) {
146-
method = 'addJsonDocument';
147-
} else {
148-
method = 'addDocument';
149-
}
144+
// addJsonDocument is deprecated
145+
//if ('.json' === suffix) {
146+
// method = 'addJsonDocument';
147+
//} else {
148+
// method = 'addDocument';
149+
//}
150+
method = 'addDocument';
150151

151152
discovery[method](params, function (err, response) {
152153
if (err) {

services/discovery/v1-query-builder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ module.exports = function(RED) {
7070
}
7171
});
7272

73-
discovery.getCollections({
73+
discovery.listCollections({
7474
environment_id: req.query.environment_id
7575
},
7676
function(err, response) {

services/discovery/v1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ module.exports = function (RED) {
251251
serviceSettings = {
252252
username: username,
253253
password: password,
254-
version_date: '2017-09-01',
254+
version_date: '2017-11-07',
255255
headers: {
256256
'User-Agent': pkg.name + '-' + pkg.version
257257
}

0 commit comments

Comments
 (0)