// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers().AddNewtonsoftJson(); // Create the Bot Framework Adapter with error handling enabled. services.AddSingleton <IBotFrameworkHttpAdapter, AdapterWithErrorHandler>(); // Create the bot as a transient. In this case the ASP Controller is expecting an IBot. services.AddTransient <IBot, Bots.UAPTCBot>(); services.AddSingleton <UAPTCBotAccessors>(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(); IStorage dataStore = new MemoryStorage(); var conversationState = new ConversationState(dataStore); if (conversationState == null) { throw new InvalidOperationException("ConversationState must be defined and added before adding conversation-scoped state accessors."); } var userState = new UserState(dataStore); 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 UAPTCBotAccessors(conversationState, userState) { ConversationDataAccessor = conversationState.CreateProperty <ConversationData>(UAPTCBotAccessors.ConversationDataName), ConversationDialogState = conversationState.CreateProperty <DialogState>("DialogState"), UserProfileAccessor = userState.CreateProperty <UserProfile>(UAPTCBotAccessors.UserProfileName), }; return(accessors); }); }
public UAPTCBot(UAPTCBotAccessors accessors) { // Set the _accessors _accessors = accessors ?? throw new System.ArgumentNullException(nameof(accessors)); // The DialogSet needs a DialogState accessor, it will call it when it has a turn context. _dialogs = new DialogSet(accessors.ConversationDialogState); // This array defines how the Waterfall will execute. var waterfallSteps = new WaterfallStep[] { NameStepAsync, NameConfirmStepAsync, }; // Add named dialogs to the DialogSet. These names are saved in the dialog state. _dialogs.Add(new WaterfallDialog(CovidDetailsID, waterfallSteps)); _dialogs.Add(new ChoicePrompt(CovidDialogID)); }