Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.
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
3 changes: 2 additions & 1 deletion libraries/Microsoft.Bot.Builder.Dialogs/DialogExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ public static class DialogExtensions
public static async Task RunAsync(this Dialog dialog, ITurnContext turnContext, IStatePropertyAccessor<DialogState> accessor, CancellationToken cancellationToken)
{
var dialogSet = new DialogSet(accessor);
dialogSet.Add(dialog);

// look for the IBotTelemetryClient on the TurnState, if not there take it from the Dialog, if not there fall back to the "null" default
dialogSet.TelemetryClient = turnContext.TurnState.Get<IBotTelemetryClient>() ?? dialog.TelemetryClient ?? NullBotTelemetryClient.Instance;

dialogSet.Add(dialog);

var dialogContext = await dialogSet.CreateContextAsync(turnContext, cancellationToken).ConfigureAwait(false);

await InternalRunAsync(turnContext, dialog.Id, dialogContext, cancellationToken).ConfigureAwait(false);
Expand Down
29 changes: 29 additions & 0 deletions tests/Microsoft.Bot.Builder.Dialogs.Tests/DialogExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Microsoft.Bot.Builder.Skills;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Schema;
using Moq;
using Xunit;

namespace Microsoft.Bot.Builder.Dialogs.Tests
Expand Down Expand Up @@ -114,6 +115,34 @@ await testFlow.Send("Hi")
Assert.Equal(DialogReason.BeginCalled, dialog.EndReason);
}

[Fact]
public async Task RunAsyncShouldSetTelemetryClient()
{
var adapter = new Mock<BotAdapter>();
var dialog = new SimpleComponentDialog();
var conversationState = new ConversationState(new MemoryStorage());

// ChannelId and Conversation.Id are required for ConversationState and
// ChannelId and From.Id are required for UserState.
var activity = new Activity
{
ChannelId = "test-channel",
Conversation = new ConversationAccount { Id = "test-conversation-id" },
From = new ChannelAccount { Id = "test-id" }
};

var telemetryClientMock = new Mock<IBotTelemetryClient>();

using (var turnContext = new TurnContext(adapter.Object, activity))
{
turnContext.TurnState.Add(telemetryClientMock.Object);

await DialogExtensions.RunAsync(dialog, turnContext, conversationState.CreateProperty<DialogState>("DialogState"), CancellationToken.None);
}

Assert.Equal(telemetryClientMock.Object, dialog.TelemetryClient);
}

/// <summary>
/// Creates a TestFlow instance with state data to recreate and assert the different test case.
/// </summary>
Expand Down