// This step routes the user to different dialogs
        // In this case, there's only one other dialog, so it is more simple,
        // but in more complex scenarios you can go off to other dialogs in a similar
        public async Task <DialogTurnResult> MainMenuAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            // Check if we are currently processing a user's search
            var state = await _accessors.PictureState.GetAsync(stepContext.Context);

            // If Regex picks up on anything, store it
            var 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:
            {
                // 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 "SearchPic":
                    await MainResponses.ReplyWithSearchConfirmation(stepContext.Context);

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

                    break;

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

                    break;
                }
                return(await stepContext.EndDialogAsync());
            }
            }
        }
示例#2
0
        // This step routes the user to different dialogs
        // In this case, there's only one other dialog, so it is more simple,
        // but in more complex scenarios you can go off to other dialogs in a similar
        public async Task <DialogTurnResult> MainMenuAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            // Check if we are currently processing a user's search
            var state = await _accessors.PictureBotState.GetAsync(stepContext.Context);

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

            // Based on the recognized intent, direct the conversation
            switch (recognizedIntents.TopIntent?.Name)
            {
            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:
            {
                var result = await _recognizer.RecognizeAsync(stepContext.Context, cancellationToken);

                var topintent = result?.GetTopScoringIntent();
                switch ((topintent != null)? topintent.Value.intent : null)
                {
                case null:
                    await MainResponses.ReplyWithConfused(stepContext.Context);

                    break;

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

                    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 "SharePics":
                    await MainResponses.ReplyWithShareConfirmation(stepContext.Context);

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

                    break;

                case "SearchPics":
                    await MainResponses.ReplyWithSearchConfirmation(stepContext.Context);

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

                    break;

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

                    break;
                }
                return(await stepContext.EndDialogAsync());
            }
            }
        }
示例#3
0
        // This step routes the user to different dialogs
        // In this case, there's only one other dialog, so it is more simple,
        // but in more complex scenarios you can go off to other dialogs in a similar
        public async Task <DialogTurnResult> MainMenuAsync(WaterfallStepContext stepContext,
                                                           CancellationToken cancellationToken)
        {
            // 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 "SearchPic":
                await MainResponses.ReplyWithSearchConfirmation(stepContext.Context);

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

                break;

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

                break;
            }

            return(await stepContext.EndDialogAsync());
        }
        // This step routes the user to different dialogs
        // In this case, there's only one other dialog, so it is more simple,
        // but in more complex scenarios you can go off to other dialogs in a similar
        public async Task <DialogTurnResult> MainMenuAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            // Check if we are currently processing a user's search
            var state = await _accessors.PictureState.GetAsync(stepContext.Context);

            // If Regex picks up on anything, store it
            var 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:
            {
                // 调用 LUIS 识别器
                var result = await _recognizer.RecognizeAsync(stepContext.Context, cancellationToken);

                // 获取结果中排在最前面的意图
                var topIntent = result?.GetTopScoringIntent();
                // 根据意图切换对话,概念与上面的 Regex 类似
                switch ((topIntent != null) ? topIntent.Value.intent : null)
                {
                case null:
                    // 无结果时,添加应用逻辑。
                    await MainResponses.ReplyWithConfused(stepContext.Context);

                    break;

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

                    // 我们将为每个语句添加 LuisScore,这只是为了测试,以便我们知道是否调用了 LUIS
                    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 "SearchPics":
                    await MainResponses.ReplyWithSearchConfirmation(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;

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

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