@@ -6,6 +6,22 @@ import { DialogSet } from './dialogSet';
66import { isSkillClaim } from './prompts/skillsHelpers' ;
77
88export 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+ }
0 commit comments