@@ -50,7 +50,7 @@ module.exports = function(RED) {
5050 RED . nodes . createNode ( this , config ) ;
5151
5252 function setCredentials ( msg ) {
53- creds = {
53+ var creds = {
5454 username : sUsername || node . credentials . username ,
5555 password : sPassword || node . credentials . password || config . password ,
5656 apikey : sApikey || node . credentials . apikey || config . apikey ,
@@ -127,7 +127,7 @@ module.exports = function(RED) {
127127 params . context :
128128 { 'skills' : { 'main skill' : { 'user_defined' : { } } } } ;
129129
130- for ( prop in msg . additional_context ) {
130+ for ( var prop in msg . additional_context ) {
131131 if ( msg . additional_context . hasOwnProperty ( prop ) ) {
132132 params . context . skills [ 'main skill' ] [ 'user_defined' ] [ prop ]
133133 = msg . additional_context [ prop ] ;
@@ -190,66 +190,66 @@ module.exports = function(RED) {
190190 }
191191
192192 function setServiceSettings ( msg , creds ) {
193- const serviceSettings = {
193+ const serviceSettings = {
194194 headers : {
195195 'User-Agent' : pkg . name + '-' + pkg . version
196196 }
197- } ;
198- let endpoint = '' ,
199- optoutLearning = false ,
200- version = SERVICE_VERSION ;
197+ } ;
198+ let endpoint = '' ,
199+ optoutLearning = false ,
200+ version = SERVICE_VERSION ;
201+
202+ if ( creds . apikey ) {
203+ serviceSettings . iam_apikey = creds . apikey ;
204+ } else {
205+ serviceSettings . username = creds . username ;
206+ serviceSettings . password = creds . password ;
207+ }
201208
202- if ( creds . apikey ) {
203- serviceSettings . iam_apikey = creds . apikey ;
204- } else {
205- serviceSettings . username = creds . username ;
206- serviceSettings . password = creds . password ;
207- }
209+ if ( service ) {
210+ endpoint = service . url ;
211+ }
212+ if ( ! config [ 'default-endpoint' ] && config [ 'service-endpoint' ] ) {
213+ endpoint = config [ 'service-endpoint' ] ;
214+ }
208215
209- if ( service ) {
210- endpoint = service . url ;
216+ if ( config [ 'optout-learning' ] ) {
217+ optoutLearning = true ;
218+ }
219+
220+ if ( config [ 'timeout' ] && config [ 'timeout' ] !== '0' && isFinite ( config [ 'timeout' ] ) ) {
221+ serviceSettings . timeout = parseInt ( config [ 'timeout' ] ) ;
222+ }
223+
224+ // Look for message overrides
225+ if ( msg . params ) {
226+ if ( msg . params . endpoint ) {
227+ endpoint = msg . params . endpoint ;
211228 }
212- if ( ! config [ 'default-endpoint' ] && config [ 'service-endpoint' ] ) {
213- endpoint = config [ 'service-endpoint' ] ;
229+ if ( msg . params . version ) {
230+ version = msg . params . version ;
214231 }
215-
216- if ( config [ 'optout-learning' ] ) {
232+ if ( ( msg . params [ 'optout_learning' ] ) ) {
217233 optoutLearning = true ;
218234 }
219-
220- if ( config [ 'timeout' ] && config [ 'timeout' ] !== '0' && isFinite ( config [ 'timeout' ] ) ) {
221- serviceSettings . timeout = parseInt ( config [ 'timeout' ] ) ;
235+ if ( msg . params . timeout !== '0' && isFinite ( msg . params . timeout ) ) {
236+ serviceSettings . timeout = parseInt ( msg . params . timeout ) ;
222237 }
223-
224- // Look for message overrides
225- if ( msg . params ) {
226- if ( msg . params . endpoint ) {
227- endpoint = msg . params . endpoint ;
228- }
229- if ( msg . params . version ) {
230- version = msg . params . version ;
231- }
232- if ( ( msg . params [ 'optout_learning' ] ) ) {
233- optoutLearning = true ;
234- }
235- if ( msg . params . timeout !== '0' && isFinite ( msg . params . timeout ) ) {
236- serviceSettings . timeout = parseInt ( msg . params . timeout ) ;
237- }
238- if ( msg . params . disable_ssl_verification ) {
239- serviceSettings . disable_ssl_verification = true ;
240- }
238+ if ( msg . params . disable_ssl_verification ) {
239+ serviceSettings . disable_ssl_verification = true ;
241240 }
241+ }
242242
243- serviceSettings . version = version ;
244- if ( endpoint ) {
245- serviceSettings . url = endpoint ;
246- }
247- if ( optoutLearning ) {
248- serviceSettings . headers = serviceSettings . headers || { } ;
249- serviceSettings . headers [ 'X-Watson-Learning-Opt-Out' ] = '1' ;
250- }
243+ serviceSettings . version = version ;
244+ if ( endpoint ) {
245+ serviceSettings . url = endpoint ;
246+ }
247+ if ( optoutLearning ) {
248+ serviceSettings . headers = serviceSettings . headers || { } ;
249+ serviceSettings . headers [ 'X-Watson-Learning-Opt-Out' ] = '1' ;
250+ }
251251
252- return Promise . resolve ( serviceSettings ) ;
252+ return Promise . resolve ( serviceSettings ) ;
253253 }
254254
255255 function buildService ( settings ) {
0 commit comments