Exemple #1
0
        // Begin Module Dialog flow
        private async Task <DialogTurnResult> IntroStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (!_luisRecognizer.IsConfigured)
            {
                await stepContext.Context.SendActivityAsync(
                    MessageFactory.Text("NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and 'LuisAPIHostName' to the web.config file.", inputHint: InputHints.IgnoringInput), cancellationToken);

                return(await stepContext.NextAsync(null, cancellationToken));
            }
            var luisResult = await _luisRecognizer.RecognizeAsync <Luis.Conversation>(stepContext.Context, cancellationToken);

            if (luisResult.TopIntent().Equals(Luis.Conversation.Intent.endConversation))
            {
                // Transition to EndConversation Dialog
                return(await stepContext.BeginDialogAsync(nameof(EndConversationDialog)));
            }
            if (luisResult.TopIntent().Equals(Luis.Conversation.Intent.None))
            {
                var didntUnderstandMessageText2 = $"Sorry, I didn't understand that. Could you please rephrase";
                var elsePromptMessage2          = new PromptOptions {
                    Prompt = MessageFactory.Text(didntUnderstandMessageText2, didntUnderstandMessageText2, InputHints.ExpectingInput)
                };

                stepContext.ActiveDialog.State[key : "stepIndex"] = (int)stepContext.ActiveDialog.State["stepIndex"] - 1;
                return(await stepContext.PromptAsync(nameof(TextPrompt), elsePromptMessage2, cancellationToken));
            }

            // Use the text provided in FinalStepAsync or the default if it is the first time.
            var messageText       = $"Excellent let's talk about your modules. \n How many modules are you taking this trimester?";
            var elsePromptMessage = new PromptOptions {
                Prompt = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput)
            };

            return(await stepContext.PromptAsync(nameof(TextPrompt), elsePromptMessage, cancellationToken));
        }
Exemple #2
0
        // Begin Dialog-Flow
        private async Task <DialogTurnResult> IntroStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (!_luisRecognizer.IsConfigured)
            {
                await stepContext.Context.SendActivityAsync(
                    MessageFactory.Text("NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and 'LuisAPIHostName' to the web.config file.", inputHint: InputHints.IgnoringInput), cancellationToken);

                return(await stepContext.NextAsync(null, cancellationToken));
            }
            var luisResult = await _luisRecognizer.RecognizeAsync <Luis.Conversation>(stepContext.Context, cancellationToken);

            //if the user has said they do an activity talk about that rather than asking again
            var userDetails = new UserProfile()
            {
                Name     = luisResult.Entities.UserName,
                Activity = luisResult.Entities.Extracurricular,
            };
            var messageText       = $"";
            var elsePromptMessage = new PromptOptions {
                Prompt = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput)
            };


            messageText       = $"We will dicuss extracurricular activities. How do you spend your free time on campus?";
            elsePromptMessage = new PromptOptions {
                Prompt = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput)
            };



            return(await stepContext.PromptAsync(nameof(TextPrompt), elsePromptMessage, cancellationToken));
        }
        public async Task <DialogTurnResult> ChoiceStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            // Ensure LUIS is configured correctly
            if (!_luisRecognizer.IsConfigured)
            {
                await stepContext.Context.SendActivityAsync(
                    MessageFactory.Text("NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and 'LuisAPIHostName' to the web.config file.", inputHint: InputHints.IgnoringInput), cancellationToken);

                return(await stepContext.NextAsync(null, cancellationToken));
            }

            // get user input and send it to LUIS for analysis
            var luisResult = await _luisRecognizer.RecognizeAsync <Luis.Conversation>(stepContext.Context, cancellationToken);


            // get the highest predicted intent from LUIS
            switch (luisResult.TopIntent().intent)
            {
            // if intent is endConversation confirm conversation has ended
            case Luis.Conversation.Intent.endConversation:
                var messageText       = $"Do you want to end this conversation?";
                var elsePromptMessage = new PromptOptions {
                    Prompt = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput)
                };

                return(await stepContext.PromptAsync(nameof(TextPrompt), elsePromptMessage, cancellationToken));

            // if intent is discussCampus begin dialog about UCD Campus
            case Luis.Conversation.Intent.discussCampus:
                return(await stepContext.BeginDialogAsync(nameof(CampusDialog)));

            // if intent is discussExtracurricular begin dialog about extracurricular activities
            case Luis.Conversation.Intent.discussExtracurricular:
                return(await stepContext.BeginDialogAsync(nameof(ExtracurricularDialog)));


            // if none intent ask to rephrase and begin this dialog again
            case Luis.Conversation.Intent.None:
                var didntUnderstandMessageText = $"I didn't understand that. Would you prefer to talk about UCD Campus or extracurricular activities?";


                var didntUnderstandMessage = MessageFactory.Text(didntUnderstandMessageText, didntUnderstandMessageText, InputHints.IgnoringInput);
                await stepContext.Context.SendActivityAsync(didntUnderstandMessage, cancellationToken);

                return(await stepContext.ReplaceDialogAsync(nameof(MainDialog)));

            // if another intent (discussModule, discussLecturer) ask to rephrase and begin this dialog again
            default:
                var didntUnderstandMessageTextDefault = $"I didn't understand that. Would you prefer to talk about UCD Campus or extracurricular activities?";

                var elsePromptMessage2 = new PromptOptions {
                    Prompt = MessageFactory.Text(didntUnderstandMessageTextDefault, didntUnderstandMessageTextDefault, InputHints.ExpectingInput)
                };

                stepContext.ActiveDialog.State[key : "stepIndex"] = (int)stepContext.ActiveDialog.State["stepIndex"] - 1;
                return(await stepContext.PromptAsync(nameof(TextPrompt), elsePromptMessage2, cancellationToken));
            }
        }
Exemple #4
0
        /* Name prompt which asks for user's name and adds to personalDetails object */
        private async Task <DialogTurnResult> GetNameAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var personalDetials = (PersonalDetails)stepContext.Options;     //Pass the personal Details object through

            if (personalDetials.Name == null)
            {
                var messageText   = "What is your name?";                                                                                   // Prompt message
                var promptMessage = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput);                               //Display prompt message
                return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken)); // Prompt for user input
            }
            var luisResult = await _luisRecognizer.RecognizeAsync <Luis.ElectionBot>(stepContext.Context, cancellationToken);               // Invoke LUIS model

            return(await stepContext.NextAsync(personalDetials.Name, cancellationToken));                                                   //Return back to waterfall step
        }
Exemple #5
0
        /* Ask users what constiuency they vote in */
        private async Task <DialogTurnResult> AskConstituency(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var personalDetails = (PersonalDetails)stepContext.Options;

            if (personalDetails.Location == null)
            {
                await Task.Delay(1500);

                var messageText   = "My voting area is in Kerry, the kingdom 😉! Where is yours?";
                var promptMessage = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput);
                return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken));
            }

            var luisResult = await _luisRecognizer.RecognizeAsync <Luis.ElectionBot>(stepContext.Context, cancellationToken);

            return(await stepContext.NextAsync(personalDetails.Location, cancellationToken));
        }
Exemple #6
0
        /* Asks if the user voted in the previous election */
        private async Task <DialogTurnResult> IntroStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var personalDetails = (PersonalDetails)stepContext.Options;

            if (personalDetails.Voted == null)
            {
                await Task.Delay(1500);     // Pause for effect

                var messageText   = "So, alot has happened since this year's general election then! Did you cast your vote in February?";
                var promptMessage = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput);
                return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken));
            }

            var luisResult = await _luisRecognizer.RecognizeAsync <Luis.ElectionBot>(stepContext.Context, cancellationToken);

            return(await stepContext.NextAsync(personalDetails, cancellationToken));
        }
Exemple #7
0
        private async Task <DialogTurnResult> GetInfoAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (!_luisRecognizer.IsConfigured)
            {
                await stepContext.Context.SendActivityAsync(
                    MessageFactory.Text("NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and 'LuisAPIHostName' to the web.config file.", inputHint: InputHints.IgnoringInput), cancellationToken);

                return(await stepContext.NextAsync(null, cancellationToken));
            }

            var luisResult = await _luisRecognizer.RecognizeAsync <Luis.Conversation>(stepContext.Context, cancellationToken);

            var moduleDetails = new ModuleDetails()
            {
                Lecturer = luisResult.Entities.Lecturer,
                Opinion  = luisResult.Entities.Opinion,
            };

            if (luisResult.TopIntent().Equals(Luis.Conversation.Intent.endConversation))
            {
                return(await stepContext.BeginDialogAsync(nameof(EndConversationDialog)));;
            }
            if (luisResult.TopIntent().Equals(Luis.Conversation.Intent.None))
            {
                var didntUnderstandMessageText2 = $"Sorry, I didn't understand that. Could you please rephrase)";
                var elsePromptMessage2          = new PromptOptions {
                    Prompt = MessageFactory.Text(didntUnderstandMessageText2, didntUnderstandMessageText2, InputHints.ExpectingInput)
                };

                stepContext.ActiveDialog.State[key : "stepIndex"] = (int)stepContext.ActiveDialog.State["stepIndex"] - 1;
                return(await stepContext.PromptAsync(nameof(TextPrompt), elsePromptMessage2, cancellationToken));
            }


            var messageText       = $"That's interesting to know!";
            var elsePromptMessage = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput);
            await stepContext.Context.SendActivityAsync(elsePromptMessage, cancellationToken);

            var message    = $"Would you like to talk about another aspect of university?.";
            var messageFac = new PromptOptions {
                Prompt = MessageFactory.Text(message, message, InputHints.ExpectingInput)
            };

            return(await stepContext.PromptAsync(nameof(TextPrompt), messageFac, cancellationToken));
        }
Exemple #8
0
        private async Task <DialogTurnResult> IntroStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (!_luisRecognizer.IsConfigured)
            {
                await stepContext.Context.SendActivityAsync(
                    MessageFactory.Text("NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and 'LuisAPIHostName' to the web.config file.", inputHint: InputHints.IgnoringInput), cancellationToken);

                return(await stepContext.NextAsync(null, cancellationToken));
            }
            var luisResult = await _luisRecognizer.RecognizeAsync <Luis.Conversation>(stepContext.Context, cancellationToken);


            // Use the text provided in FinalStepAsync or the default if it is the first time.
            var messageText       = $"How do you feel about the closure of UCD because of the virus?";
            var elsePromptMessage = new PromptOptions {
                Prompt = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput)
            };

            return(await stepContext.PromptAsync(nameof(TextPrompt), elsePromptMessage, cancellationToken));
        }
        private async Task <DialogTurnResult> GetInfoAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (!_luisRecognizer.IsConfigured)
            {
                await stepContext.Context.SendActivityAsync(
                    MessageFactory.Text("NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and 'LuisAPIHostName' to the web.config file.", inputHint: InputHints.IgnoringInput), cancellationToken);

                return(await stepContext.NextAsync(null, cancellationToken));
            }

            var luisResult = await _luisRecognizer.RecognizeAsync <Luis.Conversation>(stepContext.Context, cancellationToken);

            var moduleDetails = new ModuleDetails()
            {
                Lecturer = luisResult.Entities.Lecturer,
                Opinion  = luisResult.Entities.Opinion,
            };

            switch (luisResult.TopIntent().intent)
            {
            case Luis.Conversation.Intent.None:
                var didntUnderstandMessageText = $"I didn't understand that. Could you please rephrase";
                var elsePromptMessage2         = new PromptOptions {
                    Prompt = MessageFactory.Text(didntUnderstandMessageText, didntUnderstandMessageText, InputHints.ExpectingInput)
                };

                stepContext.ActiveDialog.State[key : "stepIndex"] = (int)stepContext.ActiveDialog.State["stepIndex"] - 1;
                return(await stepContext.PromptAsync(nameof(TextPrompt), elsePromptMessage2, cancellationToken));


            case Luis.Conversation.Intent.endConversation:
                return(await stepContext.BeginDialogAsync(nameof(EndConversationDialog)));;

            default:
                var messageText = $"Ok. Presumably they are not all like this?";
                var messageFac  = new PromptOptions {
                    Prompt = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput)
                };
                return(await stepContext.PromptAsync(nameof(TextPrompt), messageFac, cancellationToken));
            }
        }
Exemple #10
0
        /* ask for user input on party preference*/
        private async Task <DialogTurnResult> AskParty(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var personalDetails = (PersonalDetails)stepContext.Options;

            if (personalDetails.Party == null)
            {
                await Task.Delay(1500);

                await stepContext.Context.SendActivityAsync(MessageFactory.Text($"Continuing on with our imaginary scenario..."), cancellationToken);

                await Task.Delay(2500);

                var messageText   = $"Personally, if choosing parties I'd be between Renua and Labour! What about you? Would you join a party or go as an independent?";
                var promptMessage = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput);
                return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken));
            }

            var luisResult = await _luisRecognizer.RecognizeAsync <Luis.ElectionBot>(stepContext.Context, cancellationToken);

            return(await stepContext.NextAsync(personalDetails, cancellationToken));
        }
Exemple #11
0
        /* Asks user question about issues*/
        private async Task <DialogTurnResult> AskIssues(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var personalDetails = (PersonalDetails)stepContext.Options;

            if (personalDetails.Issues == null)
            {
                await Task.Delay(1000);

                await stepContext.Context.SendActivityAsync(MessageFactory.Text($"If I were elected, I'd finally bring high speed broadband to Kerry!"), cancellationToken);

                await Task.Delay(2000);

                var messageText   = $"So {personalDetails.Name.First()}, imagine you were elected in the morning... what kinds of issues would you raise in Dáil Eireann?";
                var promptMessage = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput);
                return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken));
            }

            var luisResult = await _luisRecognizer.RecognizeAsync <Luis.ElectionBot>(stepContext.Context, cancellationToken);

            return(await stepContext.NextAsync(personalDetails.Location, cancellationToken));
        }
        // Begin dialog flow
        private async Task <DialogTurnResult> IntroStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (!_luisRecognizer.IsConfigured)
            {
                await stepContext.Context.SendActivityAsync(
                    MessageFactory.Text("NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and 'LuisAPIHostName' to the web.config file.", inputHint: InputHints.IgnoringInput), cancellationToken);

                return(await stepContext.NextAsync(null, cancellationToken));
            }
            var luisResult = await _luisRecognizer.RecognizeAsync <Luis.Conversation>(stepContext.Context, cancellationToken);

            //if the user has said they do an activity talk about that rather than asking again
            var userDetails = new UserProfile()
            {
                Name     = luisResult.Entities.UserName,
                Activity = luisResult.Entities.Extracurricular,
            };
            var messageText       = $"";
            var elsePromptMessage = new PromptOptions {
                Prompt = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput)
            };

            if (!string.IsNullOrEmpty(userDetails.Activity.First()))
            {
                messageText       = $"Great idea! Are you a part of a team or a club for {userDetails.Activity.FirstOrDefault()}?";
                elsePromptMessage = new PromptOptions {
                    Prompt = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput)
                };
            }
            else
            {
                messageText       = $"Great! So what kinda things do you like doing in your spare time on campus?";
                elsePromptMessage = new PromptOptions {
                    Prompt = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput)
                };
            }


            return(await stepContext.PromptAsync(nameof(TextPrompt), elsePromptMessage, cancellationToken));
        }
Exemple #13
0
        // Begin Dialog
        private async Task <DialogTurnResult> IntroStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (!_luisRecognizer.IsConfigured)
            {
                await stepContext.Context.SendActivityAsync(
                    MessageFactory.Text("NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and 'LuisAPIHostName' to the web.config file.", inputHint: InputHints.IgnoringInput), cancellationToken);

                return(await stepContext.NextAsync(null, cancellationToken));
            }
            var luisResult = await _luisRecognizer.RecognizeAsync <Luis.Conversation>(stepContext.Context, cancellationToken);

            if (luisResult.TopIntent().Equals(Luis.Conversation.Intent.endConversation))
            {
                return(await stepContext.BeginDialogAsync(nameof(EndConversationDialog)));;
            }


            // Use the text provided in FinalStepAsync or the default if it is the first time.
            var messageText   = stepContext.Options?.ToString() ?? "What is your name?";
            var promptMessage = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput);

            return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = promptMessage }, cancellationToken));
        }
        private async Task <DialogTurnResult> EndStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            string[] stringPos;
            stringPos = new string[21] {
                "yes", "ye", "yep", "ya", "yas", "totally", "sure", "ok", "k", "okey", "okay", "alright", "sounds good", "sure thing", "of course", "gladly", "definitely", "indeed", "absolutely", "yes please", "please"
            };
            string[] stringNeg;
            stringNeg = new string[9] {
                "no", "nope", "no thanks", "unfortunately not", "apologies", "nah", "not now", "no can do", "no thank you"
            };

            if (!_luisRecognizer.IsConfigured)
            {
                await stepContext.Context.SendActivityAsync(
                    MessageFactory.Text("NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and 'LuisAPIHostName' to the web.config file.", inputHint: InputHints.IgnoringInput), cancellationToken);

                return(await stepContext.NextAsync(null, cancellationToken));
            }

            var luisResult = await _luisRecognizer.RecognizeAsync <Luis.Conversation>(stepContext.Context, cancellationToken);

            if (stringPos.Any(luisResult.Text.ToLower().Contains))
            {
                // Ensure conversation doesn't restart
                ConversationData.PromptedUserForName = true;
                await stepContext.Context.SendActivityAsync(
                    MessageFactory.Text("Goodbye."));

                return(await stepContext.EndDialogAsync());
            }
            if (stringNeg.Any(luisResult.Text.ToLower().Contains))
            {
                var messageText       = $"Ok the conversation will continue.";
                var elsePromptMessage = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput);
                // Transition to Main Dialog
                return(await stepContext.BeginDialogAsync(nameof(MainDialog)));
            }
            var didntUnderstandMessageText = $"I didn't understand that. Could you please rephrase";
            var elsePromptMessage2         = new PromptOptions {
                Prompt = MessageFactory.Text(didntUnderstandMessageText, didntUnderstandMessageText, InputHints.ExpectingInput)
            };

            stepContext.ActiveDialog.State[key : "stepIndex"] = (int)stepContext.ActiveDialog.State["stepIndex"] - 1;
            return(await stepContext.PromptAsync(nameof(TextPrompt), elsePromptMessage2, cancellationToken));
        }
Exemple #15
0
        /* Returns an error if the user doesn't use the 'wake bot' phrase, continues otherwise */
        public async Task <DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var luisResult = await _luisRecognizer.RecognizeAsync <Luis.ElectionBot>(stepContext.Context, cancellationToken);

            var personalDetails = new PersonalDetails();    // creates a new instance of the personal details class which will be used to save data varaibles disclosed by the user. See PersonalDetails.cs

            // If the user uses the 'wake bot' command, continue to the 'UserProfileDialog', otherwise, ask users to restart the process.
            switch (luisResult.TopIntent().intent)
            {
            case Luis.ElectionBot.Intent.wakeBot:
                return(await stepContext.BeginDialogAsync(nameof(UserProfileDialog), personalDetails, cancellationToken));    //Pass the cancellation token and personalDetails object

            default:
                // Catch all for unhandled intents
                var didntUnderstandMessageText = $"Sorry, I didn't get that. Please use 'wake bot' to wake the bot. Refresh the page and restart";
                var didntUnderstandMessage     = MessageFactory.Text(didntUnderstandMessageText, didntUnderstandMessageText, InputHints.IgnoringInput);
                await stepContext.Context.SendActivityAsync(didntUnderstandMessage, cancellationToken);

                break;
            }

            return(await stepContext.NextAsync(null, cancellationToken));
        }
Exemple #16
0
        private async Task <DialogTurnResult> FacStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (!_luisRecognizer.IsConfigured)
            {
                await stepContext.Context.SendActivityAsync(
                    MessageFactory.Text("NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and 'LuisAPIHostName' to the web.config file.", inputHint: InputHints.IgnoringInput), cancellationToken);

                return(await stepContext.NextAsync(null, cancellationToken));
            }

            var luisResult = await _luisRecognizer.RecognizeAsync <Luis.Conversation>(stepContext.Context, cancellationToken);

            if (luisResult.TopIntent().Equals(Luis.Conversation.Intent.endConversation))
            {
                string[] stringPos;
                stringPos = new string[21] {
                    "yes", "ye", "yep", "ya", "yas", "totally", "sure", "ok", "k", "okey", "okay", "alright", "sounds good", "sure thing", "of course", "gladly", "definitely", "indeed", "absolutely", "yes please", "please"
                };
                string[] stringNeg;
                stringNeg = new string[9] {
                    "no", "nope", "no thanks", "unfortunately not", "apologies", "nah", "not now", "no can do", "no thank you"
                };

                var messageTextEnd    = $"Are you sure you want to end our conversation?";
                var elsePromptMessage = new PromptOptions {
                    Prompt = MessageFactory.Text(messageTextEnd, messageTextEnd, InputHints.ExpectingInput)
                };
                await stepContext.PromptAsync(nameof(TextPrompt), elsePromptMessage, cancellationToken);

                if (!_luisRecognizer.IsConfigured)
                {
                    await stepContext.Context.SendActivityAsync(
                        MessageFactory.Text("NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and 'LuisAPIHostName' to the web.config file.", inputHint: InputHints.IgnoringInput), cancellationToken);

                    return(await stepContext.NextAsync(null, cancellationToken));
                }

                var luisResult2 = await _luisRecognizer.RecognizeAsync <Luis.Conversation>(stepContext.Context, cancellationToken);



                if (stringPos.Any(luisResult2.Text.ToLower().Contains))
                {
                    ConversationData.PromptedUserForName = true;
                    await stepContext.Context.SendActivityAsync(
                        MessageFactory.Text("It was great talking to you! Enjoy the rest of your day!", inputHint: InputHints.IgnoringInput), cancellationToken);

                    return(await stepContext.EndDialogAsync(null, cancellationToken));
                }
                if (stringNeg.Any(luisResult2.Text.ToLower().Contains))
                {
                    var messageTextNeg       = $"Great! Let's continue our conversation.";
                    var elsePromptMessageNeg = new PromptOptions {
                        Prompt = MessageFactory.Text(messageTextNeg, messageTextNeg, InputHints.ExpectingInput)
                    };
                    await stepContext.PromptAsync(nameof(TextPrompt), elsePromptMessageNeg, cancellationToken);
                }
            }

            if (luisResult.TopIntent().Equals(Luis.Conversation.Intent.None))
            {
                var didntUnderstandMessageText2 = $"Sorry, I didn't understand that. Could you please rephrase)";
                var elsePromptMessage2          = new PromptOptions {
                    Prompt = MessageFactory.Text(didntUnderstandMessageText2, didntUnderstandMessageText2, InputHints.ExpectingInput)
                };

                stepContext.ActiveDialog.State[key : "stepIndex"] = (int)stepContext.ActiveDialog.State["stepIndex"] - 1;
                return(await stepContext.PromptAsync(nameof(TextPrompt), elsePromptMessage2, cancellationToken));
            }
            var messageText   = $"Do you use the facilities that are available often?";
            var promptMessage = new PromptOptions {
                Prompt = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput)
            };

            return(await stepContext.PromptAsync(nameof(TextPrompt), promptMessage, cancellationToken));
        }
Exemple #17
0
        // Begin Module dialog flow
        private async Task <DialogTurnResult> IntroStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (!_luisRecognizer.IsConfigured)
            {
                await stepContext.Context.SendActivityAsync(
                    MessageFactory.Text("NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and 'LuisAPIHostName' to the web.config file.", inputHint: InputHints.IgnoringInput), cancellationToken);

                return(await stepContext.NextAsync(null, cancellationToken));
            }
            var luisResult = await _luisRecognizer.RecognizeAsync <Luis.Conversation>(stepContext.Context, cancellationToken);

            if (luisResult.TopIntent().Equals(Luis.Conversation.Intent.endConversation))
            {
                await stepContext.Context.SendActivityAsync(
                    MessageFactory.Text("Do you want to end this conversation?"));

                return(await stepContext.ReplaceDialogAsync(nameof(EndStepAsync)));
            }

            // Use the text provided in FinalStepAsync or the default if it is the first time.
            var messageText       = $"We will discuss your modules now. \n How many modules are you taking this trimester?";
            var elsePromptMessage = new PromptOptions {
                Prompt = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput)
            };

            return(await stepContext.PromptAsync(nameof(TextPrompt), elsePromptMessage, cancellationToken));
        }
Exemple #18
0
        public async Task <DialogTurnResult> ActStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (!_luisRecognizer.IsConfigured)
            {
                return(await stepContext.BeginDialogAsync(nameof(UserProfileDialog), new UserProfile(), cancellationToken));
            }


            var luisResult = await _luisRecognizer.RecognizeAsync <Luis.Conversation>(stepContext.Context, cancellationToken);

            switch (luisResult.TopIntent().intent)
            {
            case Luis.Conversation.Intent.endConversation:
                string[] stringPos;
                stringPos = new string[21] {
                    "yes", "ye", "yep", "ya", "yas", "totally", "sure", "ok", "k", "okey", "okay", "alright", "sounds good", "sure thing", "of course", "gladly", "definitely", "indeed", "absolutely", "yes please", "please"
                };
                string[] stringNeg;
                stringNeg = new string[9] {
                    "no", "nope", "no thanks", "unfortunately not", "apologies", "nah", "not now", "no can do", "no thank you"
                };

                var messageText       = $"Are you sure you want to end our conversation?";
                var elsePromptMessage = new PromptOptions {
                    Prompt = MessageFactory.Text(messageText, messageText, InputHints.ExpectingInput)
                };
                await stepContext.PromptAsync(nameof(TextPrompt), elsePromptMessage, cancellationToken);

                if (!_luisRecognizer.IsConfigured)
                {
                    await stepContext.Context.SendActivityAsync(
                        MessageFactory.Text("NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and 'LuisAPIHostName' to the web.config file.", inputHint: InputHints.IgnoringInput), cancellationToken);

                    return(await stepContext.NextAsync(null, cancellationToken));
                }

                var luisResult2 = await _luisRecognizer.RecognizeAsync <Luis.Conversation>(stepContext.Context, cancellationToken);



                if (stringPos.Any(luisResult2.Text.ToLower().Contains))
                {
                    ConversationData.PromptedUserForName = true;
                    await stepContext.Context.SendActivityAsync(
                        MessageFactory.Text("It was great talking to you! Enjoy the rest of your day!", inputHint: InputHints.IgnoringInput), cancellationToken);

                    return(await stepContext.EndDialogAsync(null, cancellationToken));
                }
                if (stringNeg.Any(luisResult2.Text.ToLower().Contains))
                {
                    var messageTextNeg       = $"Great! Let's continue our conversation.";
                    var elsePromptMessageNeg = new PromptOptions {
                        Prompt = MessageFactory.Text(messageTextNeg, messageTextNeg, InputHints.ExpectingInput)
                    };
                    await stepContext.PromptAsync(nameof(TextPrompt), elsePromptMessageNeg, cancellationToken);
                }
                return(await stepContext.BeginDialogAsync(nameof(CampusDialog)));

            case Luis.Conversation.Intent.discussCampus:
                var moduleInfoCampus = new ModuleDetails()
                {
                    ModuleName = luisResult.Entities.Module,
                    Opinion    = luisResult.Entities.Opinion,
                    Lecturer   = luisResult.Entities.Lecturer,
                    Emotion    = luisResult.Entities.Emotion
                };
                // Transition to Campus Dialog
                return(await stepContext.BeginDialogAsync(nameof(CampusDialog)));

            case Luis.Conversation.Intent.discussExtracurricular:

                var moduleInfoExtra = new ModuleDetails()
                {
                    ModuleName = luisResult.Entities.Module,
                    Opinion    = luisResult.Entities.Opinion,
                    Lecturer   = luisResult.Entities.Lecturer,
                    Emotion    = luisResult.Entities.Emotion
                };
                return(await stepContext.BeginDialogAsync(nameof(ExtracurricularDialog), moduleInfoExtra, cancellationToken));

            case Luis.Conversation.Intent.None:
                var didntUnderstandMessageText2 = $"Sorry, I didn't understand. Let's try again!";
                var didntUnderstandMessage2     = MessageFactory.Text(didntUnderstandMessageText2, didntUnderstandMessageText2, InputHints.IgnoringInput);
                await stepContext.Context.SendActivityAsync(didntUnderstandMessage2, cancellationToken);

                // Reprompt
                return(await stepContext.ReplaceDialogAsync(nameof(MainDialog)));

            default:
                // Catch all for unhandled intents
                var didntUnderstandMessageTextNone = $"Sorry, I didn't understand that. Could you please rephrase";
                var elsePromptMessageNone          = new PromptOptions {
                    Prompt = MessageFactory.Text(didntUnderstandMessageTextNone, didntUnderstandMessageTextNone, InputHints.ExpectingInput)
                };

                stepContext.ActiveDialog.State[key : "stepIndex"] = (int)stepContext.ActiveDialog.State["stepIndex"] - 1;
                return(await stepContext.PromptAsync(nameof(TextPrompt), elsePromptMessageNone, cancellationToken));
            }
        }
        private async Task <DialogTurnResult> ExplanationStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if (!_luisRecognizer.IsConfigured)
            {
                await stepContext.Context.SendActivityAsync(
                    MessageFactory.Text("NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and 'LuisAPIHostName' to the web.config file.", inputHint: InputHints.IgnoringInput), cancellationToken);

                return(await stepContext.NextAsync(null, cancellationToken));
            }
            var luisResult = await _luisRecognizer.RecognizeAsync <Luis.Conversation>(stepContext.Context, cancellationToken);

            if (luisResult.TopIntent().Equals(Luis.Conversation.Intent.endConversation))
            {
                string[] stringPos;
                stringPos = new string[21] {
                    "yes", "ye", "yep", "ya", "yas", "totally", "sure", "ok", "k", "okey", "okay", "alright", "sounds good", "sure thing", "of course", "gladly", "definitely", "indeed", "absolutely", "yes please", "please"
                };
                string[] stringNeg;
                stringNeg = new string[9] {
                    "no", "nope", "no thanks", "unfortunately not", "apologies", "nah", "not now", "no can do", "no thank you"
                };

                var messageTextEnd    = $"Are you sure you want to end our conversation?";
                var elsePromptMessage = new PromptOptions {
                    Prompt = MessageFactory.Text(messageTextEnd, messageTextEnd, InputHints.ExpectingInput)
                };
                await stepContext.PromptAsync(nameof(TextPrompt), elsePromptMessage, cancellationToken);

                if (!_luisRecognizer.IsConfigured)
                {
                    await stepContext.Context.SendActivityAsync(
                        MessageFactory.Text("NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and 'LuisAPIHostName' to the web.config file.", inputHint: InputHints.IgnoringInput), cancellationToken);

                    return(await stepContext.NextAsync(null, cancellationToken));
                }

                var luisResult2 = await _luisRecognizer.RecognizeAsync <Luis.Conversation>(stepContext.Context, cancellationToken);

                if (stringPos.Any(luisResult2.Text.ToLower().Contains))
                {
                    ConversationData.PromptedUserForName = true;
                    await stepContext.Context.SendActivityAsync(
                        MessageFactory.Text("Goodbye", inputHint: InputHints.IgnoringInput), cancellationToken);

                    return(await stepContext.EndDialogAsync(null, cancellationToken));
                }
                if (stringNeg.Any(luisResult2.Text.ToLower().Contains))
                {
                    var messageTextFix   = $"That's all we can talk about today.";
                    var promptMessageFix = new PromptOptions {
                        Prompt = MessageFactory.Text(messageTextFix, messageTextFix, InputHints.ExpectingInput)
                    };
                    return(await stepContext.PromptAsync(nameof(TextPrompt), promptMessageFix, cancellationToken));
                }
            }
            var messageText = $"That's all we can talk about today.";

            await stepContext.Context.SendActivityAsync(MessageFactory.Text(messageText, inputHint: InputHints.IgnoringInput), cancellationToken);

            return(await stepContext.NextAsync());
        }