File tree 3 files changed +26
-8
lines changed 3 files changed +26
-8
lines changed Original file line number Diff line number Diff line change @@ -177,7 +177,15 @@ export class Session extends events.EventEmitter implements ISession {
177
177
public endDialog ( msg : IMessage ) : ISession ;
178
178
public endDialog ( result ?: dialog . IDialogResult < any > ) : ISession ;
179
179
public endDialog ( result ?: any , ...args : any [ ] ) : ISession {
180
+ // Validate callstack
181
+ // - Protect against too many calls to endDialog()
180
182
var ss = this . sessionState ;
183
+ if ( ! ss || ! ss . callstack || ss . callstack . length == 0 ) {
184
+ console . error ( 'ERROR: Too many calls to session.endDialog().' )
185
+ return this ;
186
+ }
187
+
188
+ // Pop dialog off the stack.
181
189
var m : IMessage ;
182
190
var r = < dialog . IDialogResult < any > > { } ;
183
191
if ( result ) {
Original file line number Diff line number Diff line change @@ -206,9 +206,10 @@ export abstract class IntentDialog extends dialog.Dialog {
206
206
match = this . findHandler ( topIntent ) ;
207
207
}
208
208
if ( ! match ) {
209
+ topIntent = { intent : consts . Intents . Default , score : 1.0 } ;
209
210
match = {
210
211
groupId : consts . Id . DefaultGroup ,
211
- handler : this . getDefaultGroup ( ) . _intentHandler ( consts . Intents . Default )
212
+ handler : this . getDefaultGroup ( ) . _intentHandler ( topIntent . intent )
212
213
} ;
213
214
}
214
215
@@ -227,12 +228,14 @@ export abstract class IntentDialog extends dialog.Dialog {
227
228
228
229
private findTopIntent ( intents : IIntent [ ] ) : IIntent {
229
230
var topIntent : IIntent ;
230
- for ( var i = 0 ; i < intents . length ; i ++ ) {
231
- var intent = intents [ i ] ;
232
- if ( ! topIntent ) {
233
- topIntent = intent ;
234
- } else if ( intent . score > topIntent . score ) {
235
- topIntent = intent ;
231
+ if ( intents ) {
232
+ for ( var i = 0 ; i < intents . length ; i ++ ) {
233
+ var intent = intents [ i ] ;
234
+ if ( ! topIntent ) {
235
+ topIntent = intent ;
236
+ } else if ( intent . score > topIntent . score ) {
237
+ topIntent = intent ;
238
+ }
236
239
}
237
240
}
238
241
return topIntent ;
Original file line number Diff line number Diff line change @@ -59,19 +59,26 @@ export class LuisDialog extends intent.IntentDialog {
59
59
}
60
60
uri += encodeURIComponent ( utterance || '' ) ;
61
61
request . get ( uri , ( err : Error , res : any , body : string ) => {
62
+ var calledCallback = false ;
62
63
try {
63
64
if ( ! err ) {
64
65
var result : ILuisResults = JSON . parse ( body ) ;
65
66
if ( result . intents . length == 1 && typeof result . intents [ 0 ] . score !== 'number' ) {
66
67
// Intents for the builtin Cortana app don't return a score.
67
68
result . intents [ 0 ] . score = 1.0 ;
68
69
}
70
+ calledCallback = true ;
69
71
callback ( null , result . intents , result . entities ) ;
70
72
} else {
73
+ calledCallback = true ;
71
74
callback ( err ) ;
72
75
}
73
76
} catch ( e ) {
74
- callback ( e ) ;
77
+ if ( ! calledCallback ) {
78
+ callback ( e ) ;
79
+ } else {
80
+ console . error ( e . toString ( ) ) ;
81
+ }
75
82
}
76
83
} ) ;
77
84
}
You can’t perform that action at this time.
0 commit comments