Exemple #1
0
        private async Task <DialogTurnResult> GreetingAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            // Get the state for the current step in the conversation
            PictureState state = await _accessors.PictureState.GetAsync(stepContext.Context, () => new PictureState());


            // If we haven't greeted the user
            if (state.Greeted == "not greeted")
            {
                // Greet the user
                await MainResponses.ReplyWithGreeting(stepContext.Context);

                // Update the GreetedState to greeted
                state.Greeted = "greeted";
                // Save the new greeted state into the conversation state
                // This is to ensure in future turns we do not greet the user again
                await _accessors.ConversationState.SaveChangesAsync(stepContext.Context);

                // Ask the user what they want to do next
                await MainResponses.ReplyWithHelp(stepContext.Context);

                // Since we aren't explicitly prompting the user in this step, we'll end the dialog
                // When the user replies, since state is maintained, the else clause will move them
                // to the next waterfall step
                return(await stepContext.EndDialogAsync());
            }
            else // We've already greeted the user
            {
                // Move to the next waterfall step, which is MainMenuAsync
                return(await stepContext.NextAsync());
            }
        }
Exemple #2
0
        private async Task <DialogTurnResult> MainMenuAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            // Check if we are currently processing a user's search
            PictureState state = await _accessors.PictureState.GetAsync(stepContext.Context);

            // If Regex picks up on anything, store it
            IRecognizedIntents recognizedIntents = stepContext.Context.TurnState.Get <IRecognizedIntents>();

            // Based on the recognized intent, direct the conversation
            switch (recognizedIntents.TopIntent?.Name)
            {
            case "search":
                // switch to the search dialog
                return(await stepContext.BeginDialogAsync("searchDialog", null, cancellationToken));

            case "share":
                // respond that you're sharing the photo
                await MainResponses.ReplyWithShareConfirmation(stepContext.Context);

                return(await stepContext.EndDialogAsync());

            case "order":
                // respond that you're ordering
                await MainResponses.ReplyWithOrderConfirmation(stepContext.Context);

                return(await stepContext.EndDialogAsync());

            case "help":
                // show help
                await MainResponses.ReplyWithHelp(stepContext.Context);

                return(await stepContext.EndDialogAsync());

            default:
            {
                return(await BetterCallToLuis(stepContext, cancellationToken, state));
            }
            }
        }
Exemple #3
0
        private async Task <DialogTurnResult> SearchRequestAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            PictureState state =
                await _accessors.PictureState.GetAsync(stepContext.Context);

            if (state.Searching == "no")
            {
                state.Searching = "yes";
                await _accessors.ConversationState.SaveChangesAsync(stepContext.Context);

                return(await stepContext.PromptAsync("searchPrompt",
                                                     new PromptOptions()
                {
                    Prompt = MessageFactory.Text("¿Qué te gustaría buscar?")
                },
                                                     cancellationToken));
            }
            else
            {
                return(await stepContext.NextAsync());
            }
        }
Exemple #4
0
        private async Task <DialogTurnResult> SearchAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            PictureState state =
                await _accessors.PictureState.GetAsync(stepContext.Context);

            if (state.Search == string.Empty)
            {
                state.Search = (string)stepContext.Result;
                await _accessors.ConversationState.SaveChangesAsync(stepContext.Context);
            }

            var searchText = state.Search;

            await SearchResponses.ReplyWithSearchConfirmation(stepContext.Context, searchText);

            await StartAsync(stepContext.Context, searchText);

            state.Search    = string.Empty;
            state.Searching = "no";
            await _accessors.ConversationState.SaveChangesAsync(stepContext.Context);

            return(await stepContext.EndDialogAsync());
        }
Exemple #5
0
        private async Task <DialogTurnResult> BetterCallToLuis(
            WaterfallStepContext stepContext,
            CancellationToken cancellationToken,
            PictureState state)
        {
            // Call LUIS recognizer
            var result = await _recognizer.RecognizeAsync(stepContext.Context, cancellationToken);

            // Get the top intent from the results
            var topIntent = result?.GetTopScoringIntent();

            // Based on the intent, switch the conversation, similar concept as with Regex above
            switch ((topIntent != null) ? topIntent.Value.intent : null)
            {
            case null:
                // Add app logic when there is no result.
                await MainResponses.ReplyWithConfused(stepContext.Context);

                break;

            case "None":
                await MainResponses.ReplyWithConfused(stepContext.Context);

                // with each statement, we're adding the LuisScore, purely to test, so we know whether LUIS was called or not
                await MainResponses.ReplyWithLuisScore(stepContext.Context, topIntent.Value.intent, topIntent.Value.score);

                break;

            case "Greeting":
                await MainResponses.ReplyWithGreeting(stepContext.Context);

                await MainResponses.ReplyWithHelp(stepContext.Context);

                await MainResponses.ReplyWithLuisScore(stepContext.Context, topIntent.Value.intent, topIntent.Value.score);

                break;

            case "OrderPic":
                await MainResponses.ReplyWithOrderConfirmation(stepContext.Context);

                await MainResponses.ReplyWithLuisScore(stepContext.Context, topIntent.Value.intent, topIntent.Value.score);

                break;

            case "SharePic":
                await MainResponses.ReplyWithShareConfirmation(stepContext.Context);

                await MainResponses.ReplyWithLuisScore(stepContext.Context, topIntent.Value.intent, topIntent.Value.score);

                break;

            case "SearchPics":
                // Check if LUIS has identified the search term that we should look for.
                // Note: you should have stored the search term as "facet", but if you did not,
                // you will need to update.
                var entity = result?.Entities;
                var obj    = JObject.Parse(JsonConvert.SerializeObject(entity)).SelectToken("facet");

                // If entities are picked up on by LUIS, store them in state.Search
                // Also, update state.Searching to "yes", so you don't ask the user
                // what they want to search for, they've already told you
                if (obj != null)
                {
                    // format "facet", update state, and save save
                    state.Search    = obj.ToString().Replace("\"", "").Trim(']', '[').Trim();
                    state.Searching = "yes";
                    await _accessors.ConversationState.SaveChangesAsync(stepContext.Context);
                }

                // Begin the search dialog
                await MainResponses.ReplyWithLuisScore(stepContext.Context, topIntent.Value.intent, topIntent.Value.score);

                return(await stepContext.BeginDialogAsync("searchDialog", null, cancellationToken));

            default:
                await MainResponses.ReplyWithConfused(stepContext.Context);

                break;
            }
            return(await stepContext.EndDialogAsync());
        }