验证选择字段

Validating selection field

我有一个 属性 有一个枚举,在我有 "help" 的枚举值之一中,如果用户选择该选项,我想做两件事:1 . 向用户发送帮助文本。 2、询问用户是要继续,还是要离开。我不知道怎么做。 非常感谢。

public enum ContentClassification
{
    Confidential_Restricted = 1 ,
    Confidential_Secret = 2,
    Public = 3,
    Strictly_Confidential = 4,
    help = 5
};

public ContentClassification ContentClassification { get;放; }

return 新的 FormBuilder() .Field(nameof(ContentClassification))

您可以多次启动 Form,这意味着如果您从第一个 Form 中获得 "Help" 选择,请启动另一个表格进行确认。

例如:

public enum ContentClassification
{
    Confidential_Restricted = 1,
    Confidential_Secret = 2,
    Public = 3,
    Strictly_Confidential = 4,
    help = 5
};

public enum Validating
{
    Continue,
    Leave
};

[Serializable]
public class Classification
{
    public ContentClassification? Choice;

    public static IForm<Classification> BuildForm()
    {
        return new FormBuilder<Classification>()
            .Message("You want to")
            .Field(nameof(Choice))
            .Build();
    }

    public Validating? Confirmation;

    public static IForm<Classification> BuildConfirmForm()
    {
        return new FormBuilder<Classification>()
            .Message("Send your message here")
            .Field(nameof(Confirmation))
            .Build();
    }
}

然后像这样创建您的 RootDialog

[Serializable]
public class RootDialog : IDialog<object>
{
    public Task StartAsync(IDialogContext context)
    {
        var form = new FormDialog<Classification>(new Classification(), Classification.BuildForm, FormOptions.PromptInStart, null);
        context.Call(form, this.GetResultAsync);

        return Task.CompletedTask;
    }


    private async Task GetResultAsync(IDialogContext context, IAwaitable<Classification> result)
    {
        var state = await result;
        if (state.Choice == ContentClassification.help)
        {
            var form = new FormDialog<Classification>(new Classification(), Classification.BuildConfirmForm, FormOptions.PromptInStart, null);
            context.Call(form, null); //change null to your result task here to handle the result.
        }
    }
}

您还需要实现GetResultAsync方法中其他选项的逻辑代码以及处理第二种形式BuildConfirmForm.

结果的逻辑代码