Skip to content

Commit 23824ac

Browse files
authored
Merge pull request #140 from watson-developer-cloud/master
Rebasing
2 parents 5a0bb20 + e55a23c commit 23824ac

File tree

8 files changed

+168
-51
lines changed

8 files changed

+168
-51
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ 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+
11+
### New in version 0.6.6
12+
- Added Mute option for STT Node warning status when running in Streaming mode
13+
- Discard option for STT Node Streaming listening events.
14+
- Added Auto-Connect mode for STT Node - Will keep connection to service alive,
15+
else connection is restored on demand.
16+
- Fix to Discovery Query Builder Node to return schema options.
17+
1018
### New in version 0.6.5
1119
- Endpoint can now be specified in Natural Language Classifier Node
1220

package.json

Lines changed: 2 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.6.5",
3+
"version": "0.6.6",
44
"description": "A collection of Node-RED nodes for IBM Watson services",
55
"dependencies": {
66
"async": "^1.5.2",
@@ -15,7 +15,7 @@
1515
"word-count": "^0.2.2",
1616
"is-docx": "^0.0.3",
1717
"stream-to-array" : "^2.3.0",
18-
"ws" : "^4.0.0"
18+
"ws" : "^4.1.0"
1919
},
2020
"repository": {
2121
"type": "git",

services/conversation/v1.html

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
<label for="node-input-workspaceid"><i class="fa fa-tag"></i> Workspace ID</label>
5050
<input type="text" id="node-input-workspaceid" placeholder="WorkspaceID">
5151
</div>
52+
<div class="form-row">
53+
<label for="node-input-timeout"><i class="fa fa-tag"></i> Timeout Period</label>
54+
<input type="text" id="node-input-timeout" placeholder="Leave empty to disable">
55+
</div>
5256
<div class="form-row">
5357
<label>&nbsp;</label>
5458
<input type="checkbox" id="node-input-context" style="display: inline-block; width: auto; vertical-align: top;">
@@ -62,7 +66,12 @@
6266
<div class="form-row">
6367
<label>&nbsp;</label>
6468
<input type="checkbox" id="node-input-empty-payload" style="display: inline-block; width: auto; vertical-align: top;">
65-
<label for="node-input-empty-payload" style="width: 70%;"> Permit empty payload</label>
69+
<label for="node-input-empty-payload" style="width: 70%;"> Permit Empty Payload</label>
70+
</div>
71+
<div class="form-row">
72+
<label>&nbsp;</label>
73+
<input type="checkbox" id="node-input-optout-learning" style="display: inline-block; width: auto; vertical-align: top;">
74+
<label for="node-input-optout-learning" style="width: 70%;"> Opt Out Request Logging</label>
6675
</div>
6776

6877
<div class="form-tips" id="conversation-form-tips">
@@ -81,6 +90,7 @@
8190
<li><code>msg.payload</code> : the message of the conversation to analyse. Format: String </li>
8291
<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>
8392
<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>
93+
<li><code>msg.params.timeout</code> (optional): The timeout period (in millisecond) for Watson request. Leave empty or set to 0 to disable. </li>
8494
<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>
8595
<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>
8696
<li><code>msg.params.output</code> (optional) : see API documentation </li>
@@ -91,6 +101,7 @@
91101
<li><code>msg.params.username</code> : If provided will be used as the username credential for the Conversation service.</li>
92102
<li><code>msg.params.password</code> : If provided will be used as the password credential for the Conversation service.</li>
93103
<li><code>msg.params.endpoint</code> : If provided will be used as the url for the Conversation service.</li>
104+
<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>
94105
</ul>
95106
<p>See <a href="http://www.ibm.com/watson/developercloud/conversation/api/v1/#send_input" target="_blank">Conversation API documentation</a> for details.</p>
96107
<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>
@@ -108,7 +119,7 @@
108119
<script type="text/javascript">
109120
var oneditprepare = function() {
110121
$('input#node-input-context').change(function () {
111-
var checked = $('input#node-input-context').prop('checked')
122+
var checked = $('input#node-input-context').prop('checked');
112123
if (checked) {
113124
$('input#node-input-multiuser').parent().show();
114125
$('#conversation-form-tips').show();
@@ -118,7 +129,7 @@
118129
}
119130
});
120131
$('input#node-input-default-endpoint').change(function () {
121-
var checked = $('input#node-input-default-endpoint').prop('checked')
132+
var checked = $('input#node-input-default-endpoint').prop('checked');
122133
if (checked) {
123134
$('#node-input-service-endpoint').parent().hide();
124135
} else {
@@ -147,8 +158,10 @@
147158
multiuser: {value: false},
148159
context: {value: true},
149160
'empty-payload': {value: false},
150-
'default-endpoint' :{value: true},
151-
'service-endpoint' :{value: 'https://gateway.watsonplatform.net/conversation/api'}
161+
'default-endpoint' : {value: true},
162+
'service-endpoint' : {value: 'https://gateway.watsonplatform.net/conversation/api'},
163+
timeout: {value: '', validate: RED.validators.number(true)},
164+
'optout-learning': {value: false}
152165
},
153166
credentials: {
154167
username: {type:'text'},

services/conversation/v1.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ module.exports = function(RED) {
124124
if (msg.params && msg.params.alternate_intents) {
125125
params.alternate_intents = msg.params.alternate_intents;
126126
}
127+
127128
verifyOptionalInputs(node, msg, config, params);
128129
return true;
129130
}
@@ -143,7 +144,8 @@ module.exports = function(RED) {
143144

144145
var userName = sUsername || node.credentials.username,
145146
passWord = sPassword || node.credentials.password,
146-
endpoint = '';
147+
endpoint = '',
148+
optoutLearning = false;
147149

148150
if (!(userName || msg.params.username) ||
149151
!(passWord || msg.params.password)) {
@@ -165,6 +167,9 @@ module.exports = function(RED) {
165167
}
166168
}
167169

170+
serviceSettings.username = userName;
171+
serviceSettings.password = passWord;
172+
168173
if (service) {
169174
endpoint = service.url;
170175
}
@@ -179,15 +184,31 @@ module.exports = function(RED) {
179184
serviceSettings.url = endpoint;
180185
}
181186

182-
serviceSettings.username = userName;
183-
serviceSettings.password = passWord;
187+
if ((msg.params && msg.params['optout_learning'])){
188+
optoutLearning = true;
189+
} else if (config['optout-learning']){
190+
optoutLearning = true;
191+
}
192+
193+
if (optoutLearning){
194+
serviceSettings.headers = serviceSettings.headers || {};
195+
serviceSettings.headers['X-Watson-Learning-Opt-Out'] = '1';
196+
}
197+
198+
if (config['timeout'] && config['timeout'] !== '0' && isFinite(config['timeout'])){
199+
serviceSettings.timeout = parseInt(config['timeout']);
200+
}
201+
202+
if (msg.params && msg.params.timeout !== '0' && isFinite(msg.params.timeout)){
203+
serviceSettings.timeout = parseInt(msg.params.timeout);
204+
}
184205

185206
node.service = new ConversationV1(serviceSettings);
186207
return true;
187208
}
188209

189210
function processResponse(err, body, node, msg, config) {
190-
if (err !== null && body === null) {
211+
if (err !== null && (body === null || typeof (body) === 'undefined')) {
191212
node.error(err, msg);
192213
node.status({
193214
fill: 'red',

services/discovery/v1-query-builder.html

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
// can be obtained from the service.
184184
disQB.hideAll = function() {
185185
$('#credentials-not-found').show();
186-
cv1wm.hideSelectedFields(fields);
186+
//disQB.hideSelectedFields(fields);
187187
$('#something-went-wrong').hide();
188188
$('#node-input-environment').parent().hide();
189189
$('#node-input-collection').parent().hide();
@@ -609,7 +609,7 @@
609609

610610

611611
// This is the on edit prepare function, which will be invoked everytime the dialog is shown.
612-
function oneditprepare() {
612+
function disQBoneditprepare() {
613613
disQB.hideAll();
614614
disQB.restoreHidden();
615615

@@ -620,6 +620,7 @@
620620
$('.credentials').toggle(!service);
621621
// for some reason the getJSON resets the vars so need to restoreHidden again
622622
// so again.
623+
disQB.have_credentials = true;
623624
disQB.restoreHidden();
624625
if (!service) {
625626
// no bound service, so check local settings to see if they are valid
@@ -637,7 +638,7 @@
637638
$('#credentials-check').hide();
638639
})
639640
}
640-
// credentials can be set during the oneditprepare process, so check again.
641+
// credentials can be set during the disQBoneditprepare process, so check again.
641642
if (disQB.have_credentials || disQB.using_local_credentials)
642643
{
643644
$('#credentials-check').hide();
@@ -654,7 +655,7 @@
654655
}
655656

656657
// Save the values in the dyanmic lists to the hidden fields.
657-
function oneditsave(){
658+
function disQoneditsave(){
658659
disQB.environment_selected = $('#node-input-environment').val();
659660
$('#node-input-environmenthidden').val(disQB.environment_selected);
660661

@@ -736,8 +737,8 @@
736737
labelStyle: function() {
737738
return this.name ? "node_label_italic" : "";
738739
},
739-
oneditprepare: oneditprepare,
740-
oneditsave: oneditsave
740+
oneditprepare: disQBoneditprepare,
741+
oneditsave: disQoneditsave
741742
});
742743
})();
743744
</script>

services/discovery/v1-query-builder.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,16 @@ module.exports = function(RED) {
4343
username: sUsername ? sUsername : req.query.un,
4444
password: sPassword ? sPassword : req.query.pwd,
4545
url: req.query.endpoint ? req.query.endpoint : sEndpoint,
46-
version_date: '2017-09-01',
46+
version_date: '2017-11-07',
4747
headers: {
4848
'User-Agent': pkg.name + '-' + pkg.version
4949
}
5050
});
5151

52-
console.log('Getting Discovery Environments');
5352
discovery.getEnvironments({}, function(err, response) {
5453
if (err) {
55-
console.log(err);
5654
res.json(err);
5755
} else {
58-
console.log('Returning Envrionments');
5956
res.json(response.environments ? response.environments : response);
6057
}
6158
});
@@ -67,7 +64,7 @@ module.exports = function(RED) {
6764
username: sUsername ? sUsername : req.query.un,
6865
password: sPassword ? sPassword : req.query.pwd,
6966
url: req.query.endpoint ? req.query.endpoint : sEndpoint,
70-
version_date: '2017-09-01',
67+
version_date: '2017-11-07',
7168
headers: {
7269
'User-Agent': pkg.name + '-' + pkg.version
7370
}
@@ -92,7 +89,7 @@ module.exports = function(RED) {
9289
username: sUsername ? sUsername : req.query.un,
9390
password: sPassword ? sPassword : req.query.pwd,
9491
url: req.query.endpoint ? req.query.endpoint : sEndpoint,
95-
version_date: '2017-09-01',
92+
version_date: '2017-11-07',
9693
headers: {
9794
'User-Agent': pkg.name + '-' + pkg.version
9895
}
@@ -101,7 +98,9 @@ module.exports = function(RED) {
10198
discovery.query({
10299
environment_id: req.query.environment_id,
103100
collection_id: req.query.collection_id,
104-
query: 'text:a,text:ibm',
101+
//query: 'text:a,text:ibm',
102+
// Need a Query that will return some data!
103+
query: 'text:"Trump",text:"IBM",text:"Watson"',
105104
count: 1
106105
},
107106
function(err, response) {

0 commit comments

Comments
 (0)