我总共有4个对话框。在其中一个对话框(名为“产品问题”)中,我必须转到一个名为“解决方案”的新对话框,在该对话框的末尾,它们将处于特定状态。从产品发行中显示一个自适应卡,其中有4个选项,分别在“过载”,“计算机重新启动”,“低备份”上,转到名为“解析”的新对话框,其中有两个步骤:在第一步中,显示自适应卡再次使用命名为4个选项的卡当我从第1步中选择三个打开的选项(例如“重启机器”,“关闭设备”,“ Press ..”)时,“重启机器”,“关闭设备”,“新闻,需要帮助...”当我选择任何选项时,它应该显示自适应卡并终止自身并需要帮助,它将返回到产品问题并显示已定义的步骤。但是当我选择“重新启动机器”,“关闭设备”或按..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(".", "Resources", "Datepicker.json"),
};
protected readonly string[] _time =
{
Path.Combine(".", "Resources", "Timepicker.json"),
};
protected readonly string[] _cards =
{
Path.Combine(".", "Resources", "State.json"),
};
protected readonly string[] _card =
{
Path.Combine(".", "Resources", "City.json"),
};
protected readonly string[] _purchase =
{
Path.Combine(".", "Resources", "purchase.json"),
};
protected readonly string[] _service =
{
Path.Combine(".", "Resources", "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,
UserauthenticationAsync,
CityAsync,
purchaseAsync,
purchaseYesAsync,
reviewAsync,
lastAsync,
EndAsync
}));
else
AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
{
InoptionAsync,
AnyOthersAsync,
OtpAsync,
UserauthenticationAsync,
CityAsync,
purchaseAsync,
purchaseAsync,
purchaseYesAsync,
reviewAsync,
lastAsync,
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), promptOptions, 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), num, 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), num, 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), num, 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), num, 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);
return await stepContext.EndDialogAsync(null, 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), num, 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);
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);
}
var num = new PromptOptions
{
Prompt = MessageFactory.Text("")
};
return await stepContext.PromptAsync(nameof(TextPrompt), num, 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(".", "Resources", "resolution.json"),
};
protected readonly string[] _action =
{
Path.Combine(".", "Resources", "ValidationCard.json"),
};
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", anyothers, 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", null, cancellationToken);
} } }}
如果要结束对话框而不返回任何先前的对话框,则需要使用CancellAllDialogs。看起来您仅使用EndDialog,而EndDialog仅结束当前活动的对话框。