简体   繁体   中英

FormFlow ChatBot using microsoft bot framework

I am trying build a chatbot using microsoft bot framework. I am building a user guided bot using formflow. I am unable to find a correct way yo build a bot where I display a different set of options for the selection. 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? Can anyone suggest?

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

When the user first says hi to the bot, it would ask him choose between Specfic,ErrorInformation and Contact. Now, when he selects Specific support, I want to display 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?

If you'd like to display tooloption and other field(s) conditionally, you can try to use the SetActive method to specify that the field should only be enabled if user selected the specific option. The following code snippet is for your reference.

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

Test result:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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