Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.

Commit 350c77e

Browse files
ssss141414bobokids
authored andcommitted
update to rc2 (#2660)
1 parent 59eb16c commit 350c77e

File tree

9 files changed

+97
-96
lines changed

9 files changed

+97
-96
lines changed

skills/csharp/tests/todoskill.tests/Flow/Fakes/MockLuisRecognizer.cs

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,26 @@
1313

1414
namespace ToDoSkill.Tests.Flow.Fakes
1515
{
16-
public class MockLuisRecognizer : ITelemetryRecognizer
16+
public class MockLuisRecognizer : LuisRecognizer
1717
{
18+
private static LuisApplication mockApplication = new LuisApplication()
19+
{
20+
ApplicationId = "testappid",
21+
Endpoint = "testendpoint",
22+
EndpointKey = "testendpointkey"
23+
};
24+
1825
private BaseTestUtterances utterancesManager;
1926
private GeneralTestUtterances generalUtterancesManager;
2027

2128
public MockLuisRecognizer(BaseTestUtterances utterancesManager)
29+
: base(mockApplication)
2230
{
2331
this.utterancesManager = utterancesManager;
2432
}
2533

2634
public MockLuisRecognizer(params BaseTestUtterances[] utterancesManagers)
35+
: base(mockApplication)
2736
{
2837
this.utterancesManager = new BaseTestUtterances();
2938

@@ -37,21 +46,12 @@ public MockLuisRecognizer(params BaseTestUtterances[] utterancesManagers)
3746
}
3847

3948
public MockLuisRecognizer(GeneralTestUtterances generalUtterancesMananger)
49+
: base(mockApplication)
4050
{
4151
this.generalUtterancesManager = generalUtterancesMananger;
4252
}
4353

44-
public bool LogPersonalInformation { get; set; } = false;
45-
46-
public IBotTelemetryClient TelemetryClient { get; set; } = new NullBotTelemetryClient();
47-
48-
public Task<RecognizerResult> RecognizeAsync(ITurnContext turnContext, CancellationToken cancellationToken)
49-
{
50-
throw new NotImplementedException();
51-
}
52-
53-
public Task<T> RecognizeAsync<T>(ITurnContext turnContext, CancellationToken cancellationToken)
54-
where T : IRecognizerConvert, new()
54+
public override Task<T> RecognizeAsync<T>(ITurnContext turnContext, CancellationToken cancellationToken)
5555
{
5656
var mockResult = new T();
5757

@@ -74,22 +74,5 @@ public Task<T> RecognizeAsync<T>(ITurnContext turnContext, CancellationToken can
7474

7575
return Task.FromResult(mockResult);
7676
}
77-
78-
public Task<T> RecognizeAsync<T>(DialogContext dialogContext, CancellationToken cancellationToken = default(CancellationToken))
79-
where T : IRecognizerConvert, new()
80-
{
81-
throw new NotImplementedException();
82-
}
83-
84-
public Task<RecognizerResult> RecognizeAsync(ITurnContext turnContext, Dictionary<string, string> telemetryProperties, Dictionary<string, double> telemetryMetrics, CancellationToken cancellationToken = default(CancellationToken))
85-
{
86-
throw new NotImplementedException();
87-
}
88-
89-
public Task<T> RecognizeAsync<T>(ITurnContext turnContext, Dictionary<string, string> telemetryProperties, Dictionary<string, double> telemetryMetrics, CancellationToken cancellationToken = default(CancellationToken))
90-
where T : IRecognizerConvert, new()
91-
{
92-
throw new NotImplementedException();
93-
}
9477
}
9578
}

skills/csharp/tests/todoskill.tests/Flow/ToDoSkillTestBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public override void Initialize()
6363
{
6464
"en", new CognitiveModelSet()
6565
{
66-
LuisServices = new Dictionary<string, ITelemetryRecognizer>
66+
LuisServices = new Dictionary<string, LuisRecognizer>
6767
{
6868
{ MockData.LuisGeneral, new MockLuisRecognizer(new GeneralTestUtterances()) },
6969
{
@@ -111,7 +111,7 @@ public override void Initialize()
111111
Services.AddTransient<DeleteToDoItemDialog>();
112112
Services.AddTransient<MarkToDoItemDialog>();
113113
Services.AddTransient<ShowToDoItemDialog>();
114-
Services.AddTransient<IBot, DialogBot<MainDialog>>();
114+
Services.AddTransient<IBot, DefaultActivityHandler<MainDialog>>();
115115
}
116116

117117
public TestFlow GetTestFlow()

skills/csharp/todoskill/Adapters/DefaultAdapter.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Globalization;
55
using Microsoft.Bot.Builder;
66
using Microsoft.Bot.Builder.Azure;
7+
using Microsoft.Bot.Builder.Integration.ApplicationInsights.Core;
78
using Microsoft.Bot.Builder.Integration.AspNet.Core;
89
using Microsoft.Bot.Builder.Solutions.Middleware;
910
using Microsoft.Bot.Builder.Solutions.Responses;
@@ -20,7 +21,8 @@ public DefaultAdapter(
2021
BotSettings settings,
2122
ICredentialProvider credentialProvider,
2223
IBotTelemetryClient telemetryClient,
23-
ResponseManager responseManager)
24+
ResponseManager responseManager,
25+
TelemetryInitializerMiddleware telemetryMiddleware)
2426
: base(credentialProvider)
2527
{
2628
OnTurnError = async (context, exception) =>
@@ -31,6 +33,7 @@ public DefaultAdapter(
3133
telemetryClient.TrackException(exception);
3234
};
3335

36+
Use(telemetryMiddleware);
3437
Use(new TranscriptLoggerMiddleware(new AzureBlobTranscriptStore(settings.BlobStorage.ConnectionString, settings.BlobStorage.Container)));
3538
Use(new TelemetryLoggerMiddleware(telemetryClient, logPersonalInformation: true));
3639
Use(new ShowTypingMiddleware());

skills/csharp/todoskill/Adapters/ToDoSkillWebSocketBotAdapter.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.Bot.Builder;
66
using Microsoft.Bot.Builder.Azure;
77
using Microsoft.Bot.Builder.Dialogs;
8+
using Microsoft.Bot.Builder.Integration.ApplicationInsights.Core;
89
using Microsoft.Bot.Builder.Skills;
910
using Microsoft.Bot.Builder.Solutions.Middleware;
1011
using Microsoft.Bot.Builder.Solutions.Responses;
@@ -21,7 +22,8 @@ public ToDoSkillWebSocketBotAdapter(
2122
UserState userState,
2223
ConversationState conversationState,
2324
ResponseManager responseManager,
24-
IBotTelemetryClient telemetryClient)
25+
IBotTelemetryClient telemetryClient,
26+
TelemetryInitializerMiddleware telemetryMiddleware)
2527
: base(null, telemetryClient)
2628
{
2729
OnTurnError = async (context, exception) =>
@@ -32,6 +34,7 @@ public ToDoSkillWebSocketBotAdapter(
3234
telemetryClient.TrackException(exception);
3335
};
3436

37+
Use(telemetryMiddleware);
3538
Use(new TranscriptLoggerMiddleware(new AzureBlobTranscriptStore(settings.BlobStorage.ConnectionString, settings.BlobStorage.Container)));
3639
Use(new TelemetryLoggerMiddleware(telemetryClient, logPersonalInformation: true));
3740
Use(new SetLocaleMiddleware(settings.DefaultLocale ?? "en-us"));
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
using Microsoft.Bot.Builder;
6+
using Microsoft.Bot.Builder.Dialogs;
7+
using Microsoft.Bot.Schema;
8+
using Microsoft.Extensions.DependencyInjection;
9+
10+
namespace ToDoSkill.Bots
11+
{
12+
public class DefaultActivityHandler<T> : ActivityHandler
13+
where T : Dialog
14+
{
15+
private readonly Dialog _dialog;
16+
private readonly BotState _conversationState;
17+
private readonly BotState _userState;
18+
private IStatePropertyAccessor<DialogState> _dialogStateAccessor;
19+
20+
public DefaultActivityHandler(IServiceProvider serviceProvider, T dialog)
21+
{
22+
_dialog = dialog;
23+
_conversationState = serviceProvider.GetService<ConversationState>();
24+
_userState = serviceProvider.GetService<UserState>();
25+
_dialogStateAccessor = _conversationState.CreateProperty<DialogState>(nameof(DialogState));
26+
}
27+
28+
public override async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
29+
{
30+
await base.OnTurnAsync(turnContext, cancellationToken);
31+
32+
// Save any state changes that might have occured during the turn.
33+
await _conversationState.SaveChangesAsync(turnContext, false, cancellationToken);
34+
await _userState.SaveChangesAsync(turnContext, false, cancellationToken);
35+
}
36+
37+
protected override Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
38+
{
39+
return _dialog.RunAsync(turnContext, _dialogStateAccessor, cancellationToken);
40+
}
41+
42+
protected override Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
43+
{
44+
return _dialog.RunAsync(turnContext, _dialogStateAccessor, cancellationToken);
45+
}
46+
47+
protected override Task OnEventActivityAsync(ITurnContext<IEventActivity> turnContext, CancellationToken cancellationToken)
48+
{
49+
return _dialog.RunAsync(turnContext, _dialogStateAccessor, cancellationToken);
50+
}
51+
}
52+
}

skills/csharp/todoskill/Bots/DialogBot.cs

Lines changed: 0 additions & 46 deletions
This file was deleted.

skills/csharp/todoskill/Dialogs/MainDialog.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
namespace ToDoSkill.Dialogs
2525
{
26-
public class MainDialog : RouterDialog
26+
public class MainDialog : ActivityHandlerDialog
2727
{
2828
private BotSettings _settings;
2929
private BotServices _services;
@@ -55,12 +55,12 @@ public MainDialog(
5555
AddDialog(showToDoItemDialog ?? throw new ArgumentNullException(nameof(showToDoItemDialog)));
5656
}
5757

58-
protected override async Task OnStartAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
58+
protected override async Task OnMembersAddedAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
5959
{
6060
await dc.Context.SendActivityAsync(_responseManager.GetResponse(ToDoMainResponses.ToDoWelcomeMessage));
6161
}
6262

63-
protected override async Task RouteAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
63+
protected override async Task OnMessageActivityAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
6464
{
6565
var state = await _toDoStateAccessor.GetAsync(dc.Context, () => new ToDoSkillState());
6666

@@ -138,7 +138,7 @@ public MainDialog(
138138
}
139139
}
140140

141-
protected override async Task CompleteAsync(DialogContext dc, DialogTurnResult result = null, CancellationToken cancellationToken = default(CancellationToken))
141+
protected override async Task OnDialogCompleteAsync(DialogContext dc, object result = null, CancellationToken cancellationToken = default(CancellationToken))
142142
{
143143
// workaround. if connect skill directly to teams, the following response does not work.
144144
if (dc.Context.Adapter is IRemoteUserTokenProvider remoteInvocationAdapter || Channel.GetChannelId(dc.Context) != Channels.Msteams)
@@ -153,7 +153,7 @@ public MainDialog(
153153
await dc.EndDialogAsync(result);
154154
}
155155

156-
protected override async Task OnEventAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
156+
protected override async Task OnEventActivityAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
157157
{
158158
switch (dc.Context.Activity.Name)
159159
{
@@ -236,15 +236,14 @@ public MainDialog(
236236
private async Task<InterruptionAction> OnCancel(DialogContext dc)
237237
{
238238
await dc.Context.SendActivityAsync(_responseManager.GetResponse(ToDoMainResponses.CancelMessage));
239-
await CompleteAsync(dc);
240239
await dc.CancelAllDialogsAsync();
241-
return InterruptionAction.StartedDialog;
240+
return InterruptionAction.End;
242241
}
243242

244243
private async Task<InterruptionAction> OnHelp(DialogContext dc)
245244
{
246245
await dc.Context.SendActivityAsync(_responseManager.GetResponse(ToDoMainResponses.HelpMessage));
247-
return InterruptionAction.MessageSentToUser;
246+
return InterruptionAction.Resume;
248247
}
249248

250249
private async Task<InterruptionAction> OnLogout(DialogContext dc)
@@ -271,7 +270,7 @@ private async Task<InterruptionAction> OnLogout(DialogContext dc)
271270

272271
await dc.Context.SendActivityAsync(_responseManager.GetResponse(ToDoMainResponses.LogOut));
273272

274-
return InterruptionAction.StartedDialog;
273+
return InterruptionAction.End;
275274
}
276275

277276
private void InitializeConfig(ToDoSkillState state)

skills/csharp/todoskill/Startup.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System.Linq;
55
using Microsoft.ApplicationInsights;
6+
using Microsoft.ApplicationInsights.Extensibility;
67
using Microsoft.AspNetCore.Builder;
78
using Microsoft.AspNetCore.Hosting;
89
using Microsoft.AspNetCore.Http;
@@ -79,9 +80,11 @@ public void ConfigureServices(IServiceCollection services)
7980

8081
// Configure telemetry
8182
services.AddApplicationInsightsTelemetry();
82-
var telemetryClient = new BotTelemetryClient(new TelemetryClient());
83-
services.AddSingleton<IBotTelemetryClient>(telemetryClient);
84-
services.AddBotApplicationInsights(telemetryClient);
83+
services.AddSingleton<IBotTelemetryClient, BotTelemetryClient>();
84+
services.AddSingleton<ITelemetryInitializer, OperationCorrelationTelemetryInitializer>();
85+
services.AddSingleton<ITelemetryInitializer, TelemetryBotIdInitializer>();
86+
services.AddSingleton<TelemetryInitializerMiddleware>();
87+
services.AddSingleton<TelemetryLoggerMiddleware>();
8588

8689
// Configure bot services
8790
services.AddSingleton<BotServices>();
@@ -123,7 +126,7 @@ public void ConfigureServices(IServiceCollection services)
123126

124127
// Configure bot
125128
services.AddTransient<MainDialog>();
126-
services.AddTransient<IBot, DialogBot<MainDialog>>();
129+
services.AddTransient<IBot, DefaultActivityHandler<MainDialog>>();
127130
}
128131

129132
/// <summary>
@@ -138,8 +141,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
138141
app.UseDeveloperExceptionPage();
139142
}
140143

141-
app.UseBotApplicationInsights()
142-
.UseDefaultFiles()
144+
app.UseDefaultFiles()
143145
.UseStaticFiles()
144146
.UseWebSockets()
145147
.UseMvc();

skills/csharp/todoskill/ToDoSkill.csproj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@
3838
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.6.1" />
3939
<PackageReference Include="Microsoft.Bot.Builder.Integration.ApplicationInsights.Core" Version="4.6.1" />
4040
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.6.1" />
41-
<PackageReference Include="Microsoft.Bot.Builder.Skills" Version="4.5.4" />
42-
<PackageReference Include="Microsoft.Bot.Builder.Solutions" Version="4.5.4" />
4341
<PackageReference Include="Microsoft.Bot.Builder.TemplateManager" Version="4.6.1" />
4442
<PackageReference Include="Microsoft.Bot.Configuration" Version="4.6.1" />
4543
<PackageReference Include="Microsoft.Bot.Connector" Version="4.6.1" />
4644
<PackageReference Include="Microsoft.Bot.Schema" Version="4.6.1" />
4745
<PackageReference Include="Microsoft.Graph" Version="1.15.0" />
46+
47+
<PackageReference Include="Microsoft.Bot.Builder.Skills" Version="4.6.0-preview-rc2" />
48+
<PackageReference Include="Microsoft.Bot.Builder.Solutions" Version="4.6.0-preview-rc2" />
4849
</ItemGroup>
4950

5051
<ItemGroup>
@@ -178,4 +179,8 @@
178179
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
179180
</ItemGroup>
180181

182+
<ItemGroup>
183+
<Folder Include="Bots\" />
184+
</ItemGroup>
185+
181186
</Project>

0 commit comments

Comments
 (0)