首页 > 解决方案 > 将动态 Formflow 值传递回 Luis

问题描述

我创建了一个动态表单流(很好)。此外,我需要获取用户选择的值并从 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.");
    }
}

它进入异常。谁能告诉我哪里出错了。

标签: c#botframeworkazure-language-understandingformflow

解决方案


推荐阅读