Skip to content

Commit bc11591

Browse files
author
Eyal
authored
Add Orchestrator dispatch sample (simple with skill, qna, luis) (#6275)
* orchestrator docs pointers * update orchestrator readme * left NLR readme shell to be filled in * bf orchestrator cli usage * fixed TBD * fix merge * added examples * more orchestrator docs * rm white space * CR comments * one more CR item * one more * moved perf table to nlrmodels * added license term to models in docs * reference to license for models * updated api ref * with ptr to composer preview doc * fixed link... * fixed link... * added tech references * re-added ref to composer steps * doc: LU processing in Orchestrator * Orchestrator intro pptx * updates to orchestrator readme * revert to main * OrchestratorDispatch sample * fix condition * fix condition 2
1 parent 2dac7be commit bc11591

File tree

59 files changed

+16400
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+16400
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# prevent appsettings.json get checked in
2+
**/appsettings.json
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Welcome to your new bot
2+
3+
This Bot Project was created using the Empty Bot template, and contains a minimal set of files necessary to have a working bot.
4+
5+
## Next steps
6+
7+
### Start building your bot
8+
9+
Composer can help guide you through getting started building your bot. From your bot settings page (the wrench icon on the left navigation rail), click on the rocket-ship icon on the top right for some quick navigation links.
10+
11+
Another great resource if you're just getting started is the **[guided tutorial](https://docs.microsoft.com/en-us/composer/tutorial/tutorial-introduction)** in our documentation.
12+
13+
### Connect with your users
14+
15+
Your bot comes pre-configured to connect to our Web Chat and DirectLine channels, but there are many more places you can connect your bot to - including Microsoft Teams, Telephony, DirectLine Speech, Slack, Facebook, Outlook and more. Check out all of the places you can connect to on the bot settings page.
16+
17+
### Publish your bot to Azure from Composer
18+
19+
Composer can help you provision the Azure resources necessary for your bot, and publish your bot to them. To get started, create a publishing profile from your bot settings page in Composer (the wrench icon on the left navigation rail). Make sure you only provision the optional Azure resources you need!
20+
21+
### Extend your bot with packages
22+
23+
From Package Manager in Composer you can find useful packages to help add additional pre-built functionality you can add to your bot - everything from simple dialogs & custom actions for working with specific scenarios to custom adapters for connecting your bot to users on clients like Facebook or Slack.
24+
25+
### Extend your bot with code
26+
27+
You can also extend your bot with code - simply open up the folder that was generated for you in the location you chose during the creation process with your favorite IDE (like Visual Studio). You can do things like create custom actions that can be used during dialog flows, create custom middleware to pre-process (or post-process) messages, and more. See [our documentation](https://aka.ms/bf-extend-with-code) for more information.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.Bot.Builder;
7+
using Microsoft.Bot.Builder.Dialogs.Adaptive.Runtime.Settings;
8+
using Microsoft.Bot.Builder.Integration.AspNet.Core;
9+
using Microsoft.Extensions.Configuration;
10+
using Microsoft.Extensions.Logging;
11+
12+
namespace OrchestratorDispatch.Controllers
13+
{
14+
// This ASP Controller is created to handle a request. Dependency Injection will provide the Adapter and IBot
15+
// implementation at runtime. Multiple different IBot implementations running at different endpoints can be
16+
// achieved by specifying a more specific type for the bot constructor argument.
17+
[ApiController]
18+
public class BotController : ControllerBase
19+
{
20+
private readonly Dictionary<string, IBotFrameworkHttpAdapter> _adapters = new Dictionary<string, IBotFrameworkHttpAdapter>();
21+
private readonly IBot _bot;
22+
private readonly ILogger<BotController> _logger;
23+
24+
public BotController(
25+
IConfiguration configuration,
26+
IEnumerable<IBotFrameworkHttpAdapter> adapters,
27+
IBot bot,
28+
ILogger<BotController> logger)
29+
{
30+
_bot = bot ?? throw new ArgumentNullException(nameof(bot));
31+
_logger = logger;
32+
33+
var adapterSettings = configuration.GetSection(AdapterSettings.AdapterSettingsKey).Get<List<AdapterSettings>>() ?? new List<AdapterSettings>();
34+
adapterSettings.Add(AdapterSettings.CoreBotAdapterSettings);
35+
36+
foreach (var adapter in adapters ?? throw new ArgumentNullException(nameof(adapters)))
37+
{
38+
var settings = adapterSettings.FirstOrDefault(s => s.Enabled && s.Type == adapter.GetType().FullName);
39+
40+
if (settings != null)
41+
{
42+
_adapters.Add(settings.Route, adapter);
43+
}
44+
}
45+
}
46+
47+
[HttpPost]
48+
[HttpGet]
49+
[Route("api/{route}")]
50+
public async Task PostAsync(string route)
51+
{
52+
if (string.IsNullOrEmpty(route))
53+
{
54+
_logger.LogError($"PostAsync: No route provided.");
55+
throw new ArgumentNullException(nameof(route));
56+
}
57+
58+
if (_adapters.TryGetValue(route, out IBotFrameworkHttpAdapter adapter))
59+
{
60+
if (_logger.IsEnabled(LogLevel.Debug))
61+
{
62+
_logger.LogInformation($"PostAsync: routed '{route}' to {adapter.GetType().Name}");
63+
}
64+
65+
// Delegate the processing of the HTTP POST to the appropriate adapter.
66+
// The adapter will invoke the bot.
67+
await adapter.ProcessAsync(Request, Response, _bot).ConfigureAwait(false);
68+
}
69+
else
70+
{
71+
_logger.LogError($"PostAsync: No adapter registered and enabled for route {route}.");
72+
throw new KeyNotFoundException($"No adapter registered and enabled for route {route}.");
73+
}
74+
}
75+
}
76+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.Bot.Builder;
5+
using Microsoft.Bot.Builder.Integration.AspNet.Core;
6+
using Microsoft.Bot.Schema;
7+
using Microsoft.Extensions.Logging;
8+
9+
namespace OrchestratorDispatch.Controllers
10+
{
11+
/// <summary>
12+
/// A controller that handles skill replies to the bot.
13+
/// </summary>
14+
[ApiController]
15+
[Route("api/skills")]
16+
public class SkillController : ChannelServiceController
17+
{
18+
private readonly ILogger<SkillController> _logger;
19+
20+
public SkillController(ChannelServiceHandlerBase handler, ILogger<SkillController> logger)
21+
: base(handler)
22+
{
23+
_logger = logger;
24+
}
25+
26+
public override Task<IActionResult> ReplyToActivityAsync(string conversationId, string activityId, Activity activity)
27+
{
28+
try
29+
{
30+
if (_logger.IsEnabled(LogLevel.Debug))
31+
{
32+
_logger.LogDebug($"ReplyToActivityAsync: conversationId={conversationId}, activityId={activityId}");
33+
}
34+
35+
return base.ReplyToActivityAsync(conversationId, activityId, activity);
36+
}
37+
catch (Exception ex)
38+
{
39+
_logger.LogError(ex, $"ReplyToActivityAsync: {ex}");
40+
throw;
41+
}
42+
}
43+
44+
public override Task<IActionResult> SendToConversationAsync(string conversationId, Activity activity)
45+
{
46+
try
47+
{
48+
if (_logger.IsEnabled(LogLevel.Debug))
49+
{
50+
_logger.LogDebug($"SendToConversationAsync: conversationId={conversationId}");
51+
}
52+
53+
return base.SendToConversationAsync(conversationId, activity);
54+
}
55+
catch (Exception ex)
56+
{
57+
_logger.LogError(ex, $"SendToConversationAsync: {ex}");
58+
throw;
59+
}
60+
}
61+
}
62+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
5+
<add key="BotBuilder.myget.org" value="https://botbuilder.myget.org/F/botbuilder-v4-dotnet-daily/api/v3/index.json" protocolVersion="3" />
6+
</packageSources>
7+
</configuration>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/microsoft/BotFramework-Composer/main/Composer/packages/server/schemas/botproject.schema",
3+
"name": "OrchestratorDispatch",
4+
"skills": {
5+
"theSkill": {
6+
"manifest": "https://theskill.azurewebsites.net/manifests/TheSkill-2-1-manifest.json",
7+
"remote": true,
8+
"endpointName": "Prod"
9+
}
10+
}
11+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
<Project Sdk="Microsoft.NET.Sdk.Web">
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
6+
<UserSecretsId>f24230a7-de92-41e1-a10c-5c5f4b350bb4</UserSecretsId>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<Content Include="**/*.blu;**/*.dialog;**/*.lg;**/*.lu;**/*.onnx;**/*.qna;**/*.txt" Exclude="$(BaseOutputPath)/**;$(BaseIntermediateOutputPath)/**;wwwroot/**">
10+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
11+
</Content>
12+
</ItemGroup>
13+
<ItemGroup>
14+
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.8" />
15+
<PackageReference Include="Microsoft.Bot.Builder.AI.Orchestrator" Version="4.14.0-daily.preview.20210414.235020.dcacf50" />
16+
<PackageReference Include="Microsoft.Bot.Builder.Dialogs.Adaptive.Runtime" Version="4.13.0" />
17+
</ItemGroup>
18+
</Project>

0 commit comments

Comments
 (0)