public PictureBot(PictureBotAccessors accessors, LuisRecognizer recognizer, TextAnalyticsClient analyticsClient) { _recognizer = recognizer ?? throw new ArgumentNullException(nameof(recognizer)); _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.DialogStateAccessor); // This array defines how the Waterfall will execute. // We can define the different dialogs and their steps here // allowing for overlap as needed. In this case, it's fairly simple // but in more complex scenarios, you may want to separate out the different // dialogs into different files. var main_waterfallsteps = new WaterfallStep[] { GreetingAsync, MainMenuAsync, }; var search_waterfallsteps = new WaterfallStep[] { // Add SearchDialog water fall steps }; // Add named dialogs to the DialogSet. These names are saved in the dialog state. _dialogs.Add(new WaterfallDialog("mainDialog", main_waterfallsteps)); _dialogs.Add(new WaterfallDialog("searchDialog", search_waterfallsteps)); // The following line allows us to use a prompt within the dialogs _dialogs.Add(new TextPrompt("searchPrompt")); _textAnalyticsClient = analyticsClient; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); // Create the Bot Framework Adapter. services.AddSingleton <IBotFrameworkHttpAdapter, AdapterWithErrorHandler>(); // Create the bot as a transient. In this case the ASP Controller is expecting an IBot. services.AddTransient <IBot, PictureBot>(); //init bot services.AddBot <PictureBot>(options => { //read appsettings.json var secretKey = Configuration.GetSection("MicrosoftAppId")?.Value; var botFilePath = Configuration.GetSection("MicrosoftAppPassword")?.Value; options.CredentialProvider = new SimpleCredentialProvider(secretKey, botFilePath); }); services.AddSingleton <PictureBotAccessors>(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"); } //read Cosmos DB settings from appsettings.json CosmosDbStorage _myStorage = new CosmosDbStorage(new CosmosDbStorageOptions { AuthKey = Configuration.GetSection("CosmosDB").GetValue <string>("Key"), CollectionId = Configuration.GetSection("CosmosDB").GetValue <string>("CollectionName"), CosmosDBEndpoint = new Uri(Configuration.GetSection("CosmosDB").GetValue <string>("EndpointURI")), DatabaseId = Configuration.GetSection("CosmosDB").GetValue <string>("DatabaseName"), }); var conversationState = new ConversationState(_myStorage); var userState = new UserState(_myStorage); // Create the custom state accessor. // State accessors enable other components to read and write individual properties of state. var accessors = new PictureBotAccessors(conversationState, userState) { PictureState = conversationState.CreateProperty <PictureState>(PictureBotAccessors.PictureStateName), DialogStateAccessor = conversationState.CreateProperty <DialogState>("DialogState"), }; return(accessors); }); }
public PictureBot(PictureBotAccessors accessors, ILoggerFactory loggerFactory, LuisRecognizer recognizer, TextAnalyticsClient textAnalyticsClient) { _logger = loggerFactory.CreateLogger <PictureBot>(); _logger.LogTrace("PictureBot turn start."); // The DialogSet needs a DialogState accessor, it will call it when it has a turn context. _recognizer = recognizer; _textAnalyticsClient = textAnalyticsClient; _accessors = accessors; _dialogs = new DialogSet(_accessors.DialogStateAccessor); // This array defines how the Waterfall will execute. // We can define the different dialogs and their steps here // allowing for overlap as needed. In this case, it's fairly simple // but in more complex scenarios, you may want to separate out the different // dialogs into different files. var main_waterfallsteps = new WaterfallStep[] { GreetingAsync, MainMenuAsync, }; var search_waterfallsteps = new WaterfallStep[] { // Add SearchDialog water fall steps }; // Add named dialogs to the DialogSet. These names are saved in the dialog state. _dialogs.Add(new WaterfallDialog("mainDialog", main_waterfallsteps)); _dialogs.Add(new WaterfallDialog("searchDialog", search_waterfallsteps)); // The following line allows us to use a prompt within the dialogs _dialogs.Add(new TextPrompt("searchPrompt")); // Add MainDialog-related tasks // Add SearchDialog-related tasks // Add search related tasks }
public PictureBot(PictureBotAccessors accessors, ILoggerFactory loggerFactory /*, LuisRecognizer recognizer*/) { if (loggerFactory == null) { throw new System.ArgumentNullException(nameof(loggerFactory)); } // Add instance of LUIS Recognizer _logger = loggerFactory.CreateLogger <PictureBot>(); _logger.LogTrace("PictureBot turn start."); _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.DialogStateAccessor); // This array defines how the Waterfall will execute. // We can define the different dialogs and their steps here // allowing for overlap as needed. In this case, it's fairly simple // but in more complex scenarios, you may want to separate out the different // dialogs into different files. var main_waterfallsteps = new WaterfallStep[] { GreetingAsync, MainMenuAsync, }; var search_waterfallsteps = new WaterfallStep[] { // Add SearchDialog water fall steps }; // Add named dialogs to the DialogSet. These names are saved in the dialog state. _dialogs.Add(new WaterfallDialog("mainDialog", main_waterfallsteps)); _dialogs.Add(new WaterfallDialog("searchDialog", search_waterfallsteps)); // The following line allows us to use a prompt within the dialogs _dialogs.Add(new TextPrompt("searchPrompt")); }