Skip to content

Commit fcc88af

Browse files
authored
Merge pull request #155 from watson-developer-cloud/master
Rebasing
2 parents 318e241 + 149b6d7 commit fcc88af

5 files changed

Lines changed: 60 additions & 38 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ Node-RED Watson Nodes for IBM Cloud
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.7.2
11+
- Allow version date for Assistant to be specified in `msg.params.version`
12+
to allow optional usage of beta version.
13+
1014
### New in version 0.7.1
1115
- Fix to how IAM Key for bound Visual Recognition is retrieved
1216

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-node-watson",
3-
"version": "0.7.1",
3+
"version": "0.7.2",
44
"description": "A collection of Node-RED nodes for IBM Watson services",
55
"dependencies": {
66
"async": "^1.5.2",

services/conversation/v1-workspace-manager.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ module.exports = function (RED) {
2727
service = serviceutils.getServiceCreds(SERVICE_IDENTIFIER),
2828
username = '', password = '', sUsername = '', sPassword = '',
2929
apikey = '', sApikey = '',
30-
endpoint = '', sEndpoint = '';
30+
endpoint = '', sEndpoint = '',
31+
version = '2018-02-16';
3132

3233
if (!service) {
3334
service = serviceutils.getServiceCreds(OLD_SERVICE_IDENTIFIER);
@@ -504,10 +505,11 @@ module.exports = function (RED) {
504505
}
505506

506507
function executeMethod(node, method, params, msg) {
507-
var conv = null,
508+
let conv = null,
509+
version = '2018-02-16',
508510
serviceSettings = {
509-
version_date: '2018-02-16',
510-
version: '2018-02-16',
511+
version_date: version,
512+
version: version,
511513
headers: {
512514
'User-Agent': pkg.name + '-' + pkg.version
513515
}
@@ -524,6 +526,8 @@ module.exports = function (RED) {
524526
serviceSettings.url = endpoint;
525527
}
526528

529+
530+
527531
conv = new AssistantV1(serviceSettings);
528532

529533
node.status({fill:'blue', shape:'dot', text:'executing'});
@@ -1100,6 +1104,9 @@ module.exports = function (RED) {
11001104
if (msg.params.apikey) {
11011105
apikey = msg.params.apikey;
11021106
}
1107+
if (msg.params.version) {
1108+
version = msg.params.version;
1109+
}
11031110
}
11041111
endpoint = sEndpoint;
11051112
if ((!config['cwm-default-endpoint']) && config['cwm-service-endpoint']) {

services/conversation/v1.html

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,37 +86,38 @@
8686

8787

8888
<script type="text/x-red" data-help-name="watson-conversation-v1">
89-
<p>With the IBM Watson™ Conversation service you can create cognitive agents – virtual agents that combine machine learning, natural language understanding, and integrated dialog scripting tools to provide outstanding customer engagements.</p>
89+
<p>With the IBM Watson™ Assistant service you can create cognitive agents – virtual agents that combine machine learning, natural language understanding, and integrated dialog scripting tools to provide outstanding customer engagements.</p>
9090

9191
<p><b>Usage</b></p>
9292
<p>This node should be provided in input : </p>
9393
<ul>
94-
<li><code>msg.payload</code> : the message of the conversation to analyse. Format: String </li>
95-
<li><code>msg.user</code> (optional): unique identifier of the user. This will be used to maintain the context of the conversation for each user when using with multiple users. Format: String </li>
94+
<li><code>msg.payload</code> : the message of the Assistant to analyse. Format: String </li>
95+
<li><code>msg.user</code> (optional): unique identifier of the user. This will be used to maintain the context of the Assistant for each user when using with multiple users. Format: String </li>
9696
<li><code>msg.params.workspace_id</code> : unique identifier of the workspace to be used. Could be also configured in the node. Format: String </li>
9797
<li><code>msg.params.timeout</code> (optional): The timeout period (in millisecond) for Watson request. Leave empty or set to 0 to disable. </li>
98-
<li><code>msg.params.context</code> (optional): A context object that includes state information for the conversation. When you send multiple requests for the same conversation, include the context object from the response. (<a href="http://www.ibm.com/watson/developercloud/conversation/api/v1/#send_input" target="_blank">documentation</a>). This will overwrite any context saved in the node. Format: JSON </li>
98+
<li><code>msg.params.context</code> (optional): A context object that includes state information for the Assistant. When you send multiple requests for the same Assistant, include the context object from the response. (<a href="http://www.ibm.com/watson/developercloud/assistant/api/v1/#send_input" target="_blank">documentation</a>). This will overwrite any context saved in the node. Format: JSON </li>
9999
<li><code>msg.params.alternate_intents</code> (optional) : whether to return more than one intent. Default is false. Set to true to return all matching intents. For example, return all intents when the confidence is not high to allow users to choose their intent.</li>
100100
<li><code>msg.params.output</code> (optional) : see API documentation </li>
101101
<li><code>msg.params.entities</code> (optional) : see API documentation </li>
102102
<li><code>msg.params.output</code> (optional) : see API documentation </li>
103103
<li><code>msg.additional_context</code> (optional) : additional properties that will be added to the context object. Format: Object </li>
104104
<br/>
105-
<li><code>msg.params.username</code> : If provided will be used as the username credential for the Conversation service.</li>
106-
<li><code>msg.params.password</code> : If provided will be used as the password credential for the Conversation service.</li>
107-
<li><code>msg.params.apikey</code> : If provided will be used as the api key credential for the Conversation service.</li>
108-
<li><code>msg.params.endpoint</code> : If provided will be used as the url for the Conversation service.</li>
105+
<li><code>msg.params.username</code> : If provided will be used as the username credential for the Assistant service.</li>
106+
<li><code>msg.params.password</code> : If provided will be used as the password credential for the Assistant service.</li>
107+
<li><code>msg.params.apikey</code> : If provided will be used as the api key credential for the Assistant service.</li>
108+
<li><code>msg.params.endpoint</code> : If provided will be used as the url for the Assistant service.</li>
109+
<li><code>msg.params.version</code> : If provided will be used as the API version date for the Assistant service.</li>
109110
<li><code>msg.params.optout_learning</code> : Set to true to opt out of request logging. Check the <a href="https://console.bluemix.net/docs/services/watson/getting-started-logging.html#controlling-request-logging-for-watson-services" target="_blank">documentation</a> for details.</li>
110111
</ul>
111-
<p>See <a href="http://www.ibm.com/watson/developercloud/conversation/api/v1/#send_input" target="_blank">Conversation API documentation</a> for details.</p>
112-
<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>
112+
<p>See <a href="http://www.ibm.com/watson/developercloud/assistant/api/v1/#send_input" target="_blank">Assistant API documentation</a> for details.</p>
113+
<p>All Results will made available at <code>msg.payload</code> in JSON format. Check the <a href="http://www.ibm.com/watson/developercloud/assistant/api/v1/#send_input" target="_blank">documentation</a> for details.</p>
113114

114-
<p><b>Important</b> : before using this node, a workspace must be created and configured using the Watson Conversation Tool available in IBM Cloud, in the Watson Conversation instance detail page.</p>
115+
<p><b>Important</b> : before using this node, a workspace must be created and configured using the Watson Assistant Tool available in IBM Cloud, in the Watson Assistant instance detail page.</p>
115116
<p><b>Documentation</b>
116117
<ul>
117-
<li><a href="https://console.bluemix.net/docs/services/conversation/index.html" target="_blank">Watson Conversation API documentation</a></li>
118-
<li><a href="https://watson-api-explorer.mybluemix.net/apis/conversation-v1" target="_blank">Watson API Explorer</a></li>
119-
<li><a href="https://console.bluemix.net/docs/services/conversation/getting-started.html" target="_blank">Getting started tutorial</a>
118+
<li><a href="https://console.bluemix.net/docs/services/assistant/index.html" target="_blank">Watson Assistant API documentation</a></li>
119+
<li><a href="https://watson-api-explorer.mybluemix.net/apis/assistant-v1" target="_blank">Watson API Explorer</a></li>
120+
<li><a href="https://console.bluemix.net/docs/services/assistant/getting-started.html" target="_blank">Getting started tutorial</a>
120121
<li><a href="https://github.com/watson-developer-cloud/node-red-bluemix-starter" target="_blank">Sample Flow in the Watson Node-RED Starter</a>
121122
</ul>
122123
</script>

services/conversation/v1.js

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -136,38 +136,39 @@ module.exports = function(RED) {
136136
return true;
137137
}
138138

139+
function verifyCredentials(msg, k, u, p) {
140+
if ( !(k) && (!(u) || !(p)) ) {
141+
if ( (!msg.params) ||
142+
(!(msg.params.apikey) &&
143+
(!(msg.params.username) || !(msg.params.password))) ) {
144+
return false;
145+
}
146+
}
147+
return true;
148+
}
149+
139150

140151
function verifyServiceCredentials(node, msg, config) {
141152
// If it is present the newly provided user entered key
142153
// takes precedence over the existing one.
143154
// If msg.params contain credentials then these will Overridde
144155
// the bound or configured credentials.
145156
const serviceSettings = {
146-
version_date: '2018-02-16',
147-
version: '2018-02-16',
148157
headers: {
149158
'User-Agent': pkg.name + '-' + pkg.version
150159
}
151160
};
152161

153-
var userName = sUsername || node.credentials.username,
162+
let userName = sUsername || node.credentials.username,
154163
passWord = sPassword || node.credentials.password,
155164
apiKey = sApikey || node.credentials.apikey,
156165
endpoint = '',
157-
optoutLearning = false;
166+
optoutLearning = false,
167+
version = '2018-02-16';
158168

159-
if ( !(apiKey) && (!(userName) || !(passWord)) ) {
160-
if ( (!msg.params) ||
161-
(!(msg.params.apikey) &&
162-
(!(msg.params.username) || !(msg.params.password))) ) {
163-
node.status({
164-
fill: 'red',
165-
shape: 'ring',
166-
text: 'missing credentials'
167-
});
168-
node.error('Missing Watson Conversation API service credentials', msg);
169-
return false;
170-
}
169+
if (!verifyCredentials(msg, apiKey, userName, passWord)) {
170+
node.error('Missing Watson Assistant API service credentials');
171+
return false;
171172
}
172173

173174
if (msg.params) {
@@ -180,11 +181,20 @@ module.exports = function(RED) {
180181
if (msg.params.apikey) {
181182
apiKey = msg.params.apikey;
182183
}
184+
if (msg.params.version) {
185+
version = msg.params.version;
186+
}
187+
}
188+
189+
if (apiKey) {
190+
serviceSettings.iam_apikey = apiKey;
191+
} else {
192+
serviceSettings.username = userName;
193+
serviceSettings.password = passWord;
183194
}
184195

185-
serviceSettings.username = userName;
186-
serviceSettings.password = passWord;
187-
serviceSettings.iam_apikey = apiKey;
196+
serviceSettings.version = version;
197+
serviceSettings.version_date = version;
188198

189199
if (service) {
190200
endpoint = service.url;

0 commit comments

Comments
 (0)