forked from matthidinger/ContosoScubaBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStartup.cs
95 lines (80 loc) · 4.39 KB
/
Startup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using ContosoScuba.Bot.Models;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Bot.Builder.BotFramework;
using Microsoft.Bot.Builder.Core.Extensions;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Razorback;
namespace ContosoScuba.Bot
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.Configure<Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions>(o =>
{
o.ViewLocationFormats.Clear();
o.ViewLocationFormats.Add("/CardViews/{0}" + Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.ViewExtension);
});
services.AddScoped<IRazorbackTemplateEngine, RazorbackTemplateEngine>();
services.AddBot<ContosoScubaBot>(options =>
{
options.CredentialProvider = new ConfigurationCredentialProvider(Configuration);
// The CatchExceptionMiddleware provides a top-level exception handler for your bot.
// Any exceptions thrown by other Middleware, or by your OnTurn method, will be
// caught here. To facillitate debugging, the exception is sent out, via Trace,
// to the emulator. Trace activities are NOT displayed to users, so in addition
// an "Ooops" message is sent.
options.Middleware.Add(new CatchExceptionMiddleware<Exception>(async (context, exception) =>
{
await context.TraceActivity("EchoBot Exception", exception);
await context.SendActivity("Sorry, it looks like something went wrong!");
}));
// The Memory Storage used here is for local bot debugging only. When the bot
// is restarted, anything stored in memory will be gone.
IStorage dataStore = new MemoryStorage();
// The File data store, shown here, is suitable for bots that run on
// a single machine and need durable state across application restarts.
// IStorage dataStore = new FileStorage(System.IO.Path.GetTempPath());
// For production bots use the Azure Table Store, Azure Blob, or
// Azure CosmosDB storage provides, as seen below. To include any of
// the Azure based storage providers, add the Microsoft.Bot.Builder.Azure
// Nuget package to your solution. That package is found at:
// https://www.nuget.org/packages/Microsoft.Bot.Builder.Azure/
// IStorage dataStore = new Microsoft.Bot.Builder.Azure.AzureTableStorage("AzureTablesConnectionString", "TableName");
// IStorage dataStore = new Microsoft.Bot.Builder.Azure.AzureBlobStorage("AzureBlobConnectionString", "containerName");
options.Middleware.Add(new ConversationState<UserScubaData>(dataStore));
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseDefaultFiles()
.UseStaticFiles()
.UseBotFramework();
}
}
}