Skip to content

Commit 9633995

Browse files
committed
Migrate to ibm-watson
1 parent 87386fd commit 9633995

File tree

4 files changed

+41
-16
lines changed

4 files changed

+41
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ During the migration there will be a dependancy on both modules.
5454
- Update language lists for STT, TTS, Language Translator and Document Translator Nodes
5555

5656
### Watson Nodes for Node-RED
57-
A collection of nodes to interact with the IBM Watson services in [IBM Cloud](http://bluemix.net).
57+
A collection of nodes to interact with the IBM Watson services in [IBM Cloud](http://cloud.ibm.com).
5858

5959
# Nodes
6060

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"license": "Apache-2.0",
2525
"keywords": [
2626
"node-red",
27-
"bluemix",
27+
"ibm-cloud",
2828
"watson"
2929
],
3030
"contributors": [

services/discovery/discovery-utils.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,16 @@ DiscoveryUtils.prototype = {
104104
buildParamsForPassages: function (me, msg, config, params) {
105105
let passagesFound = false;
106106

107-
// Allow the passages parameters to be passed in two ways
108-
// 1. As the API is expecting
107+
// Allow the passages parameters to be passed in three ways
108+
// 1. As the API was expecting (watson-developer-cloud)
109109
['passages.fields', 'passages.count', 'passages.characters'
110110
].forEach(function(f) {
111111
params = me.buildParamsFor(msg, config, params, f);
112112
passagesFound = true;
113113
});
114114

115115
// 2. As anyone misreading the documentation might do it.
116+
// (again watson-developer-cloud)
116117
if (msg.discoveryparams && msg.discoveryparams.passages) {
117118
passagesFound = true;
118119
['fields', 'count', 'characters'
@@ -123,7 +124,25 @@ DiscoveryUtils.prototype = {
123124
});
124125
}
125126

127+
// 3. As the ibm-watson SDK expects
128+
['passagesFields', 'passagesCount', 'passagesCharacters'
129+
].forEach(function(f) {
130+
params = me.buildParamsFor(msg, config, params, f);
131+
passagesFound = true;
132+
});
133+
126134
if (passagesFound) {
135+
// Perform autocorrect for watson-developer-cloud to ibm-watson
136+
// differences
137+
['passages.fields', 'passages.count', 'passages.characters'
138+
].forEach(function(f) {
139+
if (params[f]) {
140+
let parts = f.split(".");
141+
let secondPart = parts[1]
142+
let reformedField = parts[0] + secondPart[0].toUpperCase() + secondPart.slice(1);
143+
params[reformedField] = params[f];
144+
}
145+
});
127146
params.passages = true;
128147
}
129148

services/discovery/v1.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -251,27 +251,33 @@ module.exports = function (RED) {
251251

252252
function executeQuery(node, discovery, params, msg) {
253253
var p = new Promise(function resolver(resolve, reject){
254-
discovery.query(params, function (err, response) {
255-
if (err) {
256-
reject(err);
257-
} else {
254+
discovery.query(params)
255+
.then((response) => {
258256
msg.search_results = response;
257+
if (response && response.result) {
258+
msg.search_results = response.result;
259+
}
259260
resolve();
260-
}
261-
});
261+
})
262+
.catch((err) => {
263+
reject(err);
264+
});
262265
});
263266
return p;
264267
}
265268

266269
function executeQueryNotices(node, discovery, params, msg) {
267270
var p = new Promise(function resolver(resolve, reject){
268-
discovery.queryNotices(params, function (err, response) {
269-
if (err) {
270-
reject(err);
271-
} else {
272-
msg.search_results = response;
273-
resolve();
271+
discovery.queryNotices(params)
272+
.then((response) => {
273+
msg.search_results = response;
274+
if (response && response.result) {
275+
msg.search_results = response.result;
274276
}
277+
resolve();
278+
})
279+
.catch((err) => {
280+
reject(err);
275281
});
276282
});
277283
return p;

0 commit comments

Comments
 (0)