瀑布结束问题。它提示回到其他对话框而不是结束
A waterfall end problem. It prompt back to other dialog instead of ending
我总共有4个对话。在其中一个对话框(名为 "product issue")中,我必须进入一个名为 "resolution" 的新对话框,在该对话框的末尾,它们本身处于特定条件。从产品问题中显示的自适应卡有 4 个选项,在 "Overload"、"Computer Rebooting"、"Low Backup" 上,它转到名为 "resolution" 的新对话框,其中有两个步骤:在第一步中再次显示自适应卡,其中包含 4 个选项
"Restart Machine", "off device","按下,需要帮助...当我 select 从第 1 步打开任何选项三时,如 "Restart Machine", "off device","按下。 .it 应该显示自适应卡并自行结束并需要帮助,它将返回到产品问题并显示为其定义的步骤。但是当我选择
"Restart Machine"、"off device" 或按 ..对话没有结束,它又回到了产品问题。
产品问题:
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);
} } }}
如果你想结束一个对话而不是return任何之前的对话,你需要使用CancellAllDialogs
。看起来您只使用了 EndDialog
,这只会结束当前活动的对话框。
我总共有4个对话。在其中一个对话框(名为 "product issue")中,我必须进入一个名为 "resolution" 的新对话框,在该对话框的末尾,它们本身处于特定条件。从产品问题中显示的自适应卡有 4 个选项,在 "Overload"、"Computer Rebooting"、"Low Backup" 上,它转到名为 "resolution" 的新对话框,其中有两个步骤:在第一步中再次显示自适应卡,其中包含 4 个选项 "Restart Machine", "off device","按下,需要帮助...当我 select 从第 1 步打开任何选项三时,如 "Restart Machine", "off device","按下。 .it 应该显示自适应卡并自行结束并需要帮助,它将返回到产品问题并显示为其定义的步骤。但是当我选择 "Restart Machine"、"off device" 或按 ..对话没有结束,它又回到了产品问题。
产品问题:
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);
} } }}
如果你想结束一个对话而不是return任何之前的对话,你需要使用CancellAllDialogs
。看起来您只使用了 EndDialog
,这只会结束当前活动的对话框。