public MultiDialogWithAccessorBot(DialogBotConversationStateAndUserStateAccessor accessor, BotServices services)
        {
            _dialogBotConversationStateAndUserStateAccessor = accessor ?? throw new ArgumentNullException(nameof(accessor));
            _dialogSet = new DialogSet(_dialogBotConversationStateAndUserStateAccessor.ConversationDialogState);
            _dialogSet.Add(RootWaterfallDialog.BotInstance);

            _dialogSet.Add(new TextPrompt("name"));
            _dialogSet.Add(new TextPrompt("colorName"));
            _dialogSet.Add(new TextPrompt("foodName"));
            _dialogSet.Add(new TextPrompt("thirdWaterName"));

            _dialogSet.Add(FoodWaterfallDialog.BotInstance);
            _dialogSet.Add(ColorWaterfallDialog.BotInstance);
            _dialogSet.Add(NameWaterfallDialog.BotInstance);

            _dialogSet.Add(new ChoicePrompt("dialogChoice"));
            _dialogSet.Add(ThirdWaterfallDialog.BotInstance);

            _dialogSet.Add(new ChoicePrompt("confirmHero1"));
            //_dialogSet.Add(new ConfirmPrompt("confirmHero1"));

            DialogBotConversationStateAndUserStateAccessor = accessor;

            _services = services ?? throw new System.ArgumentNullException(nameof(services));
            if (!_services.QnAServices.ContainsKey(QnAMakerKey))
            {
                throw new System.ArgumentException($"Invalid configuration. Please check your '.bot' file for a QnA service named '{QnAMakerKey}'.");
            }
        }
        public MultiDialogWithAccessorBot(DialogBotConversationStateAndUserStateAccessor accessor, BotServices services)
        {
            _dialogBotConversationStateAndUserStateAccessor = accessor ?? throw new ArgumentNullException(nameof(accessor));
            _dialogSet = new DialogSet(_dialogBotConversationStateAndUserStateAccessor.ConversationDialogState);
            _dialogSet.Add(RootWaterfallDialog.BotInstance);

            _dialogSet.Add(LocationWaterfallDialog.BotInstance);
            _dialogSet.Add(new TextPrompt("dialogLocationCollection", LocationWaterfallDialog.ValidateLocationAsync));
            _dialogSet.Add(new TextPrompt("dialogIntentCollection"));
            _dialogSet.Add(new TextPrompt("dialogPhoneCollection"));
            _dialogSet.Add(new ChoicePrompt("dialogPhoneSelection"));

            _dialogSet.Add(new ChoicePrompt("dialogChoice"));

            DialogBotConversationStateAndUserStateAccessor = accessor;

            _services = services ?? throw new System.ArgumentNullException(nameof(services));
            if (!_services.QnAServices.ContainsKey(QnAMakerKey))
            {
                throw new System.ArgumentException($"Invalid configuration. Please check your '.bot' file for a QnA service named '{QnAMakerKey}'.");
            }

            if (!_services.LuisServices.ContainsKey(LuisKey))
            {
                throw new ArgumentException($"Invalid Configuration.  Please check your .bot file for a Luis service named '{LuisKey}'.");
            }
        }
 public DuelingDialogsBot(DialogBotConversationStateAndUserStateAccessor accessor)
 {
     _dialogBotConversationStateAndUserStateAccessor = accessor ?? throw new ArgumentNullException(nameof(accessor));
     _dialogSet = new DialogSet(_dialogBotConversationStateAndUserStateAccessor.ConversationDialogState);
     _dialogSet.Add(RootWaterfallDialog.BotInstance);
     _dialogSet.Add(new TextPrompt("name"));
     _dialogSet.Add(new TextPrompt("colorName"));
     _dialogSet.Add(new TextPrompt("foodName"));
     _dialogSet.Add(FoodWaterfallDialog.BotInstance);
     _dialogSet.Add(ColorWaterfallDialog.BotInstance);
     _dialogSet.Add(new ChoicePrompt("dialogChoice"));
 }
        public WaterfallDialogWithHardcodedCases(DialogBotConversationStateAndUserStateAccessor accessor)
        {
            _dialogBotConversationStateAndUserStateAccessor = accessor ?? throw new ArgumentNullException(nameof(accessor));
            _dialogSet = new DialogSet(_dialogBotConversationStateAndUserStateAccessor.ConversationDialogState);


            // This array defines how the Waterfall will execute.
            var waterfallSteps = new WaterfallStep[]
            {
                FirstStepAsync,
                NameStepAsync,
                NameConfirmStepAsync,
                AgeStepAsync,
                ConfirmStepAsync,
                SummaryStepAsync,
            };

            _dialogSet.Add(new WaterfallDialog("details", waterfallSteps));
            _dialogSet.Add(new TextPrompt("name"));
            _dialogSet.Add(new NumberPrompt <int>("age"));
            _dialogSet.Add(new ConfirmPrompt("confirm"));
        }
Exemplo n.º 5
0
        public void ConfigureServices(IServiceCollection services)
        {
            var secretKey   = Configuration.GetSection("botFileSecret")?.Value;
            var botFilePath = Configuration.GetSection("botFilePath")?.Value;

            // Loads .bot configuration file and adds a singleton that your Bot can access through dependency injection.
            var botConfig = BotConfiguration.Load(botFilePath ?? @".\BotConfiguration.bot", secretKey);

            //#QNA
            // Initialize Bot Connected Services clients.
            var connectedServices = InitBotServices(botConfig);

            services.AddSingleton(sp => connectedServices);

            services.AddBot <MultiDialogWithAccessorBot>(options =>
            {
                //MOVED ABOVE
                //var secretKey = Configuration.GetSection("botFileSecret")?.Value;
                //var botFilePath = Configuration.GetSection("botFilePath")?.Value;

                //// Loads .bot configuration file and adds a singleton that your Bot can access through dependency injection.
                //var botConfig = BotConfiguration.Load(botFilePath ?? @".\BotConfiguration.bot", secretKey);



                ////#QNA
                //// Initialize Bot Connected Services clients.
                //var connectedServices = InitBotServices(botConfig);
                //services.AddSingleton(sp => connectedServices);
                //#QNA
                //MOVED ABOVE

                services.AddSingleton(sp => botConfig ?? throw new InvalidOperationException($"The .bot config file could not be loaded. ({botConfig})"));

                // Retrieve current endpoint.
                var environment = _isProduction ? "production" : "development";
                var service     = botConfig.Services.Where(s => s.Type == "endpoint" && s.Name == environment).FirstOrDefault();
                if (!(service is EndpointService endpointService))
                {
                    throw new InvalidOperationException($"The .bot file does not contain an endpoint with name '{environment}'.");
                }
                options.CredentialProvider = new SimpleCredentialProvider(endpointService.AppId, endpointService.AppPassword);

                IStorage dataStore = new MemoryStorage();

                var conversationState = new ConversationState(dataStore);
                options.State.Add(conversationState);

                // Create and add user state.
                var userState = new UserState(dataStore);
                options.State.Add(userState);

                //SETUP ACCORDING TO MULTI-LINGUAL BOT FROM OFFICIAL SAMPLE
                //TO SEE MORE OF HOW IT'S USED TAKE A LOOK AT THE OFFICIAL SAMPLES HERE:
                //https://github.com/Microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore
                // Look for the sample Multilingual

                var middleware3WithParameters = new SimplifiedEchoBotMiddleware3(userState.CreateProperty <string>("LanguagePreference"));

                options.Middleware.Add(new SimplifiedEchoBotMiddleware1());
                options.Middleware.Add(new SimplifiedEchoBotMiddleware2());
                options.Middleware.Add(middleware3WithParameters);
            });

            services.AddSingleton(sp =>
            {
                // We need to grab the conversationState we added on the options in the previous step.
                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.");
                }

                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.");
                }

                // The dialogs will need a state store accessor. Creating it here once (on-demand) allows the dependency injection
                // to hand it to our IBot class that is create per-request.
                var accessors = new DialogBotConversationStateAndUserStateAccessor(conversationState, userState)
                {
                    ConversationDialogState = conversationState.CreateProperty <DialogState>("DialogState"),
                    TheUserProfile          = userState.CreateProperty <UserProfile>("UserProfile"),
                    WelcomeUserState        = userState.CreateProperty <WelcomeUserState>(DialogBotConversationStateAndUserStateAccessor.WelcomeUserName),
                    LanguagePreference      = userState.CreateProperty <string>("LanguagePreference"),
                };
                return(accessors);
            });
        }
Exemplo n.º 6
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddBot <DuelingDialogsBot>(options =>
            {
                var secretKey   = Configuration.GetSection("botFileSecret")?.Value;
                var botFilePath = Configuration.GetSection("botFilePath")?.Value;

                // Loads .bot configuration file and adds a singleton that your Bot can access through dependency injection.
                var botConfig = BotConfiguration.Load(botFilePath ?? @".\BotConfiguration.bot", secretKey);
                services.AddSingleton(sp => botConfig ?? throw new InvalidOperationException($"The .bot config file could not be loaded. ({botConfig})"));

                // Retrieve current endpoint.
                var environment = _isProduction ? "production" : "development";
                var service     = botConfig.Services.Where(s => s.Type == "endpoint" && s.Name == environment).FirstOrDefault();
                if (!(service is EndpointService endpointService))
                {
                    throw new InvalidOperationException($"The .bot file does not contain an endpoint with name '{environment}'.");
                }
                options.CredentialProvider = new SimpleCredentialProvider(endpointService.AppId, endpointService.AppPassword);



                IStorage dataStore = new MemoryStorage();

                var conversationState = new ConversationState(dataStore);
                options.State.Add(conversationState);

                // Create and add user state.
                var userState = new UserState(dataStore);
                options.State.Add(userState);

                options.Middleware.Add(new SimplifiedEchoBotMiddleware1());
                options.Middleware.Add(new SimplifiedEchoBotMiddleware2());
                options.Middleware.Add(new SimplifiedEchoBotMiddleware3());
            });

            services.AddSingleton(sp =>
            {
                // We need to grab the conversationState we added on the options in the previous step.
                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.");
                }

                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.");
                }

                // The dialogs will need a state store accessor. Creating it here once (on-demand) allows the dependency injection
                // to hand it to our IBot class that is create per-request.
                var accessors = new DialogBotConversationStateAndUserStateAccessor(conversationState, userState)
                {
                    ConversationDialogState = conversationState.CreateProperty <DialogState>("DialogState"),
                    TheUserProfile          = userState.CreateProperty <UserProfile>("UserProfile"),
                    WelcomeUserState        = userState.CreateProperty <WelcomeUserState>(DialogBotConversationStateAndUserStateAccessor.WelcomeUserName),
                };
                return(accessors);
            });
        }
 public WelcomeMessageWithAccessorBot(DialogBotConversationStateAndUserStateAccessor accessor)
 {
     _dialogBotConversationStateAndUserStateAccessor = accessor ?? throw new ArgumentNullException(nameof(accessor));
     _dialogSet = new DialogSet(_dialogBotConversationStateAndUserStateAccessor.ConversationDialogState);
     _dialogSet.Add(new TextPrompt("name"));
 }