使用 MicrosoftBot 的 FormBuilder 跳过确认步骤
Skip confirmation step with MicrosoftBot's FormBuilder
我在完成表格之前不需要任何确认。但是,在 FormBuilder class 的以下 Build() 方法中有一个 Confirm("Is this your selection?\n{}")*。
public IForm<T> Build()
{
if (!_form._steps.Any((step) => step.Type == StepType.Field))
{
var paths = new List<string>();
FormBuilder<T>.FieldPaths(typeof(T), "", paths);
IFormBuilder<T> builder = this;
foreach (var path in paths)
{
builder.Field(new FieldReflector<T>(path));
}
builder.Confirm("Is this your selection?\n{*}");
}
Validate();
return this._form;
}
有什么方法可以在调用构建后从生成的表单中删除此步骤?
var form = new FormBuilder<QuestionYourThinking>()
.OnCompletionAsync(async (context, state) =>
{
await context.PostAsync("L'exercice est maintenant terminé. A bientot !");
})
.Build();
只需使用带有 ActiveDelegate
参数的重载并将方法处理程序设为 return false
则不会显示确认消息。
return new FormBuilder<QuestionYourThinking>()
.AddRemainingFields()
.Confirm("No verification will be shown", state => false)
.Message("L'exercice est maintenant terminé. A bientot !")
.Build();
要发送消息,您可以使用流畅的方法 Message
。
您可以只在 FormBuilder 上使用 .AddRemainingFields()。它不会要求任何确认。
.Confirm 当您想为任何特定字段添加自定义确认消息时应使用。
我在完成表格之前不需要任何确认。但是,在 FormBuilder class 的以下 Build() 方法中有一个 Confirm("Is this your selection?\n{}")*。
public IForm<T> Build()
{
if (!_form._steps.Any((step) => step.Type == StepType.Field))
{
var paths = new List<string>();
FormBuilder<T>.FieldPaths(typeof(T), "", paths);
IFormBuilder<T> builder = this;
foreach (var path in paths)
{
builder.Field(new FieldReflector<T>(path));
}
builder.Confirm("Is this your selection?\n{*}");
}
Validate();
return this._form;
}
有什么方法可以在调用构建后从生成的表单中删除此步骤?
var form = new FormBuilder<QuestionYourThinking>()
.OnCompletionAsync(async (context, state) =>
{
await context.PostAsync("L'exercice est maintenant terminé. A bientot !");
})
.Build();
只需使用带有 ActiveDelegate
参数的重载并将方法处理程序设为 return false
则不会显示确认消息。
return new FormBuilder<QuestionYourThinking>()
.AddRemainingFields()
.Confirm("No verification will be shown", state => false)
.Message("L'exercice est maintenant terminé. A bientot !")
.Build();
要发送消息,您可以使用流畅的方法 Message
。
您可以只在 FormBuilder 上使用 .AddRemainingFields()。它不会要求任何确认。 .Confirm 当您想为任何特定字段添加自定义确认消息时应使用。