我试图使用Azure Bot框架创建一个机器人,它将要求一个未知数量的复杂对象(每个都需要三个响应)。但我不知道如何为根形式中的每个复杂对象创建表单。见http://docs.botframework.com/sdkreference/csharp/forms.html。 它指出: "为了处理复杂对象列表,您需要为顶级C#类创建一个表单,并为复杂对象创建一个表单。您可以使用Dialogs系统一起组合表单。" 这就是我不知道该怎么做。
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();
}
}
控制器:
[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);
}
}
答案 0 :(得分:2)
您可以使用Chain
课程中的方法撰写对话框。由于这些方法也支持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));
}
您也可以手动链接对话框:
var dlg = Chain.From(() => FormDialog.FromForm(SupportRequest.BuildForm))
.ContinueWith<SupportRequest,Declaration>(async (ctx, sr) =>
{
var res = await sr;
return FormDialog.FromForm(Declaration.BuildForm);
});