public NASABot(WelcomeUserStateAccessors statePropertyAccessor, MultiTurnPromptsAccessor promptsAccessor, IDialogConfigurationService dialogConfigurationService) { _welcomeUserStateAccessors = statePropertyAccessor ?? throw new ArgumentNullException("state accessor can't be null"); _promptsAccessor = promptsAccessor ?? throw new ArgumentNullException("prompts accessor cannot be null"); _dialogs = new DialogSet(_promptsAccessor.ConversationDialogState); dialogConfigurationService.SetDialogConfiguration(_dialogs); }
// 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 void ConfigureServices(IServiceCollection services) { services.AddSingleton(configuration); services.AddBot <NASABot>(options => { options.CredentialProvider = new ConfigurationCredentialProvider(configuration); IStorage dataStorage = new MemoryStorage(null); var userState = new UserState(dataStorage); options.State.Add(userState); var conversationState = new ConversationState(dataStorage); options.State.Add(conversationState); }); // Create and register state accesssors. // Acessors created here are passed into the IBot-derived class on every turn. 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 userState = options.State.OfType <UserState>().FirstOrDefault(); if (userState == null) { throw new InvalidOperationException("UserState must be defined and added before adding user-scoped state accessors."); } // Create the custom state accessor. // State accessors enable other components to read and write individual properties of state. var accessors = new WelcomeUserStateAccessors(userState) { DidBotWelcomeUser = userState.CreateProperty <bool>("DidBotWelcomeState"), UserProfile = userState.CreateProperty <string>("UserProfile"), UserData = userState.CreateProperty <IList <MarsRoverPhoto> >("UserData") }; return(accessors); }); services.AddSingleton(q => { var options = q.GetRequiredService <IOptions <BotFrameworkOptions> >().Value; var conversationState = options.State.OfType <ConversationState>().FirstOrDefault(); if (conversationState == null) { throw new InvalidOperationException("Conversation State must be defined"); } var conversationAccessor = new MultiTurnPromptsAccessor(conversationState) { ConversationDialogState = conversationState.CreateProperty <DialogState>("DialogState") }; return(conversationAccessor); }); services.AddSingleton <IDataService, DataService>(); services.AddSingleton <IDialogConfigurationService, DialogConfigurationService>(); }