检查是否在Adaptive Card Bot框架C#中填写了输入表单 [英] Check if an input form is filled in a Adaptive Card bot framework c#

查看:95
本文介绍了检查是否在Adaptive Card Bot框架C#中填写了输入表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以检查自适应卡中的输入表格是否填写警告消息. 我当前正在使用自适应卡来收集机器人应用程序中的用户输入,我已经添加了isRequired以进行输入验证,但是当我单击提交"时它不会给出任何警告消息,因此不会转到下一种方法. 用户按下提交后,我要确保该表单不为空

Can we check whether the input form in an adaptive card is filled or not with a warning message. I am currently using an adaptive card to gather user input in bot application,I have already added isRequired for input validation but it doesnot give any warning message instead when I click on submit it doesnot go to the next method. As soon as the user presses submit I want to make sure that the form is not empty

推荐答案

如果您有这样的自适应卡(请注意输入的ID):

If you have an Adaptive Card like this (notice the ID given to the input):

var card = new AdaptiveCard
{
    Body =
    {
        new AdaptiveTextBlock("Adaptive Card"),
        new AdaptiveTextInput { Id = "text" },
    },
    Actions = {
        new AdaptiveSubmitAction { Title = "Submit" } },
    },
};

您可以像这样验证通过Submit操作发送的值:

You can validate the value sent through the submit action like this:

if (string.IsNullOrEmpty(turnContext.Activity.Text))
{
    dynamic value = turnContext.Activity.Value;
    string text = value["text"];   // The property will be named after your input's ID
    var emailRegex = new Regex(@"^\S+@\S+$");   // This is VERY basic email Regex. You might want something different.

    if (emailRegex.IsMatch(text))
    {
        await turnContext.SendActivityAsync($"I think {text} is a valid email address");
    }
    else
    {
        await turnContext.SendActivityAsync($"I don't think {text} is a valid email address");
    }
}

使用正则表达式验证电子邮件可能会变得非常复杂,因此我采用了一种简单的方法.您可以在此处阅读有关电子邮件正则表达式的更多信息:如何验证使用正则表达式的电子邮件地址?

Validating email with regex can get very complicated and I've taken a simple approach. You can read more about email Regex here: How to validate an email address using a regular expression?

这篇关于检查是否在Adaptive Card Bot框架C#中填写了输入表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆