Skip to content

Commit 72ece86

Browse files
committed
Fixed a couple of bugs related to missing intents coming back from LUIS.
1 parent 1ec7331 commit 72ece86

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

Node/src/Session.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,15 @@ export class Session extends events.EventEmitter implements ISession {
177177
public endDialog(msg: IMessage): ISession;
178178
public endDialog(result?: dialog.IDialogResult<any>): ISession;
179179
public endDialog(result?: any, ...args: any[]): ISession {
180+
// Validate callstack
181+
// - Protect against too many calls to endDialog()
180182
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.
181189
var m: IMessage;
182190
var r = <dialog.IDialogResult<any>>{};
183191
if (result) {

Node/src/dialogs/IntentDialog.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,10 @@ export abstract class IntentDialog extends dialog.Dialog {
206206
match = this.findHandler(topIntent);
207207
}
208208
if (!match) {
209+
topIntent = { intent: consts.Intents.Default, score: 1.0 };
209210
match = {
210211
groupId: consts.Id.DefaultGroup,
211-
handler: this.getDefaultGroup()._intentHandler(consts.Intents.Default)
212+
handler: this.getDefaultGroup()._intentHandler(topIntent.intent)
212213
};
213214
}
214215

@@ -227,12 +228,14 @@ export abstract class IntentDialog extends dialog.Dialog {
227228

228229
private findTopIntent(intents: IIntent[]): IIntent {
229230
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+
}
236239
}
237240
}
238241
return topIntent;

Node/src/dialogs/LuisDialog.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,26 @@ export class LuisDialog extends intent.IntentDialog {
5959
}
6060
uri += encodeURIComponent(utterance || '');
6161
request.get(uri, (err: Error, res: any, body: string) => {
62+
var calledCallback = false;
6263
try {
6364
if (!err) {
6465
var result: ILuisResults = JSON.parse(body);
6566
if (result.intents.length == 1 && typeof result.intents[0].score !== 'number') {
6667
// Intents for the builtin Cortana app don't return a score.
6768
result.intents[0].score = 1.0;
6869
}
70+
calledCallback = true;
6971
callback(null, result.intents, result.entities);
7072
} else {
73+
calledCallback = true;
7174
callback(err);
7275
}
7376
} catch (e) {
74-
callback(e);
77+
if (!calledCallback) {
78+
callback(e);
79+
} else {
80+
console.error(e.toString());
81+
}
7582
}
7683
});
7784
}

0 commit comments

Comments
 (0)