public static void ConfigureConversationStateAccessors(this IServiceCollection services) { // Create and register state accessors. // Accessors created here are passed into the IBot-derived class on every turn. services.AddSingleton <SysforeAIBotAccessors>(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."); //} IStorage storage = new MemoryStorage(); ConversationState conversationState = new ConversationState(storage); UserState userState = new UserState(storage); // Create the custom state accessor. // State accessors enable other components to read and write individual properties of state. var accessors = new SysforeAIBotAccessors(conversationState, userState) { ConversationFlowAccessor = conversationState.CreateProperty <ConversationFlow>(SysforeAIBotAccessors.ConversationFlowName), UserProfileAccessor = userState.CreateProperty <UserProfile>(SysforeAIBotAccessors.UserProfileName), Node = conversationState.CreateProperty <DialogFlow>(SysforeAIBotAccessors.NodeName), IsInDialogFlow = conversationState.CreateProperty <bool>(SysforeAIBotAccessors.IsInDialogFlowName) }; return(accessors); }); }
/// <summary> /// Initializes a new instance of the <see cref="NlpDispatchBot"/> class. /// </summary> /// <param name="services">Services configured from the ".bot" file.</param> public SysforeAIBotBot(IOptionsSnapshot <AppSettings> appSettings, IOptionsSnapshot <DialogFlow> dialogFlow, SysforeAIBotAccessors accessors) { _accessors = accessors ?? throw new System.ArgumentNullException(nameof(accessors)); _appSettings = appSettings.Value; _dialogFlow = dialogFlow.Value; _services = BotServiceHelper.InitBotServices(_appSettings); }