简体   繁体   English

通过跳过bot框架v4中第一个对话的第一步,将第一个对话的瀑布步骤调用到另一个对话中

[英]Invoke the steps of waterfall of first dialog into other dialog by skipping the first step of a first dialog in bot framework v4

I have 3 dialogs in my bot framework v4 C# project, having waterfall steps in each.我的机器人框架 v4 C# 项目中有 3 个对话框,每个对话框都有瀑布步骤。

In my second dialog have to behave the same as the first dialog but it doesn't have to execute all the steps of the first dialog, which means I need to skip the first step.在我的第二个对话框中的行为必须与第一个对话框相同,但它不必执行第一个对话框的所有步骤,这意味着我需要跳过第一步。

So is there any method to invoke all the waterfall steps of the first dialog into the other dialog by skipping the first step of the first dialog.那么是否有任何方法可以通过跳过第一个对话框的第一步来将第一个对话框的所有瀑布步骤调用到另一个对话框中。

A waterfall once formed is supposed to be executed in a step-by-step fashion. waterfall一旦形成,就应该以逐步的方式执行。 However, you can do the formation of your waterfall steps conditionally.但是,您可以有条件地形成waterfall steps

The condition here can be based on DialogId .这里的条件可以基于DialogId

It's quite difficult to understand what exactly you're trying to do so, I've formed a sample solution for you.很难理解你到底想要做什么,我已经为你形成了一个示例解决方案。 Hope you're trying to do the same.希望你也在尝试做同样的事情。

Please refer the below code for the same :请参阅以下代码以获取相同的内容:

MainDialog.cs主对话框

    namespace EchoBot.Dialogs
    {
        public class MainDialog : ComponentDialog
        {
            private readonly BotStateService _botStateService;

            public MainDialog(BotStateService botStateService) : base(nameof(MainDialog))
            {
                _botStateService = botStateService;

                InitializeWaterfallDialog();
            }

            private void InitializeWaterfallDialog()
            {
                var waterfallSteps = new WaterfallStep[]
                {
                    InitialStepAsync,
                    FinalStepAsync
                };

                AddDialog(new SecondDialog($"{nameof(MainDialog)}.second", _botStateService));
                AddDialog(new FirstDialog($"{nameof(MainDialog)}.first", _botStateService)); 
AddDialog(new FirstDialog($"{nameof(SecondDialog)}.firstFromSecond", _botStateService));
                AddDialog(new WaterfallDialog($"{nameof(MainDialog)}.mainFlow", waterfallSteps));

                InitialDialogId = $"{nameof(MainDialog)}.mainFlow";
            }

            private async Task<DialogTurnResult> InitialStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
            {
                if (Regex.Match(stepContext.Context.Activity.Text.ToLower(), "hi").Success)
                {
                    return await stepContext.BeginDialogAsync($"{nameof(MainDialog)}.second", null, cancellationToken);
                }
                else
                {
                    return await stepContext.BeginDialogAsync($"{nameof(MainDialog)}.first", null, cancellationToken);
                }

            }

            private async Task<DialogTurnResult> FinalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
            {
               return await stepContext.EndDialogAsync(null,cancellationToken);
            }
        } }

FirstDialog.cs FirstDialog.cs

    namespace EchoBot.Dialogs
{
    public class FirstDialog : ComponentDialog
    {
        private readonly BotStateService _botStateService;

        public FirstDialog(string dialogId, BotStateService botStateService) : base(dialogId)
        {
            _botStateService = botStateService ?? throw new ArgumentNullException(nameof(botStateService));
            if (dialogId == $"{ nameof(MainDialog)}.first")
                InitializeWaterfallDialog1();
            else
                InitializeWaterfallDialog2();
        }

        private void InitializeWaterfallDialog1()
        {
            var waterfallsteps = new WaterfallStep[]
            {
                GetAge,
                GetCity,
                FinalStepAsync
            };
            AddDialog(new WaterfallDialog($"{nameof(FirstDialog)}.mainFlow", waterfallsteps));
            AddDialog(new NumberPrompt<int>($"{nameof(FirstDialog)}.age"));
            AddDialog(new TextPrompt($"{nameof(FirstDialog)}.city"));

            InitialDialogId = $"{nameof(FirstDialog)}.mainFlow";
        }
        private void InitializeWaterfallDialog2()
        {
            var waterfallsteps = new WaterfallStep[]
            {
                GetCity,
                FinalStepAsync
            };
            AddDialog(new WaterfallDialog($"{nameof(FirstDialog)}.mainFlow", waterfallsteps));
            AddDialog(new NumberPrompt<int>($"{nameof(FirstDialog)}.age"));
            AddDialog(new TextPrompt($"{nameof(FirstDialog)}.city"));

            InitialDialogId = $"{nameof(FirstDialog)}.mainFlow";
        }

        private async Task<DialogTurnResult> GetAge(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            return await stepContext.PromptAsync($"{nameof(FirstDialog)}.age",
                new PromptOptions
                {
                    Prompt = MessageFactory.Text("Please enter your age."),
                    RetryPrompt = MessageFactory.Text("Please enter a valid age.")
                }, cancellationToken);
        }

        private async Task<DialogTurnResult> GetCity(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            return await stepContext.PromptAsync($"{nameof(FirstDialog)}.age",
                 new PromptOptions
                 {
                     Prompt = MessageFactory.Text("Please enter your city."),
                     RetryPrompt = MessageFactory.Text("Please enter a valid city.")
                 }, cancellationToken);
        }

        private async Task<DialogTurnResult> FinalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            return await stepContext.EndDialogAsync(null, cancellationToken);
        }
    }}

SecondDialog.cs SecondDialog.cs

    namespace EchoBot.Dialogs
{
    public class SecondDialog : ComponentDialog
    {
        private readonly BotStateService _botStateService;

        public SecondDialog(string dialogId, BotStateService botStateService) : base(dialogId) 
        {
            _botStateService = botStateService ?? throw new ArgumentNullException(nameof(botStateService));

            InitializeWaterfallDialog();
        }

        private void InitializeWaterfallDialog()
        {
            var waterfallSteps = new WaterfallStep[]
            {
                InitialStepAsync,
                FinalStepAsync
            };

            AddDialog(new WaterfallDialog($"{nameof(SecondDialog)}.mainFlow", waterfallSteps));
            AddDialog(new TextPrompt($"{nameof(SecondDialog)}.name"));


            InitialDialogId = $"{nameof(SecondDialog)}.mainFlow";
        }

        private async Task<DialogTurnResult> InitialStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
                return await stepContext.PromptAsync($"{nameof(SecondDialog)}.name",
                    new PromptOptions
                    {
                        Prompt = MessageFactory.Text("Please enter your Name.")
                    }, cancellationToken);
        }

        private async Task<DialogTurnResult> FinalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {

            //Suppose you want to call First Dialog from here
            return await stepContext.BeginDialogAsync($"{nameof(SecondDialog)}.firstFromSecond", null, cancellationToken);
        }
    }
}

Added one line - AddDialog(new FirstDialog($"{nameof(SecondDialog)}.firstFromSecond", _botStateService));添加了一行 - AddDialog(new FirstDialog($"{nameof(SecondDialog)}.firstFromSecond", _botStateService)); in MainDialog.cs .MainDialog.cs It's working fine for me.它对我来说很好用。

Image 1 : When you go into second dialog from Main Dialog, it asks name and then skips first step of First Dialog (ie. age) and asks the second step ie.图 1:当您从主对话框进入第二个对话框时,它会询问姓名,然后跳过第一个对话框的第一步(即年龄)并询问第二步,即。 city.城市。

从第二个对话框

Image 2 : When you go directly into first dialog from Main Dialog, it asks age and city both ie.图 2:当您从主对话框直接进入第一个对话框时,它会询问年龄和城市,即。 it didn't skip first step.它没有跳过第一步。

直接第一个对话框

Hope this is helpful.希望这是有帮助的。 Ask in comments if you have any query!如果您有任何疑问,请在评论中提问!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在瀑布对话框中使用 luis 验证提示(Bot 框架 V4) - Validate prompt with luis in waterfall dialog (Bot framework V4) Bot框架v4。 如何在瀑布步骤对话框中获取其他值并将其传递到下一步? - Bot framework v4. How to get the value inside if else in a waterfall step dialog and pass it to the next step? 瀑布对话框中的C#Bot V4文本提示 - C# bot V4 Text Prompt inside a waterfall dialog 具有复杂对话流的顺序瀑布模型Bot Framework C#v4 - Sequential Waterfall Models with Complex Dialog flows Bot Framework C# v4 接受瀑布对话框上的附件并将它们本地存储在机器人框架 v4 中 - Accepting attachments on a waterfall dialog and storing them locally in bot framework v4 如何从机器人框架 v4 中的 ActivityHandler.OnMessageActivityAsync 启动瀑布对话框 - How to start a waterfall dialog from ActivityHandler.OnMessageActivityAsync in bot framework v4 如何在C#[Bot Framework v4]中从QnaBot(qna制造商api)调用瀑布对话框? - How to call waterfall dialog from QnaBot (qna maker api) in C# [Bot Framework v4]? Bot Framework v4圆形对话框参考 - Bot framework v4 circular dialog reference Bot framework v4.0 如何在对话框中执行上一个瀑布步骤 - Bot framework v4.0 how to execute the previous waterfall step in a dialog 如何在使用C#创建的SDK V4 bot中的瀑布式对话框中使用oauth提示修复下一步导航而不键入任何内容? - How to fix next step navigation with oauth prompt in waterfall dialog in SDK V4 bot created using C# without typing anything?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM