コード例 #1
0
        public async Task <DialogTurnResult> FinishOnboardingDialog(WaterfallStepContext sc, CancellationToken cancellationToken)
        {
            var view = new MainResponses();

            _state = await _accessor.GetAsync(sc.Context);

            await _accessor.SetAsync(sc.Context, _state, cancellationToken);

            var name = _state.Name;

            var connect = new DataBaseOperations("Server=tcp:yoyopizzaserver.database.windows.net,1433;Initial Catalog=PizzaOrderdb;Persist Security Info=False;User ID=shubham;Password=Dota365365;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;");

            connect.addUserInfo(_state);
            //await _responder.ReplyWith(sc.Context, OnboardingResponses.ResponseIds.HaveNameMessage, new { name });
            var attachement = GetGreetingCard(name);
            var opts        = new PromptOptions
            {
                Prompt = new Activity
                {
                    Type        = ActivityTypes.Message,
                    Attachments = new List <Attachment> {
                        attachement
                    },
                },
            };
            await sc.PromptAsync(DialogIds.GreetingPrompt, opts);

            return(await sc.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.BotState.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.DialogName, null, cancellationToken));

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

                return(await stepContext.EndDialogAsync());

            case "moderated-content":
                return(await stepContext.BeginDialogAsync(ModeratedContentSearchDialog.DialogName, null, cancellationToken));

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

                return(await stepContext.EndDialogAsync());
            }
            }
        }
コード例 #3
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());
            }
        }
コード例 #4
0
        private async Task <InterruptionAction> OnLogout(DialogContext dc)
        {
            var view = new MainResponses();
            IUserTokenProvider tokenProvider;
            var supported = dc.Context.Adapter is IUserTokenProvider;

            if (!supported)
            {
                throw new InvalidOperationException("OAuthPrompt.SignOutUser(): not supported by the current adapter");
            }
            else
            {
                tokenProvider = (IUserTokenProvider)dc.Context.Adapter;
            }

            await dc.CancelAllDialogsAsync();

            // Sign out user

            var tokens = await tokenProvider.GetTokenStatusAsync(dc.Context, dc.Context.Activity.From.Id);

            foreach (var token in tokens)
            {
                await tokenProvider.SignOutUserAsync(dc.Context, token.ConnectionName);
            }

            await dc.Context.SendActivityAsync(MainStrings.LOGOUT);

            await view.ReplyWith(dc.Context, MainResponses.ResponseIds.NewUserGreeting);

            return(InterruptionAction.StartedDialog);
        }
コード例 #5
0
        private static async Task <DialogTurnResult> AskIfReturningAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var view = new MainResponses();
            await view.ReplyWith(stepContext.Context, MainResponses.ResponseIds.NewUserGreeting);

            //create set of possible choices (no isn't really needeed)
            Choice choice1 = new Choice("yes");

            choice1.Synonyms = new List <string> {
                "yeah", "yup", "y", "ye", "of course", "i am"
            };
            choice1.Value = "yes";
            Choice choice2 = new Choice("no");

            choice2.Synonyms = new List <string> {
                "nah", "i don't"
            };
            choice2.Value = "no";

            IList <Choice> choices = new List <Choice> {
                choice1, choice2
            };

            return(await stepContext.PromptAsync(nameof(ChoicePrompt), new PromptOptions { Prompt = MessageFactory.Text("Hello, are you a returning user?"), Choices = choices, Style = ListStyle.Auto }, cancellationToken));
        }
コード例 #6
0
        protected override async Task CompleteAsync(DialogContext dc, DialogTurnResult result = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            // The active dialog's stack ended with a complete status
            //await _responder.ReplyWith(dc.Context, MainResponses.ResponseIds.Completed);

            var view = new MainResponses();
            await view.ReplyWith(dc.Context, MainResponses.ResponseIds.MainMenuGreeting);
        }
コード例 #7
0
        protected virtual async Task <InterruptionStatus> OnHelp(DialogContext dc)
        {
            var view = new MainResponses();
            await view.ReplyWith(dc.Context, MainResponses.ResponseIds.Help);

            // Signal the conversation was interrupted and should immediately continue
            return(InterruptionStatus.Interrupted);
        }
コード例 #8
0
        private async Task <InterruptionAction> OnHelp(DialogContext dc)
        {
            var view = new MainResponses();
            await view.ReplyWith(dc.Context, MainResponses.ResponseIds.Help);

            // Signal the conversation was interrupted and should immediately continue
            return(InterruptionAction.MessageSentToUser);
        }
コード例 #9
0
        protected override async Task OnStartAsync(DialogContext innerDc, CancellationToken cancellationToken = default(CancellationToken))
        {
            var view = new MainResponses();
            await view.ReplyWith(innerDc.Context, MainResponses.Intro);

            var onboardingAccessor = _userState.CreateProperty <OnboardingState>(nameof(OnboardingState));
            var onboardingState    = await onboardingAccessor.GetAsync(innerDc.Context, () => new OnboardingState());

            if (string.IsNullOrEmpty(onboardingState.Name))
            {
                // This is the first time the user is interacting with the bot, so gather onboarding information.
                await innerDc.BeginDialogAsync(nameof(OnboardingDialog));
            }
        }
コード例 #10
0
        protected override async Task OnStartAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
        {
            var view            = new MainResponses();
            var onboardingState = await _onboardingState.GetAsync(dc.Context, () => new OnboardingState());

            if (string.IsNullOrEmpty(onboardingState.Name))
            {
                await view.ReplyWith(dc.Context, MainResponses.ResponseIds.NewUserGreeting);
            }
            else
            {
                await view.ReplyWith(dc.Context, MainResponses.ResponseIds.ReturningUserGreeting);
            }
        }
コード例 #11
0
        private async Task <InterruptionAction> OnCancel(DialogContext dc)
        {
            if (dc.ActiveDialog != null && dc.ActiveDialog.Id != nameof(CancelDialog))
            {
                // Don't start restart cancel dialog
                await dc.BeginDialogAsync(nameof(CancelDialog));

                // Signal that the dialog is waiting on user response
                var view1 = new MainResponses();
                await view1.ReplyWith(dc.Context, MainResponses.ResponseIds.MainMenuGreeting);

                return(InterruptionAction.StartedDialog);
            }

            var view = new CancelResponses();

            await view.ReplyWith(dc.Context, CancelResponses.ResponseIds.NothingToCancelMessage);

            return(InterruptionAction.StartedDialog);
        }
コード例 #12
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.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:
            {
                await MainResponses.ReplyWithConfused(stepContext.Context);

                return(await stepContext.EndDialogAsync());
            }
            }
        }
コード例 #13
0
        protected override async Task OnStartAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
        {
            var view            = new MainResponses();
            var onboardingState = await _onboardingState.GetAsync(dc.Context, () => new OnboardingState());

            _state = await _onboardingState.GetAsync(dc.Context, () => new OnboardingState());

            var name = _state.ConfuseCounter++;
            await _onboardingState.SetAsync(dc.Context, _state, cancellationToken);

            await dc.BeginDialogAsync(nameof(Greeting_Dialog));

            if (string.IsNullOrEmpty(onboardingState.Name))
            {
                //await view.ReplyWith(dc.Context, MainResponses.ResponseIds.NewUserGreeting);
            }
            else
            {
                //await view.ReplyWith(dc.Context, MainResponses.ResponseIds.ReturningUserGreeting);
            }
        }
コード例 #14
0
        private async Task <DialogTurnResult> SearchBingAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            // Add state so we can update it throughout the turn
            var state = await _accessors.PictureState.GetAsync(stepContext.Context);

            var searchText = state.Search;
            var searchbing = (string)stepContext.Result;

            switch (searchbing)
            {
            case "Yes":
                await SearchResponses.ReplyWithBingConfirmation(stepContext.Context, searchText);

                // add Bing Search
                await SearchBing(stepContext.Context, searchText);

                break;

            case "No":
                // End the dialog and wait for a response
                await SearchResponses.ReplyWithDontBing(stepContext.Context);

                break;

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

                await MainResponses.ReplyWithHelp(stepContext.Context);

                break;
            }
            // Clear out Search or future searches, set the searching state to no,
            // update the conversation state
            state.Search    = "";
            state.Searching = "no";
            await _accessors.ConversationState.SaveChangesAsync(stepContext.Context);

            return(await stepContext.EndDialogAsync());
        }
コード例 #15
0
        private async Task <DialogTurnResult> GreetingAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            //Retrieve the active state associated with the ITurnContext
            //If no state is set, add a factory method that creates a blank one
            var state = await _accessors.PictureState.GetAsync(stepContext.Context, () => new PictureState());

            //Check to see if we have greeted the user or not.
            //If we have not greeted the user, greet and reply with help!
            //Be sure to update the state to note that we HAVE greeted.

            //In either case, move to the next dialog
            if (!state.HasGreeted)
            {
                await MainResponses.ReplyWithGreeting(stepContext.Context);

                await MainResponses.ReplyWithHelp(stepContext.Context);

                state.HasGreeted = true;
                await _accessors.ConversationState.SaveChangesAsync(stepContext.Context);
            }

            return(await stepContext.NextAsync());
        }
コード例 #16
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());
        }
コード例 #17
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)
        {
            //detect user language
            _language = _translator.Detect(stepContext.Context.Activity.Text);
            if (_language != "en")
            {
                string translated = _translator.Translate(stepContext.Context.Activity.Text, _language, "en");
                stepContext.Context.Activity.Text = translated;
            }

            // 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, _translateDelegate);

                return(await stepContext.EndDialogAsync());

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

                return(await stepContext.EndDialogAsync());

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

                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, _translateDelegate);

                    break;

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

                    // 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, _translateDelegate);

                    await MainResponses.ReplyWithHelp(stepContext.Context, _translateDelegate);

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

                    break;

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

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

                    break;

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

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

                    break;

                case "SearchPics":
                    await MainResponses.ReplyWithSearchingConfirmation(stepContext.Context, _translateDelegate);

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

                    break;

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

                    break;
                }
                return(await stepContext.EndDialogAsync());
            }
            }
        }
コード例 #18
0
ファイル: PictureBot.cs プロジェクト: PatLac04/PictureBot
        // 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 recognizerResult = await _services.LuisServices[LuisPictureBot].RecognizeAsync <LUISPicture>(stepContext.Context, cancellationToken);
                //var result = await _recognizer.RecognizeAsync(stepContext.Context, cancellationToken);

                // Get the top intent from the results
                //var topIntent = recognizerResult?.GetTopScoringIntent();
                var topIntent      = recognizerResult.TopIntent().intent;
                var topIntentScore = recognizerResult.TopIntent().score;

                // Based on the intent, switch the conversation, similar concept as with Regex above
                switch (topIntent)
                {
                case LUISPicture.Intent.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.ToString(), topIntentScore);

                    break;

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

                    await MainResponses.ReplyWithHelp(stepContext.Context);

                    await MainResponses.ReplyWithLuisScore(stepContext.Context, topIntent.ToString(), topIntentScore);

                    break;

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

                    await MainResponses.ReplyWithLuisScore(stepContext.Context, topIntent.ToString(), topIntentScore);

                    break;

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

                    await MainResponses.ReplyWithLuisScore(stepContext.Context, topIntent.ToString(), topIntentScore);

                    break;

                case LUISPicture.Intent.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 = recognizerResult?.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.ToString(), topIntentScore);

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

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

                    break;
                }
                return(await stepContext.EndDialogAsync());
            }
            }
        }
コード例 #19
0
        private async Task <DialogTurnResult> MainMenuAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            //Our main menu is essentially the root state of the dialog. Think of it as
            //a hub that lets you access any specific part of the bot.

            //First, retrieve the PictureState or a blank PictureState if it does not exist
            var state = await _accessors.PictureState.GetAsync(stepContext.Context, () => new PictureState());

            //Then, retrieve matching intents from the middleware pipeline via getting IRecognizedIntents from ITurnContext::TurnState
            var intents = stepContext.Context.TurnState.Get <IRecognizedIntents>();

            //Save a reference to the best intent so far
            var bestIntent = intents?.TopIntent?.Name;

            //If we do not have one...
            // - pass our turn context to the LuisRecognizer's RecognizeAsync method
            // - get the top intent as a tuple (string, double)
            // - See if the score exceeds a certain threshold
            // - Use the helper method to extract the "facet" and set it to our active state's search
            // - ** Save Changes to the ConversationState anytime you alter it!!! **
            if (string.IsNullOrWhiteSpace(bestIntent))
            {
                var luisResults = await _luisRecognizer.RecognizeAsync(stepContext.Context, cancellationToken);

                (string luisIntent, double score) = luisResults.GetTopScoringIntent();

                if (score > 0.65)
                {
                    if (luisIntent == "SearchPictures")
                    {
                        var search = GetSearchQuery(luisResults.Entities);
                        if (!string.IsNullOrWhiteSpace(search))
                        {
                            state.Search      = search;
                            state.IsSearching = true;
                            await _accessors.ConversationState.SaveChangesAsync(stepContext.Context);
                        }
                    }

                    bestIntent = luisIntent;
                }
            }

            //Whether it's from LUIS or RegExp recognition,
            //Now we need a switch on the best intent to
            //move the bot. In a large bot, this can cater to
            //any number of actions, dialogs, or RPA.

            //The intents we're using are: Share, Order, Help, SearchPics.
            //The default case should cover anything else.
            //Share,Order, and Help can simply send canned responses,
            //however SearchPics should begin the SEARCH_DIALOG
            switch (bestIntent)
            {
            case "Share":
                await MainResponses.ReplyWithShareConfirmation(stepContext.Context);

                break;

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

                break;

            case "Help":
                await MainResponses.ReplyWithHelp(stepContext.Context);

                break;

            case "SearchPictures":
            case "SearchPics":
                return(await stepContext.BeginDialogAsync(SEARCH_DIALOG, null, cancellationToken));

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

                break;
            }

            return(await stepContext.EndDialogAsync());
        }
コード例 #20
0
 protected override async Task OnStartAsync(DialogContext dc, CancellationToken cancellationToken = default(CancellationToken))
 {
     var view = new MainResponses();
     await view.ReplyWith(dc.Context, MainResponses.ResponseIds.Intro);
 }
コード例 #21
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.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());
            }
            }
        }
コード例 #22
0
ファイル: PictureBot.cs プロジェクト: Hao-Qian/simplebot
        // 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());
        }
コード例 #23
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());
            }
            }
        }