瀑布尽头的问题。它提示返回其他对话框而不是结束

我总共有4个对话框。在其中一个对话框(名为“产品问题”)中,我必须转到一个名为“解决方案”的新对话框,在该对话框的末尾,在特定条件下其自身也是如此。从产品发行中显示一个自适应卡,其中有4个选项,分别在“过载”,“计算机重新启动”,“低备份”上,转到名为“解析”的新对话框,该操作有两个步骤:在第一步中,显示自适应卡再次以4个选项命名  “重新启动机器”,“关闭设备”,“按,需要帮助...”,当我从第1步中选择三个选项打开时,如“重新启动机器”,“关闭设备”,“按...”。它应显示自适应卡并终止自身并需要帮助,它将返回到产品问题并显示已定义的步骤。但是当我选择  “重新启动计算机”,“关闭设备”或按..dialog仍未结束,并返回到产品问题。

产品问题:

     namespace microsoft.BotBuilderSamples
     {
      public class ProductIssue : ComponentDialog
       {
        private const string UserInfo = "value-userInfo";
        protected readonly ILogger _logger;
        protected readonly string[] _end =
         {
            Path.Combine(".","Resources","ValidationCard.json"),};
        protected readonly string[] _date =
         {
            Path.Combine(".","Datepicker.json"),};
        protected readonly string[] _time =
        {
            Path.Combine(".","Timepicker.json"),};
        protected readonly string[] _cards =
         {
            Path.Combine(".","State.json"),};
        protected readonly string[] _card =
       {
            Path.Combine(".","City.json"),};
        protected readonly string[] _purchase =
       {
            Path.Combine(".","purchase.json"),};

        protected readonly string[] _service =
          {
             Path.Combine(".","Service.json")
         };
        public ProductIssue(string dialogId) : base(dialogId)
        {

            AddDialog(new TextPrompt(nameof(TextPrompt)));
            AddDialog(new ChoicePrompt(nameof(ChoicePrompt)));
            if (dialogId == $"{nameof(MainDialog)}.fromMain")
                AddDialog(new WaterfallDialog(nameof(WaterfallDialog),new WaterfallStep[]
        {
               optionAsync,InoptionAsync,AnyOthersAsync,OtpAsync,UserauthenticationAsync,CityAsync,purchaseAsync,purchaseYesAsync,reviewAsync,lastAsync,EndAsync
                }));

            else if (dialogId == $"{ nameof(Resolution)}.resolution")
                AddDialog(new WaterfallDialog(nameof(WaterfallDialog),new WaterfallStep[]
                 {
                       OtpAsync,EndAsync
                 }));
            else
                AddDialog(new WaterfallDialog(nameof(WaterfallDialog),new WaterfallStep[]
                {
                       InoptionAsync,EndAsync

                }));

            InitialDialogId = nameof(WaterfallDialog);
            AddDialog(new TextPrompt(nameof(TextPrompt)));
            AddDialog(new TextPrompt($"{nameof(MainDialog)}.fromMain",ValidateAsync));

        }


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

            var attachments = new List<Attachment>();
            var reply = MessageFactory.Attachment(attachments);
            reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
            reply.Attachments.Add(Cards.CreateAdaptiveCardAttachment4());
            reply.Attachments.Add(Cards.CreateAdaptiveCardAttachment5());
            reply.Attachments.Add(Cards.CreateAdaptiveCardAttachment6());
            reply.Attachments.Add(Cards.CreateAdaptiveCardAttachment7());
            var promptOptions = new PromptOptions { Prompt = MessageFactory.Text("Please select any option.") };
            await stepContext.Context.SendactivityAsync(reply,cancellationToken);
            return await stepContext.PromptAsync(nameof(TextPrompt),promptOptions,cancellationToken);

        }

        private async Task<DialogTurnResult> InoptionAsync(WaterfallStepContext stepContext,CancellationToken cancellationToken)
        {
            string choice = stepContext.Result.ToString();
            if (choice == "Inverter" || choice == "Fan" || choice == "Battery")
            {
                var attachments = new List<Attachment>();
                var reply = MessageFactory.Attachment(attachments);
                reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                reply.Attachments.Add(Cards.CreateAdaptiveCardAttachment8());
                await stepContext.Context.SendactivityAsync(reply,cancellationToken);
            }
            else 
            {
                var attachments = new List<Attachment>();
                var reply = MessageFactory.Attachment(attachments);
                reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
                reply.Attachments.Add(Cards.GetHeroCard5().ToAttachment());
                await stepContext.Context.SendactivityAsync(reply,cancellationToken);
                await stepContext.Context.SendactivityAsync(MessageFactory.Text("I will be here if you need me further."),cancellationToken);
                return await stepContext.EndDialogAsync(null,cancellationToken);
            }
            var promptOptions = new PromptOptions { Prompt = MessageFactory.Text("i will") };
            return await stepContext.PromptAsync(nameof(TextPrompt),cancellationToken);

        }

        private async Task<DialogTurnResult> AnyOthersAsync(WaterfallStepContext stepContext,CancellationToken cancellationToken)
        {
            string choice = stepContext.Result.ToString();
            if (choice == "Any Others")
            {
                await stepContext.Context.SendactivityAsync(MessageFactory.Text("We are here to help you."),cancellationToken);
            }
            else if(choice == "Overload" || choice ==  "Computer Rebooting" || choice == "Low Backup")
            {
                return await stepContext.BeginDialogAsync($"{nameof(Resolution)}.start",null,cancellationToken);
            }

            var anyothers = new PromptOptions { Prompt = MessageFactory.Text("Please enter your specific problem.") };

            return await stepContext.PromptAsync(nameof(TextPrompt),anyothers,cancellationToken);

        }

        private async Task<DialogTurnResult> OtpAsync(WaterfallStepContext stepContext,CancellationToken cancellationToken)
        {
          stepContext.Values[UserInfo] = new UserInput();
            await stepContext.Context.SendactivityAsync(MessageFactory.Text("To proceed further,we will be verifying your mobile number by sending an OTP."),cancellationToken);
            await stepContext.Context.SendactivityAsync(MessageFactory.Text("We have just sent an OTP to your number"),cancellationToken);
            var num = new PromptOptions
            {
                Prompt = MessageFactory.Text("Kindly enter the OTP sent(6 digit number)"),RetryPrompt = MessageFactory.Text("Incorrect OTP entered. Kindly re-enter the OTP sent (6 digit number).")
            };
            return await stepContext.PromptAsync($"{nameof(MainDialog)}.fromMain",num,cancellationToken);
        }
        private async Task<DialogTurnResult> UserauthenticationAsync(WaterfallStepContext stepContext,CancellationToken cancellationToken)
        {
            var Otp = (UserInput)stepContext.Values[UserInfo];
            int value;
            var len = (stepContext.Result.ToString()).Length;
            bool success = int.TryParse(stepContext.Result.ToString(),out value);
            if (success == true && len == 6)
            {
                await stepContext.Context.SendactivityAsync(MessageFactory.Text("Thanks. Your OTP is confirmed."),cancellationToken);
                await stepContext.Context.SendactivityAsync(MessageFactory.Text("We are now validating your number against our database. This may take a minute."),cancellationToken);
                await stepContext.Context.SendactivityAsync(MessageFactory.Text("We will be registering you as a user in our system. Please provide a few details."),cancellationToken);
            }

            var attachments = new List<Attachment>();
            var reply = MessageFactory.Attachment(attachments);
            reply.AttachmentLayout = AttachmentLayoutTypes.Carousel;
            reply.Attachments.Add(Cards.CreateAdaptiveCardAttachment9());
            await stepContext.Context.SendactivityAsync(reply,cancellationToken);
            await stepContext.Context.SendactivityAsync(MessageFactory.Text("Hello"),cancellationToken);
            await stepContext.Context.SendactivityAsync(MessageFactory.Text("Please select the state you are located in"),cancellationToken);

            Random r = new Random();
            var validationcard = Cards.CreateAdaptiveCardAttachment2(_cards[r.Next(_cards.Length)]);
            await stepContext.Context.SendactivityAsync(MessageFactory.Attachment(validationcard),cancellationToken);
            var num = new PromptOptions
            {
                Prompt = MessageFactory.Text(" Selected state is:")
            };
            return await stepContext.PromptAsync(nameof(TextPrompt),cancellationToken);
        }

        private async Task<DialogTurnResult> CityAsync(WaterfallStepContext stepContext,CancellationToken cancellationToken)
        {
            Random r = new Random();
            var validationcard = Cards.CreateAdaptiveCardAttachment2(_card[r.Next(_card.Length)]);
            await stepContext.Context.SendactivityAsync(MessageFactory.Attachment(validationcard),cancellationToken);
            var num = new PromptOptions
            {
                Prompt = MessageFactory.Text(" Selected city is:")
            };
            return await stepContext.PromptAsync(nameof(TextPrompt),cancellationToken);
        }
        private async Task<DialogTurnResult> purchaseAsync(WaterfallStepContext stepContext,CancellationToken cancellationToken)
        {
            Random r = new Random();
            var validationcard = Cards.CreateAdaptiveCardAttachment2(_purchase[r.Next(_purchase.Length)]);
            await stepContext.Context.SendactivityAsync(MessageFactory.Attachment(validationcard),cancellationToken);
            var num = new PromptOptions
            {
                Prompt = MessageFactory.Text("")
            };
            return await stepContext.PromptAsync(nameof(TextPrompt),cancellationToken);
        }
        private async Task<DialogTurnResult> purchaseYesAsync(WaterfallStepContext stepContext,CancellationToken cancellationToken)
        {
            string choice = stepContext.Result.ToString();
            if (choice.ToLower() == "yes")
            {
                Random r = new Random();
                var validationcard = Cards.CreateAdaptiveCardAttachment2(_date[r.Next(_date.Length)]);
                await stepContext.Context.SendactivityAsync(MessageFactory.Attachment(validationcard),cancellationToken);
            }
            else if (choice.ToLower() == "no")
            {
                Random r = new Random();
                var validationcard = Cards.CreateAdaptiveCardAttachment2(_service[r.Next(_service.Length)]);
                await stepContext.Context.SendactivityAsync(MessageFactory.Attachment(validationcard),cancellationToken);
            }

            var num = new PromptOptions
            {
                Prompt = MessageFactory.Text("")
            };
            return await stepContext.PromptAsync(nameof(TextPrompt),cancellationToken);
        }

        private async Task<DialogTurnResult> reviewAsync(WaterfallStepContext stepContext,CancellationToken cancellationToken)
        {
            string choice = stepContext.Result.ToString();
            if (choice.ToLower() == "no")
            {
                await stepContext.Context.SendactivityAsync(MessageFactory.Text("Our representative will be reviewing your comments shortly."),cancellationToken);
                Random r = new Random();
                var validationcard = Cards.CreateAdaptiveCardAttachment2(_end[r.Next(_end.Length)]);
                await stepContext.Context.SendactivityAsync(MessageFactory.Attachment(validationcard),cancellationToken);

            }
            else
            {
                ServiceDate serviceDate = JsonConvert.DeserializeObject<ServiceDate>(choice);
                Random r2 = new Random();
                var validationcards = Cards.CreateAdaptiveCardAttachment2(_service[r2.Next(_service.Length)]);
                await stepContext.Context.SendactivityAsync(MessageFactory.Attachment(validationcards),cancellationToken);

            }

            var num = new PromptOptions
            {
                Prompt = MessageFactory.Text("")
            };
            return await stepContext.PromptAsync(nameof(TextPrompt),cancellationToken);

        }

        private async Task<DialogTurnResult> lastAsync(WaterfallStepContext stepContext,CancellationToken cancellationToken)
        {
            string choice = stepContext.Result.ToString();

            if (choice.ToLower() == "yes")
            {
                Random r = new Random();
                var validationcard = Cards.CreateAdaptiveCardAttachment2(_time[r.Next(_time.Length)]);
                await stepContext.Context.SendactivityAsync(MessageFactory.Attachment(validationcard),cancellationToken);
            }

            else if (choice.ToLower() == "no")
            {
                await stepContext.Context.SendactivityAsync(MessageFactory.Text("Our representative will be reviewing your comments shortly."),cancellationToken);
               return await stepContext.EndDialogAsync(null,cancellationToken);
            }
            var num = new PromptOptions
            {
                Prompt = MessageFactory.Text("")
            };
            return await stepContext.PromptAsync(nameof(TextPrompt),cancellationToken);


        }
        private async Task<DialogTurnResult> EndAsync(WaterfallStepContext stepContext,CancellationToken cancellationToken)
        {
            string choice = stepContext.Result.ToString();
            ServiceDate serviceDate = JsonConvert.DeserializeObject<ServiceDate>(choice);

            if (serviceDate.id == "12")
            {
                await stepContext.Context.SendactivityAsync(MessageFactory.Text("Starting to raise service request with the team. Please give it a minute."),cancellationToken);
                await stepContext.Context.SendactivityAsync(MessageFactory.Text("Our representative will be reviewing your comments shortly."),cancellationToken);
            }
            Random r = new Random();
            var validationcard = Cards.CreateAdaptiveCardAttachment2(_end[r.Next(_end.Length)]);
            await stepContext.Context.SendactivityAsync(MessageFactory.Attachment(validationcard),cancellationToken);
            return await stepContext.EndDialogAsync(null,cancellationToken);

        }
        private Task<bool> ValidateAsync(PromptValidatorContext<string> promptContext,CancellationToken cancellationToken)
        {
            int value;
            int len = (promptContext.Context.activity.Text).Length;
            bool success = int.TryParse(promptContext.Context.activity.Text,out value);
            if (success == true && len == 6)
            {
                return Task.FromResult(true);
            }
            else
            {
                return Task.FromResult(false);
            }
        }

    }

    public class ServiceDate
    {
        public string id { get; set; }

        public string value { get; set; }

        public string date { get; set; }
    }

}
**resolution dialog**
     namespace microsoft.BotBuilderSamples
    {
     public class Resolution : ComponentDialog
    {
        protected readonly string[] _solution =
        {
            Path.Combine(".","resolution.json"),};
        protected readonly string[] _action =
        {
            Path.Combine(".",};

        public Resolution(string dialogId) : base(dialogId)
        {
            AddDialog(new TextPrompt($"{nameof(Resolution)}.solution"));
            AddDialog(new TextPrompt(nameof(TextPrompt)));
            AddDialog(new ChoicePrompt(nameof(ChoicePrompt)));
            AddDialog(new WaterfallDialog($"{nameof(Resolution)}.start",new WaterfallStep[]
            {
                solutionAsync,actionAsync

                }));
            InitialDialogId = $"{nameof(Resolution)}.start";
            AddDialog(new TextPrompt(nameof(TextPrompt)));
            AddDialog(new TextPrompt($"{nameof(Resolution)}.end"));
        }
        private async Task<DialogTurnResult> solutionAsync(WaterfallStepContext stepContext,CancellationToken cancellationToken)
        {

            Random r = new Random();
            var validationcard = Cards.CreateAdaptiveCardAttachment2(_solution[r.Next(_solution.Length)]);
            await stepContext.Context.SendactivityAsync(MessageFactory.Attachment(validationcard),cancellationToken);
            var anyothers = new PromptOptions { Prompt = MessageFactory.Text("Please select the problem resloution.") };
            return await stepContext.PromptAsync($"{nameof(Resolution)}.solution",cancellationToken);

        }

        private async Task<DialogTurnResult> actionAsync(WaterfallStepContext stepContext,CancellationToken cancellationToken)
        {
            string choice = stepContext.Result.ToString();
            if (choice == "Restart Machice" || choice == "off device" || choice == "Press")
            {
                Random r = new Random();
                var validationcard = Cards.CreateAdaptiveCardAttachment2(_action[r.Next(_action.Length)]);
                await stepContext.Context.SendactivityAsync(MessageFactory.Attachment(validationcard),cancellationToken);
                return await stepContext.EndDialogAsync($"{nameof(Resolution)}.end",cancellationToken);
            }
            else
            {
                return await stepContext.BeginDialogAsync($"{ nameof(Resolution)}.resolution",cancellationToken);
     } } }}
szv123_rier 回答:瀑布尽头的问题。它提示返回其他对话框而不是结束

如果您想结束对话框而不返回任何先前的对话框,则需要使用CancellAllDialogs。看来您只使用EndDialog,它仅结束当前活动的对话框。

本文链接:https://www.f2er.com/2972696.html

大家都在问