├── .gitignore ├── AllProjects.sln ├── demo1 ├── Bots │ └── SimpleBot.cs ├── Controllers │ └── ValuesController.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json ├── demo1.sln ├── demo1helloworld.csproj └── demo1helloworld.csproj.user ├── demo10adaptivecards ├── Bot.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── adaptiveCard.json ├── appsettings.json ├── card.json └── demo10adaptivecards.csproj ├── demo11prompts ├── BotAccessors.cs ├── Bots │ └── SimpleBot.cs ├── Controllers │ └── ValuesController.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json ├── demo11prompts.csproj └── demo11prompts.csproj.user ├── demo12dispatch ├── Bot.cs ├── Config.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── appsettings.json ├── demo12dispatch.csproj └── dispatch.sln ├── demo2mysimplemiddleware ├── Bots │ └── SimpleBot.cs ├── Middleware │ ├── SimpleMiddleware1.cs │ └── SimpleMiddleware2.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json ├── demo2mysimplemiddleware.csproj ├── demo2mysimplemiddleware.csproj.user └── demo2mysimplemiddleware.sln ├── demo3qnamakermiddleware ├── Bots │ └── SimpleBot.cs ├── Controllers │ └── ValuesController.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json ├── demo3qnamakermiddleware.csproj ├── demo3qnamakermiddleware.csproj.user └── demo3qnamakermiddleware.sln ├── demo4sentiment ├── demo4sentiment.bot │ ├── Bots │ │ └── SimpleBot.cs │ ├── Middleware │ │ └── SentimentAnalysisMiddleware.cs │ ├── Model.zip │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── SentimentData.cs │ ├── Startup.cs │ ├── appsettings.Development.json │ ├── appsettings.json │ └── demo4sentiment.bot.csproj ├── demo4sentiment.sln └── demo4sentiment.train │ ├── Program.cs │ ├── SentimentData.cs │ └── demo4sentiment.train.csproj ├── demo5luismiddleware ├── Bots │ └── SimpleBot.cs ├── Controllers │ └── ValuesController.cs ├── HomeAutomationBot.json ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json ├── demo5luismiddleware.csproj ├── demo5luismiddleware.csproj.user └── demo5luismiddleware.sln ├── demo6cards ├── AdaptiveCard.json ├── Bots │ └── RichCardsBot.cs ├── Controllers │ └── ValuesController.cs ├── Program.cs ├── Properties │ ├── PublishProfiles │ │ ├── demo-180718-botapplication - FTP.pubxml.user │ │ └── demo-180718-botapplication - Web Deploy.pubxml.user │ └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json ├── demo6cards.csproj ├── demo6cards.csproj.user └── demo6cards.sln ├── demo7dialogs ├── BotAccessors.cs ├── Bots │ ├── BankingBot.cs │ └── BankingBotState.cs ├── Dialogs │ ├── Balance │ │ ├── CheckBalanceDialog.cs │ │ ├── CurrentAccount │ │ │ └── CheckCurrentAccountBalanceDialog.cs │ │ └── SavingsAccount │ │ │ └── CheckSavingsAccountBalanceDialog.cs │ ├── MainDialog.cs │ └── Payment │ │ └── MakePaymentDialog.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json ├── demo7dialogs.csproj ├── demo7dialogs.csproj.user └── demo7dialogs.sln ├── demo8statemiddleware ├── BotAccessors.cs ├── Bots │ ├── DemoState.cs │ └── StateBot.cs ├── Program.cs ├── Properties │ └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json ├── demo8statemiddleware.csproj ├── demo8statemiddleware.csproj.user └── demo8statemiddleware.sln └── demo9proactive ├── Bots └── SimpleBot.cs ├── CURL.txt ├── Controllers ├── CallbackController.cs └── ValuesController.cs ├── Program.cs ├── Properties └── launchSettings.json ├── Startup.cs ├── appsettings.Development.json ├── appsettings.json ├── demo3qnamakermiddleware.csproj.user ├── demo9proactive.csproj ├── demo9proactive.sln └── wwwroot └── resume.json /.gitignore: -------------------------------------------------------------------------------- 1 | **/.vs/**/*.* 2 | **/bin/**/*.* 3 | **/obj/**/*.* 4 | **/db.lock 5 | **/*.pubxml 6 | -------------------------------------------------------------------------------- /AllProjects.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2000 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "demo1helloworld", "demo1\demo1helloworld.csproj", "{16D86D5D-80E9-4572-BA69-DD83DA32192A}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "demo2mysimplemiddleware", "demo2mysimplemiddleware\demo2mysimplemiddleware.csproj", "{AA5674DA-D43D-4AC3-ABF8-30370A42D079}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "demo3qnamakermiddleware", "demo3qnamakermiddleware\demo3qnamakermiddleware.csproj", "{7A6B3B9D-8F52-48C3-B2A9-403D3B8992B0}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "demo4sentiment.train", "demo4sentiment\demo4sentiment.train\demo4sentiment.train.csproj", "{B800038E-928F-4E07-AEE4-60DBBD2B85C2}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "demo4sentiment.bot", "demo4sentiment\demo4sentiment.bot\demo4sentiment.bot.csproj", "{56AD02E3-2806-447C-9867-D8EA10768FF1}" 15 | EndProject 16 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "demo5luismiddleware", "demo5luismiddleware\demo5luismiddleware.csproj", "{0EE2C824-08BA-4F95-A357-76EF036D8580}" 17 | EndProject 18 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "demo6cards", "demo6cards\demo6cards.csproj", "{A34AD1AE-4E5F-44B2-B69E-150FEE897B93}" 19 | EndProject 20 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "demo7dialogs", "demo7dialogs\demo7dialogs.csproj", "{76DF05EA-B628-4DC0-848A-9F39947289B1}" 21 | EndProject 22 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "demo8statemiddleware", "demo8statemiddleware\demo8statemiddleware.csproj", "{161572BC-A566-4997-B532-F72C501DC154}" 23 | EndProject 24 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "demo9proactive", "demo9proactive\demo9proactive.csproj", "{66F2A9BE-E48C-408C-9B99-A7D188C610BA}" 25 | EndProject 26 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "demo10adaptivecards", "demo10adaptivecards\demo10adaptivecards.csproj", "{D96DEFC1-2599-4837-9A78-4E1896E3399D}" 27 | EndProject 28 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "demo11prompts", "demo11prompts\demo11prompts.csproj", "{FAEB2DA9-5277-4335-8D89-CD786EB2594F}" 29 | EndProject 30 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "demo12dispatch", "demo12dispatch\demo12dispatch.csproj", "{5A4F1262-9F9A-4187-BADD-1D45D76ED4D5}" 31 | EndProject 32 | Global 33 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 34 | Debug|Any CPU = Debug|Any CPU 35 | Release|Any CPU = Release|Any CPU 36 | EndGlobalSection 37 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 38 | {16D86D5D-80E9-4572-BA69-DD83DA32192A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {16D86D5D-80E9-4572-BA69-DD83DA32192A}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {16D86D5D-80E9-4572-BA69-DD83DA32192A}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {16D86D5D-80E9-4572-BA69-DD83DA32192A}.Release|Any CPU.Build.0 = Release|Any CPU 42 | {AA5674DA-D43D-4AC3-ABF8-30370A42D079}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 43 | {AA5674DA-D43D-4AC3-ABF8-30370A42D079}.Debug|Any CPU.Build.0 = Debug|Any CPU 44 | {AA5674DA-D43D-4AC3-ABF8-30370A42D079}.Release|Any CPU.ActiveCfg = Release|Any CPU 45 | {AA5674DA-D43D-4AC3-ABF8-30370A42D079}.Release|Any CPU.Build.0 = Release|Any CPU 46 | {7A6B3B9D-8F52-48C3-B2A9-403D3B8992B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 47 | {7A6B3B9D-8F52-48C3-B2A9-403D3B8992B0}.Debug|Any CPU.Build.0 = Debug|Any CPU 48 | {7A6B3B9D-8F52-48C3-B2A9-403D3B8992B0}.Release|Any CPU.ActiveCfg = Release|Any CPU 49 | {7A6B3B9D-8F52-48C3-B2A9-403D3B8992B0}.Release|Any CPU.Build.0 = Release|Any CPU 50 | {B800038E-928F-4E07-AEE4-60DBBD2B85C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 51 | {B800038E-928F-4E07-AEE4-60DBBD2B85C2}.Debug|Any CPU.Build.0 = Debug|Any CPU 52 | {B800038E-928F-4E07-AEE4-60DBBD2B85C2}.Release|Any CPU.ActiveCfg = Release|Any CPU 53 | {B800038E-928F-4E07-AEE4-60DBBD2B85C2}.Release|Any CPU.Build.0 = Release|Any CPU 54 | {56AD02E3-2806-447C-9867-D8EA10768FF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 55 | {56AD02E3-2806-447C-9867-D8EA10768FF1}.Debug|Any CPU.Build.0 = Debug|Any CPU 56 | {56AD02E3-2806-447C-9867-D8EA10768FF1}.Release|Any CPU.ActiveCfg = Release|Any CPU 57 | {56AD02E3-2806-447C-9867-D8EA10768FF1}.Release|Any CPU.Build.0 = Release|Any CPU 58 | {0EE2C824-08BA-4F95-A357-76EF036D8580}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 59 | {0EE2C824-08BA-4F95-A357-76EF036D8580}.Debug|Any CPU.Build.0 = Debug|Any CPU 60 | {0EE2C824-08BA-4F95-A357-76EF036D8580}.Release|Any CPU.ActiveCfg = Release|Any CPU 61 | {0EE2C824-08BA-4F95-A357-76EF036D8580}.Release|Any CPU.Build.0 = Release|Any CPU 62 | {A34AD1AE-4E5F-44B2-B69E-150FEE897B93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 63 | {A34AD1AE-4E5F-44B2-B69E-150FEE897B93}.Debug|Any CPU.Build.0 = Debug|Any CPU 64 | {A34AD1AE-4E5F-44B2-B69E-150FEE897B93}.Release|Any CPU.ActiveCfg = Release|Any CPU 65 | {A34AD1AE-4E5F-44B2-B69E-150FEE897B93}.Release|Any CPU.Build.0 = Release|Any CPU 66 | {76DF05EA-B628-4DC0-848A-9F39947289B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 67 | {76DF05EA-B628-4DC0-848A-9F39947289B1}.Debug|Any CPU.Build.0 = Debug|Any CPU 68 | {76DF05EA-B628-4DC0-848A-9F39947289B1}.Release|Any CPU.ActiveCfg = Release|Any CPU 69 | {76DF05EA-B628-4DC0-848A-9F39947289B1}.Release|Any CPU.Build.0 = Release|Any CPU 70 | {161572BC-A566-4997-B532-F72C501DC154}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 71 | {161572BC-A566-4997-B532-F72C501DC154}.Debug|Any CPU.Build.0 = Debug|Any CPU 72 | {161572BC-A566-4997-B532-F72C501DC154}.Release|Any CPU.ActiveCfg = Release|Any CPU 73 | {161572BC-A566-4997-B532-F72C501DC154}.Release|Any CPU.Build.0 = Release|Any CPU 74 | {66F2A9BE-E48C-408C-9B99-A7D188C610BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 75 | {66F2A9BE-E48C-408C-9B99-A7D188C610BA}.Debug|Any CPU.Build.0 = Debug|Any CPU 76 | {66F2A9BE-E48C-408C-9B99-A7D188C610BA}.Release|Any CPU.ActiveCfg = Release|Any CPU 77 | {66F2A9BE-E48C-408C-9B99-A7D188C610BA}.Release|Any CPU.Build.0 = Release|Any CPU 78 | {D96DEFC1-2599-4837-9A78-4E1896E3399D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 79 | {D96DEFC1-2599-4837-9A78-4E1896E3399D}.Debug|Any CPU.Build.0 = Debug|Any CPU 80 | {D96DEFC1-2599-4837-9A78-4E1896E3399D}.Release|Any CPU.ActiveCfg = Release|Any CPU 81 | {D96DEFC1-2599-4837-9A78-4E1896E3399D}.Release|Any CPU.Build.0 = Release|Any CPU 82 | {FAEB2DA9-5277-4335-8D89-CD786EB2594F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 83 | {FAEB2DA9-5277-4335-8D89-CD786EB2594F}.Debug|Any CPU.Build.0 = Debug|Any CPU 84 | {FAEB2DA9-5277-4335-8D89-CD786EB2594F}.Release|Any CPU.ActiveCfg = Release|Any CPU 85 | {FAEB2DA9-5277-4335-8D89-CD786EB2594F}.Release|Any CPU.Build.0 = Release|Any CPU 86 | {5A4F1262-9F9A-4187-BADD-1D45D76ED4D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 87 | {5A4F1262-9F9A-4187-BADD-1D45D76ED4D5}.Debug|Any CPU.Build.0 = Debug|Any CPU 88 | {5A4F1262-9F9A-4187-BADD-1D45D76ED4D5}.Release|Any CPU.ActiveCfg = Release|Any CPU 89 | {5A4F1262-9F9A-4187-BADD-1D45D76ED4D5}.Release|Any CPU.Build.0 = Release|Any CPU 90 | EndGlobalSection 91 | GlobalSection(SolutionProperties) = preSolution 92 | HideSolutionNode = FALSE 93 | EndGlobalSection 94 | GlobalSection(ExtensibilityGlobals) = postSolution 95 | SolutionGuid = {5A501C17-B466-4D6D-B2AB-DBE3EC611B8C} 96 | EndGlobalSection 97 | EndGlobal 98 | -------------------------------------------------------------------------------- /demo1/Bots/SimpleBot.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Bot; 2 | using Microsoft.Bot.Builder; 3 | using Microsoft.Bot.Schema; 4 | using System.Threading; 5 | //using Microsoft.Bot.Builder.Core.Extensions; 6 | using System.Threading.Tasks; 7 | 8 | namespace demo1.Bots 9 | { 10 | public class SimpleBot : IBot 11 | { 12 | public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken)) 13 | { 14 | if (turnContext.Activity.Type is ActivityTypes.Message) 15 | { 16 | string input = turnContext.Activity.Text; 17 | await turnContext.SendActivityAsync($"SimpleBot: {input}"); 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /demo1/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace demo1.Controllers 8 | { 9 | [Route("api/[controller]")] 10 | public class ValuesController : Controller 11 | { 12 | // GET api/values 13 | [HttpGet] 14 | public IEnumerable Get() 15 | { 16 | return new string[] { "value1", "value2" }; 17 | } 18 | 19 | // GET api/values/5 20 | [HttpGet("{id}")] 21 | public string Get(int id) 22 | { 23 | return "value"; 24 | } 25 | 26 | // POST api/values 27 | [HttpPost] 28 | public void Post([FromBody]string value) 29 | { 30 | } 31 | 32 | // PUT api/values/5 33 | [HttpPut("{id}")] 34 | public void Put(int id, [FromBody]string value) 35 | { 36 | } 37 | 38 | // DELETE api/values/5 39 | [HttpDelete("{id}")] 40 | public void Delete(int id) 41 | { 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /demo1/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace demo1 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /demo1/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:50047/", 7 | "sslPort": 44396 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "environmentVariables": { 14 | "ASPNETCORE_ENVIRONMENT": "Development" 15 | } 16 | }, 17 | "demo1": { 18 | "commandName": "Project", 19 | "launchBrowser": true, 20 | "environmentVariables": { 21 | "ASPNETCORE_ENVIRONMENT": "Development" 22 | }, 23 | "applicationUrl": "http://localhost:50049/" 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /demo1/Startup.cs: -------------------------------------------------------------------------------- 1 | using demo1.Bots; 2 | using Microsoft.AspNetCore.Builder; 3 | using Microsoft.AspNetCore.Hosting; 4 | using Microsoft.Bot.Builder.BotFramework; 5 | using Microsoft.Bot.Builder.Integration.AspNet.Core; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.DependencyInjection; 8 | 9 | public class Startup 10 | { 11 | // Inject the IHostingEnvironment into constructor 12 | public Startup(IHostingEnvironment env) 13 | { 14 | // Set the root path 15 | ContentRootPath = env.ContentRootPath; 16 | } 17 | 18 | // Track the root path so that it can be used to setup the app configuration 19 | public string ContentRootPath { get; private set; } 20 | 21 | public void ConfigureServices(IServiceCollection services) 22 | { 23 | // Set up the service configuration 24 | var builder = new ConfigurationBuilder() 25 | .SetBasePath(ContentRootPath) 26 | .AddJsonFile("appsettings.json") 27 | .AddEnvironmentVariables(); 28 | var configuration = builder.Build(); 29 | services.AddSingleton(configuration); 30 | 31 | // Add your SimpleBot to your application 32 | services.AddBot(options => 33 | { 34 | options.CredentialProvider = new ConfigurationCredentialProvider(configuration); 35 | }); 36 | } 37 | 38 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 39 | { 40 | app.UseStaticFiles(); 41 | 42 | // Tell your application to use Bot Framework 43 | app.UseBotFramework(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /demo1/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /demo1/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "Debug": { 5 | "LogLevel": { 6 | "Default": "Warning" 7 | } 8 | }, 9 | "Console": { 10 | "LogLevel": { 11 | "Default": "Warning" 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /demo1/demo1.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2000 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "demo1", "demo1.csproj", "{64E85BF0-E01D-4731-AF68-5D6F69CFA57C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {64E85BF0-E01D-4731-AF68-5D6F69CFA57C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {64E85BF0-E01D-4731-AF68-5D6F69CFA57C}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {64E85BF0-E01D-4731-AF68-5D6F69CFA57C}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {64E85BF0-E01D-4731-AF68-5D6F69CFA57C}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {C00530FD-1515-4A23-AEAB-B084B545002C} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /demo1/demo1helloworld.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /demo1/demo1helloworld.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | IIS Express 5 | 6 | -------------------------------------------------------------------------------- /demo10adaptivecards/Bot.cs: -------------------------------------------------------------------------------- 1 | using AdaptiveCards; 2 | using Microsoft.Bot; 3 | using Microsoft.Bot.Builder; 4 | using Microsoft.Bot.Schema; 5 | using Newtonsoft.Json; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.IO; 9 | using System.Threading; 10 | using System.Threading.Tasks; 11 | // https://adaptivecards.io/ 12 | // https://adaptivecards.io/explorer/ 13 | // https://adaptivecards.io/visualizer/ 14 | // https://adaptivecards.io/samples/ 15 | // uses NuGet pkg AdaptiveCards - https://docs.microsoft.com/en-us/adaptive-cards/sdk/authoring-cards/net 16 | namespace demo10adaptivecards 17 | { 18 | public class Bot : IBot 19 | { 20 | private Attachment CreateAdaptiveCardUsingSdk() 21 | { 22 | var card = new AdaptiveCard(); 23 | card.Body.Add(new AdaptiveTextBlock() { Text = "Colour", Size = AdaptiveTextSize.Medium, Weight = AdaptiveTextWeight.Bolder }); 24 | card.Body.Add(new AdaptiveChoiceSetInput() 25 | { 26 | Id = "Colour", 27 | Style = AdaptiveChoiceInputStyle.Compact, 28 | Choices = new List(new[] { 29 | new AdaptiveChoice() { Title = "Red", Value = "RED" }, 30 | new AdaptiveChoice() { Title = "Green", Value = "GREEN" }, 31 | new AdaptiveChoice() { Title = "Blue", Value = "BLUE" } }) 32 | }); 33 | card.Body.Add(new AdaptiveTextBlock() { Text = "Registration number:", Size = AdaptiveTextSize.Medium, Weight = AdaptiveTextWeight.Bolder }); 34 | card.Body.Add(new AdaptiveTextInput() { Style = AdaptiveTextInputStyle.Text, Id = "RegistrationNumber" }); 35 | card.Actions.Add(new AdaptiveSubmitAction() { Title = "Submit" }); 36 | return new Attachment() 37 | { 38 | ContentType = AdaptiveCard.ContentType, 39 | Content = card 40 | }; 41 | } 42 | 43 | private Attachment CreateAdaptiveCardUsingJson() 44 | { 45 | return new Attachment 46 | { 47 | ContentType = AdaptiveCard.ContentType, 48 | Content = AdaptiveCard.FromJson(File.ReadAllText("adaptiveCard.json")).Card 49 | }; 50 | } 51 | 52 | public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken)) 53 | { 54 | // display result 55 | if (turnContext.Activity.Value != null) 56 | { 57 | await turnContext.SendActivityAsync(turnContext.Activity.Value.ToString()); 58 | } 59 | 60 | // display adaptive card 61 | if (turnContext.Activity.Type == ActivityTypes.Message) 62 | { 63 | var response = turnContext.Activity.CreateReply(); 64 | response.Attachments = new List() { CreateAdaptiveCardUsingJson() }; 65 | 66 | await turnContext.SendActivityAsync(response); 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /demo10adaptivecards/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore; 2 | using Microsoft.AspNetCore.Hosting; 3 | 4 | namespace demo10adaptivecards 5 | { 6 | public class Program 7 | { 8 | public static void Main(string[] args) 9 | { 10 | BuildWebHost(args).Run(); 11 | } 12 | 13 | public static IWebHost BuildWebHost(string[] args) => 14 | WebHost.CreateDefaultBuilder(args) 15 | .UseStartup() 16 | .Build(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /demo10adaptivecards/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:19061/", 7 | "sslPort": 44378 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "environmentVariables": { 14 | "ASPNETCORE_ENVIRONMENT": "Development" 15 | } 16 | }, 17 | "appinsights": { 18 | "commandName": "Project", 19 | "launchBrowser": true, 20 | "environmentVariables": { 21 | "ASPNETCORE_ENVIRONMENT": "Development" 22 | }, 23 | "applicationUrl": "http://localhost:19065/" 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /demo10adaptivecards/Startup.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using Microsoft.AspNetCore.Hosting; 3 | using Microsoft.Bot.Builder.BotFramework; 4 | using Microsoft.Bot.Builder.Integration.AspNet.Core; 5 | using Microsoft.Extensions.Configuration; 6 | using Microsoft.Extensions.DependencyInjection; 7 | 8 | namespace demo10adaptivecards 9 | { 10 | public class Startup 11 | { 12 | public Startup(IConfiguration configuration, IHostingEnvironment env) 13 | { 14 | Configuration = configuration; 15 | Env = env; 16 | } 17 | 18 | public IConfiguration Configuration { get; } 19 | public IHostingEnvironment Env { get; } 20 | 21 | public void ConfigureServices(IServiceCollection services) 22 | { 23 | var configurationBuilder = new ConfigurationBuilder() 24 | .SetBasePath(Env.ContentRootPath) 25 | .AddJsonFile("appsettings.json"); 26 | 27 | var configuration = configurationBuilder 28 | .Build(); 29 | 30 | services.AddBot((options) => { 31 | options.CredentialProvider = new ConfigurationCredentialProvider(configuration); 32 | }); 33 | 34 | services.AddMvc(); 35 | } 36 | 37 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 38 | { 39 | if (env.IsDevelopment()) 40 | { 41 | app.UseDeveloperExceptionPage(); 42 | } 43 | 44 | app.UseMvc(); 45 | app.UseBotFramework(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /demo10adaptivecards/adaptiveCard.json: -------------------------------------------------------------------------------- 1 | {"type":"AdaptiveCard","version":"1.0","body":[{"type":"Container","items":[{"type":"TextBlock","size":"medium","weight":"bolder","text":"Publish Adaptive Card schema"},{"type":"ColumnSet","columns":[{"type":"Column","width":"auto","items":[{"type":"Image","size":"small","style":"person","url":"https://pbs.twimg.com/profile_images/3647943215/d7f12830b3c17a5a9e4afcc370e3a37e_400x400.jpeg"}]},{"type":"Column","width":"stretch","items":[{"type":"TextBlock","weight":"bolder","text":"Matt Hidinger","wrap":true},{"type":"TextBlock","isSubtle":true,"text":"Created {{DATE(2017-02-14T06:08:39Z, SHORT)}}","wrap":true,"spacing":"none","separation":"none"}]}]}]},{"type":"Container","items":[{"type":"TextBlock","text":"Now that we have defined the main rules and features of the format, we need to produce a schema and publish it to GitHub. The schema will be the starting point of our reference documentation.","wrap":true},{"type":"FactSet","facts":[{"title":"Board:","value":"Adaptive Card"},{"title":"List:","value":"Backlog"},{"title":"Assigned to:","value":"Matt Hidinger"},{"title":"Due date:","value":"Not set"}]}]}],"actions":[{"type":"Action.ShowCard","card":{"type":"AdaptiveCard","body":[{"type":"Input.Date","id":"dueDate"}],"actions":[{"type":"Action.Submit","title":"OK"}]},"title":"Set due date"},{"type":"Action.ShowCard","card":{"type":"AdaptiveCard","body":[{"type":"Input.Text","id":"comment","placeholder":"Enter your comment","isMultiline":true}],"actions":[{"type":"Action.Submit","title":"OK"}]},"title":"Comment"}],"$schema":"http://adaptivecards.io/schemas/adaptive-card.json"} -------------------------------------------------------------------------------- /demo10adaptivecards/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "MicrosoftAppId": "", 3 | "MicrosoftAppPassword": "" 4 | } -------------------------------------------------------------------------------- /demo10adaptivecards/card.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", 3 | "type": "AdaptiveCard", 4 | "version": "1.0", 5 | "body": [ 6 | { 7 | "type": "Container", 8 | "items": [ 9 | { 10 | "type": "TextBlock", 11 | "text": "Publish Adaptive Card schema", 12 | "weight": "bolder", 13 | "size": "medium" 14 | }, 15 | { 16 | "type": "ColumnSet", 17 | "columns": [ 18 | { 19 | "type": "Column", 20 | "width": "auto", 21 | "items": [ 22 | { 23 | "type": "Image", 24 | "url": "https://pbs.twimg.com/profile_images/3647943215/d7f12830b3c17a5a9e4afcc370e3a37e_400x400.jpeg", 25 | "size": "small", 26 | "style": "person" 27 | } 28 | ] 29 | }, 30 | { 31 | "type": "Column", 32 | "width": "stretch", 33 | "items": [ 34 | { 35 | "type": "TextBlock", 36 | "text": "Matt Hidinger", 37 | "weight": "bolder", 38 | "wrap": true 39 | }, 40 | { 41 | "type": "TextBlock", 42 | "spacing": "none", 43 | "text": "Created {{DATE(2017-02-14T06:08:39Z, SHORT)}}", 44 | "isSubtle": true, 45 | "wrap": true 46 | } 47 | ] 48 | } 49 | ] 50 | } 51 | ] 52 | }, 53 | { 54 | "type": "Container", 55 | "items": [ 56 | { 57 | "type": "TextBlock", 58 | "text": "Now that we have defined the main rules and features of the format, we need to produce a schema and publish it to GitHub. The schema will be the starting point of our reference documentation.", 59 | "wrap": true 60 | }, 61 | { 62 | "type": "FactSet", 63 | "facts": [ 64 | { 65 | "title": "Board:", 66 | "value": "Adaptive Card" 67 | }, 68 | { 69 | "title": "List:", 70 | "value": "Backlog" 71 | }, 72 | { 73 | "title": "Assigned to:", 74 | "value": "Matt Hidinger" 75 | }, 76 | { 77 | "title": "Due date:", 78 | "value": "Not set" 79 | } 80 | ] 81 | } 82 | ] 83 | } 84 | ], 85 | "actions": [ 86 | { 87 | "type": "Action.ShowCard", 88 | "title": "Set due date", 89 | "card": { 90 | "type": "AdaptiveCard", 91 | "body": [ 92 | { 93 | "type": "Input.Date", 94 | "id": "dueDate" 95 | } 96 | ], 97 | "actions": [ 98 | { 99 | "type": "Action.Submit", 100 | "title": "OK" 101 | } 102 | ] 103 | } 104 | }, 105 | { 106 | "type": "Action.ShowCard", 107 | "title": "Comment", 108 | "card": { 109 | "type": "AdaptiveCard", 110 | "body": [ 111 | { 112 | "type": "Input.Text", 113 | "id": "comment", 114 | "isMultiline": true, 115 | "placeholder": "Enter your comment" 116 | } 117 | ], 118 | "actions": [ 119 | { 120 | "type": "Action.Submit", 121 | "title": "OK" 122 | } 123 | ] 124 | } 125 | } 126 | ] 127 | } -------------------------------------------------------------------------------- /demo10adaptivecards/demo10adaptivecards.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | demo10adaptivecards 6 | demo10adaptivecards 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | Always 26 | 27 | 28 | Always 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /demo11prompts/BotAccessors.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.Bot.Builder; 6 | using Microsoft.Bot.Builder.Dialogs; 7 | 8 | namespace demo10prompts 9 | { 10 | public class BotAccessors 11 | { 12 | public BotAccessors(ConversationState conversationState) 13 | { 14 | ConversationState = conversationState ?? throw new ArgumentNullException(nameof(conversationState)); 15 | } 16 | 17 | public static string DialogStateAccessorName { get; } = $"{nameof(BotAccessors)}.DialogState"; 18 | public IStatePropertyAccessor DialogStateAccessor { get; internal set; } 19 | public ConversationState ConversationState { get; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /demo11prompts/Bots/SimpleBot.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Threading; 3 | using System.Threading.Tasks; 4 | using Microsoft.Bot.Builder; 5 | using Microsoft.Bot.Builder.Dialogs; 6 | using Microsoft.Bot.Builder.Dialogs.Choices; 7 | using Microsoft.Bot.Schema; 8 | 9 | namespace demo10prompts.Bots 10 | { 11 | public class SimpleBot : IBot 12 | { 13 | private readonly DialogSet dialogs; 14 | 15 | public SimpleBot(BotAccessors botAccessors) 16 | { 17 | var dialogState = botAccessors.DialogStateAccessor; 18 | 19 | dialogs = new DialogSet(dialogState); 20 | dialogs.Add(new TextPrompt("textPrompt")); 21 | dialogs.Add(new ChoicePrompt("choicePrompt")); 22 | dialogs.Add(new ConfirmPrompt("confirmPrompt")); 23 | dialogs.Add(new DateTimePrompt("dateTimePrompt")); 24 | dialogs.Add(new AttachmentPrompt("attachmentPrompt")); 25 | dialogs.Add(new NumberPrompt("numberPrompt")); 26 | dialogs.Add(new WaterfallDialog("greetings", new WaterfallStep[] 27 | { 28 | async (stepContext, cancellationToken) => 29 | { 30 | return await stepContext.PromptAsync("choicePrompt", 31 | new PromptOptions 32 | { 33 | Prompt = stepContext.Context.Activity.CreateReply("Which prompt would you like to test :-)"), 34 | Choices = new[] 35 | { 36 | new Choice {Value = "dateTimePrompt"}, 37 | new Choice {Value = "textPrompt"}, 38 | new Choice {Value = "confirmPrompt"}, 39 | new Choice {Value = "attachmentPrompt"}, 40 | new Choice {Value = "numberPrompt"} 41 | }.ToList() 42 | }); 43 | }, 44 | async (stepContext, cancellationToken) => 45 | { 46 | var choice = stepContext.Result as FoundChoice; 47 | 48 | return await stepContext.PromptAsync(choice.Value, 49 | new PromptOptions 50 | { 51 | Prompt = stepContext.Context.Activity.CreateReply($"Please provide a response") 52 | }); 53 | }, 54 | async (stepContext, cancellationToken) => 55 | { 56 | await stepContext.Context.SendActivityAsync($"Handle response data here = {stepContext.Result.ToString()}"); 57 | return await stepContext.EndDialogAsync(); 58 | } 59 | })); 60 | BotAccessors = botAccessors; 61 | } 62 | 63 | public BotAccessors BotAccessors { get; } 64 | 65 | public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken)) 66 | { 67 | if (turnContext.Activity.Type == ActivityTypes.Message) 68 | { 69 | var dialogCtx = await dialogs.CreateContextAsync(turnContext, cancellationToken); 70 | 71 | if (dialogCtx.ActiveDialog == null) 72 | { 73 | await dialogCtx.BeginDialogAsync("greetings", cancellationToken); 74 | } 75 | else 76 | { 77 | await dialogCtx.ContinueDialogAsync(cancellationToken); 78 | } 79 | 80 | await BotAccessors.ConversationState.SaveChangesAsync(turnContext, false, cancellationToken); 81 | } 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /demo11prompts/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace demo10prompts.Controllers 8 | { 9 | [Route("api/[controller]")] 10 | public class ValuesController : Controller 11 | { 12 | // GET api/values 13 | [HttpGet] 14 | public IEnumerable Get() 15 | { 16 | return new string[] { "value1", "value2" }; 17 | } 18 | 19 | // GET api/values/5 20 | [HttpGet("{id}")] 21 | public string Get(int id) 22 | { 23 | return "value"; 24 | } 25 | 26 | // POST api/values 27 | [HttpPost] 28 | public void Post([FromBody]string value) 29 | { 30 | } 31 | 32 | // PUT api/values/5 33 | [HttpPut("{id}")] 34 | public void Put(int id, [FromBody]string value) 35 | { 36 | } 37 | 38 | // DELETE api/values/5 39 | [HttpDelete("{id}")] 40 | public void Delete(int id) 41 | { 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /demo11prompts/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace demo10prompts 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /demo11prompts/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:53992/", 7 | "sslPort": 44307 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "environmentVariables": { 14 | "ASPNETCORE_ENVIRONMENT": "Development" 15 | } 16 | }, 17 | "demo10prompts": { 18 | "commandName": "Project", 19 | "launchBrowser": true, 20 | "environmentVariables": { 21 | "ASPNETCORE_ENVIRONMENT": "Development" 22 | }, 23 | "applicationUrl": "http://localhost:53994/" 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /demo11prompts/Startup.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using demo10prompts.Bots; 3 | using Microsoft.AspNetCore.Builder; 4 | using Microsoft.AspNetCore.Hosting; 5 | using Microsoft.Bot.Builder; 6 | using Microsoft.Bot.Builder.BotFramework; 7 | using Microsoft.Bot.Builder.Dialogs; 8 | using Microsoft.Bot.Builder.Integration; 9 | using Microsoft.Bot.Builder.Integration.AspNet.Core; 10 | using Microsoft.Extensions.Configuration; 11 | using Microsoft.Extensions.DependencyInjection; 12 | using Microsoft.Extensions.Options; 13 | 14 | namespace demo10prompts 15 | { 16 | public class Startup 17 | { 18 | public Startup(IConfiguration configuration, IHostingEnvironment hostingEnvironment) 19 | { 20 | Configuration = configuration; 21 | HostingEnvironment = hostingEnvironment; 22 | } 23 | 24 | public IConfiguration Configuration { get; } 25 | public IHostingEnvironment HostingEnvironment { get; } 26 | 27 | // This method gets called by the runtime. Use this method to add services to the container. 28 | public void ConfigureServices(IServiceCollection services) 29 | { 30 | var builder = new ConfigurationBuilder() 31 | .SetBasePath(HostingEnvironment.ContentRootPath) 32 | .AddJsonFile("appsettings.json") 33 | .AddEnvironmentVariables(); 34 | var configuration = builder.Build(); 35 | 36 | services.AddSingleton(configuration); 37 | 38 | services.AddMvc(); 39 | 40 | services.AddBot(options => 41 | { 42 | var conversationState = new ConversationState(new MemoryStorage()); 43 | options.State.Add(conversationState); 44 | 45 | options.CredentialProvider = new ConfigurationCredentialProvider(configuration); 46 | }); 47 | 48 | services.AddSingleton(serviceProvider => 49 | { 50 | var options = serviceProvider.GetRequiredService>().Value; 51 | var conversationState = options.State.OfType().FirstOrDefault(); 52 | 53 | var accessors = new BotAccessors(conversationState) 54 | { 55 | DialogStateAccessor = conversationState.CreateProperty(BotAccessors.DialogStateAccessorName), 56 | }; 57 | 58 | return accessors; 59 | }); 60 | } 61 | 62 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 63 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 64 | { 65 | if (env.IsDevelopment()) 66 | { 67 | app.UseDeveloperExceptionPage(); 68 | } 69 | 70 | app.UseMvc(); 71 | app.UseBotFramework(); 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /demo11prompts/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /demo11prompts/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "Debug": { 5 | "LogLevel": { 6 | "Default": "Warning" 7 | } 8 | }, 9 | "Console": { 10 | "LogLevel": { 11 | "Default": "Warning" 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /demo11prompts/demo11prompts.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /demo11prompts/demo11prompts.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | IIS Express 5 | 6 | -------------------------------------------------------------------------------- /demo12dispatch/Bot.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | using Microsoft.Bot.Builder; 6 | using Microsoft.Bot.Builder.AI.Luis; 7 | using Microsoft.Bot.Builder.AI.QnA; 8 | using Microsoft.Bot.Schema; 9 | using Microsoft.Extensions.Configuration; 10 | 11 | namespace dispatch 12 | { 13 | public class Bot : IBot 14 | { 15 | private readonly Dictionary models; 16 | 17 | public Bot(IConfiguration configuration, LuisRecognizer dispatchRecognizer) 18 | { 19 | DispatchRecognizer = dispatchRecognizer; 20 | 21 | var modelConfigurations = Config.GetDispatchConfiguration(configuration).Models; 22 | 23 | models = new Dictionary(); 24 | foreach (var modelConfiguration in modelConfigurations) 25 | { 26 | if (modelConfiguration.ModelType == DispatchConfiguration.ModelConfiguration.ModelTypes.luis) 27 | { 28 | models.Add(modelConfiguration.Name, new LuisApplication(modelConfiguration.Id, modelConfiguration.Key, modelConfiguration.Url)); 29 | } 30 | else if (modelConfiguration.ModelType == DispatchConfiguration.ModelConfiguration.ModelTypes.qna) 31 | { 32 | models.Add(modelConfiguration.Name, new QnAMakerEndpoint {KnowledgeBaseId = modelConfiguration.Id, EndpointKey = modelConfiguration.Key, Host = modelConfiguration.Url}); 33 | } 34 | } 35 | } 36 | 37 | public LuisRecognizer DispatchRecognizer { get; } 38 | 39 | public async Task OnTurnAsync(ITurnContext context, CancellationToken cancellationToken = default(CancellationToken)) 40 | { 41 | if (context.Activity.Type is ActivityTypes.Message) 42 | { 43 | var dispatchResult = await DispatchRecognizer.RecognizeAsync(context, cancellationToken); 44 | 45 | var topIntent = dispatchResult?.GetTopScoringIntent(); 46 | 47 | if (topIntent == null) 48 | { 49 | await context.SendActivityAsync("Unable to get the top intent."); 50 | } 51 | else 52 | { 53 | // we can use the model name to index into our array of qna/luis models 54 | var modelName = topIntent.Value.intent; 55 | 56 | var targetModel = models[modelName]; 57 | 58 | if (targetModel is QnAMakerEndpoint qnaModel) 59 | { 60 | await context.SendActivityAsync($"Dispatching to QnAMaker model {modelName}"); 61 | var qnaMaker = new QnAMaker(qnaModel); 62 | var qnaResponse = await qnaMaker.GetAnswersAsync(context); 63 | await context.SendActivityAsync($"Result from QnAMaker: {qnaResponse.FirstOrDefault().Answer}"); 64 | } 65 | else if (targetModel is LuisApplication luisModel) 66 | { 67 | await context.SendActivityAsync($"Dispatching to luis model {modelName}"); 68 | 69 | var luisRecognizer = new LuisRecognizer(luisModel); 70 | var recognizerResult = await luisRecognizer.RecognizeAsync(context, cancellationToken); 71 | await context.SendActivityAsync($"Result from luis: {recognizerResult.GetTopScoringIntent().intent}"); 72 | } 73 | } 74 | } 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /demo12dispatch/Config.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.Extensions.Configuration; 6 | using Microsoft.Extensions.DependencyInjection; 7 | 8 | namespace dispatch 9 | { 10 | public static class Config 11 | { 12 | public static DispatchConfiguration GetDispatchConfiguration(IConfiguration configuration) 13 | { 14 | var dispatchConfig = new DispatchConfiguration(); 15 | configuration.GetSection("Dispatch").Bind(dispatchConfig); 16 | return dispatchConfig; 17 | } 18 | } 19 | 20 | public class DispatchConfiguration 21 | { 22 | public DispatcherConfiguration Dispatcher { get; set; } 23 | public ModelConfiguration[] Models { get; set; } 24 | 25 | public class DispatcherConfiguration 26 | { 27 | public string Id { get; set; } 28 | public string Key { get; set; } 29 | public string Url { get; set; } 30 | 31 | } 32 | 33 | public class ModelConfiguration 34 | { 35 | public ModelTypes ModelType { get; set; } 36 | public string Name{ get; set; } 37 | public string Id { get; set; } 38 | public string Key { get; set; } 39 | public string Url { get; set; } 40 | 41 | public enum ModelTypes 42 | { 43 | qna,luis 44 | } 45 | } 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /demo12dispatch/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore; 2 | using Microsoft.AspNetCore.Hosting; 3 | 4 | namespace dispatch 5 | { 6 | public class Program 7 | { 8 | public static void Main(string[] args) 9 | { 10 | BuildWebHost(args).Run(); 11 | } 12 | 13 | public static IWebHost BuildWebHost(string[] args) => 14 | WebHost.CreateDefaultBuilder(args) 15 | .UseStartup() 16 | .Build(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /demo12dispatch/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:19061/", 7 | "sslPort": 44378 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "environmentVariables": { 14 | "ASPNETCORE_ENVIRONMENT": "Development" 15 | } 16 | }, 17 | "appinsights": { 18 | "commandName": "Project", 19 | "launchBrowser": true, 20 | "environmentVariables": { 21 | "ASPNETCORE_ENVIRONMENT": "Development" 22 | }, 23 | "applicationUrl": "http://localhost:19065/" 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /demo12dispatch/Startup.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using Microsoft.AspNetCore.Hosting; 3 | using Microsoft.Bot.Builder.AI.Luis; 4 | using Microsoft.Bot.Builder.BotFramework; 5 | using Microsoft.Bot.Builder.Integration.AspNet.Core; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.DependencyInjection; 8 | 9 | namespace dispatch 10 | { 11 | public class Startup 12 | { 13 | public Startup(IConfiguration configuration, IHostingEnvironment env) 14 | { 15 | Configuration = configuration; 16 | Env = env; 17 | } 18 | 19 | public IConfiguration Configuration { get; } 20 | public IHostingEnvironment Env { get; } 21 | 22 | public void ConfigureServices(IServiceCollection services) 23 | { 24 | var configurationBuilder = new ConfigurationBuilder() 25 | .SetBasePath(Env.ContentRootPath) 26 | .AddJsonFile("appsettings.json"); 27 | 28 | var configuration = configurationBuilder 29 | .Build(); 30 | 31 | services.AddSingleton(sp => 32 | { 33 | var dispatcherConfiguration = Config.GetDispatchConfiguration(this.Configuration).Dispatcher; 34 | 35 | return new LuisRecognizer(new LuisApplication(dispatcherConfiguration.Id, dispatcherConfiguration.Key, dispatcherConfiguration.Url)); 36 | }); 37 | 38 | services.AddBot((options) => { 39 | options.CredentialProvider = new ConfigurationCredentialProvider(configuration); 40 | }); 41 | 42 | services.AddMvc(); 43 | } 44 | 45 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 46 | { 47 | if (env.IsDevelopment()) 48 | { 49 | app.UseDeveloperExceptionPage(); 50 | } 51 | 52 | app.UseMvc(); 53 | app.UseBotFramework(); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /demo12dispatch/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "MicrosoftAppId": "", 3 | "MicrosoftAppPassword": "", 4 | "Dispatch": { 5 | "Dispatcher": { 6 | "Id": "", 7 | "Key": "", 8 | "Url" : "https://westus.api.cognitive.microsoft.com/" 9 | }, 10 | "Models": [ 11 | { 12 | "Name": "", 13 | "ModelType": "qna", 14 | "Id": "", 15 | "Key": "", 16 | "Url" : "https://dispatchqna.azurewebsites.net/qnamaker" 17 | }, 18 | { 19 | "Name": "", 20 | "ModelType": "luis", 21 | "Id": "", 22 | "Key": "", 23 | "Url" : "https://westus.api.cognitive.microsoft.com/" 24 | } 25 | ] 26 | 27 | } 28 | } -------------------------------------------------------------------------------- /demo12dispatch/demo12dispatch.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | dispatch 6 | dispatch 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /demo12dispatch/dispatch.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2000 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dispatch", "dispatch.csproj", "{B135B7BA-197E-43FD-8F8F-F9A959A97969}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {B135B7BA-197E-43FD-8F8F-F9A959A97969}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {B135B7BA-197E-43FD-8F8F-F9A959A97969}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {B135B7BA-197E-43FD-8F8F-F9A959A97969}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {B135B7BA-197E-43FD-8F8F-F9A959A97969}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {9F17814C-473F-41E4-A4E8-F109C0C428EB} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /demo2mysimplemiddleware/Bots/SimpleBot.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Bot; 2 | using Microsoft.Bot.Builder; 3 | using Microsoft.Bot.Schema; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | 10 | namespace demo2mysimplemiddleware.Bots 11 | { 12 | public class SimpleBot : IBot 13 | { 14 | public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken)) 15 | { 16 | await turnContext.SendActivityAsync($"[SimpleBot] {turnContext.Activity.Type}/OnTurn"); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /demo2mysimplemiddleware/Middleware/SimpleMiddleware1.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Bot.Builder; 2 | using Microsoft.Bot.Schema; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | 9 | namespace demo2mysimplemiddleware.Middleware 10 | { 11 | public class SimpleMiddleware1 : IMiddleware 12 | { 13 | public async Task OnTurnAsync(ITurnContext context, NextDelegate next, CancellationToken cancellationToken = default(CancellationToken)) 14 | { 15 | await context.SendActivityAsync($"[SimpleMiddleware1] {context.Activity.Type}/OnTurn/Before"); 16 | 17 | await next(cancellationToken); 18 | 19 | await context.SendActivityAsync($"[SimpleMiddleware1] {context.Activity.Type}/OnTurn/After"); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /demo2mysimplemiddleware/Middleware/SimpleMiddleware2.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Bot.Builder; 2 | using Microsoft.Bot.Schema; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Threading; 7 | using System.Threading.Tasks; 8 | 9 | namespace demo2mysimplemiddleware.Middleware 10 | { 11 | public class SimpleMiddleware2 : IMiddleware 12 | { 13 | public async Task OnTurnAsync(ITurnContext context, NextDelegate next, CancellationToken cancellationToken = default(CancellationToken)) 14 | { 15 | await context.SendActivityAsync($"[SimpleMiddleware2] {context.Activity.Type}/OnTurn/Before"); 16 | 17 | if (context.Activity.Type == ActivityTypes.Message && context.Activity.Text == "secret password") 18 | { 19 | // calling next() is totally optional. if the middleware does not call next then the 20 | // next middleware in the pipeline will not be called, AND the bot will not receive the message. 21 | // 22 | // in this instance, we are only handing the message to downstream bots if the user says "secret password" 23 | await next(cancellationToken); 24 | } 25 | 26 | await context.SendActivityAsync($"[SimpleMiddleware2] {context.Activity.Type}/OnTurn/After"); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /demo2mysimplemiddleware/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace demo2mysimplemiddleware 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /demo2mysimplemiddleware/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:50002/", 7 | "sslPort": 44328 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "environmentVariables": { 14 | "ASPNETCORE_ENVIRONMENT": "Development" 15 | } 16 | }, 17 | "demo2mysimplemiddleware": { 18 | "commandName": "Project", 19 | "launchBrowser": true, 20 | "environmentVariables": { 21 | "ASPNETCORE_ENVIRONMENT": "Development" 22 | }, 23 | "applicationUrl": "http://localhost:50003/" 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /demo2mysimplemiddleware/Startup.cs: -------------------------------------------------------------------------------- 1 | using demo2mysimplemiddleware.Bots; 2 | using demo2mysimplemiddleware.Middleware; 3 | using Microsoft.AspNetCore.Builder; 4 | using Microsoft.AspNetCore.Hosting; 5 | using Microsoft.Bot.Builder.BotFramework; 6 | using Microsoft.Bot.Builder.Integration.AspNet.Core; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.DependencyInjection; 9 | 10 | public class Startup 11 | { 12 | public Startup(IHostingEnvironment env) 13 | { 14 | ContentRootPath = env.ContentRootPath; 15 | } 16 | 17 | public string ContentRootPath { get; private set; } 18 | 19 | public void ConfigureServices(IServiceCollection services) 20 | { 21 | var builder = new ConfigurationBuilder() 22 | .SetBasePath(ContentRootPath) 23 | .AddJsonFile("appsettings.json") 24 | .AddEnvironmentVariables(); 25 | var configuration = builder.Build(); 26 | services.AddSingleton(configuration); 27 | 28 | services.AddBot(options => 29 | { 30 | options.CredentialProvider = new ConfigurationCredentialProvider(configuration); 31 | 32 | options.Middleware.Add(new SimpleMiddleware1()); 33 | options.Middleware.Add(new SimpleMiddleware2()); 34 | }); 35 | } 36 | 37 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 38 | { 39 | app.UseStaticFiles(); 40 | app.UseBotFramework(); 41 | } 42 | } -------------------------------------------------------------------------------- /demo2mysimplemiddleware/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /demo2mysimplemiddleware/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "Debug": { 5 | "LogLevel": { 6 | "Default": "Warning" 7 | } 8 | }, 9 | "Console": { 10 | "LogLevel": { 11 | "Default": "Warning" 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /demo2mysimplemiddleware/demo2mysimplemiddleware.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /demo2mysimplemiddleware/demo2mysimplemiddleware.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | IIS Express 5 | 6 | -------------------------------------------------------------------------------- /demo2mysimplemiddleware/demo2mysimplemiddleware.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2000 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "demo2mysimplemiddleware", "demo2mysimplemiddleware.csproj", "{4ABB5888-917F-412D-81CF-70198F8AC42C}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {4ABB5888-917F-412D-81CF-70198F8AC42C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {4ABB5888-917F-412D-81CF-70198F8AC42C}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {4ABB5888-917F-412D-81CF-70198F8AC42C}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {4ABB5888-917F-412D-81CF-70198F8AC42C}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {105546B0-B196-4639-9B73-04948907550E} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /demo3qnamakermiddleware/Bots/SimpleBot.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Bot; 2 | using Microsoft.Bot.Builder; 3 | using Microsoft.Bot.Schema; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | using Microsoft.Bot.Builder.AI.QnA; 10 | 11 | namespace demo3qnamakermiddleware.Bots 12 | { 13 | public class SimpleBot : IBot 14 | { 15 | public SimpleBot(QnAMaker qnAMaker) 16 | { 17 | QnAMaker = qnAMaker; 18 | } 19 | 20 | public QnAMaker QnAMaker { get; } 21 | 22 | public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken)) 23 | { 24 | if (!turnContext.Responded && turnContext.Activity.Type == ActivityTypes.Message) 25 | { 26 | var result = await QnAMaker.GetAnswersAsync(turnContext); 27 | 28 | if (result != null && result.Length > 0) 29 | { 30 | await turnContext.SendActivityAsync(result[0].Answer, cancellationToken: cancellationToken); 31 | } 32 | else 33 | { 34 | var msg = @"Sorry, I don't know how to answer that..."; 35 | 36 | await turnContext.SendActivityAsync(msg, cancellationToken: cancellationToken); 37 | } 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /demo3qnamakermiddleware/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace demo3qnamakermiddleware.Controllers 8 | { 9 | [Route("api/[controller]")] 10 | public class ValuesController : Controller 11 | { 12 | // GET api/values 13 | [HttpGet] 14 | public IEnumerable Get() 15 | { 16 | return new string[] { "value1", "value2" }; 17 | } 18 | 19 | // GET api/values/5 20 | [HttpGet("{id}")] 21 | public string Get(int id) 22 | { 23 | return "value"; 24 | } 25 | 26 | // POST api/values 27 | [HttpPost] 28 | public void Post([FromBody]string value) 29 | { 30 | } 31 | 32 | // PUT api/values/5 33 | [HttpPut("{id}")] 34 | public void Put(int id, [FromBody]string value) 35 | { 36 | } 37 | 38 | // DELETE api/values/5 39 | [HttpDelete("{id}")] 40 | public void Delete(int id) 41 | { 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /demo3qnamakermiddleware/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace demo3qnamakermiddleware 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /demo3qnamakermiddleware/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:49840/", 7 | "sslPort": 44376 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "environmentVariables": { 14 | "ASPNETCORE_ENVIRONMENT": "Development" 15 | } 16 | }, 17 | "demo3qnamakermiddleware": { 18 | "commandName": "Project", 19 | "launchBrowser": true, 20 | "environmentVariables": { 21 | "ASPNETCORE_ENVIRONMENT": "Development" 22 | }, 23 | "applicationUrl": "http://localhost:49841/" 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /demo3qnamakermiddleware/Startup.cs: -------------------------------------------------------------------------------- 1 | using demo3qnamakermiddleware.Bots; 2 | using Microsoft.AspNetCore.Builder; 3 | using Microsoft.AspNetCore.Hosting; 4 | using Microsoft.Bot.Builder.AI.QnA; 5 | using Microsoft.Bot.Builder.BotFramework; 6 | using Microsoft.Bot.Builder.Integration.AspNet.Core; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.DependencyInjection; 9 | 10 | public class Startup 11 | { 12 | // Inject the IHostingEnvironment into constructor 13 | public Startup(IHostingEnvironment env) 14 | { 15 | // Set the root path 16 | ContentRootPath = env.ContentRootPath; 17 | } 18 | 19 | // Track the root path so that it can be used to setup the app configuration 20 | public string ContentRootPath { get; private set; } 21 | 22 | public void ConfigureServices(IServiceCollection services) 23 | { 24 | // Set up the service configuration 25 | var builder = new ConfigurationBuilder() 26 | .SetBasePath(ContentRootPath) 27 | .AddJsonFile("appsettings.json") 28 | .AddEnvironmentVariables(); 29 | var configuration = builder.Build(); 30 | services.AddSingleton(configuration); 31 | 32 | services.AddSingleton(sp => 33 | { 34 | var qnaService = new QnAMaker(new QnAMakerEndpoint() 35 | { 36 | // get these details from qnamaker.ai 37 | // https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-howto-qna?view=azure-bot-service-4.0&tabs=cs 38 | KnowledgeBaseId = "", 39 | Host = "", 40 | EndpointKey = "" 41 | }); 42 | 43 | return qnaService; 44 | }); 45 | 46 | // Add your SimpleBot to your application 47 | services.AddBot(options => 48 | { 49 | options.CredentialProvider = new ConfigurationCredentialProvider(configuration); 50 | }); 51 | 52 | 53 | } 54 | 55 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 56 | { 57 | app.UseStaticFiles(); 58 | 59 | // Tell your application to use Bot Framework 60 | app.UseBotFramework(); 61 | } 62 | } -------------------------------------------------------------------------------- /demo3qnamakermiddleware/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /demo3qnamakermiddleware/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "Debug": { 5 | "LogLevel": { 6 | "Default": "Warning" 7 | } 8 | }, 9 | "Console": { 10 | "LogLevel": { 11 | "Default": "Warning" 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /demo3qnamakermiddleware/demo3qnamakermiddleware.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /demo3qnamakermiddleware/demo3qnamakermiddleware.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | IIS Express 5 | 6 | -------------------------------------------------------------------------------- /demo3qnamakermiddleware/demo3qnamakermiddleware.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2000 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "demo3qnamakermiddleware", "demo3qnamakermiddleware.csproj", "{915FE6CD-F3FA-471B-BD87-B64C38449A4A}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {915FE6CD-F3FA-471B-BD87-B64C38449A4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {915FE6CD-F3FA-471B-BD87-B64C38449A4A}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {915FE6CD-F3FA-471B-BD87-B64C38449A4A}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {915FE6CD-F3FA-471B-BD87-B64C38449A4A}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {4EA84C13-43A5-4EEE-89C5-79E11384D98B} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /demo4sentiment/demo4sentiment.bot/Bots/SimpleBot.cs: -------------------------------------------------------------------------------- 1 | using demo4sentiment.bot; 2 | using Microsoft.Bot; 3 | using Microsoft.Bot.Builder; 4 | using Microsoft.Bot.Schema; 5 | using System.Threading; 6 | using System.Threading.Tasks; 7 | 8 | namespace demo4mysentimentmiddleware.Bots 9 | { 10 | public class SimpleBot : IBot 11 | { 12 | public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken)) 13 | { 14 | if (turnContext.Activity.Type == ActivityTypes.Message) 15 | { 16 | var sentimentAnalysisResult = (SentimentPrediction)turnContext.TurnState["SentimentPrediction"]; 17 | 18 | var result = sentimentAnalysisResult.Sentiment ? "Positive" : "Negative"; 19 | await turnContext.SendActivityAsync($"You said {turnContext.Activity.Text}, the sentiment according to the middleware is {result}"); 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /demo4sentiment/demo4sentiment.bot/Middleware/SentimentAnalysisMiddleware.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Azure.CognitiveServices.Language.TextAnalytics; 2 | using Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Models; 3 | using Microsoft.Bot.Builder; 4 | using Microsoft.Bot.Schema; 5 | using Microsoft.ML; 6 | using Microsoft.Rest; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | using System.Net.Http; 11 | using System.Threading; 12 | using System.Threading.Tasks; 13 | 14 | namespace demo4sentiment.bot.Middleware 15 | { 16 | public class SentimentAnalysisMiddleware : IMiddleware 17 | { 18 | private PredictionModel model; 19 | 20 | public SentimentAnalysisMiddleware() 21 | { 22 | 23 | } 24 | 25 | public async Task OnTurnAsync(ITurnContext context, NextDelegate next, CancellationToken cancellationToken = default(CancellationToken)) 26 | { 27 | if (context.Activity.Type == ActivityTypes.Message) 28 | { 29 | if (model == null) 30 | { 31 | model = await PredictionModel.ReadAsync("Model.zip"); 32 | } 33 | 34 | var predictedSentiment = model.Predict(new SentimentData() { SentimentText = context.Activity.Text }); 35 | context.TurnState.Add("SentimentPrediction",new SentimentPrediction() { Sentiment = predictedSentiment.Sentiment }); 36 | } 37 | 38 | await next(cancellationToken); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /demo4sentiment/demo4sentiment.bot/Model.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jamesemann/bot-framework-v4-intro-dotnet-core/c881d3cddd97b99234840e823ca20b3ba4278070/demo4sentiment/demo4sentiment.bot/Model.zip -------------------------------------------------------------------------------- /demo4sentiment/demo4sentiment.bot/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace demo4sentiment.bot 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /demo4sentiment/demo4sentiment.bot/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:50214/", 7 | "sslPort": 44351 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "environmentVariables": { 14 | "ASPNETCORE_ENVIRONMENT": "Development" 15 | } 16 | }, 17 | "demo4mysentimentmiddleware": { 18 | "commandName": "Project", 19 | "launchBrowser": true, 20 | "environmentVariables": { 21 | "ASPNETCORE_ENVIRONMENT": "Development" 22 | }, 23 | "applicationUrl": "http://localhost:50215/" 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /demo4sentiment/demo4sentiment.bot/SentimentData.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.ML.Runtime.Api; 2 | 3 | namespace demo4sentiment.bot 4 | { 5 | public class SentimentData 6 | { 7 | [Column(ordinal: "1", name: "Label")] 8 | public float Sentiment; 9 | [Column(ordinal: "0")] 10 | public string SentimentText; 11 | } 12 | 13 | public class SentimentPrediction 14 | { 15 | [ColumnName("PredictedLabel")] 16 | public bool Sentiment; 17 | } 18 | } -------------------------------------------------------------------------------- /demo4sentiment/demo4sentiment.bot/Startup.cs: -------------------------------------------------------------------------------- 1 | using demo4mysentimentmiddleware.Bots; 2 | using demo4sentiment.bot.Middleware; 3 | using Microsoft.AspNetCore.Builder; 4 | using Microsoft.AspNetCore.Hosting; 5 | using Microsoft.Bot.Builder.BotFramework; 6 | using Microsoft.Bot.Builder.Integration.AspNet.Core; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.DependencyInjection; 9 | 10 | public class Startup 11 | { 12 | // Inject the IHostingEnvironment into constructor 13 | public Startup(IHostingEnvironment env) 14 | { 15 | // Set the root path 16 | ContentRootPath = env.ContentRootPath; 17 | } 18 | 19 | // Track the root path so that it can be used to setup the app configuration 20 | public string ContentRootPath { get; private set; } 21 | 22 | public void ConfigureServices(IServiceCollection services) 23 | { 24 | // Set up the service configuration 25 | var builder = new ConfigurationBuilder() 26 | .SetBasePath(ContentRootPath) 27 | .AddJsonFile("appsettings.json") 28 | .AddEnvironmentVariables(); 29 | var configuration = builder.Build(); 30 | services.AddSingleton(configuration); 31 | 32 | 33 | // Add your SimpleBot to your application 34 | services.AddBot(options => 35 | { 36 | options.CredentialProvider = new ConfigurationCredentialProvider(configuration); 37 | 38 | options.Middleware.Add(new SentimentAnalysisMiddleware()); 39 | }); 40 | } 41 | 42 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 43 | { 44 | app.UseStaticFiles(); 45 | 46 | // Tell your application to use Bot Framework 47 | app.UseBotFramework(); 48 | } 49 | } -------------------------------------------------------------------------------- /demo4sentiment/demo4sentiment.bot/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /demo4sentiment/demo4sentiment.bot/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "Debug": { 5 | "LogLevel": { 6 | "Default": "Warning" 7 | } 8 | }, 9 | "Console": { 10 | "LogLevel": { 11 | "Default": "Warning" 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /demo4sentiment/demo4sentiment.bot/demo4sentiment.bot.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | PreserveNewest 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /demo4sentiment/demo4sentiment.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2000 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "demo4sentiment.train", "demo4sentiment.train\demo4sentiment.train.csproj", "{20B3BA90-0BE5-4635-B221-55A3B638F665}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "demo4sentiment.bot", "demo4sentiment.bot\demo4sentiment.bot.csproj", "{FA1ABB09-E186-4347-ACF6-1F926073ACF7}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {20B3BA90-0BE5-4635-B221-55A3B638F665}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {20B3BA90-0BE5-4635-B221-55A3B638F665}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {20B3BA90-0BE5-4635-B221-55A3B638F665}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {20B3BA90-0BE5-4635-B221-55A3B638F665}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {FA1ABB09-E186-4347-ACF6-1F926073ACF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {FA1ABB09-E186-4347-ACF6-1F926073ACF7}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {FA1ABB09-E186-4347-ACF6-1F926073ACF7}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {FA1ABB09-E186-4347-ACF6-1F926073ACF7}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {93F605E8-E7EB-4964-A20B-3C3A3C5DEA0F} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /demo4sentiment/demo4sentiment.train/Program.cs: -------------------------------------------------------------------------------- 1 | // 2 | using demo4sentiment.train; 3 | using Microsoft.ML; 4 | using Microsoft.ML.Data; 5 | using Microsoft.ML.Trainers; 6 | using Microsoft.ML.Transforms; 7 | using System; 8 | using System.IO; 9 | using System.Threading.Tasks; 10 | 11 | namespace SentimentAnalysis 12 | { 13 | class Program 14 | { 15 | static async Task Main(string[] args) 16 | { 17 | PrepareData(); 18 | 19 | var model = await Train(); 20 | } 21 | 22 | private static void PrepareData() 23 | { 24 | // this is designed to work on the IMDB dataset available @ 25 | // http://ai.stanford.edu/~amaas/data/sentiment/ 26 | // extract this file and change this path to point to the local folder for training 27 | 28 | var imdbRoot = @"C:\mlnet\imdb"; 29 | 30 | var positiveReviewsDirectory = new DirectoryInfo(Path.Combine(imdbRoot, "train", "pos")); 31 | var negativeReviewsDirectory = new DirectoryInfo(Path.Combine(imdbRoot, "train", "neg")); 32 | 33 | var outFile = "imbd-sentiment.txt"; 34 | using (var logWriter = new System.IO.StreamWriter(outFile, false)) 35 | { 36 | foreach (var positiveReview in positiveReviewsDirectory.GetFiles()) 37 | { 38 | logWriter.WriteLine($"1{"\t"}{File.ReadAllText(positiveReview.FullName)}"); 39 | } 40 | foreach (var negativeReview in negativeReviewsDirectory.GetFiles()) 41 | { 42 | logWriter.WriteLine($"0{"\t"}{File.ReadAllText(negativeReview.FullName)}"); 43 | } 44 | } 45 | } 46 | 47 | public static async Task> Train() 48 | { 49 | var pipeline = new LearningPipeline(); 50 | pipeline.Add(new TextLoader(Path.Combine(Environment.CurrentDirectory, "imbd-sentiment.txt")).CreateFrom()); 51 | pipeline.Add(new TextFeaturizer("Features", "SentimentText")); 52 | pipeline.Add(new FastTreeBinaryClassifier() { NumLeaves = 5, NumTrees = 5, MinDocumentsInLeafs = 2 }); 53 | PredictionModel model = 54 | pipeline.Train(); 55 | await model.WriteAsync(Path.Combine(Environment.CurrentDirectory, "Model.zip")); 56 | return model; 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /demo4sentiment/demo4sentiment.train/SentimentData.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.ML.Runtime.Api; 2 | 3 | namespace demo4sentiment.train 4 | { 5 | public class SentimentData 6 | { 7 | [Column(ordinal: "0", name: "Label")] 8 | public float Sentiment; 9 | [Column(ordinal: "1")] 10 | public string SentimentText; 11 | } 12 | 13 | public class SentimentPrediction 14 | { 15 | [ColumnName("PredictedLabel")] 16 | public bool Sentiment; 17 | } 18 | } -------------------------------------------------------------------------------- /demo4sentiment/demo4sentiment.train/demo4sentiment.train.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | netcoreapp2.0 6 | 7 | 8 | 9 | 7.1 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /demo5luismiddleware/Bots/SimpleBot.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Bot; 2 | using Microsoft.Bot.Builder; 3 | using Microsoft.Bot.Schema; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | using Microsoft.Bot.Builder.AI.Luis; 10 | 11 | namespace demo5luismiddleware.Bots 12 | { 13 | public class SimpleBot : IBot 14 | { 15 | public SimpleBot(LuisRecognizer luisRecognizer) 16 | { 17 | LuisRecognizer = luisRecognizer; 18 | } 19 | 20 | public LuisRecognizer LuisRecognizer { get; } 21 | 22 | public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken)) 23 | { 24 | if (turnContext.Activity.Type == ActivityTypes.Message) 25 | { 26 | var result = await LuisRecognizer.RecognizeAsync(turnContext, cancellationToken); 27 | var topIntent = result?.GetTopScoringIntent(); 28 | switch ((topIntent != null) ? topIntent.Value.intent : null) 29 | { 30 | case null: 31 | await turnContext.SendActivityAsync("Failed to get results from LUIS."); 32 | break; 33 | case "none": 34 | await turnContext.SendActivityAsync("Sorry, I don't understand."); 35 | break; 36 | case "adjustlights": 37 | await turnContext.SendActivityAsync("Adjusting the lights"); 38 | break; 39 | case "adjusttemperature": 40 | // Cancel the process. 41 | await turnContext.SendActivityAsync("Adjusting the temperature."); 42 | break; 43 | default: 44 | // Received an intent we didn't expect, so send its name and score. 45 | await turnContext.SendActivityAsync($"Intent: {topIntent.Value.intent} ({topIntent.Value.score})."); 46 | break; 47 | } 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /demo5luismiddleware/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace demo5luismiddleware.Controllers 8 | { 9 | [Route("api/[controller]")] 10 | public class ValuesController : Controller 11 | { 12 | // GET api/values 13 | [HttpGet] 14 | public IEnumerable Get() 15 | { 16 | return new string[] { "value1", "value2" }; 17 | } 18 | 19 | // GET api/values/5 20 | [HttpGet("{id}")] 21 | public string Get(int id) 22 | { 23 | return "value"; 24 | } 25 | 26 | // POST api/values 27 | [HttpPost] 28 | public void Post([FromBody]string value) 29 | { 30 | } 31 | 32 | // PUT api/values/5 33 | [HttpPut("{id}")] 34 | public void Put(int id, [FromBody]string value) 35 | { 36 | } 37 | 38 | // DELETE api/values/5 39 | [HttpDelete("{id}")] 40 | public void Delete(int id) 41 | { 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /demo5luismiddleware/HomeAutomationBot.json: -------------------------------------------------------------------------------- 1 | { 2 | "luis_schema_version": "3.0.0", 3 | "versionId": "0.1", 4 | "name": "HomeAutomationBot", 5 | "desc": "", 6 | "culture": "en-us", 7 | "intents": [ 8 | { 9 | "name": "adjustlights" 10 | }, 11 | { 12 | "name": "adjusttemperature" 13 | }, 14 | { 15 | "name": "None" 16 | } 17 | ], 18 | "entities": [], 19 | "composites": [], 20 | "closedLists": [ 21 | { 22 | "name": "onoroff", 23 | "subLists": [ 24 | { 25 | "canonicalForm": "on", 26 | "list": [] 27 | }, 28 | { 29 | "canonicalForm": "off", 30 | "list": [ 31 | "out" 32 | ] 33 | } 34 | ], 35 | "roles": [] 36 | }, 37 | { 38 | "name": "Room", 39 | "subLists": [ 40 | { 41 | "canonicalForm": "kitchen", 42 | "list": [] 43 | }, 44 | { 45 | "canonicalForm": "bathroom", 46 | "list": [ 47 | "toilet" 48 | ] 49 | }, 50 | { 51 | "canonicalForm": "bedroom", 52 | "list": [] 53 | }, 54 | { 55 | "canonicalForm": "living room", 56 | "list": [ 57 | "lounge" 58 | ] 59 | }, 60 | { 61 | "canonicalForm": "dining room", 62 | "list": [] 63 | }, 64 | { 65 | "canonicalForm": "office", 66 | "list": [] 67 | }, 68 | { 69 | "canonicalForm": "garage", 70 | "list": [] 71 | }, 72 | { 73 | "canonicalForm": "study", 74 | "list": [ 75 | "living room" 76 | ] 77 | } 78 | ], 79 | "roles": [] 80 | } 81 | ], 82 | "patternAnyEntities": [], 83 | "regex_entities": [], 84 | "prebuiltEntities": [ 85 | { 86 | "name": "temperature", 87 | "roles": [] 88 | } 89 | ], 90 | "model_features": [], 91 | "regex_features": [], 92 | "patterns": [], 93 | "utterances": [ 94 | { 95 | "text": "cool down the kitchen", 96 | "intent": "adjusttemperature", 97 | "entities": [] 98 | }, 99 | { 100 | "text": "heat up the bathroom", 101 | "intent": "adjusttemperature", 102 | "entities": [] 103 | }, 104 | { 105 | "text": "in the kitchen set the temperature to 30 degrees", 106 | "intent": "adjusttemperature", 107 | "entities": [] 108 | }, 109 | { 110 | "text": "kitchen lights off", 111 | "intent": "adjustlights", 112 | "entities": [] 113 | }, 114 | { 115 | "text": "kitchen to 30 degrees", 116 | "intent": "adjusttemperature", 117 | "entities": [] 118 | }, 119 | { 120 | "text": "lights in kitchen off", 121 | "intent": "adjustlights", 122 | "entities": [] 123 | }, 124 | { 125 | "text": "lower the temperature in the kitchen", 126 | "intent": "adjusttemperature", 127 | "entities": [] 128 | }, 129 | { 130 | "text": "set kitchen to 30 degrees c", 131 | "intent": "adjusttemperature", 132 | "entities": [] 133 | }, 134 | { 135 | "text": "set temperature in kitchen to 30 degrees", 136 | "intent": "adjusttemperature", 137 | "entities": [] 138 | }, 139 | { 140 | "text": "set the kitchen to 21 degrees", 141 | "intent": "adjusttemperature", 142 | "entities": [] 143 | }, 144 | { 145 | "text": "set the lights off in the kitchen", 146 | "intent": "adjustlights", 147 | "entities": [] 148 | }, 149 | { 150 | "text": "switch lights off in bathroom", 151 | "intent": "adjustlights", 152 | "entities": [] 153 | }, 154 | { 155 | "text": "switch off the lights in the kitchen", 156 | "intent": "adjustlights", 157 | "entities": [] 158 | }, 159 | { 160 | "text": "switch out the lights", 161 | "intent": "adjustlights", 162 | "entities": [] 163 | }, 164 | { 165 | "text": "the bathroom is too cold", 166 | "intent": "adjusttemperature", 167 | "entities": [] 168 | }, 169 | { 170 | "text": "the kitchen is too hot", 171 | "intent": "adjusttemperature", 172 | "entities": [] 173 | }, 174 | { 175 | "text": "turn on the lights in the kitchen", 176 | "intent": "adjustlights", 177 | "entities": [] 178 | }, 179 | { 180 | "text": "turn out the lights", 181 | "intent": "adjustlights", 182 | "entities": [] 183 | }, 184 | { 185 | "text": "turn the kitchen lights on", 186 | "intent": "adjustlights", 187 | "entities": [] 188 | }, 189 | { 190 | "text": "turn the lights on", 191 | "intent": "adjustlights", 192 | "entities": [] 193 | }, 194 | { 195 | "text": "turn the lights on in the kitchen", 196 | "intent": "adjustlights", 197 | "entities": [] 198 | }, 199 | { 200 | "text": "turn up the kitchen a few degrees", 201 | "intent": "adjusttemperature", 202 | "entities": [] 203 | }, 204 | { 205 | "text": "turn up the kitchen to 21 degrees", 206 | "intent": "adjusttemperature", 207 | "entities": [] 208 | }, 209 | { 210 | "text": "turn up the temperature in the kitchen", 211 | "intent": "adjusttemperature", 212 | "entities": [] 213 | } 214 | ] 215 | } -------------------------------------------------------------------------------- /demo5luismiddleware/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace demo5luismiddleware 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /demo5luismiddleware/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:53560/", 7 | "sslPort": 44334 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "environmentVariables": { 14 | "ASPNETCORE_ENVIRONMENT": "Development" 15 | } 16 | }, 17 | "demo5luismiddleware": { 18 | "commandName": "Project", 19 | "launchBrowser": true, 20 | "environmentVariables": { 21 | "ASPNETCORE_ENVIRONMENT": "Development" 22 | }, 23 | "applicationUrl": "http://localhost:53561/" 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /demo5luismiddleware/Startup.cs: -------------------------------------------------------------------------------- 1 | using demo5luismiddleware.Bots; 2 | using Microsoft.AspNetCore.Builder; 3 | using Microsoft.AspNetCore.Hosting; 4 | using Microsoft.Bot.Builder.BotFramework; 5 | using Microsoft.Bot.Builder.Integration.AspNet.Core; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.DependencyInjection; 8 | using System; 9 | using Microsoft.Bot.Builder.AI.Luis; 10 | 11 | public class Startup 12 | { 13 | // Inject the IHostingEnvironment into constructor 14 | public Startup(IHostingEnvironment env) 15 | { 16 | // Set the root path 17 | ContentRootPath = env.ContentRootPath; 18 | } 19 | 20 | // Track the root path so that it can be used to setup the app configuration 21 | public string ContentRootPath { get; private set; } 22 | 23 | public void ConfigureServices(IServiceCollection services) 24 | { 25 | // Set up the service configuration 26 | var builder = new ConfigurationBuilder() 27 | .SetBasePath(ContentRootPath) 28 | .AddJsonFile("appsettings.json") 29 | .AddEnvironmentVariables(); 30 | var configuration = builder.Build(); 31 | services.AddSingleton(configuration); 32 | 33 | services.AddSingleton(sp => 34 | { 35 | // get these values from luis.ai 36 | // i've left the endpoint in so you have an example of an url that works 37 | // because all luis client libs seem to vary 38 | var luisApp = new LuisApplication( 39 | applicationId: "", 40 | endpointKey: "", 41 | endpoint:"https://westus.api.cognitive.microsoft.com"); 42 | 43 | var luisPredictionOptions = new LuisPredictionOptions 44 | { 45 | IncludeAllIntents = true, 46 | }; 47 | 48 | return new LuisRecognizer( 49 | application: luisApp, 50 | predictionOptions: luisPredictionOptions, 51 | includeApiResults: true); 52 | }); 53 | 54 | // Add your SimpleBot to your application 55 | services.AddBot(options => 56 | { 57 | options.CredentialProvider = new ConfigurationCredentialProvider(configuration); 58 | }); 59 | 60 | } 61 | 62 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 63 | { 64 | app.UseStaticFiles(); 65 | 66 | // Tell your application to use Bot Framework 67 | app.UseBotFramework(); 68 | } 69 | } -------------------------------------------------------------------------------- /demo5luismiddleware/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /demo5luismiddleware/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "Debug": { 5 | "LogLevel": { 6 | "Default": "Warning" 7 | } 8 | }, 9 | "Console": { 10 | "LogLevel": { 11 | "Default": "Warning" 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /demo5luismiddleware/demo5luismiddleware.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /demo5luismiddleware/demo5luismiddleware.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | IIS Express 5 | 6 | -------------------------------------------------------------------------------- /demo5luismiddleware/demo5luismiddleware.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2000 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "demo5luismiddleware", "demo5luismiddleware.csproj", "{2C937D7F-BD3D-4E6B-904E-9B65C1A6F7D7}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {2C937D7F-BD3D-4E6B-904E-9B65C1A6F7D7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {2C937D7F-BD3D-4E6B-904E-9B65C1A6F7D7}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {2C937D7F-BD3D-4E6B-904E-9B65C1A6F7D7}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {2C937D7F-BD3D-4E6B-904E-9B65C1A6F7D7}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {FF5B5498-0AE0-4CB7-BA07-D1993245AA2E} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /demo6cards/AdaptiveCard.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", 3 | "type": "AdaptiveCard", 4 | "version": "1.0", 5 | "body": [ 6 | { 7 | "type": "Container", 8 | "items": [ 9 | { 10 | "type": "TextBlock", 11 | "text": "Publish Adaptive Card schema", 12 | "weight": "bolder", 13 | "size": "medium" 14 | }, 15 | { 16 | "type": "ColumnSet", 17 | "columns": [ 18 | { 19 | "type": "Column", 20 | "width": "auto", 21 | "items": [ 22 | { 23 | "type": "Image", 24 | "url": "https://pbs.twimg.com/profile_images/3647943215/d7f12830b3c17a5a9e4afcc370e3a37e_400x400.jpeg", 25 | "size": "small", 26 | "style": "person" 27 | } 28 | ] 29 | }, 30 | { 31 | "type": "Column", 32 | "width": "stretch", 33 | "items": [ 34 | { 35 | "type": "TextBlock", 36 | "text": "Matt Hidinger", 37 | "weight": "bolder", 38 | "wrap": true 39 | }, 40 | { 41 | "type": "TextBlock", 42 | "spacing": "none", 43 | "text": "Created {{DATE(2017-02-14T06:08:39Z, SHORT)}}", 44 | "isSubtle": true, 45 | "wrap": true 46 | } 47 | ] 48 | } 49 | ] 50 | } 51 | ] 52 | }, 53 | { 54 | "type": "Container", 55 | "items": [ 56 | { 57 | "type": "TextBlock", 58 | "text": "Now that we have defined the main rules and features of the format, we need to produce a schema and publish it to GitHub. The schema will be the starting point of our reference documentation.", 59 | "wrap": true 60 | }, 61 | { 62 | "type": "FactSet", 63 | "facts": [ 64 | { 65 | "title": "Board:", 66 | "value": "Adaptive Card" 67 | }, 68 | { 69 | "title": "List:", 70 | "value": "Backlog" 71 | }, 72 | { 73 | "title": "Assigned to:", 74 | "value": "Matt Hidinger" 75 | }, 76 | { 77 | "title": "Due date:", 78 | "value": "Not set" 79 | } 80 | ] 81 | } 82 | ] 83 | } 84 | ], 85 | "actions": [ 86 | { 87 | "type": "Action.ShowCard", 88 | "title": "Set due date", 89 | "card": { 90 | "type": "AdaptiveCard", 91 | "body": [ 92 | { 93 | "type": "Input.Date", 94 | "id": "dueDate" 95 | } 96 | ], 97 | "actions": [ 98 | { 99 | "type": "Action.Submit", 100 | "title": "OK" 101 | } 102 | ] 103 | } 104 | }, 105 | { 106 | "type": "Action.ShowCard", 107 | "title": "Comment", 108 | "card": { 109 | "type": "AdaptiveCard", 110 | "body": [ 111 | { 112 | "type": "Input.Text", 113 | "id": "comment", 114 | "isMultiline": true, 115 | "placeholder": "Enter your comment" 116 | } 117 | ], 118 | "actions": [ 119 | { 120 | "type": "Action.Submit", 121 | "title": "OK" 122 | } 123 | ] 124 | } 125 | } 126 | ] 127 | } -------------------------------------------------------------------------------- /demo6cards/Bots/RichCardsBot.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT License. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.IO; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | using Microsoft.Bot; 10 | using Microsoft.Bot.Builder; 11 | using Microsoft.Bot.Builder.Dialogs; 12 | using Microsoft.Bot.Schema; 13 | using Microsoft.Recognizers.Text; 14 | using Newtonsoft.Json; 15 | 16 | namespace demo6cards 17 | { 18 | public class RichCardsBot : IBot 19 | { 20 | public RichCardsBot() 21 | { 22 | } 23 | 24 | public async Task OnTurnAsync(ITurnContext context, CancellationToken cancellationToken = default(CancellationToken)) 25 | { 26 | if (context.Activity.Type == ActivityTypes.Message) 27 | { 28 | var activity = context.Activity; 29 | switch (activity.Text) 30 | { 31 | case "Adaptive card": 32 | await context.SendActivityAsync(CreateResponse(activity, CreateAdaptiveCardAttachment())); 33 | break; 34 | case "Animation card": 35 | await context.SendActivityAsync(CreateResponse(activity, CreateAnimationCardAttachment())); 36 | break; 37 | case "Audio card": 38 | await context.SendActivityAsync(CreateResponse(activity, CreateAudioCardAttachment())); 39 | break; 40 | case "Hero card": 41 | await context.SendActivityAsync(CreateResponse(activity, CreateHeroCardAttachment())); 42 | break; 43 | case "Receipt card": 44 | await context.SendActivityAsync(CreateResponse(activity, CreateReceiptCardAttachment())); 45 | break; 46 | case "Signin card": 47 | await context.SendActivityAsync(CreateResponse(activity, CreateSignInCardAttachment())); 48 | break; 49 | case "Thumbnail card": 50 | await context.SendActivityAsync(CreateResponse(activity, CreateThumbnailCardAttachment())); 51 | break; 52 | case "Video card": 53 | await context.SendActivityAsync(CreateResponse(activity, CreateVideoCardAttacment())); 54 | break; 55 | default: 56 | activity.Text = ""; 57 | activity.Text += $"Adaptive card{Environment.NewLine}"; 58 | activity.Text += $"Animation card{Environment.NewLine}"; 59 | activity.Text += $"Audio card{Environment.NewLine}"; 60 | activity.Text += $"Hero card{Environment.NewLine}"; 61 | activity.Text += $"Receipt card{Environment.NewLine}"; 62 | activity.Text += $"Signin card{Environment.NewLine}"; 63 | activity.Text += $"Thumbnail card{Environment.NewLine}"; 64 | activity.Text += $"Video card{Environment.NewLine}"; 65 | await context.SendActivityAsync(activity); 66 | 67 | break; 68 | } 69 | 70 | } 71 | } 72 | 73 | private Activity CreateResponse(Activity activity, Attachment attachment) 74 | { 75 | var response = activity.CreateReply(); 76 | response.Attachments = new List() { attachment }; 77 | return response; 78 | } 79 | 80 | private Attachment CreateAdaptiveCardAttachment() 81 | { 82 | var adaptiveCard = File.ReadAllText(@".\AdaptiveCard.json"); 83 | return new Attachment() 84 | { 85 | ContentType = "application/vnd.microsoft.card.adaptive", 86 | Content = JsonConvert.DeserializeObject(adaptiveCard) 87 | }; 88 | } 89 | 90 | private Attachment CreateAnimationCardAttachment() 91 | { 92 | return new AnimationCard() 93 | { 94 | Title = "Microsoft Bot Framework", 95 | Media = new List() 96 | { 97 | new MediaUrl("http://i.giphy.com/Ki55RUbOV5njy.gif") 98 | }, 99 | Subtitle = "Animation Card" 100 | }.ToAttachment(); 101 | } 102 | 103 | private Attachment CreateAudioCardAttachment() 104 | { 105 | return new AudioCard() 106 | { 107 | Title = "I am your father", 108 | Media = new List() 109 | { 110 | new MediaUrl("http://www.wavlist.com/movies/004/father.wav") 111 | }, 112 | Buttons = new List() 113 | { 114 | new CardAction() 115 | { 116 | Type = ActionTypes.OpenUrl, 117 | Title = "Read more", 118 | Value = "https://en.wikipedia.org/wiki/The_Empire_Strikes_Back" 119 | } 120 | }, 121 | Subtitle = "Star Wars: Episode V - The Empire Strikes Back", 122 | Text = "The Empire Strikes Back (also known as Star Wars: Episode V – The Empire Strikes Back) is a 1980 American epic space opera film directed by Irvin Kershner. Leigh Brackett and Lawrence Kasdan wrote the screenplay, with George Lucas writing the film\'s story and serving as executive producer. The second installment in the original Star Wars trilogy, it was produced by Gary Kurtz for Lucasfilm Ltd. and stars Mark Hamill, Harrison Ford, Carrie Fisher, Billy Dee Williams, Anthony Daniels, David Prowse, Kenny Baker, Peter Mayhew and Frank Oz.", 123 | Image = new ThumbnailUrl("https://upload.wikimedia.org/wikipedia/en/3/3c/SW_-_Empire_Strikes_Back.jpg") 124 | }.ToAttachment(); 125 | } 126 | 127 | private Attachment CreateHeroCardAttachment() 128 | { 129 | return new HeroCard() 130 | { 131 | Title = "", 132 | Images = new List() 133 | { 134 | new CardImage("https://sec.ch9.ms/ch9/7ff5/e07cfef0-aa3b-40bb-9baa-7c9ef8ff7ff5/buildreactionbotframework_960.jpg") 135 | }, 136 | Buttons = new List() 137 | { 138 | new CardAction() 139 | { 140 | Type = ActionTypes.OpenUrl, 141 | Title = "Get Started", 142 | Value = "https://docs.microsoft.com/en-us/azure/bot-service/" 143 | } 144 | } 145 | }.ToAttachment(); 146 | } 147 | 148 | private Attachment CreateReceiptCardAttachment() 149 | { 150 | return new ReceiptCard() 151 | { 152 | Title = "John Doe", 153 | Facts = new List() 154 | { 155 | new Fact(key: "Order Number", value: "1234"), 156 | new Fact(key: "Payment Method", value: "VISA 5555-****") 157 | }, 158 | Items = new List() 159 | { 160 | new ReceiptItem() 161 | { 162 | Title = "Data Transfer", 163 | Price = "$38.45", 164 | Quantity = "368", 165 | Image = new CardImage("https://github.com/amido/azure-vector-icons/raw/master/renders/traffic-manager.png") 166 | }, 167 | new ReceiptItem() 168 | { 169 | Title = "App Service", 170 | Price = "$45.00", 171 | Quantity = "720", 172 | Image = new CardImage("https://github.com/amido/azure-vector-icons/raw/master/renders/cloud-service.png") 173 | } 174 | }, 175 | Tax = "$7.50", 176 | Total = "$90.95", 177 | Buttons = new List() 178 | { 179 | new CardAction() 180 | { 181 | Type = ActionTypes.OpenUrl, 182 | Title = "More Information", 183 | Value = "https://azure.microsoft.com/en-us/pricing/details/bot-service/" 184 | } 185 | } 186 | }.ToAttachment(); 187 | } 188 | 189 | private Attachment CreateSignInCardAttachment() 190 | { 191 | return new SigninCard() 192 | { 193 | Text = "BotFramework Sign-in Card", 194 | Buttons = new List() 195 | { 196 | new CardAction() 197 | { 198 | Type = ActionTypes.Signin, 199 | Title = "Sign-in", 200 | Value = "https://login.microsoftonline.com" 201 | } 202 | } 203 | }.ToAttachment(); 204 | } 205 | 206 | private Attachment CreateThumbnailCardAttachment() 207 | { 208 | return new ThumbnailCard() 209 | { 210 | Title = "BotFramework Thumbnail Card", 211 | Images = new List() 212 | { 213 | new CardImage() 214 | { 215 | Url = "https://sec.ch9.ms/ch9/7ff5/e07cfef0-aa3b-40bb-9baa-7c9ef8ff7ff5/buildreactionbotframework_960.jpg" 216 | } 217 | }, 218 | Buttons = new List() 219 | { 220 | new CardAction() 221 | { 222 | Type = ActionTypes.OpenUrl, 223 | Title = "Get Started", 224 | Value = "https://docs.microsoft.com/en-us/azure/bot-service/" 225 | } 226 | }, 227 | Subtitle = "Your bots — wherever your users are talking", 228 | Text = "Build and connect intelligent bots to interact with your users naturally wherever they are, from text/sms to Skype, Slack, Office 365 mail and other popular services." 229 | }.ToAttachment(); 230 | } 231 | 232 | private Attachment CreateVideoCardAttacment() 233 | { 234 | return new VideoCard() 235 | { 236 | Title = "Big Buck Bunny", 237 | Media = new List() 238 | { 239 | new MediaUrl("http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4") 240 | }, 241 | Buttons = new List() 242 | { 243 | new CardAction() 244 | { 245 | Type = ActionTypes.OpenUrl, 246 | Title = "Learn More", 247 | Value = "https://peach.blender.org/" 248 | } 249 | }, 250 | Subtitle = "by the Blender Institute", 251 | Text = "Big Buck Bunny (code-named Peach) is a short computer-animated comedy film by the Blender Institute, part of the Blender Foundation. Like the foundation\'s previous film Elephants Dream, the film was made using Blender, a free software application for animation made by the same foundation. It was released as an open-source film under Creative Commons License Attribution 3.0." 252 | }.ToAttachment(); 253 | } 254 | } 255 | } -------------------------------------------------------------------------------- /demo6cards/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace demo6cards.Controllers 8 | { 9 | [Route("api/[controller]")] 10 | public class ValuesController : Controller 11 | { 12 | // GET api/values 13 | [HttpGet] 14 | public IEnumerable Get() 15 | { 16 | return new string[] { "value1", "value2" }; 17 | } 18 | 19 | // GET api/values/5 20 | [HttpGet("{id}")] 21 | public string Get(int id) 22 | { 23 | return "value"; 24 | } 25 | 26 | // POST api/values 27 | [HttpPost] 28 | public void Post([FromBody]string value) 29 | { 30 | } 31 | 32 | // PUT api/values/5 33 | [HttpPut("{id}")] 34 | public void Put(int id, [FromBody]string value) 35 | { 36 | } 37 | 38 | // DELETE api/values/5 39 | [HttpDelete("{id}")] 40 | public void Delete(int id) 41 | { 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /demo6cards/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace demo6cards 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /demo6cards/Properties/PublishProfiles/demo-180718-botapplication - FTP.pubxml.user: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAA8NvlkXV4EEmCAbVrX5MdLwAAAAACAAAAAAAQZgAAAAEAACAAAAAQtPpvebK4ES3oo8SQlm1ve23xZVXBWLQ1DERiP5MvzAAAAAAOgAAAAAIAACAAAABPhPBMPREGtcpJoLDt+t208CE/KuTSZJwp3hhktg1VPYAAAAAd+hxJE/y9jkFzX62TUarcSE0u0CyXBxgAxxTGBYct8iYDycWf/lxkqtGKBTCBEbedwTD0YcSSTeIy0tIf7K7aO1tgAXoWgL82di2usysCzbkMFyQcOrBydpAcsP/KZKTE5qieX0fmnTfiqIqQV8mPNZUuza1iuE1TBg44BFru+EAAAACXqzM9zNH8+UrPhvJ1PuX8yyfuoPb7SRD2mbwyUBM3kvXf5jMp5QkOoIhMjQyBlJdrQGOBdUD9F4sdToB+zl+o 10 | 11 | -------------------------------------------------------------------------------- /demo6cards/Properties/PublishProfiles/demo-180718-botapplication - Web Deploy.pubxml.user: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAA8NvlkXV4EEmCAbVrX5MdLwAAAAACAAAAAAAQZgAAAAEAACAAAABW/u4UZM0PYu2jmqNGOpvBVEqh7nzwqcSAuhg1dxNceAAAAAAOgAAAAAIAACAAAACY7E4sTGSI9eqbhYjfJ2bc31KiW96QBV5WWpHTqWCwz4AAAABoYer7FhQ5Bk814U1vnEuel7xZL+3Iavr2BWOINbtshoYDZp1yCAK4E81anddyY7few48KM4mvssTlv+u6O/hqC1g6TbFrhR7pPzZwkESGp7xH1nvwiYOa0axIJzoqAj33hoGFThgHDJNIT+20VbLRJoL5MeQGNZA4FXXI2fyEB0AAAAAZbHi8IfA8cyK7RXU/7vMeOjUXxMpAcgwGOBZHfH9lqLsgQmJHl57YnkRarZiZGx2mEG4aC1q3qz9c9jUnzI4y 10 | 11 | -------------------------------------------------------------------------------- /demo6cards/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iis": { 6 | "applicationUrl": "http://localhost/demo6cards", 7 | "sslPort": 0 8 | }, 9 | "iisExpress": { 10 | "applicationUrl": "http://localhost:54269/", 11 | "sslPort": 44345 12 | } 13 | }, 14 | "profiles": { 15 | "IIS Express": { 16 | "commandName": "IISExpress", 17 | "environmentVariables": { 18 | "ASPNETCORE_ENVIRONMENT": "Development" 19 | } 20 | }, 21 | "demo6cards": { 22 | "commandName": "Project", 23 | "launchBrowser": true, 24 | "environmentVariables": { 25 | "ASPNETCORE_ENVIRONMENT": "Development" 26 | }, 27 | "applicationUrl": "http://localhost:54272/" 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /demo6cards/Startup.cs: -------------------------------------------------------------------------------- 1 | using demo6cards; 2 | using Microsoft.AspNetCore.Builder; 3 | using Microsoft.AspNetCore.Hosting; 4 | using Microsoft.Bot.Builder.BotFramework; 5 | using Microsoft.Bot.Builder.Integration.AspNet.Core; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.DependencyInjection; 8 | using System; 9 | using System.Collections.Generic; 10 | using Microsoft.Bot.Builder; 11 | 12 | public class Startup 13 | { 14 | // Inject the IHostingEnvironment into constructor 15 | public Startup(IHostingEnvironment env) 16 | { 17 | // Set the root path 18 | ContentRootPath = env.ContentRootPath; 19 | } 20 | 21 | // Track the root path so that it can be used to setup the app configuration 22 | public string ContentRootPath { get; private set; } 23 | 24 | public void ConfigureServices(IServiceCollection services) 25 | { 26 | // Set up the service configuration 27 | var builder = new ConfigurationBuilder() 28 | .SetBasePath(ContentRootPath) 29 | .AddJsonFile("appsettings.json") 30 | .AddEnvironmentVariables(); 31 | var configuration = builder.Build(); 32 | services.AddSingleton(configuration); 33 | 34 | // Add your SimpleBot to your application 35 | services.AddBot(options => 36 | { 37 | options.CredentialProvider = new ConfigurationCredentialProvider(configuration); 38 | }); 39 | 40 | 41 | } 42 | 43 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 44 | { 45 | app.UseStaticFiles(); 46 | 47 | // Tell your application to use Bot Framework 48 | app.UseBotFramework(); 49 | } 50 | } -------------------------------------------------------------------------------- /demo6cards/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /demo6cards/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "MicrosoftAppId": "", 3 | "MicrosoftAppPassword": "" 4 | } -------------------------------------------------------------------------------- /demo6cards/demo6cards.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /demo6cards/demo6cards.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | IIS Express 5 | demo-180718-botapplication - Web Deploy 6 | 7 | 8 | ProjectDebugger 9 | 10 | -------------------------------------------------------------------------------- /demo6cards/demo6cards.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2000 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "demo6cards", "demo6cards.csproj", "{725C9CF7-B3D0-4D9C-A173-93C1A68008E8}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {725C9CF7-B3D0-4D9C-A173-93C1A68008E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {725C9CF7-B3D0-4D9C-A173-93C1A68008E8}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {725C9CF7-B3D0-4D9C-A173-93C1A68008E8}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {725C9CF7-B3D0-4D9C-A173-93C1A68008E8}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {2E79ECB0-24DF-47FF-ADA1-A2A36E11A2BD} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /demo7dialogs/BotAccessors.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using demo7dialogs.Bots; 3 | using Microsoft.Bot.Builder; 4 | using Microsoft.Bot.Builder.Dialogs; 5 | 6 | namespace demo7dialogs 7 | { 8 | public class BotAccessors 9 | { 10 | public BotAccessors(ConversationState conversationState) 11 | { 12 | ConversationState = conversationState ?? throw new ArgumentNullException(nameof(conversationState)); 13 | } 14 | 15 | public static string BankingBotStateAccessorName { get; } = $"{nameof(BotAccessors)}.BankingBotState"; 16 | public IStatePropertyAccessor BankingBotStateStateAccessor { get; internal set; } 17 | 18 | public static string DialogStateAccessorName { get; } = $"{nameof(BotAccessors)}.DialogState"; 19 | public IStatePropertyAccessor DialogStateAccessor { get; internal set; } 20 | public ConversationState ConversationState { get; } 21 | } 22 | } -------------------------------------------------------------------------------- /demo7dialogs/Bots/BankingBot.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | using demo7dialogs.Dialogs; 4 | using demo7dialogs.Dialogs.Balance; 5 | using demo7dialogs.Dialogs.Balance.CurrentAccount; 6 | using demo7dialogs.Dialogs.Balance.SavingsAccount; 7 | using demo7dialogs.Dialogs.Payment; 8 | using Microsoft.Bot.Builder; 9 | using Microsoft.Bot.Builder.Dialogs; 10 | using Microsoft.Bot.Schema; 11 | 12 | namespace demo7dialogs.Bots 13 | { 14 | public class BankingBot : IBot 15 | { 16 | private readonly DialogSet dialogs; 17 | 18 | public BankingBot(BotAccessors botAccessors) 19 | { 20 | var dialogState = botAccessors.DialogStateAccessor; 21 | // compose dialogs 22 | dialogs = new DialogSet(dialogState); 23 | dialogs.Add(MainDialog.Instance); 24 | dialogs.Add(MakePaymentDialog.Instance); 25 | dialogs.Add(CheckBalanceDialog.Instance); 26 | dialogs.Add(CheckCurrentAccountBalanceDialog.Instance); 27 | dialogs.Add(CheckSavingsAccountBalanceDialog.Instance); 28 | dialogs.Add(new ChoicePrompt("choicePrompt")); 29 | dialogs.Add(new TextPrompt("textPrompt")); 30 | dialogs.Add(new NumberPrompt("numberPrompt")); 31 | BotAccessors = botAccessors; 32 | } 33 | 34 | public BotAccessors BotAccessors { get; } 35 | 36 | 37 | public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken)) 38 | { 39 | if (turnContext.Activity.Type == ActivityTypes.Message) 40 | { 41 | // initialize state if necessary 42 | var state = await BotAccessors.BankingBotStateStateAccessor.GetAsync(turnContext, () => new BankingBotState(), cancellationToken); 43 | 44 | turnContext.TurnState.Add("BotAccessors", BotAccessors); 45 | 46 | var dialogCtx = await dialogs.CreateContextAsync(turnContext, cancellationToken); 47 | 48 | if (dialogCtx.ActiveDialog == null) 49 | { 50 | await dialogCtx.BeginDialogAsync(MainDialog.Id, cancellationToken); 51 | } 52 | else 53 | { 54 | await dialogCtx.ContinueDialogAsync(cancellationToken); 55 | } 56 | 57 | await BotAccessors.ConversationState.SaveChangesAsync(turnContext, false, cancellationToken); 58 | } 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /demo7dialogs/Bots/BankingBotState.cs: -------------------------------------------------------------------------------- 1 | namespace demo7dialogs.Bots 2 | { 3 | public class BankingBotState 4 | { 5 | public string Recipient { get; set; } 6 | public int Amount { get; set; } 7 | } 8 | } -------------------------------------------------------------------------------- /demo7dialogs/Dialogs/Balance/CheckBalanceDialog.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using demo7dialogs.Dialogs.Balance.CurrentAccount; 4 | using demo7dialogs.Dialogs.Balance.SavingsAccount; 5 | using Microsoft.Bot.Builder.Dialogs; 6 | using Microsoft.Bot.Builder.Dialogs.Choices; 7 | 8 | namespace demo7dialogs.Dialogs.Balance 9 | { 10 | public class CheckBalanceDialog : WaterfallDialog 11 | { 12 | public CheckBalanceDialog(string dialogId, IEnumerable steps = null) : base(dialogId, steps) 13 | { 14 | AddStep(async (stepContext, cancellationToken) => 15 | { 16 | return await stepContext.PromptAsync("choicePrompt", 17 | new PromptOptions 18 | { 19 | Prompt = stepContext.Context.Activity.CreateReply($"[CheckBalanceDialog] Which account?"), 20 | Choices = new[] {new Choice {Value = "Current"}, new Choice {Value = "Savings"}}.ToList() 21 | }); 22 | }); 23 | 24 | AddStep(async (stepContext, cancellationToken) => 25 | { 26 | var response = stepContext.Result as FoundChoice; 27 | 28 | if (response.Value == "Current") 29 | { 30 | return await stepContext.BeginDialogAsync(CheckCurrentAccountBalanceDialog.Id); 31 | } 32 | 33 | if (response.Value == "Savings") 34 | { 35 | return await stepContext.BeginDialogAsync(CheckSavingsAccountBalanceDialog.Id); 36 | } 37 | 38 | return await stepContext.NextAsync(); 39 | }); 40 | } 41 | 42 | public static string Id => "checkBalanceDialog"; 43 | public static CheckBalanceDialog Instance { get; } = new CheckBalanceDialog(Id); 44 | } 45 | } -------------------------------------------------------------------------------- /demo7dialogs/Dialogs/Balance/CurrentAccount/CheckCurrentAccountBalanceDialog.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.Bot.Builder.Dialogs; 3 | 4 | namespace demo7dialogs.Dialogs.Balance.CurrentAccount 5 | { 6 | public class CheckCurrentAccountBalanceDialog : WaterfallDialog 7 | { 8 | public CheckCurrentAccountBalanceDialog(string dialogId, IEnumerable steps = null) : base(dialogId, steps) 9 | { 10 | AddStep(async (stepContext, cancellationToken) => 11 | { 12 | await stepContext.Context.SendActivityAsync($"Your current balance is..."); 13 | return await stepContext.EndDialogAsync(); 14 | }); 15 | } 16 | 17 | public static string Id => "checkCurrentAccountBalanceDialog"; 18 | public static CheckCurrentAccountBalanceDialog Instance { get; } = new CheckCurrentAccountBalanceDialog(Id); 19 | } 20 | } -------------------------------------------------------------------------------- /demo7dialogs/Dialogs/Balance/SavingsAccount/CheckSavingsAccountBalanceDialog.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using Microsoft.Bot.Builder.Dialogs; 3 | 4 | namespace demo7dialogs.Dialogs.Balance.SavingsAccount 5 | { 6 | public class CheckSavingsAccountBalanceDialog : WaterfallDialog 7 | { 8 | public CheckSavingsAccountBalanceDialog(string dialogId, IEnumerable steps = null) : base(dialogId, steps) 9 | { 10 | this.AddStep(async (stepContext, cancellationToken) => 11 | { 12 | await stepContext.Context.SendActivityAsync($"Your savings balance is..."); 13 | return await stepContext.EndDialogAsync(); 14 | }); 15 | } 16 | 17 | public static string Id => "checkSavingsAccountBalanceDialog"; 18 | public static CheckSavingsAccountBalanceDialog Instance { get; } = new CheckSavingsAccountBalanceDialog(Id); 19 | } 20 | } -------------------------------------------------------------------------------- /demo7dialogs/Dialogs/MainDialog.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using demo7dialogs.Dialogs.Balance; 4 | using demo7dialogs.Dialogs.Payment; 5 | using Microsoft.Bot.Builder.Dialogs; 6 | using Microsoft.Bot.Builder.Dialogs.Choices; 7 | 8 | namespace demo7dialogs.Dialogs 9 | { 10 | public class MainDialog : WaterfallDialog 11 | { 12 | public MainDialog(string dialogId, IEnumerable steps = null) : base(dialogId, steps) 13 | { 14 | AddStep(async (stepContext, cancellationToken) => 15 | { 16 | return await stepContext.PromptAsync("choicePrompt", 17 | new PromptOptions 18 | { 19 | Prompt = stepContext.Context.Activity.CreateReply("[MainDialog] I'm banking 🤖{Environment.NewLine}Would you like to check balance or make payment?"), 20 | Choices = new[] {new Choice {Value = "Check balance"}, new Choice {Value = "Make payment"}}.ToList() 21 | }); 22 | }); 23 | AddStep(async (stepContext, cancellationToken) => 24 | { 25 | var response = (stepContext.Result as FoundChoice)?.Value; 26 | 27 | if (response == "Check balance") 28 | { 29 | return await stepContext.BeginDialogAsync(CheckBalanceDialog.Id); 30 | } 31 | 32 | if (response == "Make payment") 33 | { 34 | return await stepContext.BeginDialogAsync(MakePaymentDialog.Id); 35 | } 36 | 37 | return await stepContext.NextAsync(); 38 | }); 39 | 40 | AddStep(async (stepContext, cancellationToken) => { return await stepContext.ReplaceDialogAsync(Id); }); 41 | } 42 | 43 | 44 | public static string Id => "mainDialog"; 45 | 46 | public static MainDialog Instance { get; } = new MainDialog(Id); 47 | } 48 | } -------------------------------------------------------------------------------- /demo7dialogs/Dialogs/Payment/MakePaymentDialog.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Microsoft.Bot.Builder.Dialogs; 4 | 5 | namespace demo7dialogs.Dialogs.Payment 6 | { 7 | public class MakePaymentDialog : WaterfallDialog 8 | { 9 | public MakePaymentDialog(string dialogId, IEnumerable steps = null) : base(dialogId, steps) 10 | { 11 | AddStep(async (stepContext, cancellationToken) => 12 | { 13 | return await stepContext.PromptAsync("textPrompt", 14 | new PromptOptions 15 | { 16 | Prompt = stepContext.Context.Activity.CreateReply("Who would you like to pay?") 17 | }); 18 | }); 19 | 20 | AddStep(async (stepContext, cancellationToken) => 21 | { 22 | var state = await (stepContext.Context.TurnState["BotAccessors"] as BotAccessors).BankingBotStateStateAccessor.GetAsync(stepContext.Context); 23 | state.Recipient = stepContext.Result.ToString(); 24 | 25 | return await stepContext.PromptAsync("numberPrompt", 26 | new PromptOptions 27 | { 28 | Prompt = stepContext.Context.Activity.CreateReply($"{state.Recipient}, got it{Environment.NewLine}How much should I pay?"), 29 | RetryPrompt = stepContext.Context.Activity.CreateReply("Sorry, please give me a number.") 30 | }); 31 | }); 32 | 33 | AddStep(async (stepContext, cancellationToken) => 34 | { 35 | var state = await (stepContext.Context.TurnState["BotAccessors"] as BotAccessors).BankingBotStateStateAccessor.GetAsync(stepContext.Context); 36 | state.Amount = int.Parse(stepContext.Result.ToString()); 37 | 38 | await stepContext.Context.SendActivityAsync($"Thank you, I've paid {state.Amount} to {state.Recipient} 💸"); 39 | return await stepContext.EndDialogAsync(); 40 | }); 41 | } 42 | 43 | public static string Id => "makePaymentDialog"; 44 | public static MakePaymentDialog Instance { get; } = new MakePaymentDialog(Id); 45 | } 46 | } -------------------------------------------------------------------------------- /demo7dialogs/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore; 2 | using Microsoft.AspNetCore.Hosting; 3 | 4 | namespace demo7dialogs 5 | { 6 | public class Program 7 | { 8 | public static void Main(string[] args) 9 | { 10 | BuildWebHost(args).Run(); 11 | } 12 | 13 | public static IWebHost BuildWebHost(string[] args) 14 | { 15 | return WebHost.CreateDefaultBuilder(args) 16 | .UseStartup() 17 | .Build(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /demo7dialogs/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:54433/", 7 | "sslPort": 44386 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "environmentVariables": { 14 | "ASPNETCORE_ENVIRONMENT": "Development" 15 | } 16 | }, 17 | "demo7dialogs": { 18 | "commandName": "Project", 19 | "launchBrowser": true, 20 | "environmentVariables": { 21 | "ASPNETCORE_ENVIRONMENT": "Development" 22 | }, 23 | "applicationUrl": "http://localhost:54434/" 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /demo7dialogs/Startup.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using demo7dialogs; 3 | using demo7dialogs.Bots; 4 | using Microsoft.AspNetCore.Builder; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Bot.Builder; 7 | using Microsoft.Bot.Builder.BotFramework; 8 | using Microsoft.Bot.Builder.Dialogs; 9 | using Microsoft.Bot.Builder.Integration; 10 | using Microsoft.Bot.Builder.Integration.AspNet.Core; 11 | using Microsoft.Extensions.Configuration; 12 | using Microsoft.Extensions.DependencyInjection; 13 | using Microsoft.Extensions.Options; 14 | 15 | public class Startup 16 | { 17 | // Inject the IHostingEnvironment into constructor 18 | public Startup(IHostingEnvironment env) 19 | { 20 | // Set the root path 21 | ContentRootPath = env.ContentRootPath; 22 | } 23 | 24 | // Track the root path so that it can be used to setup the app configuration 25 | public string ContentRootPath { get; } 26 | 27 | public void ConfigureServices(IServiceCollection services) 28 | { 29 | // Set up the service configuration 30 | var builder = new ConfigurationBuilder() 31 | .SetBasePath(ContentRootPath) 32 | .AddJsonFile("appsettings.json") 33 | .AddEnvironmentVariables(); 34 | var configuration = builder.Build(); 35 | services.AddSingleton(configuration); 36 | 37 | services.AddBot(options => 38 | { 39 | var conversationState = new ConversationState(new MemoryStorage()); 40 | options.State.Add(conversationState); 41 | 42 | options.CredentialProvider = new ConfigurationCredentialProvider(configuration); 43 | }); 44 | 45 | services.AddSingleton(serviceProvider => 46 | { 47 | var options = serviceProvider.GetRequiredService>().Value; 48 | var conversationState = options.State.OfType().FirstOrDefault(); 49 | 50 | var accessors = new BotAccessors(conversationState) 51 | { 52 | DialogStateAccessor = conversationState.CreateProperty(BotAccessors.DialogStateAccessorName), 53 | BankingBotStateStateAccessor = conversationState.CreateProperty(BotAccessors.BankingBotStateAccessorName) 54 | }; 55 | 56 | return accessors; 57 | }); 58 | } 59 | 60 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 61 | { 62 | app.UseStaticFiles(); 63 | 64 | // Tell your application to use Bot Framework 65 | app.UseBotFramework(); 66 | } 67 | } -------------------------------------------------------------------------------- /demo7dialogs/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /demo7dialogs/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "Debug": { 5 | "LogLevel": { 6 | "Default": "Warning" 7 | } 8 | }, 9 | "Console": { 10 | "LogLevel": { 11 | "Default": "Warning" 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /demo7dialogs/demo7dialogs.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /demo7dialogs/demo7dialogs.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | IIS Express 5 | 6 | -------------------------------------------------------------------------------- /demo7dialogs/demo7dialogs.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2000 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "demo7dialogs", "demo7dialogs.csproj", "{05EE03D7-100E-46AD-AF52-3889A534BF25}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {05EE03D7-100E-46AD-AF52-3889A534BF25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {05EE03D7-100E-46AD-AF52-3889A534BF25}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {05EE03D7-100E-46AD-AF52-3889A534BF25}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {05EE03D7-100E-46AD-AF52-3889A534BF25}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {E3ECCD8D-420D-4FF2-A581-850CB2527F6A} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /demo8statemiddleware/BotAccessors.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using demo8statemiddleware.Bots; 6 | using Microsoft.Bot.Builder; 7 | 8 | namespace demo8statemiddleware 9 | { 10 | public class BotAccessors 11 | { 12 | public BotAccessors(ConversationState conversationState) 13 | { 14 | ConversationState = conversationState ?? throw new ArgumentNullException(nameof(conversationState)); 15 | } 16 | 17 | public static string DemoStateName { get; } = $"{nameof(BotAccessors)}.DemoStateAccessor"; 18 | 19 | public IStatePropertyAccessor DemoStateAccessor { get; set; } 20 | public ConversationState ConversationState { get; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /demo8statemiddleware/Bots/DemoState.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace demo8statemiddleware.Bots 7 | { 8 | public class DemoState 9 | { 10 | public int Counter { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /demo8statemiddleware/Bots/StateBot.cs: -------------------------------------------------------------------------------- 1 | using System.Threading; 2 | using System.Threading.Tasks; 3 | using Microsoft.Bot.Builder; 4 | using Microsoft.Bot.Schema; 5 | 6 | namespace demo8statemiddleware.Bots 7 | { 8 | public class StateBot : IBot 9 | { 10 | public StateBot(BotAccessors botAccessors) 11 | { 12 | BotAccessors = botAccessors; 13 | } 14 | 15 | public BotAccessors BotAccessors { get; } 16 | 17 | public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken)) 18 | { 19 | if (turnContext.Activity.Type == ActivityTypes.Message) 20 | { 21 | var state = await BotAccessors.DemoStateAccessor.GetAsync(turnContext, () => new DemoState(), cancellationToken:cancellationToken); 22 | await turnContext.SendActivityAsync($"You said {turnContext.Activity.Text}, and you have made {++state.Counter} requests."); 23 | } 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /demo8statemiddleware/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace demo8statemiddleware 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /demo8statemiddleware/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:51414/", 7 | "sslPort": 44353 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "environmentVariables": { 14 | "ASPNETCORE_ENVIRONMENT": "Development" 15 | } 16 | }, 17 | "demo8statemiddleware": { 18 | "commandName": "Project", 19 | "launchBrowser": true, 20 | "environmentVariables": { 21 | "ASPNETCORE_ENVIRONMENT": "Development" 22 | }, 23 | "applicationUrl": "http://localhost:51415/" 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /demo8statemiddleware/Startup.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Linq; 3 | using demo8statemiddleware; 4 | using demo8statemiddleware.Bots; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Bot.Builder; 8 | using Microsoft.Bot.Builder.BotFramework; 9 | using Microsoft.Bot.Builder.Integration; 10 | using Microsoft.Bot.Builder.Integration.AspNet.Core; 11 | using Microsoft.Extensions.Configuration; 12 | using Microsoft.Extensions.DependencyInjection; 13 | using Microsoft.Extensions.Options; 14 | 15 | public class Startup 16 | { 17 | // Inject the IHostingEnvironment into constructor 18 | public Startup(IHostingEnvironment env) 19 | { 20 | // Set the root path 21 | ContentRootPath = env.ContentRootPath; 22 | } 23 | 24 | // Track the root path so that it can be used to setup the app configuration 25 | public string ContentRootPath { get; } 26 | 27 | public void ConfigureServices(IServiceCollection services) 28 | { 29 | // Set up the service configuration 30 | var builder = new ConfigurationBuilder() 31 | .SetBasePath(ContentRootPath) 32 | .AddJsonFile("appsettings.json") 33 | .AddEnvironmentVariables(); 34 | 35 | var configuration = builder.Build(); 36 | services.AddSingleton(configuration); 37 | 38 | // Add your SimpleBot to your application 39 | services.AddBot(options => 40 | { 41 | options.CredentialProvider = new ConfigurationCredentialProvider(configuration); 42 | var conversationState = new ConversationState(new MemoryStorage()); 43 | options.State.Add(conversationState); 44 | }); 45 | 46 | services.AddSingleton(serviceProvider => 47 | { 48 | var options = serviceProvider.GetRequiredService>().Value; 49 | var conversationState = options.State.OfType().FirstOrDefault(); 50 | 51 | var accessors = new BotAccessors(conversationState) 52 | { 53 | DemoStateAccessor = conversationState.CreateProperty(BotAccessors.DemoStateName), 54 | }; 55 | 56 | return accessors; 57 | }); 58 | } 59 | 60 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 61 | { 62 | app.UseStaticFiles(); 63 | 64 | // Tell your application to use Bot Framework 65 | app.UseBotFramework(); 66 | } 67 | } -------------------------------------------------------------------------------- /demo8statemiddleware/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /demo8statemiddleware/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "Debug": { 5 | "LogLevel": { 6 | "Default": "Warning" 7 | } 8 | }, 9 | "Console": { 10 | "LogLevel": { 11 | "Default": "Warning" 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /demo8statemiddleware/demo8statemiddleware.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /demo8statemiddleware/demo8statemiddleware.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | IIS Express 5 | 6 | -------------------------------------------------------------------------------- /demo8statemiddleware/demo8statemiddleware.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2000 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "demo8statemiddleware", "demo8statemiddleware.csproj", "{3519FD33-176B-49FC-AAA0-5714E0374562}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {3519FD33-176B-49FC-AAA0-5714E0374562}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {3519FD33-176B-49FC-AAA0-5714E0374562}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {3519FD33-176B-49FC-AAA0-5714E0374562}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {3519FD33-176B-49FC-AAA0-5714E0374562}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {1F031849-B8A2-420B-83CD-C784EC7CCDB4} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /demo9proactive/Bots/SimpleBot.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Hosting; 2 | using Microsoft.Bot.Builder; 3 | using Microsoft.Bot.Schema; 4 | using Newtonsoft.Json; 5 | using System; 6 | using System.IO; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | 10 | namespace demo9proactive.Bots 11 | { 12 | public class SimpleBot : IBot 13 | { 14 | private IHostingEnvironment hostingEnvironment; 15 | 16 | public SimpleBot(IHostingEnvironment hostingEnvironment) 17 | { 18 | this.hostingEnvironment = hostingEnvironment; 19 | } 20 | 21 | public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken)) 22 | { 23 | // turnContext.Responded will be false if qna doesn't know how to answer. An example is 'how do I install office 365'. 24 | if (!turnContext.Responded && turnContext.Activity.Type == ActivityTypes.Message) 25 | { 26 | var conversationReference = turnContext.Activity.GetConversationReference(); 27 | 28 | var filepath = Path.Combine(hostingEnvironment.WebRootPath, "resume.json"); 29 | File.WriteAllText(filepath, JsonConvert.SerializeObject(conversationReference)); 30 | 31 | await turnContext.SendActivityAsync($"Sorry, I don't know how to answer that automatically, we will get an answer to you ASAP and get back to you. Your reference number is {String.Format("{0:X}", conversationReference.ActivityId.GetHashCode())}"); 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /demo9proactive/CURL.txt: -------------------------------------------------------------------------------- 1 | curl -k -X POST -H 'Content-Type: application/json' --data '{ "Text" :"go to portal.office.com and log in as your user" }' https://localhost:44376/api/callback -------------------------------------------------------------------------------- /demo9proactive/Controllers/CallbackController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Net.Http; 6 | using System.IO; 7 | using System.Threading.Tasks; 8 | using Newtonsoft.Json; 9 | using Microsoft.Bot.Connector; 10 | using Microsoft.Bot.Schema; 11 | using Microsoft.AspNetCore.Hosting; 12 | 13 | namespace demo9proactive.Controllers 14 | { 15 | [Route("api/callback")] 16 | public class CallbackController : Controller 17 | { 18 | private IHostingEnvironment hostingEnvironment; 19 | 20 | public CallbackController(IHostingEnvironment hostingEnvironment) 21 | { 22 | this.hostingEnvironment = hostingEnvironment; 23 | } 24 | 25 | // This HTTP Endpoint simulates a long running Proactive callback. Use a HTTP client to simulate: 26 | // 27 | // POST http://localhost:3979/api/callback 28 | // Content-Type: application/json 29 | // 30 | // { "Text" :"this is a proactive message!" } 31 | // 32 | [HttpPost] 33 | public async Task Post([FromBody] ProactiveMessage message) 34 | { 35 | // For demonstration - read the cookie from disk. For a real application 36 | // read from your persistent store - e.g. blob storage, table storage, document db, etc 37 | 38 | var filepath = Path.Combine(hostingEnvironment.WebRootPath,"resume.json"); 39 | 40 | if (System.IO.File.Exists(filepath)) 41 | { 42 | var resumeJson = System.IO.File.ReadAllText(filepath); 43 | var resumeData = JsonConvert.DeserializeObject(resumeJson); 44 | var client = new ConnectorClient(new Uri(resumeData.ServiceUrl)); 45 | var message1 =resumeData.GetContinuationActivity().CreateReply($"This is a response to your enquiry reference {String.Format("{0:X}", resumeData.ActivityId.GetHashCode())}..."); 46 | var message2 = resumeData.GetContinuationActivity().CreateReply($"{message.Text}"); 47 | await client.Conversations.ReplyToActivityAsync((Activity)message1); 48 | await client.Conversations.ReplyToActivityAsync((Activity)message2); 49 | return new HttpResponseMessage(System.Net.HttpStatusCode.OK); 50 | } 51 | else 52 | { 53 | return new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); 54 | } 55 | } 56 | } 57 | 58 | public class ProactiveMessage 59 | { 60 | public string Text { get; set; } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /demo9proactive/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace demo9proactive.Controllers 8 | { 9 | [Route("api/[controller]")] 10 | public class ValuesController : Controller 11 | { 12 | // GET api/values 13 | [HttpGet] 14 | public IEnumerable Get() 15 | { 16 | return new string[] { "value1", "value2" }; 17 | } 18 | 19 | // GET api/values/5 20 | [HttpGet("{id}")] 21 | public string Get(int id) 22 | { 23 | return "value"; 24 | } 25 | 26 | // POST api/values 27 | [HttpPost] 28 | public void Post([FromBody]string value) 29 | { 30 | } 31 | 32 | // PUT api/values/5 33 | [HttpPut("{id}")] 34 | public void Put(int id, [FromBody]string value) 35 | { 36 | } 37 | 38 | // DELETE api/values/5 39 | [HttpDelete("{id}")] 40 | public void Delete(int id) 41 | { 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /demo9proactive/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace demo9proactive 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /demo9proactive/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:49840/", 7 | "sslPort": 44376 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "environmentVariables": { 14 | "ASPNETCORE_ENVIRONMENT": "Development" 15 | } 16 | }, 17 | "demo9proactive": { 18 | "commandName": "Project", 19 | "launchBrowser": true, 20 | "environmentVariables": { 21 | "ASPNETCORE_ENVIRONMENT": "Development" 22 | }, 23 | "applicationUrl": "http://localhost:49841/" 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /demo9proactive/Startup.cs: -------------------------------------------------------------------------------- 1 | using demo9proactive.Bots; 2 | using Microsoft.AspNetCore.Builder; 3 | using Microsoft.AspNetCore.Hosting; 4 | using Microsoft.Bot.Builder.BotFramework; 5 | using Microsoft.Bot.Builder.Integration.AspNet.Core; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.DependencyInjection; 8 | 9 | public class Startup 10 | { 11 | // Inject the IHostingEnvironment into constructor 12 | public Startup(IHostingEnvironment env) 13 | { 14 | // Set the root path 15 | ContentRootPath = env.ContentRootPath; 16 | } 17 | 18 | // Track the root path so that it can be used to setup the app configuration 19 | public string ContentRootPath { get; private set; } 20 | 21 | public void ConfigureServices(IServiceCollection services) 22 | { 23 | 24 | services.AddMvc(); 25 | 26 | // Set up the service configuration 27 | var builder = new ConfigurationBuilder() 28 | .SetBasePath(ContentRootPath) 29 | .AddJsonFile("appsettings.json") 30 | .AddEnvironmentVariables(); 31 | var configuration = builder.Build(); 32 | services.AddSingleton(configuration); 33 | 34 | // Add your SimpleBot to your application 35 | services.AddBot(options => 36 | { 37 | options.CredentialProvider = new ConfigurationCredentialProvider(configuration); 38 | }); 39 | } 40 | 41 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 42 | { 43 | app.UseStaticFiles(); 44 | app.UseMvcWithDefaultRoute(); 45 | // Tell your application to use Bot Framework 46 | app.UseBotFramework(); 47 | } 48 | } -------------------------------------------------------------------------------- /demo9proactive/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /demo9proactive/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "Debug": { 5 | "LogLevel": { 6 | "Default": "Warning" 7 | } 8 | }, 9 | "Console": { 10 | "LogLevel": { 11 | "Default": "Warning" 12 | } 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /demo9proactive/demo3qnamakermiddleware.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | IIS Express 5 | 6 | -------------------------------------------------------------------------------- /demo9proactive/demo9proactive.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /demo9proactive/demo9proactive.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.2000 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "demo9proactive", "demo9proactive.csproj", "{915FE6CD-F3FA-471B-BD87-B64C38449A4A}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{239E4C9B-ED8F-45A5-996C-9FBB7A8F9A0B}" 9 | ProjectSection(SolutionItems) = preProject 10 | CURL.txt = CURL.txt 11 | EndProjectSection 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Any CPU = Debug|Any CPU 16 | Release|Any CPU = Release|Any CPU 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {915FE6CD-F3FA-471B-BD87-B64C38449A4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 20 | {915FE6CD-F3FA-471B-BD87-B64C38449A4A}.Debug|Any CPU.Build.0 = Debug|Any CPU 21 | {915FE6CD-F3FA-471B-BD87-B64C38449A4A}.Release|Any CPU.ActiveCfg = Release|Any CPU 22 | {915FE6CD-F3FA-471B-BD87-B64C38449A4A}.Release|Any CPU.Build.0 = Release|Any CPU 23 | EndGlobalSection 24 | GlobalSection(SolutionProperties) = preSolution 25 | HideSolutionNode = FALSE 26 | EndGlobalSection 27 | GlobalSection(ExtensibilityGlobals) = postSolution 28 | SolutionGuid = {4EA84C13-43A5-4EEE-89C5-79E11384D98B} 29 | EndGlobalSection 30 | EndGlobal 31 | -------------------------------------------------------------------------------- /demo9proactive/wwwroot/resume.json: -------------------------------------------------------------------------------- 1 | {"activityId":"ebc21300-c3bd-11e8-ad0b-95faa5f899d5","user":{"id":"default-user","name":"User","role":null},"bot":{"id":"f665b350-c36a-11e8-b289-253eb9face34","name":"Bot","role":"bot"},"conversation":{"isGroup":null,"conversationType":null,"id":"ea79db90-c3bd-11e8-b289-253eb9face34|livechat","name":null,"role":null},"channelId":"emulator","serviceUrl":"http://localhost:51584"} --------------------------------------------------------------------------------