![](/img/trans.png)
[英]How to set field value based on the value of other fields in FormFlow in botframework?
[英]Validating a field in a FormFlow
碼
[Serializable]
public class FAQConversation
{
[Prompt("What product is your concern? {||}")]
public VASetting.SupportedProducts Products { get; set; }
[Prompt("Okay, tell me what is your question. Enter \"back\" to go back to Products Selection.")]
public string Inquiry { get; set; }
public static IForm<FAQConversation> BuildForm()
{
return new FormBuilder<FAQConversation>()
.AddRemainingFields()
.Field(new FieldReflector<FAQConversation>(nameof(Inquiry)).SetValidate(AnswerInquiry))
.Message("Hi this is Test Virtual Assistant")
.Build();
}
private static async Task<ValidateResult> AnswerInquiry(FAQConversation state, object value)
{
var asString = value as String;
var vaConfig = new SmartCareSetting(state.Products);
var result = new ValidateResult() { IsValid = false, Value = value };
if (!string.IsNullOrEmpty(asString))
{
var luisService = new LuisService(new LuisModelAttribute(vaConfig.AppID, vaConfig.SubscriptionKey, domain: vaConfig.HostName));
var luisResult = await luisService.QueryAsync(asString, CancellationToken.None);
result.Feedback = luisResult.TopScoringIntent.Intent.ToString();
}
return result;
}
}
我上面的機器人代碼顯示了下面的對話。
我正在使用FormFlow
和Bot Framework創建一個簡單的查詢機器人。 我正在通過LUIS驗證“ Inquiry
字段,並返回處理意圖。 我得到正確的意圖,在這種情況下是EXC01
。 之后,我想知道為什么我仍然得到Inquiry
提示。
問題:
1.確認查詢意圖后如何完成FormFlow
?
2.我想處理返回的Intent,但不顯示給用戶。 我將使用Intent字符串查詢數據庫。 我可以在BuildForm()
執行此操作嗎?
確認查詢意圖后如何完成FormFlow?
在驗證函數AnswerInquiry
,我們可以發現ValidateResult的 IsValid屬性始終為false
,這會導致問題。 在將返回的意圖分配為反饋后,可以將IsValid屬性設置為true
。 以下代碼段對我有用,您可以參考它。
private static async Task<ValidateResult> AnswerInquiry(FAQConversation state, object value)
{
var asString = value as String;
var vaConfig = new SmartCareSetting(state.Products);
var result = new ValidateResult() { IsValid = false, Value = value };
if (!string.IsNullOrEmpty(asString))
{
var luisService = new LuisService(new LuisModelAttribute(vaConfig.AppID, vaConfig.SubscriptionKey, domain: vaConfig.HostName));
var luisResult = await luisService.QueryAsync(asString, CancellationToken.None);
result.Feedback = luisResult.TopScoringIntent.Intent.ToString();
//set IsValid to true
result.IsValid = true;
}
return result;
}
我想處理返回的Intent,但不顯示給用戶。 我將使用Intent字符串查詢數據庫。 我可以在BuildForm()中執行此操作嗎?
獲得返回的意圖后,如果您想基於返回的意圖從數據庫中查詢記錄,則可以在驗證函數中進行操作。
測試結果:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.