c# - Azure Bot Framework FormFlow 复杂表单

标签 c# azure bots botframework

我正在尝试使用 Azure 机器人框架创建一个机器人,该机器人将请求未知数量的复杂对象(每个对象需要三个响应)。但我不知道如何为根表单中的每个复杂对象创建表单。请参阅http://docs.botframework.com/sdkreference/csharp/forms.html 。 它指出: “为了处理一系列复杂对象,您需要为顶级 C# 类创建一个表单,并为复杂对象创建一个表单。您可以使用对话框系统将表单组合在一起。” 这就是我不知道该怎么做。

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);
        }
    }

最佳答案

您可以使用 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);
            });

关于c# - Azure Bot Framework FormFlow 复杂表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37157347/

相关文章:

python - 如何让 Discord 机器人在 on_message 中使用自定义表情符号响应消息

node.js - 如何让不和谐机器人回答我的命令

c# - 套接字只读取断点设置

c# - 如何获取唯一对象引用作为列表中项目的字符串

azure - Azure 云服务器 2019 上出现 "The RPC server is unavailable"错误

azure - 错误: The received token is of incorrect token type -- What should the token look like?

javascript - 机器人不等待 react 或消息

c# - 将包含大量 "locks"的代码重构为更多无锁代码

c# - c#中有距离、速度、加速度等类库吗?

azure - 服务总线触发器 : Could not load file or assembly 'Microsoft.Azure.ServiceBus'