Skip to content

Commit

Permalink
Merge pull request #216 from chughts/discovery
Browse files Browse the repository at this point in the history
Discovery V1 Experimental
  • Loading branch information
chughts committed Nov 10, 2016
2 parents b9e05c7 + 16a2ee5 commit d985ea0
Show file tree
Hide file tree
Showing 5 changed files with 200 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Node-RED Watson Nodes for IBM Bluemix

<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.4.28
- New V1 Experimental Discovery Node

### New in version 0.4.27
- Change color of V3 Personality Insights Node

Expand Down Expand Up @@ -137,6 +140,8 @@ A collection of nodes to interact with the IBM Watson services in [IBM Bluemix](
- Dialog
- Automate branching conversation between a user and your application.
- 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.
- Discovery
- List environments created for the Discovery service
- Document Conversion
- Prepare documents for the Retrieve and Rank service.
- Feature Extract
Expand Down
5 changes: 3 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.4.27",
"version": "0.4.28",
"description": "A collection of Node-RED nodes for IBM Watson services",
"dependencies": {
"alchemy-api": "^1.3.0",
Expand All @@ -11,7 +11,7 @@
"temp": "^0.8.3",
"qs": "6.x",
"image-type": "^2.0.2",
"watson-developer-cloud": "^2.7.1",
"watson-developer-cloud": "^2.8.2",
"kuromoji": "^0.0.5",
"is-docx": "^0.0.3"
},
Expand All @@ -34,6 +34,7 @@
"nodes": {
"watson-conversation-v1":"services/conversation/v1.js",
"watson-conversation-v1-experimental":"services/conversation/v1-exp.js",
"watson-discovery-v1-experimental":"services/discovery/v1-exp.js",
"watson-document-conversion-v1": "services/document_conversion/v1.js",
"watson-concept-insights-v2": "services/concept_insights/v2.js",
"alchemy-date-extraction": "services/alchemy_date_extraction/v1.js",
Expand Down
Binary file added services/discovery/icons/discovery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
100 changes: 100 additions & 0 deletions services/discovery/v1-exp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<!--
Copyright 2016 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<script type="text/x-red" data-template-name="watson-discovery">
<div id="credentials-check" class="form-row">
<div class="form-tips">
<i class="fa fa-question-circle"></i><b> Please wait: </b> Checking for bound service credentials...
</div>
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row credentials" style="display: none;">
<label for="node-input-username"><i class="fa fa-user"></i> Username</label>
<input type="text" id="node-input-username" placeholder="Username">
</div>
<div class="form-row credentials" style="display: none;">
<label for="node-input-password"><i class="fa fa-key"></i> Password</label>
<input type="password" id="node-input-password" placeholder="Password">
</div>
<div class="form-row">
<label for="node-input-environmentname"><i class="fa fa-tag"></i> Environment Name</label>
<input type="text" id="node-input-envrionmentname" placeholder="">
</div>
</script>

<script type="text/x-red" data-help-name="watson-discovery">
<p>This is the Node for the V1 Experimental Watson Discovery service.</p>
<p>This version of the Node will only list the envrionments created for
the service.
</p>
<p>The node does not need any input. If the envrionment name field is left blank
it will list all envrionments created for the instance of the Discovery service.
If the envrionment name is specified, then only the details for
the Discovery envrionment with the specified name will be returned.
</p>
<p>The environment being requested can be overridden by specifying the search name
in <code>msg.discoveryparams.envrionmentname</code>
</p>

<p>Node output : </p>
<ul>
<li><code>msg.envrionments</code> : A list of the envrionments created under
the Discovery service instance.</li>
</ul>
<p>For more information about the Discovery service,
read the service <a href="https://www.ibm.com/watson/developercloud/doc/discovery/">documentation</a>.</p>
</script>

<script type="text/javascript">
(function() {
RED.nodes.registerType('watson-discovery', {
category: 'IBM Watson',
defaults: {
name: {value: ""},
envrionmentname: {value: ""}
},
credentials: {
username: {type:"text"},
password: {type:"password"}
},
color: "rgb(84,149,230)",
inputs: 1,
outputs: 1,
icon: "discovery.png",
paletteLabel: "discovery",
label: function() {
return this.name || "discovery";
},
labelStyle: function() {
return this.name ? "node_label_italic" : "";
},
oneditprepare: function() {
$.getJSON('watson-discovery/vcap/')
.done(function (service) {
$('.credentials').toggle(!service);
})
.fail(function () {
$('.credentials').show();
}).always(function () {
$('#credentials-check').hide();
})
}
});
})();
</script>
92 changes: 92 additions & 0 deletions services/discovery/v1-exp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/**
* Copyright 20016 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the 'License');
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an 'AS IS' BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

module.exports = function (RED) {

function buildParams(msg,config) {
var params = {};
if (msg.discoveryparams && msg.discoveryparams.envrionmentname) {
params.name = msg.discoveryparams.envrionmentname;
} else if (config.envrionmentname) {
params.name = config.envrionmentname;
}
return params;
}

var DiscoveryV1Experimental = require('watson-developer-cloud/discovery/v1-experimental'),
cfenv = require('cfenv'),
service = cfenv.getAppEnv().getServiceCreds(/discovery/i),
username = null,
password = null,
sUsername = null,
sPassword = null;

if (service) {
sUsername = service.username;
sPassword = service.password;
}

RED.httpAdmin.get('/watson-discovery/vcap', function (req, res) {
res.json(service ? {bound_service: true} : null);
});

function Node (config) {
var node = this;
RED.nodes.createNode(this, config);

this.on('input', function (msg) {
var message = '',
params = {};

username = sUsername || this.credentials.username;
password = sPassword || this.credentials.password;

if (!username || !password) {
message = 'Missing Watson Discovery service credentials';
node.error(message, msg);
return;
}

var discovery = new DiscoveryV1Experimental({
username: username,
password: password,
version_date: '2016-11-07'
});

params = buildParams(msg,config);
node.status({fill:'blue', shape:'dot', text:'requesting'});

discovery.getEnvironments(params, function (err, response) {
node.status({});
if (err) {
console.log(err);
node.status({fill:'red', shape:'dot', text:err.error});
node.error(err, msg);
} else {
msg.environments = response.environments ? response.environments : [];
}
node.send(msg);
});
});
}

RED.nodes.registerType('watson-discovery', Node, {
credentials: {
username: {type:'text'},
password: {type:'password'}
}
});
};

0 comments on commit d985ea0

Please sign in to comment.