Beispiel #1
0
        /// <summary>
        /// Execution for the <see cref="GetWeatherForecastDialog"/> starts here.
        /// </summary>
        /// <param name="context">Mandatory. The context for the execution of a dialog's conversational process.</param>
        public async Task StartAsync(IDialogContext context)
        {
            string cityName    = _messageHelpers.ExtractEntityFromMessage("City.Name", _entities);
            string countryCode = _messageHelpers.ExtractEntityFromMessage("City.CountryCode", _entities, TextCaseType.UpperCase);
            string countryName = _messageHelpers.ExtractEntityFromMessage("City.CountryName", _entities);

            City preferredCity = _botDataService.GetPreferredWeatherLocation(context);

            if (string.IsNullOrEmpty(cityName))
            {
                if (preferredCity?.Name == null)
                {
                    PromptDialog.Text(context, ResumeAfterSpecifyCityNamePrompt, "What's the name of the city you want the forecast for?",
                                      "I can't understand you. Tell me the name of the city you want the forecast for");
                }
                else
                {
                    var weatherForecast = await _weatherService.GetWeather(preferredCity);

                    context.Done(weatherForecast != null
                            ? $"Currently the weather in {preferredCity.Name} is {weatherForecast}"
                            : "🤧⛅ - I'm having trouble accessing weather reports. We'll have to try again later!");
                }
            }
            else
            {
                IList <City> citySearchResults = await _weatherService.SearchForCities(cityName, countryCode, countryName);
                await ResumeAfterCitySearch(context, cityName, citySearchResults);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Execution for the <see cref="NameDialog"/> starts here.
        /// </summary>
        /// <param name="context">Mandatory. The context for the execution of a dialog's conversational process.</param>
        public Task StartAsync(IDialogContext context)
        {
            if (_entities != null)
            {
                _preferredName = _messageHelpers.ExtractEntityFromMessage("User.PreferredName", _entities);
            }

            string name = _botDataService.GetPreferredName(context);

            if (!string.IsNullOrWhiteSpace(_preferredName))
            {
                PromptDialog.Confirm(context, ResumeAfterPreferredNameConfirmation,
                                     $"So you'd like me to call you {_preferredName}?", $"Sorry I don't understand - try again! Should I call you {_preferredName}?");
                return(Task.CompletedTask);
            }

            if (!string.IsNullOrWhiteSpace(name))
            {
                PromptDialog.Confirm(context, ResumeAfterConfirmation,
                                     $"Do you want me to keep calling you {name}?", $"Sorry I don't understand - try again! Should I call you {name}?");
                return(Task.CompletedTask);
            }

            PromptDialog.Text(context, ResumeAfterNameFilled,
                              "What is your name?", "Sorry I didn't get that - try again! What should I call you?");
            return(Task.CompletedTask);
        }
        /// <summary>
        /// Execution for the <see cref="DeleteUserDataDialog"/> starts here.
        /// </summary>
        /// <param name="context">Mandatory. The context for the execution of a dialog's conversational process.</param>
        public Task StartAsync(IDialogContext context)
        {
            string command = _messageHelpers.ExtractEntityFromMessage("Bot.Command", _entities) ?? string.Empty;

            if (command.Replace(" ", string.Empty) == "--Quick")
            {
                _botDataService.DeleteUserData(context);

                context.Done("Buddy restored to factory defaults.");
                return(Task.CompletedTask);
            }


            PromptDialog.Confirm(context, ResumeAfterConfirmation, $"Would you like to delete your user data?", $"Would you like to delete your user data");
            return(Task.CompletedTask);
        }
        /// <summary>
        /// Execution for the <see cref="PreferredWeatherLocationDialog"/> starts here.
        /// </summary>
        /// <param name="context">Mandatory. The context for the execution of a dialog's conversational process.</param>
        public Task StartAsync(IDialogContext context)
        {
            City savedPreferredCity = _botDataService.GetPreferredWeatherLocation(context);

            if (_entities != null)
            {
                _extractedCityFromMessage = _messageHelpers.ExtractEntityFromMessage("City.Name", _entities);
            }

            if (!string.IsNullOrWhiteSpace(_extractedCityFromMessage))
            {
                PromptDialog.Confirm(context, ResumeAfterPreferredCityConfirmation, $"So you'd like to change your preferred weather location to {_extractedCityFromMessage}?", $"Sorry I don't understand - try again! So you'd like to change your preferred weather location to {_extractedCityFromMessage}");
                return(Task.CompletedTask);
            }

            if (savedPreferredCity != null)
            {
                PromptDialog.Confirm(context, ResumeAfterConfirmation, $"Your saved weather location is {savedPreferredCity.Name}, {savedPreferredCity.Country}, would you like to change it?", $"Sorry I don't understand - try again! Would you like to change your preferred weather location?");
                return(Task.CompletedTask);
            }

            PromptDialog.Text(context, ResumeAfterPromptForPreferredLocation, "What's the name of your preferred weather location?", "Sorry I didn't get that - try again! What's the name of your preferred weather location?");
            return(Task.CompletedTask);
        }
        /// <summary>
        /// Execution for the <see cref="BotPersonaDialog"/> starts here.
        /// </summary>
        /// <param name="context">Mandatory. The context for the execution of a dialog's conversational process.</param>
        public Task StartAsync(IDialogContext context)
        {
            /**
             * ----------------------------------------------------
             *  Order of Dialog Flow:
             * ----------------------------------------------------
             *
             * - Check if there is hero card selection, if yes,
             *   confirm and finish.
             *
             * - Check if dialog has entities, extract, confirm and
             *   finish.
             *
             * - Check if user has pre-saved persona, prompt to
             *   update, if yes,prompt options, confirm and finish.
             *
             * - Else, prompt user for option, confirm and finish.
             **/

            // Check if there is hero card selection
            if (_preferredBotPersona != PersonalityChatPersona.None)
            {
                PromptDialog.Confirm(context, ResumeAfterConfirmChosenPersona,
                                     $"So you'd like to set my personality as {_preferredBotPersona}?",
                                     $"Sorry I don't understand - try again! Should I set my personality to {_preferredBotPersona}?");

                return(Task.CompletedTask);
            }
            // Else we can assume LUIS called the dialog
            else
            {
                if (_entities.Count > 0 || _entities != null)
                {
                    Enum.TryParse(_messageHelper.ExtractEntityFromMessage("User.PreferredBotPersona", _entities),
                                  out PersonalityChatPersona parsedResult);

                    _preferredBotPersona = parsedResult;
                }
            }

            // Check If LUIS found entity preference, otherwise continue
            if (_preferredBotPersona != PersonalityChatPersona.None)
            {
                PromptDialog.Confirm(context, ResumeAfterConfirmChosenPersona,
                                     $"So you'd like me to change my personality to {_preferredBotPersona}?",
                                     $"Sorry I don't understand - try again! Should I change my personality to {_preferredBotPersona}?");

                return(Task.CompletedTask);
            }

            PersonalityChatPersona preSavedPersona = _botDataService.GetPreferredBotPersona(context);

            // Check if user has pre-saved persona, otherwise continue
            if (preSavedPersona != PersonalityChatPersona.None)
            {
                PromptDialog.Confirm(context, ResumeAfterUpdateConfirmation, $"My persona is set to {preSavedPersona}. Would you like to change it?",
                                     $"Sorry I don't understand - try again! Would you like to change my persona?");
                return(Task.CompletedTask);
            }

            // Could not determine preferred personality prompt user to choose
            PromptDialog.Choice(context, ResumeAfterPromptDialogChoice,
                                Enum.GetValues(typeof(PersonalityChatPersona))
                                .Cast <PersonalityChatPersona>()
                                .Where(p => p != PersonalityChatPersona.None),
                                "What would you like my personality to be?");

            return(Task.CompletedTask);
        }