Skip to content

Commit 2a1a1f0

Browse files
committed
- Added Timeout and optout learning
- Fixed processResponse when there is error - Minor typo fixes
1 parent 40d3c2d commit 2a1a1f0

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

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: 24 additions & 3 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
}
@@ -165,6 +166,9 @@ module.exports = function(RED) {
165166
}
166167
}
167168

169+
serviceSettings.username = userName;
170+
serviceSettings.password = passWord;
171+
168172
if (service) {
169173
endpoint = service.url;
170174
}
@@ -179,15 +183,32 @@ module.exports = function(RED) {
179183
serviceSettings.url = endpoint;
180184
}
181185

182-
serviceSettings.username = userName;
183-
serviceSettings.password = passWord;
186+
var optoutLearning = false;
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',

0 commit comments

Comments
 (0)