C# n如果未输入有效图像,则继续循环: [Serializable] public class PhotoInputDialog : IDialog<string> { public ICustomInputValidator<IMessageActivity> Validator { get; private set; } public string InputPrompt { get; private set; } public string WrongInputPrompt { get; private set; } public static PhotoInputDialog Create (string inputPrompt, string wrongInputPrompt, ICustomInputValidator<IMessageActivity> validator) { return new PhotoInputDialog() { InputPrompt = inputPrompt, WrongInputPrompt = wrongInputPrompt, Validator = validator }; } public async Task StartAsync(IDialogContext context) { await context.PostAsync(InputPrompt); context.Wait(InputGiven); } private async Task InputGiven(IDialogContext context, IAwaitable<IMessageActivity> result) { var message = await result; if (!Validator.IsValid(message)) { await context.PostAsync(WrongInputPrompt); context.Wait(InputGiven); } else context.Done(message.Attachments.First().ContentUrl); } } [可序列化] 公共类PhotoInputDialog:IDialog { 公共ICustomInputValidator验证程序{get;private set;} 公共字符串输入提示符{get;private set;} 公共字符串错误输入提示{get;private set;} 公共静态光电输入对话框创建 (字符串inputPrompt、字符串错误inputPrompt、ICustomInputValidator验证器) { 返回新的PhotoInputDialog() {InputPrompt=InputPrompt,ErrorInputPrompt=ErrorInputPrompt,Validator=Validator}; } 公共异步任务StartAsync(IDialogContext上下文) { wait context.PostAsync(InputPrompt); context.Wait(InputGiven); } 私有异步任务输入给定(IDialogContext上下文,IAwaitable结果) { var消息=等待结果; 如果(!Validator.IsValid(消息)) { wait context.PostAsync(错误输入提示); context.Wait(InputGiven); } 其他的 context.Done(message.Attachments.First().ContentUrl); } }

C# n如果未输入有效图像,则继续循环: [Serializable] public class PhotoInputDialog : IDialog<string> { public ICustomInputValidator<IMessageActivity> Validator { get; private set; } public string InputPrompt { get; private set; } public string WrongInputPrompt { get; private set; } public static PhotoInputDialog Create (string inputPrompt, string wrongInputPrompt, ICustomInputValidator<IMessageActivity> validator) { return new PhotoInputDialog() { InputPrompt = inputPrompt, WrongInputPrompt = wrongInputPrompt, Validator = validator }; } public async Task StartAsync(IDialogContext context) { await context.PostAsync(InputPrompt); context.Wait(InputGiven); } private async Task InputGiven(IDialogContext context, IAwaitable<IMessageActivity> result) { var message = await result; if (!Validator.IsValid(message)) { await context.PostAsync(WrongInputPrompt); context.Wait(InputGiven); } else context.Done(message.Attachments.First().ContentUrl); } } [可序列化] 公共类PhotoInputDialog:IDialog { 公共ICustomInputValidator验证程序{get;private set;} 公共字符串输入提示符{get;private set;} 公共字符串错误输入提示{get;private set;} 公共静态光电输入对话框创建 (字符串inputPrompt、字符串错误inputPrompt、ICustomInputValidator验证器) { 返回新的PhotoInputDialog() {InputPrompt=InputPrompt,ErrorInputPrompt=ErrorInputPrompt,Validator=Validator}; } 公共异步任务StartAsync(IDialogContext上下文) { wait context.PostAsync(InputPrompt); context.Wait(InputGiven); } 私有异步任务输入给定(IDialogContext上下文,IAwaitable结果) { var消息=等待结果; 如果(!Validator.IsValid(消息)) { wait context.PostAsync(错误输入提示); context.Wait(InputGiven); } 其他的 context.Done(message.Attachments.First().ContentUrl); } },c#,botframework,C#,Botframework,工作原理: 提示用户输入 等待拍照 验证输入 如果有效,则调用context.Done;如果失败,则向用户显示消息并等待再次输入 当我创建对话框时,我提交了一个用于验证结果的验证器类,下面是我创建的用于验证特定长度的文本输入的类。它不是100%必需的,但现在它很好,可以重复使用: [Serializable()] public class TextCustomInputValidator : ICustomInputValidator<string> { private in

工作原理:

  • 提示用户输入
  • 等待拍照
  • 验证输入
  • 如果有效,则调用context.Done;如果失败,则向用户显示消息并等待再次输入
  • 当我创建对话框时,我提交了一个用于验证结果的验证器类,下面是我创建的用于验证特定长度的文本输入的类。它不是100%必需的,但现在它很好,可以重复使用:

    [Serializable()]
    public class TextCustomInputValidator : ICustomInputValidator<string>
    {
        private int MinLength, MaxLength;
        public TextCustomInputValidator(int minLength, int maxLength)
        {
            MinLength = minLength;
            MaxLength = maxLength;
        }
        public bool IsValid(string input)
        {
            return input.Length >= MinLength && input.Length <= MaxLength;
        }
    }
    
    [Serializable()]
    公共类TextCustomInputValidator:ICustomInputValidator
    {
    私有int MinLength、MaxLength;
    公共文本CustomInputValidator(int minLength,int maxLength)
    {
    MinLength=MinLength;
    MaxLength=MaxLength;
    }
    公共bool有效(字符串输入)
    {
    
    return input.Length>=MinLength&&input.Length您可以使用DateTimePrompt,或者如果您确实需要更多控制,可以使用一个简单的TextPrompt并为其提供自定义验证程序:

    AddDialog(new DateTimePrompt(nameof(DateTimePrompt), DateTimePromptValidator));
    
    在对话框中,您可以启动提示,提供重试提示,以便在重试失败时显示单独的消息:

    return await stepcontext.PromptAsync(nameof(DateTimePrompt), new PromptOptions
                {
                    Prompt = MessageFactory.Text("Please enter the date."),
                    RetryPrompt = MessageFactory.Text("Please enter a valid date")
    
                }, cancellationtoken);
    

    如果你想用多种语言处理高级的约会案例,我建议你看看微软,它目前为LUIS:Language Understanding Intelligent Service中的预构建实体提供了支持。

    你可以使用DateTimePrompt,或者如果你真的想更多地控制一个简单的TextPrompt,并提供一个自定义验证器f或者它:

    AddDialog(new DateTimePrompt(nameof(DateTimePrompt), DateTimePromptValidator));
    
    在对话框中,您可以启动提示,提供重试提示,以便在重试失败时显示单独的消息:

    return await stepcontext.PromptAsync(nameof(DateTimePrompt), new PromptOptions
                {
                    Prompt = MessageFactory.Text("Please enter the date."),
                    RetryPrompt = MessageFactory.Text("Please enter a valid date")
    
                }, cancellationtoken);
    
    如果你想处理像多种语言一样的高级约会案例,我建议你看看微软,它目前为LUIS:Language Understanding Intelligent Service中的预构建实体提供支持

    [Serializable()]
    public class TextCustomInputValidator : ICustomInputValidator<string>
    {
        private int MinLength, MaxLength;
        public TextCustomInputValidator(int minLength, int maxLength)
        {
            MinLength = minLength;
            MaxLength = maxLength;
        }
        public bool IsValid(string input)
        {
            return input.Length >= MinLength && input.Length <= MaxLength;
        }
    }
    
    AddDialog(new DateTimePrompt(nameof(DateTimePrompt), DateTimePromptValidator));
    
    return await stepcontext.PromptAsync(nameof(DateTimePrompt), new PromptOptions
                {
                    Prompt = MessageFactory.Text("Please enter the date."),
                    RetryPrompt = MessageFactory.Text("Please enter a valid date")
    
                }, cancellationtoken);