// This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            var storageOptions = new Microsoft.Bot.Builder.Azure.CosmosDbStorageOptions()
            {
                AuthKey          = Configuration["CosmosAuthKey"],
                CollectionId     = Configuration["CosmosDbCollection"],
                CosmosDBEndpoint = new Uri(Configuration["CosmosDbUrl"]),
                DatabaseId       = Configuration["CosmosDbDatabase"]
            };

            IStorage dataStore = new Microsoft.Bot.Builder.Azure.CosmosDbStorage(storageOptions);

            var userState = new UserState(dataStore);

            services.AddSingleton(userState);

            // Create the credential provider to be used with the Bot Framework Adapter.
            services.AddSingleton <ICredentialProvider, ConfigurationCredentialProvider>();

            // Create the Bot Framework Adapter.
            services.AddSingleton <IBotFrameworkHttpAdapter, BotFrameworkHttpAdapter>();

            // Create the bot as a transient. In this case the ASP Controller is expecting an IBot.
            services.AddTransient <IBot, EchoBot>();
        }
Пример #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddBot <TaskBot>(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("TaskBot 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();

                var uri = new Uri(@"https://taskbot-db.documents.azure.com:443/");

                IStorage dataStoreUsers =
                    new Microsoft.Bot.Builder.Azure.CosmosDbStorage(uri,
                                                                    "vLJnjjqAN4veC2zTo2VVhd2Uy7bYVPhQ4EqgNXjDO08XbL0aPr7yq443ekTB6eFRlXPtj2gh5Ev1NOvUlZU0aA=="
                                                                    , "TaskBotDB"
                                                                    , "users");

                IStorage dataStoreTasks =
                    new Microsoft.Bot.Builder.Azure.CosmosDbStorage(uri,
                                                                    "vLJnjjqAN4veC2zTo2VVhd2Uy7bYVPhQ4EqgNXjDO08XbL0aPr7yq443ekTB6eFRlXPtj2gh5Ev1NOvUlZU0aA=="
                                                                    , "TaskBotDB"
                                                                    , "tasks");


                // options.Middleware.Add(new UserState<CurrentUser>(dataStoreUserState));
                options.Middleware.Add(new ConversationState <Dictionary <string, object> >(dataStore));
                options.Middleware.Add(new UserState <Users>(dataStoreUsers));
                // options.Middleware.Add(new UserState<Tasks>(dataStoreTasks));
            });
        }