简体   繁体   English

Azure Bot Framework FormFlow复杂表单

[英]Azure Bot Framework FormFlow complex forms

I'm trying to create a bot with the Azure Bot Framework that will ask for an unknown amount of complex objects (each will require three responses). 我正在尝试使用Azure Bot Framework创建一个机器人,该机器人将询问未知数量的复杂对象(每个对象都需要三个响应)。 But I don't know how to create a form for each of the complex objects within the rootform. 但是我不知道如何为rootform中的每个复杂对象创建一个表单。 See http://docs.botframework.com/sdkreference/csharp/forms.html . 请参阅http://docs.botframework.com/sdkreference/csharp/forms.html It states: "In order to handle a list of complex objects, you need to create a form for the top level C# class and also one for the complex object. You can use the Dialogs system to compose the forms together." 它指出:“为了处理一组复杂对象,您需要为顶级C#类创建一个表单,还需要为复杂对象创建一个表单。您可以使用Dialogs系统将这些表单组合在一起。” That is what I dont know how to do. 那就是我不知道该怎么做。

public enum SystemSelection { SharePoint, BizTalk, Azure, Office365 };

public enum RequestType { Bug, SupportRequest, Question };

public enum Importance { Blocking, High, Medium, Low };

[Serializable]
class Declaration
{
    public string Type;
    public string Amount;
    public string Date;

    public static IForm<Declaration> BuildForm()
    {
        return new FormBuilder<Declaration>()
                .Message("Add a declaration")
                .Build();
    }
}

[Serializable]
class SupportRequest
{

    public SystemSelection? SystemSelection;
    public RequestType? RequestType;
    public Importance? Importance;

    public List<Declaration> Declarations;

    public static IForm<SupportRequest> BuildForm()
    {
        IForm<Declaration> aForm = new FormBuilder<Declaration>().Message("Add declaration").Build();

        // now what?

        return new FormBuilder<SupportRequest>()
                .Message("Welcome to the simple support bot!")
                .Build();
    }
}

Controller: 控制器:

  [BotAuthentication]
  public class MessagesController : ApiController
{
    internal static IDialog<SupportRequest> MakeRootDialog()
    {
        // change something here??
        return Chain.From(() => FormDialog.FromForm(SupportRequest.BuildForm));
    }

    public async Task<Message> Post([FromBody]Message message)
    {
        if (message.Type == "Message")
        {
            return await Conversation.SendAsync(message, MakeRootDialog);
        }
        else
        {
            return HandleSystemMessage(message);
        }
    }

You can compose your Dialogs using methods from Chain class. 您可以使用Chain类中的方法来编写对话框。 Since those methods also support LINQ syntax, you can write something like this in your MakeRootDialog to execute SupportRequest dialog and Decalaration dialog in sequence: 由于这些方法也支持LINQ语法,你可以写这样的事情在你的MakeRootDialog执行SupportRequest对话和Decalaration顺序对话框:

    internal static IDialog<SupportRequest> MakeRootDialog()
    {
        var dlg = from x in FormDialog.FromForm(SupportRequest.BuildForm)
                  from y in FormDialog.FromForm(Declaration.BuildForm)
                  select x;
        return dlg;
        // return Chain.From(() => FormDialog.FromForm(SupportRequest.BuildForm));
    }

You can also chain dialogs manually like this: 您也可以像这样手动链接对话框:

        var dlg = Chain.From(() => FormDialog.FromForm(SupportRequest.BuildForm))
            .ContinueWith<SupportRequest,Declaration>(async (ctx, sr) =>
            {
                var res = await sr;
                return FormDialog.FromForm(Declaration.BuildForm);
            });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM