Beispiel #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            IStorage dataStore         = new MemoryStorage();
            var      conversationState = new ConversationState(dataStore);
            var      userState         = new UserState(dataStore);
            var      userStateMap      = userState.CreateProperty <StateMap>("user");

            // Get Bot file
            string rootDialog = string.Empty;
            var    botFile    = Configuration.GetSection("bot").Get <BotFile>();
            var    botProject = BotProject.Load(botFile);

            rootDialog = botProject.entry;

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

            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));
            });
        }
Beispiel #2
0
 public static BotProject Load(BotFile file)
 {
     return(BotProject.LoadAsync(file).GetAwaiter().GetResult());
 }