Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions libraries/Microsoft.Bot.Builder.Dialogs/DialogExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public static async Task RunAsync(this Dialog dialog, ITurnContext turnContext,
if (turnContext.TurnState.Get<IIdentity>(BotAdapter.BotIdentityKey) is ClaimsIdentity claimIdentity && SkillValidation.IsSkillClaim(claimIdentity.Claims))
{
// The bot is running as a skill.
if (turnContext.Activity.Type == ActivityTypes.EndOfConversation && dialogContext.Stack.Any())
if (turnContext.Activity.Type == ActivityTypes.EndOfConversation && dialogContext.Stack.Any() && IsEocComingFromParent(turnContext))
{
// Handle remote cancellation request if we have something in the stack.
// Handle remote cancellation request from parent.
var activeDialogContext = GetActiveDialogContext(dialogContext);

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

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

// We should only cancel the current dialog stack if the EoC activity is coming from a parent (a root bot or another skill).
// When the EoC is coming back from a child, we should just process that EoC normally through the
// dialog stack and let the child dialogs handle that.
private static bool IsEocComingFromParent(ITurnContext turnContext)
{
// To determine the direction we check callerId property which is set to the parent bot
// by the BotFrameworkHttpClient on outgoing requests.
return !string.IsNullOrWhiteSpace(turnContext.Activity.CallerId);
}

// Recursively walk up the DC stack to find the active DC.
private static DialogContext GetActiveDialogContext(DialogContext dialogContext)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public override async Task<InvokeResponse<T>> PostActivityAsync<T>(string fromBo
};
activity.Conversation.Id = conversationId;
activity.ServiceUrl = serviceUrl.ToString();
activity.CallerId = fromBotId;
activity.CallerId = $"urn:botframework:aadappid:{fromBotId}";

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