FormBuilderとMicrosoft Botフレームワークを使用してフォームを構築しようとしています。私はオプションを動的に追加するという要件があります。Microsoft Bot framework dynamic options issue
私は状態を追加することができましたが、状態の1つを選択すると、そこでフローが終了します。
以下のサンプルコードを見つけてください:
public enum StatesOptions
{
}
public enum BranchOptions
{
}
[Serializable]
public class AppointmentQuery
{
[Prompt("Please enter {&}")]
[Required(AllowEmptyStrings = false, ErrorMessage = "Please enter your Name, it is a mandatory field")]
public string Name;
[Prompt("Please enter {&}")]
[Required(AllowEmptyStrings = false, ErrorMessage = "Please enter your Email, it is a mandatory field")]
[EmailAddressAttribute(ErrorMessage = "Email Id is invalid")]
public string Email;
[Prompt("Please enter {&}")]
[Required(AllowEmptyStrings = false, ErrorMessage = "Please enter appointment date, it is a mandatory field")]
[EmailAddressAttribute(ErrorMessage = "Appointment date is invalid")]
public DateTime ApptDate;
[Prompt("Please enter {&}")]
public StatesOptions States;
public string SelectedState;
[Prompt("Please enter {&}")]
[Required(AllowEmptyStrings = false, ErrorMessage = "Please enter your Email, it is a mandatory field")]
[EmailAddressAttribute(ErrorMessage = "Email Id is invalid")]
public string NewEmail;
[Prompt("Please enter {&}")]
public BranchOptions? Branches;
public string SelectedBranch;
public static IForm<AppointmentQuery> BuildAppointmentBookingForm()
{
OnCompletionAsyncDelegate<AppointmentQuery> bookAppointment = async (context, state) =>
{
};
return new FormBuilder<AppointmentQuery>()
.Field(nameof(Name))
.Field(nameof(Email))
.Field(nameof(ApptDate))
//.Field(nameof(States))
.Field(new FieldReflector<AppointmentQuery>(nameof(States))
.SetActive((state) => true)
.SetPrompt(new PromptAttribute("Please select one of the state from the following options: {||}")
{
ChoiceStyle = ChoiceStyleOptions.Buttons
})
.SetDefine((state, field) =>
{
var data = new FeedStateData().feedData();
var states = data.Select(r => r.StateName);
foreach (var item in states)
{
field
.AddDescription(item, item)
.AddTerms(item, item);
//return true;
}
return Task.FromResult(true);
})
.SetNext((value, state) =>
{
var selection = (States)value;
state.SelectedState = selection.StateName.ToString();
return new NextStep(new[] { nameof(Branches) });
}))
.OnCompletion(bookAppointment)
.Build();
}
}
をまた、私はそれに別の動的フィールドブランチを追加する必要がありますが、コードはそれすなわち分岐に到達していない、例外がスローされないが、フォームが動作しません。
同様
.Field(new FieldReflector<AppointmentQuery>(nameof(Branches))
.SetActive((state) => true)
.SetPrompt(new PromptAttribute("Please select branch from following options: {||}")
{
ChoiceStyle = ChoiceStyleOptions.Buttons
})
.SetDefine((state, field) =>
{
var data = new FeedStateData().feedData();
var states = data.Select(r => r.StateName);
var bracnhList = data.Where(s => s.StateName == state.SelectedState).Select(a => a.Branches).FirstOrDefault().Select(n => n.BranchName).ToList();
foreach (var item in bracnhList)
{
field
.AddDescription(item, item)
.AddTerms(item);
}
return Task.FromResult(true);
})
.SetNext((value, state) =>
{
var selection = (Branch)value;
state.SelectedBranch = selection.ToString();
return new NextStep(new[] { nameof(Branches) });
}))
をブランチフィールドのためのサンプルコードを見つけてください誰かがこれで私を助けることができますか?