Я использую форму ввода AdaptiveCard в своем чате Microsoft для получения информации о пользователе.Есть ли способ проверить TextInput?Как валидатор поля asp.net?или любое свойство в C #, с помощью которого я могу проверить все виды TextInput AdaptiveCard.
var card = new AdaptiveCard()
{
Body = new List<CardElement>()
{
new TextBlock() { Text = "Email" },
new TextInput()
{
Id = "Email",
Placeholder = "Enter your email",
Style = TextInputStyle.Email,
IsRequired = true
},
new TextBlock() { Text = "Mobile" },
new TextInput()
{
Id = "Mobile",
Placeholder = "+(country code)(Your Phone Number)",
Style = TextInputStyle.Tel,
IsRequired = true
},
},
Actions = new List<ActionBase>()
{
new SubmitAction()
{
Title = "Submit"
}
}
};
Attachment attachment = new Attachment()
{
ContentType = AdaptiveCard.ContentType,
Content = card
};
Извлечение данных из Adaptive Card MessageReceivedAsync
protected async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> result)
{
var message = await result;
PersonalInfo userinfo = new PersonalInfo();
if (message.Value != null)
{
// Got an Action Submit
dynamic formvalue = message.Value;
if (formvalue != null)
{
userinfo.Email = GetValue((JObject)formvalue, "Email");
userinfo.Phone = GetValue((JObject)formvalue, "Mobile");
var error = GetErrorMessage(userinfo); // Validation
IMessageActivity replyMessage = context.MakeMessage();
if (!string.IsNullOrEmpty(error))
{
replyMessage.Text = error;
await context.PostAsync(replyMessage);
}
else
{
// Save Information in service bus
if (sbConnectionString != "" && queueName != "")
await MainAsync(sbConnectionString, queueName, userinfo);
replyMessage.Text = "Thank you for taking the time! \n We've submitted your query and an agent will get back to you soon. \n\n Have a great day!";
await context.PostAsync(replyMessage);
context.Done(true);
}
}
}
}
// For Validating the Adaptive Card **GetErrorMessage** function pass userinfo
GetErrorMessage(PersonalInfo personalInfo){
if (string.IsNullOrWhiteSpace(personalInfo.Email)
|| string.IsNullOrWhiteSpace(personalInfo.Phone))
return "Please fill out all the fields";
return string.Empty;
}