使用微软机器人框架的 FormFlow ChatBot

FormFlow ChatBot using microsoft bot framework

我正在尝试使用 Microsoft Bot Framework 构建聊天机器人。我正在使用 formflow 构建一个用户引导的机器人。我无法找到构建机器人的正确方法,我在其中显示一组不同的选项供选择。假设我提供的第一个选项是支持、联系方式和其他信息,当用户选择时我必须显示一组选项,当他选择联系方式时我会显示另一组选项,另一组用于其他信息。我该怎么做? 谁能推荐一下?

namespace Microsoft.Bot.Sample.FormBot
{
public enum SupportOptions
{
    Specific,ErrorInformation,ContactInformation
};

[Serializable]
public class Specific
{        
    public ToolOptions? Tools;        
}

public enum ToolOptions
{
    Merge,Extend,Generate,Calculate,Memory
}

[Serializable]
public class SupportBox
{

    public SupportOptions? Sandwich;        

    public static IForm<SupportBox> BuildForm()
    {
        OnCompletionAsyncDelegate<SupportBox> processOrder = async (context, state) =>
        {
            await context.PostAsync("This is the end of the form, you would give a final confirmation, and then start the ordering process as needed.");
        };

        return new FormBuilder<SupportBox>()
                .Message("Welcome to the Support Bot!")
                .OnCompletion(processOrder)
                .Build();
    }
};
}

当用户第一次向机器人打招呼时,它会要求他在 Specfic、ErrorInformation 和 Contact 之间进行选择。现在,当他选择 Specific support 时,我想显示 ToolOptions。

Assume the first options i provide are support,contact details and other information, when user selects I have to display a set of options and when he selects contact details I would display another set of options, another set for other information. How would I do this?

如果您想有条件地显示 tooloption 和其他字段,您可以尝试使用 SetActive 方法来指定只有在用户选择具体选项。以下代码片段供您参考。

return new FormBuilder<SupportBox>()
        .Message("Welcome to the Support Bot!")
        .Field(nameof(supportoption))
        .Field(new FieldReflector<SupportBox>(nameof(tooloption))
        .SetActive(state=>state.supportoption== SupportOptions.Specific)
        )
        .Field(new FieldReflector<SupportBox>(nameof(contactinformation))
        .SetActive(state => state.supportoption == SupportOptions.ContactInformation)
        )
        .OnCompletion(processOrder)
        .Build();

测试结果: