예제 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddBot <TestBot>(options =>
            {
                IStorage dataStore = new MemoryStorage();
                options.State.Add(new ConversationState(dataStore));
                options.Middleware.Add(new AutoSaveStateMiddleware(options.State.ToArray()));
                options.Middleware.Add(new ShowTypingMiddleware());
            });

            services.AddSingleton(sp =>
            {
                var options = sp.GetRequiredService <IOptions <BotFrameworkOptions> >().Value;
                if (options == null)
                {
                    throw new InvalidOperationException("BotFrameworkOptions must be configured prior to setting up the State Accessors");
                }

                var conversationState = options.State.OfType <ConversationState>().FirstOrDefault();
                if (conversationState == null)
                {
                    throw new InvalidOperationException("ConversationState must be defined and added before adding conversation-scoped state accessors.");
                }

                var accessors = new TestBotAccessors
                {
                    ConversationDialogState = conversationState.CreateProperty <DialogState>("DialogState")
                };

                return(accessors);
            });
        }
예제 #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton <IAdapterIntegration>(sp =>
            {
                var options = sp.GetRequiredService <IOptions <BotFrameworkOptions> >().Value;

                IStorage dataStore = new MemoryStorage();
                options.State.Add(new ConversationState(dataStore));
                options.Middleware.Add(new AutoSaveStateMiddleware(options.State.ToArray()));
                options.Middleware.Add(new ShowTypingMiddleware());

                var botFrameworkAdapter = new BotFrameworkAdapter(options.CredentialProvider, options.ChannelProvider, options.ConnectorClientRetryPolicy, options.HttpClient)
                {
                    OnTurnError = options.OnTurnError,
                };

                foreach (var middleware in options.Middleware)
                {
                    botFrameworkAdapter.Use(middleware);
                }

                //return botFrameworkAdapter;

                return(new InteceptorAdapter(botFrameworkAdapter));
            });

            services.AddBot <TestBot>();

            //services.AddBot<TestBot>(options =>
            //{
            //    IStorage dataStore = new MemoryStorage();
            //    options.State.Add(new ConversationState(dataStore));
            //    options.Middleware.Add(new AutoSaveStateMiddleware(options.State.ToArray()));
            //    options.Middleware.Add(new ShowTypingMiddleware());
            //});

            services.AddSingleton(sp =>
            {
                var options = sp.GetRequiredService <IOptions <BotFrameworkOptions> >().Value;
                if (options == null)
                {
                    throw new InvalidOperationException("BotFrameworkOptions must be configured prior to setting up the State Accessors");
                }

                var conversationState = options.State.OfType <ConversationState>().FirstOrDefault();
                if (conversationState == null)
                {
                    throw new InvalidOperationException("ConversationState must be defined and added before adding conversation-scoped state accessors.");
                }

                var accessors = new TestBotAccessors
                {
                    ConversationDialogState = conversationState.CreateProperty <DialogState>("DialogState")
                };

                return(accessors);
            });
        }
예제 #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //services.AddSingleton<IAdapterIntegration>(sp =>
            //{
            //    var options = sp.GetRequiredService<IOptions<BotFrameworkOptions>>().Value;
            //    var accessors = sp.GetRequiredService<TestBotAccessors>();

            //    options.Middleware.Add(new AutoSaveStateMiddleware(accessors.ConversationState));
            //    options.Middleware.Add(new ShowTypingMiddleware());

            //    var botFrameworkAdapter = new BotFrameworkAdapter(options.CredentialProvider, options.ChannelProvider, options.ConnectorClientRetryPolicy, options.HttpClient)
            //    {
            //        OnTurnError = options.OnTurnError,
            //    };

            //    foreach (var middleware in options.Middleware)
            //    {
            //        botFrameworkAdapter.Use(middleware);
            //    }

            //    //return botFrameworkAdapter;

            //    return new InteceptorAdapter(botFrameworkAdapter);
            //});

            IStorage dataStore         = new MemoryStorage();
            var      conversationState = new ConversationState(dataStore);

            var accessors = new TestBotAccessors
            {
                ConversationDialogState = conversationState.CreateProperty <DialogState>("DialogState"),
                ConversationState       = conversationState
            };

            services.AddBot <IBot>(
                (IServiceProvider sp) =>
            {
                return(new TestBot(accessors));
            },
                (BotFrameworkOptions options) =>
            {
                options.OnTurnError = async(turnContext, exception) =>
                {
                    await conversationState.ClearStateAsync(turnContext);
                    await conversationState.SaveChangesAsync(turnContext);
                };
                options.Middleware.Add(new AutoSaveStateMiddleware(conversationState));
            });

            //services.AddBot<TestBot>(options =>
            //{
            //    IStorage dataStore = new MemoryStorage();
            //    options.State.Add(new ConversationState(dataStore));
            //    options.Middleware.Add(new AutoSaveStateMiddleware(options.State.ToArray()));
            //    options.Middleware.Add(new ShowTypingMiddleware());
            //});
        }
예제 #4
0
        public TestBot(TestBotAccessors accessors)
        {
            // create the DialogSet from accessor
            _dialogs = new DialogSet(accessors.ConversationDialogState);

            // a semaphore to serialize access to the bot state
            _semaphore = accessors.SemaphoreSlim;

            // add the various named dialogs that can be used
            _dialogs.Add(CreateWaterfall());
            _dialogs.Add(new NumberPrompt <int>("number", defaultLocale: Culture.English));
        }
예제 #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton(sp =>
            {
                IStorage dataStore = new MemoryStorage();

                var conversationState = new ConversationState(dataStore);

                var accessors = new TestBotAccessors
                {
                    ConversationDialogState = conversationState.CreateProperty <DialogState>("DialogState"),
                    ConversationState       = new ConversationState(dataStore)
                };

                return(accessors);
            });

            services.AddSingleton <IAdapterIntegration>(sp =>
            {
                var options   = sp.GetRequiredService <IOptions <BotFrameworkOptions> >().Value;
                var accessors = sp.GetRequiredService <TestBotAccessors>();

                options.Middleware.Add(new AutoSaveStateMiddleware(accessors.ConversationState));
                options.Middleware.Add(new ShowTypingMiddleware());

                var botFrameworkAdapter = new BotFrameworkAdapter(options.CredentialProvider, options.ChannelProvider, options.ConnectorClientRetryPolicy, options.HttpClient)
                {
                    OnTurnError = options.OnTurnError,
                };

                foreach (var middleware in options.Middleware)
                {
                    botFrameworkAdapter.Use(middleware);
                }

                //return botFrameworkAdapter;

                return(new InteceptorAdapter(botFrameworkAdapter));
            });

            services.AddBot <TestBot>();

            //services.AddBot<TestBot>(options =>
            //{
            //    IStorage dataStore = new MemoryStorage();
            //    options.State.Add(new ConversationState(dataStore));
            //    options.Middleware.Add(new AutoSaveStateMiddleware(options.State.ToArray()));
            //    options.Middleware.Add(new ShowTypingMiddleware());
            //});
        }
예제 #6
0
 public TestBot(TestBotAccessors accessors)
 {
     _accessors = accessors;
 }