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

Commit

Permalink
enable websocket for skills by referencing the latest skills package (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lzc850612 committed Apr 22, 2019
1 parent 742e64f commit 8c4d6ca
Show file tree
Hide file tree
Showing 35 changed files with 380 additions and 259 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
using AutomotiveSkill.Services;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Azure;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Skills;
using Microsoft.Bot.Builder.Solutions.Middleware;
using Microsoft.Bot.Builder.Solutions.Responses;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Schema;

namespace AutomotiveSkill.Adapters
{
public class AutomotiveSkillAdapter : SkillAdapter
public class AutomotiveSkillHttpBotAdapter : SkillHttpBotAdapter
{
public AutomotiveSkillAdapter(
public AutomotiveSkillHttpBotAdapter(
BotSettings settings,
ICredentialProvider credentialProvider,
UserState userState,
ConversationState conversationState,
BotStateSet botStateSet,
ResponseManager responseManager,
IBotTelemetryClient telemetryClient)
: base(credentialProvider)
{
OnTurnError = async (context, exception) =>
{
Expand All @@ -36,8 +35,8 @@ public AutomotiveSkillAdapter(
Use(new ShowTypingMiddleware());
Use(new SetLocaleMiddleware(settings.DefaultLocale ?? "en-us"));
Use(new EventDebuggerMiddleware());
Use(new AutoSaveStateMiddleware(userState, conversationState));
Use(new SkillMiddleware(userState));
Use(new AutoSaveStateMiddleware(botStateSet));
Use(new SkillMiddleware(userState, conversationState, conversationState.CreateProperty<DialogState>(nameof(AutomotiveSkill))));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Globalization;
using AutomotiveSkill.Responses.Shared;
using AutomotiveSkill.Services;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Azure;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Skills;
using Microsoft.Bot.Builder.Solutions.Middleware;
using Microsoft.Bot.Builder.Solutions.Responses;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using Microsoft.Bot.Schema;

namespace AutomotiveSkill.Adapters
{
public class AutomotiveSkillWebSocketBotAdapter : SkillWebSocketBotAdapter
{
public AutomotiveSkillWebSocketBotAdapter(
BotSettings settings,
UserState userState,
ConversationState conversationState,
BotStateSet botStateSet,
ResponseManager responseManager,
IBotTelemetryClient telemetryClient)
{
OnTurnError = async (context, exception) =>
{
CultureInfo.CurrentUICulture = new CultureInfo(context.Activity.Locale);
await context.SendActivityAsync(responseManager.GetResponse(AutomotiveSkillSharedResponses.ErrorMessage));
await context.SendActivityAsync(new Activity(type: ActivityTypes.Trace, text: $"Automotive Skill Error: {exception.Message} | {exception.StackTrace}"));
telemetryClient.TrackExceptionEx(exception, context.Activity);
};

Use(new TranscriptLoggerMiddleware(new AzureBlobTranscriptStore(settings.BlobStorage.ConnectionString, settings.BlobStorage.Container)));
Use(new TelemetryLoggerMiddleware(telemetryClient, logPersonalInformation: true));
Use(new ShowTypingMiddleware());
Use(new SetLocaleMiddleware(settings.DefaultLocale ?? "en-us"));
Use(new EventDebuggerMiddleware());
Use(new AutoSaveStateMiddleware(botStateSet));
Use(new SkillMiddleware(userState, conversationState, conversationState.CreateProperty<DialogState>(nameof(AutomotiveSkill))));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.ApplicationInsights.Core" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.Skills" Version="4.4.0-preview-19" />
<PackageReference Include="Microsoft.Bot.Builder.TemplateManager" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Configuration" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Connector" Version="4.3.1" />
Expand Down Expand Up @@ -104,11 +105,6 @@
<EmbeddedResource Include="Responses\VehicleSettings\VehicleSettingsResponses.it.json" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\..\lib\csharp\microsoft.bot.builder.skills\Microsoft.Bot.Builder.Skills\Microsoft.Bot.Builder.Skills.csproj" />
<ProjectReference Include="..\..\..\..\..\lib\csharp\microsoft.bot.builder.solutions\microsoft.bot.builder.solutions\Microsoft.Bot.Builder.Solutions.csproj" />
</ItemGroup>

<ItemGroup>
<Content Update="wwwroot\images\settingcog.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down

This file was deleted.

10 changes: 5 additions & 5 deletions skills/src/csharp/automotiveskill/automotiveskill/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,12 @@ public void ConfigureServices(IServiceCollection services)
};
});

// comment out for now to disable whitelist checking
// services.AddSingleton<ISkillAuthProvider, JwtClaimAuthProvider>();
// services.AddSingleton<ISkillWhitelist, SkillWhitelist>();

// Configure adapters
services.AddTransient<IBotFrameworkHttpAdapter, DefaultAdapter>();
services.AddTransient<SkillAdapter, AutomotiveSkillAdapter>();
services.AddTransient<SkillWebSocketBotAdapter, AutomotiveSkillWebSocketBotAdapter>();
services.AddTransient<SkillWebSocketAdapter>();
services.AddTransient<SkillHttpBotAdapter, AutomotiveSkillHttpBotAdapter>();
services.AddTransient<SkillHttpAdapter>();

// Configure bot
services.AddTransient<MainDialog>();
Expand All @@ -138,6 +137,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
app.UseDefaultFiles()
.UseStaticFiles()
.UseAuthentication()
.UseWebSockets()
.UseMvc();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
using CalendarSkill.Services;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Azure;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Skills;
using Microsoft.Bot.Builder.Solutions.Middleware;
using Microsoft.Bot.Builder.Solutions.Responses;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Schema;

namespace CalendarSkill.Adapters
{
public class CalendarSkillAdapter : SkillAdapter
public class CalendarSkillHttpBotAdapter : SkillHttpBotAdapter
{
public CalendarSkillAdapter(
public CalendarSkillHttpBotAdapter(
BotSettings settings,
ICredentialProvider credentialProvider,
UserState userState,
ConversationState conversationState,
BotStateSet botStateSet,
ResponseManager responseManager,
IBotTelemetryClient telemetryClient,
UserState userState)
: base(credentialProvider)
IBotTelemetryClient telemetryClient)
{
OnTurnError = async (context, exception) =>
{
Expand All @@ -37,7 +36,7 @@ public CalendarSkillAdapter(
Use(new SetLocaleMiddleware(settings.DefaultLocale ?? "en-us"));
Use(new EventDebuggerMiddleware());
Use(new AutoSaveStateMiddleware(botStateSet));
Use(new SkillMiddleware(userState));
Use(new SkillMiddleware(userState, conversationState, conversationState.CreateProperty<DialogState>(nameof(CalendarSkill))));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Globalization;
using CalendarSkill.Responses.Shared;
using CalendarSkill.Services;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Azure;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Skills;
using Microsoft.Bot.Builder.Solutions.Middleware;
using Microsoft.Bot.Builder.Solutions.Responses;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using Microsoft.Bot.Schema;

namespace CalendarSkill.Adapters
{
public class CalendarSkillWebSocketBotAdapter : SkillWebSocketBotAdapter
{
public CalendarSkillWebSocketBotAdapter(
BotSettings settings,
UserState userState,
ConversationState conversationState,
BotStateSet botStateSet,
ResponseManager responseManager,
IBotTelemetryClient telemetryClient)
{
OnTurnError = async (context, exception) =>
{
CultureInfo.CurrentUICulture = new CultureInfo(context.Activity.Locale);
await context.SendActivityAsync(responseManager.GetResponse(CalendarSharedResponses.CalendarErrorMessage));
await context.SendActivityAsync(new Activity(type: ActivityTypes.Trace, text: $"Calendar Skill Error: {exception.Message} | {exception.StackTrace}"));
telemetryClient.TrackExceptionEx(exception, context.Activity);
};

Use(new TranscriptLoggerMiddleware(new AzureBlobTranscriptStore(settings.BlobStorage.ConnectionString, settings.BlobStorage.Container)));
Use(new TelemetryLoggerMiddleware(telemetryClient, logPersonalInformation: true));
Use(new ShowTypingMiddleware());
Use(new SetLocaleMiddleware(settings.DefaultLocale ?? "en-us"));
Use(new EventDebuggerMiddleware());
Use(new AutoSaveStateMiddleware(botStateSet));
Use(new SkillMiddleware(userState, conversationState, conversationState.CreateProperty<DialogState>(nameof(CalendarSkill))));
}
}
}
21 changes: 0 additions & 21 deletions skills/src/csharp/calendarskill/calendarskill/SkillWhitelist.cs

This file was deleted.

10 changes: 5 additions & 5 deletions skills/src/csharp/calendarskill/calendarskill/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,12 @@ public void ConfigureServices(IServiceCollection services)
};
});

// comment out for now to disable whitelist checking
// services.AddSingleton<ISkillAuthProvider, JwtClaimAuthProvider>();
// services.AddSingleton<ISkillWhitelist, SkillWhitelist>();

// Configure adapters
services.AddTransient<IBotFrameworkHttpAdapter, DefaultAdapter>();
services.AddTransient<SkillAdapter, CalendarSkillAdapter>();
services.AddTransient<SkillWebSocketBotAdapter, CalendarSkillWebSocketBotAdapter>();
services.AddTransient<SkillWebSocketAdapter>();
services.AddTransient<SkillHttpBotAdapter, CalendarSkillHttpBotAdapter>();
services.AddTransient<SkillHttpAdapter>();

// Configure bot
services.AddTransient<MainDialog>();
Expand All @@ -149,6 +148,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
.UseDefaultFiles()
.UseStaticFiles()
.UseAuthentication()
.UseWebSockets()
.UseMvc();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
using EmailSkill.Services;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Azure;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Skills;
using Microsoft.Bot.Builder.Solutions.Middleware;
using Microsoft.Bot.Builder.Solutions.Responses;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Schema;

namespace EmailSkill.Adapters
{
public class EmailSkillAdapter : SkillAdapter
public class EmailSkillHttpBotAdapter : SkillHttpBotAdapter
{
public EmailSkillAdapter(
public EmailSkillHttpBotAdapter(
BotSettings settings,
ICredentialProvider credentialProvider,
UserState userState,
ConversationState conversationState,
BotStateSet botStateSet,
ResponseManager responseManager,
IBotTelemetryClient telemetryClient,
UserState userState)
: base(credentialProvider)
IBotTelemetryClient telemetryClient)
{
OnTurnError = async (context, exception) =>
{
Expand All @@ -37,7 +36,7 @@ public EmailSkillAdapter(
Use(new SetLocaleMiddleware(settings.DefaultLocale ?? "en-us"));
Use(new EventDebuggerMiddleware());
Use(new AutoSaveStateMiddleware(botStateSet));
Use(new SkillMiddleware(userState));
Use(new SkillMiddleware(userState, conversationState, conversationState.CreateProperty<DialogState>(nameof(EmailSkill))));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Globalization;
using EmailSkill.Responses.Shared;
using EmailSkill.Services;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Azure;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Skills;
using Microsoft.Bot.Builder.Solutions.Middleware;
using Microsoft.Bot.Builder.Solutions.Responses;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using Microsoft.Bot.Schema;

namespace EmailSkill.Adapters
{
public class EmailSkillWebSocketBotAdapter : SkillWebSocketBotAdapter
{
public EmailSkillWebSocketBotAdapter(
BotSettings settings,
UserState userState,
ConversationState conversationState,
BotStateSet botStateSet,
ResponseManager responseManager,
IBotTelemetryClient telemetryClient)
{
OnTurnError = async (context, exception) =>
{
CultureInfo.CurrentUICulture = new CultureInfo(context.Activity.Locale);
await context.SendActivityAsync(responseManager.GetResponse(EmailSharedResponses.EmailErrorMessage));
await context.SendActivityAsync(new Activity(type: ActivityTypes.Trace, text: $"Email Skill Error: {exception.Message} | {exception.StackTrace}"));
telemetryClient.TrackExceptionEx(exception, context.Activity);
};

Use(new TranscriptLoggerMiddleware(new AzureBlobTranscriptStore(settings.BlobStorage.ConnectionString, settings.BlobStorage.Container)));
Use(new TelemetryLoggerMiddleware(telemetryClient, logPersonalInformation: true));
Use(new ShowTypingMiddleware());
Use(new SetLocaleMiddleware(settings.DefaultLocale ?? "en-us"));
Use(new EventDebuggerMiddleware());
Use(new AutoSaveStateMiddleware(botStateSet));
Use(new SkillMiddleware(userState, conversationState, conversationState.CreateProperty<DialogState>(nameof(EmailSkill))));
}
}
}
6 changes: 1 addition & 5 deletions skills/src/csharp/emailskill/emailskill/EmailSkill.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<PackageReference Include="Microsoft.Bot.Builder.Dialogs" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.ApplicationInsights.Core" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Builder.Skills" Version="4.4.0-preview-19" />
<PackageReference Include="Microsoft.Bot.Builder.TemplateManager" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Configuration" Version="4.3.1" />
<PackageReference Include="Microsoft.Bot.Connector" Version="4.3.1" />
Expand Down Expand Up @@ -164,11 +165,6 @@
<EmbeddedResource Include="Responses\ShowEmail\ShowEmailResponses.json" />
<EmbeddedResource Include="Responses\ShowEmail\ShowEmailResponses.zh.json" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\..\lib\csharp\microsoft.bot.builder.skills\Microsoft.Bot.Builder.Skills\Microsoft.Bot.Builder.Skills.csproj" />
<ProjectReference Include="..\..\..\..\..\lib\csharp\microsoft.bot.builder.solutions\microsoft.bot.builder.solutions\Microsoft.Bot.Builder.Solutions.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="Responses\DeleteEmail\DeleteEmailResponses.tt">
Expand Down
Loading

0 comments on commit 8c4d6ca

Please sign in to comment.