如何通过重新开始或进入特定步骤来控制Microsoft Bot Framework对话框以重复对话框顺序? [英] How can I control the Microsoft Bot Framework dialog to repeat the dialog sequence by either starting over or stepping into a particular step?

查看:112
本文介绍了如何通过重新开始或进入特定步骤来控制Microsoft Bot Framework对话框以重复对话框顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在机器人对话的对话开始时,它似乎走在一条路径上,即
1 2 34。我想在第2点本身回到路径标记1,并重新开始该过程,甚至可能会从3转到标记2,以重新寻址/再次回答标记2 ...

As the dialog from the bot conversation starts it seems to go on a path i.e. 1 2 3 4. I would like to at point 2 per se go back to path marker 1 and start the process over or even potentially go to marker 2 from 3 to re-address / answer marker 2 over again...

我尝试使用if语句(==匹兹堡返回到先前的方法,但是我注意到通过bot仿真器,无论我重新寻址先前的方法如何,对话框都会继续。

I have attempted to do this with an if statement ( == "Pittsburgh" ) that returns to the previous method but I notice through the bot emulator the dialog moves on regardless of me readdressing the previous method.

简而言之,我想问的是如何遍历Waterfall对话框,并根据与机器人和luis对话的结果返回我选择的任何对话点。意思是,如果我从1-5开始,然后从3开始,我需要重新开始如何使Waterfalldialog符合具体要求?我遇到的问题是,即使我在对话框链中调用了先前的方法,也没有正式从该方法开始。我特别关心这个问题。

In short, I am asking how to traverse through the waterfalldialog and go back to any dialog point I choose based on outcomes of conversation with the bot and luis responses. Meaning, if I am stepping through from 1 - 5 and at 3 I need to start over how can I conform the waterfalldialog to specifically do this? The issue I am having is that even though I am calling the previous method i the dialog chain it doesn't officially start from that method called onwards. That is my concern specifically.

       private async Task<DialogTurnResult> DestinationStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var bookingDetails = (BookingDetails)stepContext.Options;

            if (bookingDetails.Destination == null)
            {
                return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text("Where would you like to travel to Christian?") }, cancellationToken);
            }
            else
            {
                Console.WriteLine("testing christian" + bookingDetails);
                return await stepContext.NextAsync(bookingDetails.Destination, cancellationToken);
            }
        }

        private async Task<DialogTurnResult> OriginStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            Console.WriteLine("testing paul");
            var bookingDetails = (BookingDetails)stepContext.Options;

            //await LuisHelper.ExecuteLuisQuery(Configuration, Logger, stepContext.Context, cancellationToken);

            if ((string)stepContext.Result == "Pittsburgh")
            {
               return await DestinationStepAsync(stepContext, cancellationToken);
            }

            bookingDetails.Destination = (string)stepContext.Result;

            if (bookingDetails.Origin == null)
            {
                Console.WriteLine("testing tall" + bookingDetails.Destination);
                return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text("Where are you traveling from?") }, cancellationToken);
            }
            else
            {
                return await stepContext.NextAsync(bookingDetails.Origin, cancellationToken);
            }
        }


推荐答案

到将其塞进答案中,并使其脱离评论:

To tuck this into an answer and get it out of comments:

瀑布的设计目的并非要遍历瀑布,而是要逐步/向下进行。您可以在每个瀑布步骤中嵌套迷你瀑布,从而允许循环单个步骤 ,或者进行了条件检查以跳过某些步骤

Waterfalls are not designed to be traversed in anyway but step-by-step/down. You can either nest mini waterfalls inside each waterfall step which would allow for looping individual steps shown here or having conditional checks to skip certain steps shown here.

您似乎是什么寻找的是 ComponentDialogs 或使用 ReplaceDialogAsync 。组件对话框是botbuilder-dialogs库的一部分,可让您将bot的逻辑分解为可添加到DialogSet甚至另一个组件对话框中的组件(件)。例如,这是bot框架示例github repo上Core-Bot示例的Cancel / Help组件。该组件用于在另一个瀑布中间,如果用户说取消或帮助的情况

What you seem to be looking for is ComponentDialogs or using ReplaceDialogAsync. Component Dialogs, part of the botbuilder-dialogs library let you break your bot's logic into components (pieces) that can be added into either a DialogSet or even another component dialog. For example, this is the Cancel/Help component of the Core-Bot sample on the bot framework samples github repo. This component is for what happens if in the middle of another waterfall, the user says 'cancel' or 'help'

public class CancelAndHelpDialog : ComponentDialog
    {
        public CancelAndHelpDialog(string id)
            : base(id)
        {
        }

        protected override async Task<DialogTurnResult> OnBeginDialogAsync(DialogContext innerDc, object options, CancellationToken cancellationToken)
        {
            var result = await InterruptAsync(innerDc, cancellationToken);
            if (result != null)
            {
                return result;
            }

            return await base.OnBeginDialogAsync(innerDc, options, cancellationToken);
        }

        protected override async Task<DialogTurnResult> OnContinueDialogAsync(DialogContext innerDc, CancellationToken cancellationToken)
        {
            var result = await InterruptAsync(innerDc, cancellationToken);
            if (result != null)
            {
                return result;
            }

            return await base.OnContinueDialogAsync(innerDc, cancellationToken);
        }

        private async Task<DialogTurnResult> InterruptAsync(DialogContext innerDc, CancellationToken cancellationToken)
        {
            if (innerDc.Context.Activity.Type == ActivityTypes.Message)
            {
                var text = innerDc.Context.Activity.Text.ToLowerInvariant();

                switch (text)
                {
                    case "help":
                    case "?":
                        await innerDc.Context.SendActivityAsync($"Show Help...");
                        return new DialogTurnResult(DialogTurnStatus.Waiting);

                    case "cancel":
                    case "quit":
                        await innerDc.Context.SendActivityAsync($"Cancelling");
                        return await innerDc.CancelAllDialogsAsync();
                }
            }

            return null;
        }
    }

正如@ Matt-Stannett所说:有一个教程截至19年5月22日此处介绍如何制作包括组件对话框在内的复杂对话框。

As @Matt-Stannett mentioned: there is a tutorial as of 5/22/19 here on how to make complex dialogs including component dialogs.

这篇关于如何通过重新开始或进入特定步骤来控制Microsoft Bot Framework对话框以重复对话框顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆