Skip to content

Commit a552620

Browse files
authored
Merge pull request #238 from chughts/ccreds
Conversation Credentials
2 parents 724bdb0 + ce2b744 commit a552620

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Node-RED Watson Nodes for IBM Bluemix
99

1010
### New in version 0.4.34
1111
- Added Keyword and Entity emotion and sentiment as options on Alchemy Feature Extract Node.
12+
- Allow Conversation credentials to be provided on msg.params
13+
- Similarity Search and Visual Recognition Nodes updated to use url based services to detect bound service.
1214

1315
### New in version 0.4.33
1416
- Personality Insights node updated to latest December 15, 2016 GloVe profiles.

services/conversation/v1.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
<li><code>msg.params.entities</code> (optional) : see API documentation </li>
6969
<li><code>msg.params.output</code> (optional) : see API documentation </li>
7070
<li><code>msg.additional_context</code> (optional) : additional properties that will be added to the context object. Format: Object </li>
71+
<br/>
72+
<li><code>msg.params.username</code> : If provided will be used as the username credential for the Conversation service.</li>
73+
<li><code>msg.params.password</code> : If provided will be used as the password credential for the Conversation service.</li>
7174
</ul>
7275
<p>See <a href="http://www.ibm.com/watson/developercloud/conversation/api/v1/#send_input" target="_blank">Conversation API documentation</a> for details.</p>
7376
<p>All Results will made available at <code>msg.payload</code> in JSON format. Check the <a href="http://www.ibm.com/watson/developercloud/conversation/api/v1/#send_input" target="_blank">documentation</a> for details.</p>

services/conversation/v1.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,20 @@ module.exports = function (RED) {
121121
function verifyServiceCredentials(node, msg) {
122122
// If it is present the newly provided user entered key
123123
// takes precedence over the existing one.
124+
// If msg.params contain credentials then these will Overridde
125+
// the bound or configured credentials.
124126
var userName = sUsername || node.credentials.username,
125127
passWord = sPassword || node.credentials.password;
126128

127-
if (!userName || !passWord) {
129+
if ( !(userName || msg.params.username) ||
130+
!(passWord || msg.params.password) ) {
128131
node.status({fill:'red', shape:'ring', text:'missing credentials'});
129132
node.error('Missing Watson Conversation API service credentials', msg);
130133
return false;
131134
}
132135
node.service = new ConversationV1({
133-
username: userName,
134-
password: passWord,
136+
username: msg.params.username ? msg.params.username : userName,
137+
password: msg.params.password ? msg.params.password :passWord,
135138
version_date: '2016-09-20'
136139
});
137140
return true;

services/similarity_search/v3.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
**/
1616

1717
module.exports = function (RED) {
18-
var cfenv = require('cfenv'),
18+
const SERVICE_IDENTIFIER = 'visual-recognition';
19+
var serviceutils = require('../../utilities/service-utils'),
1920
watson = require('watson-developer-cloud'),
2021
imageType = require('image-type'),
2122
temp = require('temp'),
@@ -27,7 +28,7 @@ module.exports = function (RED) {
2728
// temp is being used for file streaming to allow the file to arrive so it can be processed.
2829
temp.track();
2930

30-
service = cfenv.getAppEnv().getServiceCreds(/visual recognition/i);
31+
service = serviceutils.getServiceCreds(SERVICE_IDENTIFIER);
3132

3233
if (service) {
3334
sAPIKey = service.api_key;

services/visual_recognition/v3.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
**/
1616

1717
module.exports = function (RED) {
18-
var cfenv = require('cfenv'),
18+
const SERVICE_IDENTIFIER = 'visual-recognition';
19+
var serviceutils = require('../../utilities/service-utils'),
1920
watson = require('watson-developer-cloud'),
2021
imageType = require('image-type'),
2122
url = require('url'),
@@ -28,7 +29,7 @@ module.exports = function (RED) {
2829
// temp is being used for file streaming to allow the file to arrive so it can be processed.
2930
temp.track();
3031

31-
service = cfenv.getAppEnv().getServiceCreds(/visual recognition/i);
32+
service = serviceutils.getServiceCreds(SERVICE_IDENTIFIER);
3233

3334
if (service) {
3435
sAPIKey = service.api_key;

0 commit comments

Comments
 (0)