我创建了一个动态表单流(可以正常运行)。另外,我需要获取用户选择的值,并从LUIS返回答案。
我的动态表单流为:
[Serializable]
public class Troubleshooting
{
public List<TroubleShootingQuestion> questions
{
get;
set;
}
public static IForm<Troubleshooting> BuildForm()
{
var menuItems = DynamicGenericQuestions.GetAllGenericOptions();
var builder = new FormBuilder<Troubleshooting>();
//object MenuItems = null;
builder.Field(new FieldReflector<Troubleshooting>(nameof(questions)).SetType(null).SetDefine((state, field) =>
{
foreach (var item in menuItems)
{
field.AddDescription(item, new DescribeAttribute()
{
Title = item.GenericQuestion,
Description = item.GenericQuestion
//Image = item.ItemImage
}).AddTerms(item, item.GenericQuestion);
}
return Task.FromResult(true);
}).SetPrompt(new PromptAttribute("Please choose your query. \n {||} \n")
{
ChoiceStyle = ChoiceStyleOptions.Auto
}).SetAllowsMultiple(false)).AddRemainingFields();
return builder.Build();
}
}
[Serializable]
public class TroubleShootingQuestion
{
public string GenericQuestion
{
get;
set;
}
}
public class DynamicGenericQuestions
{
public static List<TroubleShootingQuestion> GetAllGenericOptions()
{
return new List<TroubleShootingQuestion>() {
new TroubleShootingQuestion() {
GenericQuestion = "How to migrate the site?"
},
new TroubleShootingQuestion() {
GenericQuestion = "My site is not opening."
},
new TroubleShootingQuestion() {
GenericQuestion = "Home page is not loading"
},
new TroubleShootingQuestion() {
GenericQuestion = "No Preference"
},
};
}
}
在LUIS中,我已执行以下操作:
[LuisIntent("Troubleshooting")]
public async Task TroubleshootingIntent(IDialogContext context, LuisResult result)
{
var TroubleshootingForm = new FormDialog<Troubleshooting>(new Troubleshooting(), Troubleshooting.BuildForm, FormOptions.PromptInStart, null);
context.Call<Troubleshooting>(TroubleshootingForm, TroubleshootingFormCompleteAsync);
//await this.ShowLuisResult(context, result);
}
private async Task TroubleshootingFormCompleteAsync(IDialogContext context, IAwaitable<Troubleshooting> result)
{
try
{
var TroubleshootingFormData = await result;
await context.PostAsync(TroubleshootingFormData.ToString());
await context.PostAsync(result.ToString());
context.Wait(MessageReceived);
}
catch (FormCanceledException<Troubleshooting> e)
{
string reply;
if (e.InnerException == null)
{
reply = $"You quit the request. Maybe you can finish next time!";
}
else
{
reply = "Sorry, the request could not be processed. Please try again.";
}
await context.PostAsync(reply);
}
catch (Exception)
{
await context.PostAsync("Sorry, the request could not be processed. Please try again.");
}
}
例外。谁能告诉我我要去哪里错了。