Skip to content

Commit 0f61f91

Browse files
authored
[master, cherry-pick] fix runDialog helper, fix callerId (#1898)
* fix runDialog helper, fix callerId (#1896) * fix private isEocComingFromParent in dialogHelper.ts Manually cherry pick 70e7b94
1 parent 4967c77 commit 0f61f91

File tree

3 files changed

+68
-3
lines changed

3 files changed

+68
-3
lines changed

libraries/botbuilder-dialogs/src/dialogHelper.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ import { DialogSet } from './dialogSet';
66
import { isSkillClaim } from './prompts/skillsHelpers';
77

88
export async function runDialog(dialog: Dialog, context: TurnContext, accessor: StatePropertyAccessor<DialogState>): Promise<void> {
9+
if (!dialog) {
10+
throw new Error('runDialog(): missing dialog');
11+
}
12+
13+
if (!context) {
14+
throw new Error('runDialog(): missing context');
15+
}
16+
17+
if (!context.activity) {
18+
throw new Error('runDialog(): missing context.activity');
19+
}
20+
21+
if (!accessor) {
22+
throw new Error('runDialog(): missing accessor');
23+
}
24+
925
const dialogSet = new DialogSet(accessor);
1026
dialogSet.telemetryClient = dialog.telemetryClient;
1127
dialogSet.add(dialog);
@@ -16,11 +32,11 @@ export async function runDialog(dialog: Dialog, context: TurnContext, accessor:
1632
const identity = context.turnState.get(context.adapter.BotIdentityKey);
1733
if (identity && isSkillClaim(identity.claims)) {
1834
// The bot is running as a skill.
19-
if (context.activity.type === ActivityTypes.EndOfConversation && dialogContext.stack.length > 0) {
35+
if (context.activity.type === ActivityTypes.EndOfConversation && dialogContext.stack.length > 0 && isEocComingFromParent(context)) {
2036
// Handle remote cancellation request if we have something in the stack.
2137
const activeDialogContext = getActiveDialogContext(dialogContext);
2238

23-
const remoteCancelText = 'Skill was canceled by a request from the host.';
39+
const remoteCancelText = 'Skill was canceled through an EndOfConversation activity from the parent.';
2440
await context.sendTraceActivity(telemetryEventName, undefined, undefined, `${ remoteCancelText }`);
2541

2642
// Send cancellation message to the top dialog in the stack to ensure all the parents are canceled in the right order.
@@ -68,3 +84,12 @@ function getActiveDialogContext(dialogContext: DialogContext): DialogContext {
6884

6985
return getActiveDialogContext(child);
7086
}
87+
88+
// We should only cancel the current dialog stack if the EoC activity is coming from a parent (a root bot or another skill).
89+
// When the EoC is coming back from a child, we should just process that EoC normally through the
90+
// dialog stack and let the child dialogs handle that.
91+
function isEocComingFromParent(context: TurnContext): boolean {
92+
// To determine the direction we check callerId property which is set to the parent bot
93+
// by the BotFrameworkHttpClient on outgoing requests.
94+
return !!context.activity.callerId;
95+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const { strictEqual } = require('assert');
2+
const { runDialog } = require('../');
3+
4+
describe('runDialog()', function() {
5+
this.timeout(300);
6+
7+
describe('parameter validation', () => {
8+
it('should throw if missing dialog parameter', (done) => {
9+
runDialog().then(
10+
() => done(new Error('should have throw error')),
11+
(err) => {
12+
done(strictEqual(err.message, 'runDialog(): missing dialog'));
13+
});
14+
});
15+
16+
it('should throw if missing context parameter', (done) => {
17+
runDialog({}).then(
18+
() => done(new Error('should have throw error')),
19+
(err) => {
20+
done(strictEqual(err.message, 'runDialog(): missing context'));
21+
});
22+
});
23+
24+
it('should throw if missing context.activity', (done) => {
25+
runDialog({}, {}).then(
26+
() => done(new Error('should have throw error')),
27+
(err) => {
28+
done(strictEqual(err.message, 'runDialog(): missing context.activity'));
29+
});
30+
});
31+
32+
it('should throw if missing accessor parameter', (done) => {
33+
runDialog({}, { activity: {} }).then(
34+
() => done(new Error('should have throw error')),
35+
(err) => {
36+
done(strictEqual(err.message, 'runDialog(): missing accessor'));
37+
});
38+
});
39+
});
40+
});

libraries/botbuilder/src/botFrameworkHttpClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class BotFrameworkHttpClient extends BotFrameworkClient {
9090
};
9191
activity.conversation.id = conversationId;
9292
activity.serviceUrl = serviceUrl;
93-
activity.callerId = fromBotId;
93+
activity.callerId = `urn:botframework:aadappid:${ fromBotId }`;
9494
const config = {
9595
headers: {
9696
Accept: 'application/json',

0 commit comments

Comments
 (0)