Skip to content

Commit

Permalink
Update skill template (microsoft#989)
Browse files Browse the repository at this point in the history
* update skill template for proactive dependencies

* update skill doc

* update response template file

* update response generate c# code
  • Loading branch information
lzc850612 authored Mar 18, 2019
1 parent 8d0ad81 commit 7188210
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 26 deletions.
21 changes: 10 additions & 11 deletions docs/skills/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
![Screenshot](../media/skills_projects.jpg)

3. Add references to **Microsoft.Bot.Solutions** to your new skill and test projects. (Right-click your project, go to **Add > Reference** and select your skill project from the list.)
4. Rebuild project to verify there are no errors.
5. Add your Skill LUIS models to the bot.recipe file located within your assistant project: `assistant\DeploymentScripts\en\bot.recipe
3. Rebuild project to verify there are no errors.
4. Add your Skill LUIS models to the bot.recipe file located within your assistant project: `assistant\DeploymentScripts\en\bot.recipe
```
{
"type": "luis",
Expand All @@ -20,14 +19,14 @@
"luPath": "..\\skills\\MySkill\\MySkill\\CognitiveModels\\LUIS\\en\\MySkill.lu"
}
```
6. Add dispatch references to the core LUIS intents for the skill within the `assistant\CognitiveModels\LOCALE\dispatch.lu` file as shown below and repeat for all locales your skill supports. This enables the Dispatcher to understand your new capabilities and route utterances to your skill.
5. Add dispatch references to the core LUIS intents for the skill within the `assistant\CognitiveModels\LOCALE\dispatch.lu` file as shown below and repeat for all locales your skill supports. This enables the Dispatcher to understand your new capabilities and route utterances to your skill.
```
# l_MySkill
- [Sample intent](../../../../skills/MySkill/MySkill/CognitiveModels/LUIS/en/MySkill.lu#Sample)
```
7. If you have **already deployed your Virtual Assistant** prior to adding your skill, run **update_published_models.ps1** to deploy the new Skill LUIS models and to update the dispatcher (NOTE: if you omit the locales parameter it will update all languages).
6. If you have **already deployed your Virtual Assistant** prior to adding your skill, run **update_published_models.ps1** to deploy the new Skill LUIS models and to update the dispatcher (NOTE: if you omit the locales parameter it will update all languages).
```
pwsh.exe -ExecutionPolicy Bypass -File DeploymentScripts\update_published_models.ps1 -locales "en-us"
```
Expand All @@ -36,9 +35,9 @@
pwsh.exe -ExecutionPolicy Bypass -File DeploymentScripts\Deploy_Bot.ps1
```
8. In Virtual Assistant, add a project reference to your new skill project. This tells the Virtual Assistant that there is a new skill available for use. (Right-click your project, go to **Add > Reference** and select your skill project from the list.)
7. In Virtual Assistant, add a project reference to your new skill project. This tells the Virtual Assistant that there is a new skill available for use. (Right-click your project, go to **Add > Reference** and select your skill project from the list.)
9. In Virtual Assistant, add your skill configuration to **appsettings.json**
8. In Virtual Assistant, add your skill configuration to **appsettings.json**
```
"skills":[
Expand All @@ -58,15 +57,15 @@
}
]
```
10. Run the LuisGen tool to update Dispatch.cs.
9. Run the LuisGen tool to update Dispatch.cs.
```
LUISGen assistant\DeploymentScripts\en\dispatch.luis -cs Dispatch -o assistant\Dialogs\Shared\Resources
```
11. Update **assistant\Dialogs\Main\MainDialog.cs** with the dispatch intent for your skill.
10. Update **assistant\Dialogs\Main\MainDialog.cs** with the dispatch intent for your skill.
![](../media/skills_maindialogupdate.jpg)
12. Run the Virtual Assistant project.
13. Test your new skill with the query "sample dialog".
11. Run the Virtual Assistant project.
12. Test your new skill with the query "sample dialog".
![Screenshot](../media/skills_testnewskill.jpg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Bot.Solutions.Responses;
using Microsoft.Bot.Builder.Solutions.Responses;

namespace $safeprojectname$.Dialogs.Main.Resources
{
Expand All @@ -19,6 +19,5 @@ public class MainResponses : IResponseIdCollection
public const string LogOut = "LogOut";
public const string FeatureNotAvailable = "FeatureNotAvailable";
public const string CancelMessage = "CancelMessage";

}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ output extension=".cs" #>
<#@ include file="..\..\..\..\..\..\Microsoft.Bot.Solutions\Responses\ResponseIdCollection.t4"#>
<#@ include file="..\..\Shared\Resources\ResponseIdCollection.t4"#>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Bot.Solutions.Responses;
using Microsoft.Bot.Builder.Solutions.Responses;

namespace $safeprojectname$.Dialogs.Sample.Resources
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ output extension=".cs" #>
<#@ include file="..\..\..\..\..\..\Microsoft.Bot.Solutions\Responses\ResponseIdCollection.t4"#>
<#@ include file="..\..\Shared\Resources\ResponseIdCollection.t4"#>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<#@ assembly name="Newtonsoft.Json.dll" #>
<#
var className = System.IO.Path.GetFileNameWithoutExtension(Host.TemplateFile);
var namespaceName = System.Runtime.Remoting.Messaging.CallContext.LogicalGetData("NamespaceHint");
string myFile = System.IO.File.ReadAllText(this.Host.ResolvePath(className + ".json"));
var json = Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.Generic.Dictionary<string, dynamic>>(myFile);
var responses = string.Empty;
var cards = string.Empty;
#>
// https://docs.microsoft.com/en-us/visualstudio/modeling/t4-include-directive?view=vs-2017
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Bot.Builder.Solutions.Responses;

namespace <#= namespaceName #>
{
/// <summary>
/// Contains bot responses.
/// </summary>
public class <#= className #> : IResponseIdCollection
{
// Generated accessors
<#
// This code runs in the text json:
foreach (var propertyName in json) {
#>
public const string <#= propertyName.Key.Substring(0, 1).ToUpperInvariant() + propertyName.Key.Substring(1) #> = "<#= propertyName.Key #>";
<# } #>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Bot.Solutions.Responses;
using Microsoft.Bot.Builder.Solutions.Responses;

namespace $safeprojectname$.Dialogs.Shared.Resources
{
Expand All @@ -18,6 +18,5 @@ public class SharedResponses : IResponseIdCollection
public const string AuthFailed = "AuthFailed";
public const string ActionEnded = "ActionEnded";
public const string ErrorMessage = "ErrorMessage";

}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ output extension=".cs" #>
<#@ include file="..\..\..\..\..\..\Microsoft.Bot.Solutions\Responses\ResponseIdCollection.t4"#>
<#@ include file="..\..\Shared\Resources\ResponseIdCollection.t4"#>
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
using System.Threading.Tasks;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Solutions.Responses;
using Microsoft.Bot.Solutions.Skills;
using Microsoft.Bot.Builder.Solutions.Proactive;
using Microsoft.Bot.Builder.Solutions.Responses;
using Microsoft.Bot.Builder.Solutions.Skills;
using Microsoft.Bot.Builder.Solutions.TaskExtensions;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using Microsoft.Bot.Configuration;
using $safeprojectname$.Dialogs.Main;
using $safeprojectname$.Dialogs.Main.Resources;
using $safeprojectname$.Dialogs.Sample.Resources;
Expand All @@ -23,27 +27,36 @@ namespace $safeprojectname$
public class $safeprojectname$ : IBot
{
private readonly SkillConfigurationBase _services;
private readonly EndpointService _endpointService;
private readonly ResponseManager _responseManager;
private readonly ConversationState _conversationState;
private readonly ProactiveState _proactiveState;
private readonly UserState _userState;
private readonly IBotTelemetryClient _telemetryClient;
private readonly IBackgroundTaskQueue _backgroundTaskQueue;
private IServiceManager _serviceManager;
private DialogSet _dialogs;
private bool _skillMode;

public $safeprojectname$(SkillConfigurationBase services,
EndpointService endpointService,
ConversationState conversationState,
UserState userState,
ProactiveState proactiveState,
IBotTelemetryClient telemetryClient,
IBackgroundTaskQueue backgroundTaskQueue,
bool skillMode = false,
ResponseManager responseManager = null,
IServiceManager serviceManager = null)
{
_skillMode = skillMode;
_services = services ?? throw new ArgumentNullException(nameof(services));
_endpointService = endpointService ?? throw new ArgumentNullException(nameof(endpointService));
_userState = userState ?? throw new ArgumentNullException(nameof(userState));
_conversationState = conversationState ?? throw new ArgumentNullException(nameof(conversationState));
_proactiveState = proactiveState ?? throw new ArgumentNullException(nameof(proactiveState));
_telemetryClient = telemetryClient ?? throw new ArgumentNullException(nameof(telemetryClient));
_backgroundTaskQueue = backgroundTaskQueue ?? throw new ArgumentNullException(nameof(backgroundTaskQueue));
_serviceManager = serviceManager ?? new ServiceManager();

if (responseManager == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,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.Solutions" Version="4.4.0-preview-3" />
<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
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
using Microsoft.Bot.Configuration;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Schema;
using Microsoft.Bot.Solutions.Middleware;
using Microsoft.Bot.Solutions.Telemetry;
using Microsoft.Bot.Solutions.Responses;
using Microsoft.Bot.Solutions.Skills;
using Microsoft.Bot.Builder.Solutions.Middleware;
using Microsoft.Bot.Builder.Solutions.Proactive;
using Microsoft.Bot.Builder.Solutions.Skills;
using Microsoft.Bot.Builder.Solutions.TaskExtensions;
using Microsoft.Bot.Builder.Solutions.Telemetry;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using $safeprojectname$.Dialogs.Main.Resources;
Expand Down Expand Up @@ -47,7 +48,11 @@ public Startup(IHostingEnvironment env)
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_2);


// add background task queue
services.AddSingleton<IBackgroundTaskQueue, BackgroundTaskQueue>();
services.AddHostedService<QueuedHostedService>();

// Load the connected services from .bot file.
var botFilePath = Configuration.GetSection("botFilePath")?.Value;
var botFileSecret = Configuration.GetSection("botFileSecret")?.Value;
Expand Down Expand Up @@ -88,10 +93,12 @@ public void ConfigureServices(IServiceCollection services)
var dataStore = new CosmosDbStorage(cosmosOptions);
var userState = new UserState(dataStore);
var conversationState = new ConversationState(dataStore);
var proactiveState = new ProactiveState(dataStore);

services.AddSingleton(dataStore);
services.AddSingleton(userState);
services.AddSingleton(conversationState);
services.AddSingleton(proactiveState);
services.AddSingleton(new BotStateSet(userState, conversationState));

services.AddTransient<IServiceManager, ServiceManager>();
Expand Down Expand Up @@ -140,6 +147,7 @@ public void ConfigureServices(IServiceCollection services)
botFrameworkHttpAdapter.Use(typingMiddleware);
botFrameworkHttpAdapter.Use(new SetLocaleMiddleware(defaultLocale ?? "en-us"));
botFrameworkHttpAdapter.Use(new AutoSaveStateMiddleware(userState, conversationState));
botFrameworkHttpAdapter.Use(new ProactiveStateMiddleware(proactiveState));

return botFrameworkHttpAdapter;
});
Expand Down

0 comments on commit 7188210

Please sign in to comment.