Skip to content

Commit

Permalink
Merge pull request #118 from watson-developer-cloud/master
Browse files Browse the repository at this point in the history
Rebase
  • Loading branch information
chughts committed Oct 3, 2017
2 parents fc4ca0d + 1efec80 commit 117b1e7
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 72 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ 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.5.14
- Bump to latest version of watson-developer-cloud node.js sdk
- Allow empty input into converse for Conversation Node
- Endpoint can now be specified in Natural Language Understanding, Discovery and Discover Query Builder Nodes
- Full Promises implementation for on input processing for Natural Language Understanding Node
- Fix to node.error invocation in Conversation node.

### New in version 0.5.13
- Personality Insights on Bluemix needed new path to node_modules

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.5.13",
"version": "0.5.14",
"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.37.0",
"watson-developer-cloud": "^2.39.2",
"kuromoji": "^0.1.1",
"is-docx": "^0.0.3",
"stream-to-array" : "^2.3.0"
Expand Down
7 changes: 7 additions & 0 deletions services/conversation/v1.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
<input type="checkbox" id="node-input-multiuser" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-multiuser" style="width: 70%;"> Multiple Users</label>
</div>
<div class="form-row">
<label>&nbsp;</label>
<input type="checkbox" id="node-input-empty-payload" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-empty-payload" style="width: 70%;"> Permit empty payload</label>
</div>

<div class="form-tips" id="conversation-form-tips">
<strong>Note:</strong> When using with multiple users, <code>msg.user</code> must be set.<br>
See info box for details.
Expand Down Expand Up @@ -140,6 +146,7 @@
workspaceid: {value: ''},
multiuser: {value: false},
context: {value: true},
'empty-payload': {value: false},
'default-endpoint' :{value: true},
'service-endpoint' :{value: 'https://gateway.watsonplatform.net/conversation/api'}
},
Expand Down
8 changes: 4 additions & 4 deletions services/conversation/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ module.exports = function(RED) {
} : null);
});

function verifyPayload(node, msg) {
if (!msg.payload) {
function verifyPayload(node, msg, config) {
if (!(msg.payload || config['empty-payload'])) {
node.status({
fill: 'red',
shape: 'ring',
Expand Down Expand Up @@ -188,7 +188,7 @@ module.exports = function(RED) {

function processResponse(err, body, node, msg, config) {
if (err !== null && body === null) {
node.error(err);
node.error(err, msg);
node.status({
fill: 'red',
shape: 'ring',
Expand Down Expand Up @@ -237,7 +237,7 @@ module.exports = function(RED) {

node.status({});

b = verifyPayload(node, msg);
b = verifyPayload(node, msg, config);
if (!b) {
return;
}
Expand Down
58 changes: 47 additions & 11 deletions services/discovery/v1-query-builder.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@
<input type="password" id="node-input-password" placeholder="Password">
</div>

<div class="form-row credentials">
<label>&nbsp;</label>
<input type="checkbox" id="node-input-default-endpoint" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-default-endpoint" style="width: 70%;"> Use Default Service Endpoint</label>
</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/discovery/api">
</div>

<div class="form-row">
<label for="node-input-environment"><i class="fa fa-book"></i> Environment</label>
<select type="text" id="node-input-environment" style="display: inline-block; vertical-align:middle; width: 70%;">
Expand Down Expand Up @@ -257,6 +267,15 @@
}
});

$('input#node-input-default-endpoint').change(function () {
var checked = $('input#node-input-default-endpoint').prop('checked')
if (checked) {
$('#node-input-service-endpoint').parent().hide();
} else {
$('#node-input-service-endpoint').parent().show();
}
});

}

// The dialog is about to be shown.
Expand Down Expand Up @@ -429,8 +448,13 @@
var u = $('#node-input-username').val();
var p = $('#node-input-password').val();

$.getJSON('watson-discovery-v1-query-builder/environments',
{un: u, pwd: p}
var creds = {un: u, pwd: p};
var eChecked = $('input#node-input-default-endpoint').prop('checked')
if (!eChecked) {
creds.endpoint = $('#node-input-service-endpoint').val();
}

$.getJSON('watson-discovery-v1-query-builder/environments', creds
).done(function (data) {
$('#something-went-wrong').hide();
if (data.error) {
Expand Down Expand Up @@ -461,9 +485,14 @@
var u = $('#node-input-username').val();
var p = $('#node-input-password').val();

$.getJSON('watson-discovery-v1-query-builder/collections',
{un: u, pwd: p,
environment_id: disQB.environment_selected}
var creds = {un: u, pwd: p};
var eChecked = $('input#node-input-default-endpoint').prop('checked')
if (!eChecked) {
creds.endpoint = $('#node-input-service-endpoint').val();
}
creds.environment_id = disQB.environment_selected;

$.getJSON('watson-discovery-v1-query-builder/collections', creds
).done(function (data) {
$('#something-went-wrong').hide();
if (data.error) {
Expand Down Expand Up @@ -492,11 +521,15 @@
var u = $('#node-input-username').val();
var p = $('#node-input-password').val();

$.getJSON('watson-discovery-v1-query-builder/schemas',
{un: u, pwd: p,
environment_id: disQB.environment_selected,
collection_id: disQB.collection_selected
}
var creds = {un: u, pwd: p};
var eChecked = $('input#node-input-default-endpoint').prop('checked')
if (!eChecked) {
creds.endpoint = $('#node-input-service-endpoint').val();
}
creds.environment_id = disQB.environment_selected;
creds.collection_id = disQB.collection_selected;

$.getJSON('watson-discovery-v1-query-builder/schemas', creds
).done(function (data) {
$('#something-went-wrong').hide();
if (data.error) {
Expand Down Expand Up @@ -683,7 +716,10 @@
queryvalue3: {value: ''},
queryvalue3hidden: {value: ''},
passages: {value: false},
passageshidden: {value: false}
passageshidden: {value: false},
'default-endpoint' :{value: true},
'service-endpoint' :{value: 'https://gateway.watsonplatform.net/discovery/api'}

},
credentials: {
username: {type:"text"} //,
Expand Down
13 changes: 10 additions & 3 deletions services/discovery/v1-query-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ module.exports = function(RED) {
DiscoveryV1 = require('watson-developer-cloud/discovery/v1'),
serviceutils = require('../../utilities/service-utils'),
dservice = serviceutils.getServiceCreds(SERVICE_IDENTIFIER),
username = null,
password = null,
sUsername = null,
sPassword = null;
sPassword = null,
sEndpoint = 'https://gateway.watsonplatform.net/discovery/api';


if (dservice) {
sUsername = dservice.username;
sPassword = dservice.password;
sEndpoint = dservice.url;
}

RED.httpAdmin.get('/watson-discovery-v1-query-builder/vcap', function(req, res) {
Expand All @@ -41,16 +42,20 @@ module.exports = function(RED) {
var discovery = new DiscoveryV1({
username: sUsername ? sUsername : req.query.un,
password: sPassword ? sPassword : req.query.pwd,
url: req.query.endpoint ? req.query.endpoint : sEndpoint,
version_date: '2017-08-01',
headers: {
'User-Agent': pkg.name + '-' + pkg.version
}
});

console.log('Getting Discovery Environments');
discovery.getEnvironments({}, function(err, response) {
if (err) {
console.log(err);
res.json(err);
} else {
console.log('Returning Envrionments');
res.json(response.environments ? response.environments : response);
}
});
Expand All @@ -61,6 +66,7 @@ module.exports = function(RED) {
var discovery = new DiscoveryV1({
username: sUsername ? sUsername : req.query.un,
password: sPassword ? sPassword : req.query.pwd,
url: req.query.endpoint ? req.query.endpoint : sEndpoint,
version_date: '2017-08-01',
headers: {
'User-Agent': pkg.name + '-' + pkg.version
Expand All @@ -85,6 +91,7 @@ module.exports = function(RED) {
var discovery = new DiscoveryV1({
username: sUsername ? sUsername : req.query.un,
password: sPassword ? sPassword : req.query.pwd,
url: req.query.endpoint ? req.query.endpoint : sEndpoint,
version_date: '2017-08-01',
headers: {
'User-Agent': pkg.name + '-' + pkg.version
Expand Down
23 changes: 22 additions & 1 deletion services/discovery/v1.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
<input type="password" id="node-input-password" placeholder="Password">
</div>

<div class="form-row credentials">
<label>&nbsp;</label>
<input type="checkbox" id="node-input-default-endpoint" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-default-endpoint" style="width: 70%;"> Use Default Service Endpoint</label>
</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/discovery/api">
</div>

<div class="form-row">
<label for="node-input-discovery-method"><i class="fa fa-book"></i> Method: </label>
<select type="text" id="node-input-discovery-method" style="display: inline-block; width: 70%;">
Expand Down Expand Up @@ -357,6 +367,15 @@
var method = $('#node-input-discovery-method').val();
disV1.processSelectedMethod(method);
});

$('input#node-input-default-endpoint').change(function () {
var checked = $('input#node-input-default-endpoint').prop('checked')
if (checked) {
$('#node-input-service-endpoint').parent().hide();
} else {
$('#node-input-service-endpoint').parent().show();
}
});
}

disV1.checkForPrepare = function () {
Expand Down Expand Up @@ -398,7 +417,9 @@
return: {value: ''},
description: {value: ''},
size: {value: 0},
'discovery-method': {value:'listEnvrionments'}
'discovery-method': {value:'listEnvrionments'},
'default-endpoint' :{value: true},
'service-endpoint' :{value: 'https://gateway.watsonplatform.net/discovery/api'}
},
credentials: {
username: {type:'text'},
Expand Down
34 changes: 24 additions & 10 deletions services/discovery/v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ module.exports = function (RED) {
username = null,
password = null,
sUsername = null,
sPassword = null;
sPassword = null,
endpoint = '',
sEndpoint = 'https://gateway.watsonplatform.net/discovery/api';


function checkParams(method, params){
var response = '';
Expand Down Expand Up @@ -218,16 +221,21 @@ module.exports = function (RED) {
}

function executeMethod(node, method, params, msg) {
const discovery = new DiscoveryV1({
username: username,
password: password,
version_date: '2017-08-01',
headers: {
'User-Agent': pkg.name + '-' + pkg.version
}
});
var discovery = null, p = null,
serviceSettings = {
username: username,
password: password,
version_date: '2017-08-01',
headers: {
'User-Agent': pkg.name + '-' + pkg.version
}
};

var p = null;
if (endpoint) {
serviceSettings.url = endpoint;
}

discovery = new DiscoveryV1(serviceSettings);

switch (method) {
case 'createEnvrionment':
Expand Down Expand Up @@ -284,6 +292,7 @@ module.exports = function (RED) {
if (dservice) {
sUsername = dservice.username;
sPassword = dservice.password;
sEndpoint = dservice.url;
}

RED.httpAdmin.get('/watson-discovery/vcap', function (req, res) {
Expand All @@ -303,6 +312,11 @@ module.exports = function (RED) {
username = sUsername || this.credentials.username;
password = sPassword || this.credentials.password;

endpoint = sEndpoint;
if ((!config['default-endpoint']) && config['service-endpoint']) {
endpoint = config['service-endpoint'];
}

node.status({});
initialCheck(username, password, method)
.then(function(){
Expand Down
2 changes: 1 addition & 1 deletion services/language_translator_identify/v2.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</script>

<script type="text/x-red" data-help-name="watson-language-translator-identify">
<p>Packaged in with release 0.5.11 of node-red-node-watson</p>
<p>Packaged in with release 0.5.14 of node-red-node-watson</p>
<p>The Watson Language Translator service can be used to identify languages used in a text input. <p>
<p>Node input : </p>
<ul>
Expand Down
Loading

0 comments on commit 117b1e7

Please sign in to comment.