Я создал динамический поток форм (который подходит нормально).Далее мне нужно получить значение, выбранное пользователем, и вернуть ответ от 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.");
}
}
Идет в исключении.Кто-нибудь может сказать, где я иду не так.