Пример #1
0
        public async Task SmallTalk(IDialogContext context, LuisResult result)
        {
            await context.PostAsync(await _conversationService.GetResponseByIntentName(result.TopScoringIntent.Intent,
                                                                                       _botDataService.GetPreferredBotPersona(context)));

            context.Wait(MessageReceived);
        }
Пример #2
0
        /// <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);
        }