.net core C#Bot对话框步骤验证

.net core C#Bot对话框步骤验证,.net-core,botframework,waterfall,.net Core,Botframework,Waterfall,嗨,我正在使用.net内核实现一个机器人。我使用瀑布对话框来进行对话。问题是,在一个步骤和另一个步骤之间,我需要验证数据库接收到的信息。我尝试在提示选项中使用验证,但我无法做到这一点。有人能帮我吗。这是我的密码 公共类检测问题步骤:ComponentDialog { //为公司选择提示定义“完成”响应。 private const string DoneOption=“完成”; //为对话框内跟踪的值定义值名称。 private const string UserInfo=“value User

嗨,我正在使用.net内核实现一个机器人。我使用瀑布对话框来进行对话。问题是,在一个步骤和另一个步骤之间,我需要验证数据库接收到的信息。我尝试在提示选项中使用验证,但我无法做到这一点。有人能帮我吗。这是我的密码

公共类检测问题步骤:ComponentDialog
{
//为公司选择提示定义“完成”响应。
private const string DoneOption=“完成”;
//为对话框内跟踪的值定义值名称。
private const string UserInfo=“value UserInfo”;
公共检测问题步骤()
:base(名称(DetectProblemStep))
{
AddDialog(新建文本提示(名称)(文本提示));
AddDialog(newnumbercompt(nameof(numbercompt)));
AddDialog(新建ReviewSelectionDialog());
AddDialog(新建WaterWallDialog)(名称(WaterWallDialog),新建WaterWallStep[]
{
名称步异步,
EmailStepAsync
}));
InitialDialogId=nameof(WaterWallDialog);
}
专用静态异步任务名称StepAsync(WaterCallStepContext stepContext,CancellationToken CancellationToken)
{
//创建一个对象,以便在对话框中收集用户信息。
stepContext.Values[UserInfo]=newuserprofile();
var promptOptions=newpromptoptions{Prompt=MessageFactory.Text(“请输入您的姓名”),
Validations=nameof(NameValidation)
};
//请用户输入他们的姓名。
返回wait wait stepContext.PromptAsync(名称(TextPrompt)、提示、取消令牌);
}
专用静态异步任务EmailStepAsync(WaterWallStepContext stepContext,CancellationToken CancellationToken)
{
//创建一个对象,以便在对话框中收集用户信息。
stepContext.Values[UserInfo]=newuserprofile();
var prompoptions=新的prompoptions
{
Prompt=MessageFactory.Text(“请输入您的电子邮件”),
};
//请用户输入他们的姓名。
返回wait wait stepContext.PromptAsync(名称(TextPrompt)、提示、取消令牌);
}
公共任务名称验证(PromptValidatorContext promptContext,CancellationToken CancellationToken)
{
返回Task.FromResult(false);
}
}

}

不幸的是,文档中对此还很不清楚

Validations
-对象用于将对象传递给自定义验证器函数。当您希望在运行时更改验证时,这非常有用。也就是说,验证取决于将提示添加到DialogSet(在构造函数中执行)时没有的信息

如果在将提示添加到对话框集中时可以确定验证,则只需执行以下操作:

AddDialog(new TextPrompt(nameof(TextPrompt), NameValidation));
但是,如果您想在实际调用PromptAsync()时向提示中添加额外的验证,您可以向验证器传递任何内容,如下所示:

private static async Task<DialogTurnResult> NameStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
    // Create an object in which to collect the user's information within the dialog.
    stepContext.Values[UserInfo] = new UserProfile();

    var validations = new AdditionalValidationOptions { MinLength = 3 };

    var promptOptions = new PromptOptions { Prompt = MessageFactory.Text("Please enter your name."),
        Validations = validations 
    };

    // Ask the user to enter their name.
    return await stepContext.PromptAsync(nameof(TextPrompt), promptOptions, cancellationToken);
}

public Task<bool> NameValidation(PromptValidatorContext<string> promptContext, CancellationToken cancellationToken)
{
    var validations = (AdditionalValidationOptions)promptContext.Options.Validations;

    return Task.FromResult(promptContext.Recognized.Value >= validations.MinLength);
}

为什么不把瀑布式的一个步骤作为验证步骤呢?在所选瀑布式步骤的“开始”处,使用上一步中的信息调用数据库,然后发送到cx“确认!”或者‘请等一下!’,然后继续下一步。
public class AdditionalValidationOptions 
{
    public int MinLength {get; set;}
}