Skip to content

Commit 3781365

Browse files
committed
Allow Version override for Assistant Node
1 parent 8ade4af commit 3781365

1 file changed

Lines changed: 53 additions & 53 deletions

File tree

  • services/conversation

services/conversation/v1.js

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -166,71 +166,71 @@ module.exports = function(RED) {
166166
optoutLearning = false,
167167
version = '2018-02-16';
168168

169-
if (verifyCredentials(msg, apiKey, userName, passWord)) {
170-
if (msg.params) {
171-
if (msg.params.username) {
172-
userName = msg.params.username;
173-
}
174-
if (msg.params.password) {
175-
passWord = msg.params.password;
176-
}
177-
if (msg.params.apikey) {
178-
apiKey = msg.params.apikey;
179-
}
180-
if (msg.params.version) {
181-
version = msg.params.version;
182-
}
183-
}
169+
if (!verifyCredentials(msg, apiKey, userName, passWord)) {
170+
node.error('Missing Watson Assistant API service credentials');
171+
return false;
172+
}
184173

185-
if (apiKey) {
186-
serviceSettings.iam_apikey = apiKey;
187-
} else {
188-
serviceSettings.username = userName;
189-
serviceSettings.password = passWord;
174+
if (msg.params) {
175+
if (msg.params.username) {
176+
userName = msg.params.username;
190177
}
191-
192-
serviceSettings.version = version;
193-
serviceSettings.version_date = version;
194-
195-
if (service) {
196-
endpoint = service.url;
178+
if (msg.params.password) {
179+
passWord = msg.params.password;
197180
}
198-
if (!config['default-endpoint'] && config['service-endpoint']) {
199-
endpoint = config['service-endpoint'];
181+
if (msg.params.apikey) {
182+
apiKey = msg.params.apikey;
200183
}
201-
if (msg.params && msg.params.endpoint) {
202-
endpoint = msg.params.endpoint;
184+
if (msg.params.version) {
185+
version = msg.params.version;
203186
}
187+
}
204188

205-
if (endpoint) {
206-
serviceSettings.url = endpoint;
207-
}
189+
if (apiKey) {
190+
serviceSettings.iam_apikey = apiKey;
191+
} else {
192+
serviceSettings.username = userName;
193+
serviceSettings.password = passWord;
194+
}
208195

209-
if ((msg.params && msg.params['optout_learning'])){
210-
optoutLearning = true;
211-
} else if (config['optout-learning']){
212-
optoutLearning = true;
213-
}
196+
serviceSettings.version = version;
197+
serviceSettings.version_date = version;
214198

215-
if (optoutLearning){
216-
serviceSettings.headers = serviceSettings.headers || {};
217-
serviceSettings.headers['X-Watson-Learning-Opt-Out'] = '1';
218-
}
199+
if (service) {
200+
endpoint = service.url;
201+
}
202+
if (!config['default-endpoint'] && config['service-endpoint']) {
203+
endpoint = config['service-endpoint'];
204+
}
205+
if (msg.params && msg.params.endpoint) {
206+
endpoint = msg.params.endpoint;
207+
}
219208

220-
if (config['timeout'] && config['timeout'] !== '0' && isFinite(config['timeout'])){
221-
serviceSettings.timeout = parseInt(config['timeout']);
222-
}
209+
if (endpoint) {
210+
serviceSettings.url = endpoint;
211+
}
223212

224-
if (msg.params && msg.params.timeout !== '0' && isFinite(msg.params.timeout)){
225-
serviceSettings.timeout = parseInt(msg.params.timeout);
226-
}
213+
if ((msg.params && msg.params['optout_learning'])){
214+
optoutLearning = true;
215+
} else if (config['optout-learning']){
216+
optoutLearning = true;
217+
}
227218

228-
node.service = new AssistantV1(serviceSettings);
229-
return true;
230-
} else {
231-
node.error('Missing Watson Assistant API service credentials');
232-
return false;
219+
if (optoutLearning){
220+
serviceSettings.headers = serviceSettings.headers || {};
221+
serviceSettings.headers['X-Watson-Learning-Opt-Out'] = '1';
222+
}
223+
224+
if (config['timeout'] && config['timeout'] !== '0' && isFinite(config['timeout'])){
225+
serviceSettings.timeout = parseInt(config['timeout']);
233226
}
227+
228+
if (msg.params && msg.params.timeout !== '0' && isFinite(msg.params.timeout)){
229+
serviceSettings.timeout = parseInt(msg.params.timeout);
230+
}
231+
232+
node.service = new AssistantV1(serviceSettings);
233+
return true;
234234
}
235235

236236
function processResponse(err, body, node, msg, config) {

0 commit comments

Comments
 (0)