Skip to content

Commit d985ea0

Browse files
authored
Merge pull request #216 from chughts/discovery
Discovery V1 Experimental
2 parents b9e05c7 + 16a2ee5 commit d985ea0

File tree

5 files changed

+200
-2
lines changed

5 files changed

+200
-2
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ Node-RED Watson Nodes for IBM Bluemix
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.4.28
11+
- New V1 Experimental Discovery Node
12+
1013
### New in version 0.4.27
1114
- Change color of V3 Personality Insights Node
1215

@@ -137,6 +140,8 @@ A collection of nodes to interact with the IBM Watson services in [IBM Bluemix](
137140
- Dialog
138141
- Automate branching conversation between a user and your application.
139142
- Use natural language to automatically respond to user questions, cross-sell and up-sell, walk users through processes or applications, or even hand-hold users through difficult tasks.
143+
- Discovery
144+
- List environments created for the Discovery service
140145
- Document Conversion
141146
- Prepare documents for the Retrieve and Rank service.
142147
- Feature Extract

package.json

Lines changed: 3 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.4.27",
3+
"version": "0.4.28",
44
"description": "A collection of Node-RED nodes for IBM Watson services",
55
"dependencies": {
66
"alchemy-api": "^1.3.0",
@@ -11,7 +11,7 @@
1111
"temp": "^0.8.3",
1212
"qs": "6.x",
1313
"image-type": "^2.0.2",
14-
"watson-developer-cloud": "^2.7.1",
14+
"watson-developer-cloud": "^2.8.2",
1515
"kuromoji": "^0.0.5",
1616
"is-docx": "^0.0.3"
1717
},
@@ -34,6 +34,7 @@
3434
"nodes": {
3535
"watson-conversation-v1":"services/conversation/v1.js",
3636
"watson-conversation-v1-experimental":"services/conversation/v1-exp.js",
37+
"watson-discovery-v1-experimental":"services/discovery/v1-exp.js",
3738
"watson-document-conversion-v1": "services/document_conversion/v1.js",
3839
"watson-concept-insights-v2": "services/concept_insights/v2.js",
3940
"alchemy-date-extraction": "services/alchemy_date_extraction/v1.js",
630 Bytes
Loading

services/discovery/v1-exp.html

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<!--
2+
Copyright 2016 IBM Corp.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<script type="text/x-red" data-template-name="watson-discovery">
18+
<div id="credentials-check" class="form-row">
19+
<div class="form-tips">
20+
<i class="fa fa-question-circle"></i><b> Please wait: </b> Checking for bound service credentials...
21+
</div>
22+
</div>
23+
<div class="form-row">
24+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
25+
<input type="text" id="node-input-name" placeholder="Name">
26+
</div>
27+
<div class="form-row credentials" style="display: none;">
28+
<label for="node-input-username"><i class="fa fa-user"></i> Username</label>
29+
<input type="text" id="node-input-username" placeholder="Username">
30+
</div>
31+
<div class="form-row credentials" style="display: none;">
32+
<label for="node-input-password"><i class="fa fa-key"></i> Password</label>
33+
<input type="password" id="node-input-password" placeholder="Password">
34+
</div>
35+
<div class="form-row">
36+
<label for="node-input-environmentname"><i class="fa fa-tag"></i> Environment Name</label>
37+
<input type="text" id="node-input-envrionmentname" placeholder="">
38+
</div>
39+
</script>
40+
41+
<script type="text/x-red" data-help-name="watson-discovery">
42+
<p>This is the Node for the V1 Experimental Watson Discovery service.</p>
43+
<p>This version of the Node will only list the envrionments created for
44+
the service.
45+
</p>
46+
<p>The node does not need any input. If the envrionment name field is left blank
47+
it will list all envrionments created for the instance of the Discovery service.
48+
If the envrionment name is specified, then only the details for
49+
the Discovery envrionment with the specified name will be returned.
50+
</p>
51+
<p>The environment being requested can be overridden by specifying the search name
52+
in <code>msg.discoveryparams.envrionmentname</code>
53+
</p>
54+
55+
<p>Node output : </p>
56+
<ul>
57+
<li><code>msg.envrionments</code> : A list of the envrionments created under
58+
the Discovery service instance.</li>
59+
</ul>
60+
<p>For more information about the Discovery service,
61+
read the service <a href="https://www.ibm.com/watson/developercloud/doc/discovery/">documentation</a>.</p>
62+
</script>
63+
64+
<script type="text/javascript">
65+
(function() {
66+
RED.nodes.registerType('watson-discovery', {
67+
category: 'IBM Watson',
68+
defaults: {
69+
name: {value: ""},
70+
envrionmentname: {value: ""}
71+
},
72+
credentials: {
73+
username: {type:"text"},
74+
password: {type:"password"}
75+
},
76+
color: "rgb(84,149,230)",
77+
inputs: 1,
78+
outputs: 1,
79+
icon: "discovery.png",
80+
paletteLabel: "discovery",
81+
label: function() {
82+
return this.name || "discovery";
83+
},
84+
labelStyle: function() {
85+
return this.name ? "node_label_italic" : "";
86+
},
87+
oneditprepare: function() {
88+
$.getJSON('watson-discovery/vcap/')
89+
.done(function (service) {
90+
$('.credentials').toggle(!service);
91+
})
92+
.fail(function () {
93+
$('.credentials').show();
94+
}).always(function () {
95+
$('#credentials-check').hide();
96+
})
97+
}
98+
});
99+
})();
100+
</script>

services/discovery/v1-exp.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/**
2+
* Copyright 20016 IBM Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the 'License');
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an 'AS IS' BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
**/
16+
17+
module.exports = function (RED) {
18+
19+
function buildParams(msg,config) {
20+
var params = {};
21+
if (msg.discoveryparams && msg.discoveryparams.envrionmentname) {
22+
params.name = msg.discoveryparams.envrionmentname;
23+
} else if (config.envrionmentname) {
24+
params.name = config.envrionmentname;
25+
}
26+
return params;
27+
}
28+
29+
var DiscoveryV1Experimental = require('watson-developer-cloud/discovery/v1-experimental'),
30+
cfenv = require('cfenv'),
31+
service = cfenv.getAppEnv().getServiceCreds(/discovery/i),
32+
username = null,
33+
password = null,
34+
sUsername = null,
35+
sPassword = null;
36+
37+
if (service) {
38+
sUsername = service.username;
39+
sPassword = service.password;
40+
}
41+
42+
RED.httpAdmin.get('/watson-discovery/vcap', function (req, res) {
43+
res.json(service ? {bound_service: true} : null);
44+
});
45+
46+
function Node (config) {
47+
var node = this;
48+
RED.nodes.createNode(this, config);
49+
50+
this.on('input', function (msg) {
51+
var message = '',
52+
params = {};
53+
54+
username = sUsername || this.credentials.username;
55+
password = sPassword || this.credentials.password;
56+
57+
if (!username || !password) {
58+
message = 'Missing Watson Discovery service credentials';
59+
node.error(message, msg);
60+
return;
61+
}
62+
63+
var discovery = new DiscoveryV1Experimental({
64+
username: username,
65+
password: password,
66+
version_date: '2016-11-07'
67+
});
68+
69+
params = buildParams(msg,config);
70+
node.status({fill:'blue', shape:'dot', text:'requesting'});
71+
72+
discovery.getEnvironments(params, function (err, response) {
73+
node.status({});
74+
if (err) {
75+
console.log(err);
76+
node.status({fill:'red', shape:'dot', text:err.error});
77+
node.error(err, msg);
78+
} else {
79+
msg.environments = response.environments ? response.environments : [];
80+
}
81+
node.send(msg);
82+
});
83+
});
84+
}
85+
86+
RED.nodes.registerType('watson-discovery', Node, {
87+
credentials: {
88+
username: {type:'text'},
89+
password: {type:'password'}
90+
}
91+
});
92+
};

0 commit comments

Comments
 (0)