我正在使用 FormFlow 使用 botFrameWork(C#) 构建我的机器人。我想要求用户从四个报告中选择一个,并在选择的基础上打开和关闭某些字段并只询问与选择相关的问题。
以下是报告类型的枚举:
public enum ReportType
{
Application = 1,
Emotion,
AppVsEmotion,
Help
}
以下是所有字段:
public bool AskToChooseReport = true;
[Prompt("What kind of report you would like? {||}")]
public ReportType? Report { get; set; }
[Prompt("What is the application name?")]
public string ReportApplicationName { get; set; }
[Prompt("Please enter the emotion name? {||}")]
public string EmotionName { get; set; }
[Prompt("What is starting date (MM-DD-YYYY) for report?{||}")]
public string StartDate { get; set; }
[Prompt("What is the end date (MM-DD-YYYY) for report? {||}")]
public string EndDate { get; set; }
public string ReportRequest = string.Empty;
我有四种情况:
案例 1:如果用户选择Application,那么我只想向用户询问ReportApplicationName、StartDate、EndDate
案例 2:如果用户选择Emotion,那么我只想向用户询问EmotionName和StartDate,EndDate
案例 3:如果用户选择AppVsEmotion,我想向用户询问ReportApplicationName、EmotionName和StartDate、EndDate
案例 4:如果用户选择Help,那么我只想询问ReportApplicationName、StartDate、EndDate
我尝试执行以下操作,但它不起作用:
public static IForm<StandardInfoForm> BuildForm()
{
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
var parser = new Parser();
return new FormBuilder<StandardInfoForm>()
.Message("Welcome to reporting information!!")
.Field(new FieldReflector<StandardInfoForm>( nameof(Report))
.SetActive( state => state.AskToChooseReport)
.SetNext( (value, state) =>
{
var selection = (ReportType)value;
if (selection == ReportType.Application)
{
state.ReportRequest = "application";
return new NextStep(new[] { nameof(ReportApplicationName) });
}
else if (selection == ReportType.Emotion)
{
state.ReportRequest = "emotion";
return new NextStep(new[] { nameof (EmotionName) });
}
else if (selection == ReportType.AppVsEmotion)
{
state.ReportRequest = "application,emotion";
return new NextStep(new[] { nameof (ReportApplicationName), nameof(EmotionName) });
}
else if (selection == ReportType.Help)
{
state.ReportRequest = "help";
return new NextStep(new[] { nameof(ReportApplicationName) });
}
else
{
return new NextStep();
}
}))
.Field(nameof(StartDate))
.Field(nameof(EndDate), EndReportDateActive)
.Confirm("Would you like to confirm.Yes or No")
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
.Build();
}
如果我太天真,请帮助我。我试图遵循这个: Change Flow Of Message In Microsoft Bot FrameWork