1

I currently have a chatbot running in visual studio using Microsoft's bot framework in the language c#. I integrated LUIS into the bot and I'm wondering how can I make it so that a FormFlow similar to this example appears on a specific intent.

So far this is the code for my Form:

internal static IDialog<InfoGroup> MakeRootDialog()
    {
        return Chain.From(() => FormDialog.FromForm(InfoGroup.BuildForm));
    }
public enum GroupOptions
{
    A, B, C, D, E, F, G, H
};
[Serializable]
public class InfoGroup
{
    public GroupOptions? groupId;

    public static IForm<InfoGroup> BuildForm()
    {
        return new FormBuilder<InfoGroup>()
                .Message("Please select an option")
                .Build();
    }
};

And I'm trying to send it form my LUIS intent method like so:

[LuisIntent("SpecificGroup")]
    public async Task SpecificGroupIntent(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
    {
        await context.PostAsync(FormDialog.FromForm(InfoGroup.BuildForm));
        context.Wait(MessageReceived);
        return;
    }

This is obviously not the correct way to call the form, how can I make it so that a form appears as a response called directly from my SpecificGroupIntent() method? Any help will be greatly appreciated. After the form is filled I want to use the option that the user selected to display text accordingly.

4

1 回答 1

2

您可以从 luis intent 方法调用 formflow 构建器,例如使用 context.Call() 方法从父对话框调用对话框。您还需要指定填写表单后将执行的方法。

例如:通过创建 InfoGroup(Your form) 类型的 FormDialog 并指定要在它之后执行的方法来调用 formbuilder。

InfoGroup form = new InfoGroup();    
FormDialog<InfoGroup> InfoGroupform = new FormDialog<InfoGroup>(form, InfoGroup.BuildForm, FormOptions.PromptInStart);
context.Call(InfoGroupform, InfoGroupFormSubmitted);

InfoGroupFormSubmitted 是填写表单后将调用的方法。你需要这个,因为如果你使用 context.Call() 方法,你需要为它指定一个 resumeAfter 方法。在这个 InfoGroupFormSubmitted 方法中,您可以确认表单是否正确填写或用户退出,您可以捕获异常并显示用户退出的位置。

public static async Task InfoGroupFormSubmitted(IDialogContext context, IAwaitable<InfoGroup> result)
{
        try
        {
             var query = await result;
             context.PostAsync("Your choice has been recorded.");
        } 
        catch (FormCanceledException<InfoGroup> e)
        {
              string reply;
              if (e.InnerException == null)
              {
                    reply = $"You quit on {e.Last}--maybe you can finish next time!";
              }
              else
              {
                    reply = $"Sorry, I've had a short circuit.  Please try again.";
              }
              context.Done(true);
              await context.PostAsync(reply);
        }
}
于 2018-04-11T05:43:44.273 回答