我正在研究 bot 框架技术,在我当前的一个项目中,我只想在用户键入“ivr”或“IVR”时才允许用户,否则它会向用户显示一些反馈。
为此,我在下面写了几行代码,但是这段代码向用户显示了一些错误的输出。即使用户第一次输入 ivr 或 IVR,它也会向用户显示反馈,但从第二次开始,它会正常工作。
[Serializable]
class Customer
{
//Create Account Template
[Prompt("Please send any of these commands like **IVR** (or) **ivr**.")]
public string StartingWord;
public static IForm<Customer> BuildForm()
{
OnCompletionAsyncDelegate<Customer> accountStatus = async (context, state) =>
{
await Task.Delay(TimeSpan.FromSeconds(5));
await context.PostAsync("We are currently processing your account details. We will message you the status.");
};
var builder = new FormBuilder<Customer>();
return builder
//.Message("Welcome to the BankIVR bot! To start an conversation with this bot send **ivr** or **IVR** command.\r \n if you need help, send the **Help** command")
.Field(nameof(Customer.StartingWord), validate: async (state, response) =>
{
var result = new ValidateResult { IsValid = true, Value = response };
string str = (response as string);
if (str.ToLower() != "ivr")
{
result.Feedback = "I'm sorry. I didn't understand you.";
result.IsValid = false;
return result;
}
else if (str.ToLower() == "ivr")
{
result.IsValid = true;
return result;
}
else
{
return result;
}
})
.OnCompletion(accountStatus)
.Build();
}
};
请告诉我如何使用表单流概念解决此问题。
-普拉迪普