public AirBotBot(AirBotAccessors accessors) { _accessors = accessors; _dialogs = new DialogSet(accessors.ConversationDialogState); var waterfallSteps = new WaterfallStep[] { FromStepAsync, ToStepAsync, HowManyPeopleStepAsync, SummaryStepAsync }; _dialogs.Add(new WaterfallDialog("booking", waterfallSteps)); _dialogs.Add(new TextPrompt("from")); _dialogs.Add(new TextPrompt("to")); _dialogs.Add(new NumberPrompt <int>("howmany")); _dialogs.Add(new ConfirmPrompt("confirm")); }
/// <summary> /// This method gets called by the runtime. Use this method to add services to the container. /// </summary> /// <param name="services">The <see cref="IServiceCollection"/> specifies the contract for a collection of service descriptors.</param> /// <seealso cref="IStatePropertyAccessor{T}"/> /// <seealso cref="https://docs.microsoft.com/en-us/aspnet/web-api/overview/advanced/dependency-injection"/> /// <seealso cref="https://docs.microsoft.com/en-us/azure/bot-service/bot-service-manage-channels?view=azure-bot-service-4.0"/> public void ConfigureServices(IServiceCollection services) { services.AddBot <AirBotBot>(options => { var secretKey = Configuration.GetSection("botFileSecret")?.Value; // Loads .bot configuration file and adds a singleton that your Bot can access through dependency injection. var botConfig = BotConfiguration.Load(@".\AirBot.bot", secretKey); services.AddSingleton(sp => botConfig); // Retrieve current endpoint. var service = botConfig.Services.Where(s => s.Type == "endpoint" && s.Name == "development").FirstOrDefault(); if (!(service is EndpointService endpointService)) { throw new InvalidOperationException($"The .bot file does not contain a development endpoint."); } options.CredentialProvider = new SimpleCredentialProvider(endpointService.AppId, endpointService.AppPassword); // Catches any errors that occur during a conversation turn and logs them. options.OnTurnError = async(context, exception) => { await context.SendActivityAsync("Sorry, it looks like something went wrong."); }; IStorage dataStore = new MemoryStorage(); ConversationState conversationState = new ConversationState(dataStore); options.State.Add(conversationState); UserState userState = new UserState(dataStore); options.State.Add(userState); }); services.AddSingleton <AirBotAccessors>(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("ConverState must be defined and added before adding user-scoped 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 AirBotAccessors(conversationState, userState) { ConversationDialogState = conversationState.CreateProperty <DialogState>("DialogState"), WelcomeUserState = userState.CreateProperty <WelcomeUserState>(AirBotAccessors.WelcomeUserName), UserProfile = userState.CreateProperty <UserProfile>("UserProfile") }; return(accessors); }); }