Skip to content

Commit b5b31cc

Browse files
committed
EoC should only be handled when coming from parent in RunAsync (#3540)
* Added check to only cancel dialogs in RunAsync when EoC comes from a parent bot (root or skill). * Applied URI prefix to caller ID as per OBI spec https://github.com/microsoft/botframework-obi/blob/master/protocols/botframework-activity/botframework-activity.md#bot-calling-skill (cherry picked from commit 3730963)
1 parent 0d1dc37 commit b5b31cc

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

libraries/Microsoft.Bot.Builder.Dialogs/DialogExtensions.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public static async Task RunAsync(this Dialog dialog, ITurnContext turnContext,
3838
if (turnContext.TurnState.Get<IIdentity>(BotAdapter.BotIdentityKey) is ClaimsIdentity claimIdentity && SkillValidation.IsSkillClaim(claimIdentity.Claims))
3939
{
4040
// The bot is running as a skill.
41-
if (turnContext.Activity.Type == ActivityTypes.EndOfConversation && dialogContext.Stack.Any())
41+
if (turnContext.Activity.Type == ActivityTypes.EndOfConversation && dialogContext.Stack.Any() && IsEocComingFromParent(turnContext))
4242
{
43-
// Handle remote cancellation request if we have something in the stack.
43+
// Handle remote cancellation request from parent.
4444
var activeDialogContext = GetActiveDialogContext(dialogContext);
4545

46-
var remoteCancelText = "Skill was canceled by a request from the host.";
46+
var remoteCancelText = "Skill was canceled through an EndOfConversation activity from the parent.";
4747
await turnContext.TraceActivityAsync($"{typeof(Dialog).Name}.RunAsync()", label: $"{remoteCancelText}", cancellationToken: cancellationToken).ConfigureAwait(false);
4848

4949
// Send cancellation message to the top dialog in the stack to ensure all the parents are canceled in the right order.
@@ -90,6 +90,16 @@ public static async Task RunAsync(this Dialog dialog, ITurnContext turnContext,
9090
}
9191
}
9292

93+
// We should only cancel the current dialog stack if the EoC activity is coming from a parent (a root bot or another skill).
94+
// When the EoC is coming back from a child, we should just process that EoC normally through the
95+
// dialog stack and let the child dialogs handle that.
96+
private static bool IsEocComingFromParent(ITurnContext turnContext)
97+
{
98+
// To determine the direction we check callerId property which is set to the parent bot
99+
// by the BotFrameworkHttpClient on outgoing requests.
100+
return !string.IsNullOrWhiteSpace(turnContext.Activity.CallerId);
101+
}
102+
93103
// Recursively walk up the DC stack to find the active DC.
94104
private static DialogContext GetActiveDialogContext(DialogContext dialogContext)
95105
{

libraries/integration/Microsoft.Bot.Builder.Integration.AspNet.Core/BotFrameworkHttpClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public override async Task<InvokeResponse<T>> PostActivityAsync<T>(string fromBo
100100
};
101101
activity.Conversation.Id = conversationId;
102102
activity.ServiceUrl = serviceUrl.ToString();
103-
activity.CallerId = fromBotId;
103+
activity.CallerId = $"urn:botframework:aadappid:{fromBotId}";
104104

105105
using (var jsonContent = new StringContent(JsonConvert.SerializeObject(activity, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }), Encoding.UTF8, "application/json"))
106106
{

0 commit comments

Comments
 (0)