FormBuilderJson Class


Build a form by specifying messages, fields and confirmations through JSON Schema or programatically.

public sealed class FormBuilderJson : Microsoft.Bot.Builder.FormFlow.FormBuilderBase<Newtonsoft.Json.Linq.JObject>
type FormBuilderJson = class
    inherit FormBuilderBase<JObject>
Public NotInheritable Class FormBuilderJson
Inherits FormBuilderBase(Of JObject)


Define a form via JSON Schema with optional additional annotations that correspond to the attributes provided for C#.
%FormFlow makes use of a number of standard JSON Schema keywords include:

  • type -- Defines the fields type.
  • enum -- Defines the possible field values.
  • minimum -- Defines the minimum allowed value as described in NumericAttribute.
  • maximum -- Defines the maximum allowed value as described in NumericAttribute.
  • required -- Defines what fields are required.
  • pattern -- For string fields will be used to validate the entered pattern as described in PatternAttribute.

Templates and prompts use the same vocabulary as TemplateAttribute and PromptAttribute.
The property names are the same and the values are the same as those in the underlying C# enumeration.
For example to define a template to override the NotUnderstood template and specify a TemplateBaseAttribute.ChoiceStyle, you would put this in your schema:

"Templates":{ "NotUnderstood": { Patterns: ["I don't get it"], "ChoiceStyle":"Auto"}}

%Extensions defined at the root fo the schema

  • OnCompletion: script -- C# script with arguments (IDialogContext context, JObject state) for completing form.
  • References: [assemblyReference, ...] -- Define references to include in scripts. Paths should be absolute, or relative to the current directory. By default Microsoft.Bot.Builder.dll is included.
  • Imports: [import, ...] -- Define imports to include in scripts with usings. By default these namespaces are included: Microsoft.Bot.Builder, Microsoft.Bot.Builder.Dialogs, Microsoft.Bot.Builder.FormFlow, Microsoft.Bot.Builder.FormFlow.Advanced, System.Collections.Generic, System.Linq

%Extensions defined at the root of a schema or as a peer of the "type" property.

  • Templates:{TemplateUsage: { Patterns:[string, ...], &lt;args&gt; }, ...} -- Define templates.
  • Prompt: { Patterns:[string, ...] &lt;args&gt;} -- Define a prompt.

%Extensions that are found in a property description as peers to the "type" property of a JSON Schema.

  • DateTime:bool -- Marks a field as being a DateTime field.
  • Describe:string -- Description of a field as described in DescribeAttribute.
  • Terms:[string,...] -- Regular expressions for matching a field value as described in TermsAttribute.
  • MaxPhrase:int -- This will run your terms through GenerateTerms(String, Int32) to expand them.
  • Values:{ string: {Describe:string, Terms:[string, ...], MaxPhrase}, ...} -- The string must be found in the types "enum" and this allows you to override the automatically generated descriptions and terms. If MaxPhrase is specified the terms are passed through GenerateTerms(String, Int32).
  • Active:script -- C# script with arguments (JObject state)->bool to test to see if field/message/confirm is active.
  • Validate:script -- C# script with arguments (JObject state, object value)->ValidateResult for validating a field value.
  • Define:script -- C# script with arguments (JObject state, Field<JObject> field) for dynamically defining a field.
  • Before:[confirm|message, ...] -- Messages or confirmations before the containing field.
  • After:[confirm|message, ...] -- Messages or confirmations after the containing field.
  • {Confirm:script|[string, ...], ...templateArgs} -- With Before/After define a confirmation through either C# script with argument (JObject state) or through a set of patterns that will be randomly selected with optional template arguments.
  • {Message:script|[string, ...] ...templateArgs} -- With Before/After define a message through either C# script with argument (JObject state) or through a set of patterns that will be randomly selected with optional template arguments.
  • Dependencies:[string, ...]` -- Fields that this field, message or confirm depends on.

Scripts can be any C# code you would find in a method body. You can add references through "References" and using through "Imports". Special global variables include:

  • choice -- internal dispatch for script to execute.
  • state -- JObject form state bound for all scripts.
  • ifield -- IField<T> to allow reasoning over the current field for all scripts except %Message/Confirm prompt builders.
  • value -- object value to be validated for Validate.
  • field -- Field<T> to allow dynamically updating a field in Define.
  • context -- IDialogContext context to allow posting results in OnCompletion.

%Fields defined through this class have the same ability to extend or override the definitions programatically as any other field. They can also be localized in the same way.



Create a JSON form builder.


_form (Inherited from FormBuilderBase<T>)


Configuration (Inherited from FormBuilderBase<T>)


Build(Assembly, String)
Confirm(MessageDelegate<T>, ActiveDelegate<T>, IEnumerable<String>) (Inherited from FormBuilderBase<T>)
Confirm(PromptAttribute, ActiveDelegate<T>, IEnumerable<String>) (Inherited from FormBuilderBase<T>)
Confirm(String, ActiveDelegate<T>, IEnumerable<String>) (Inherited from FormBuilderBase<T>)
Field(IField<T>) (Inherited from FormBuilderBase<T>)
Field(String, ActiveDelegate<JObject>, ValidateAsyncDelegate<JObject>)
Field(String, ActiveDelegate<T>, ValidateAsyncDelegate<T>) (Inherited from FormBuilderBase<T>)
Field(String, PromptAttribute, ActiveDelegate<JObject>, ValidateAsyncDelegate<JObject>)
Field(String, PromptAttribute, ActiveDelegate<T>, ValidateAsyncDelegate<T>) (Inherited from FormBuilderBase<T>)
Field(String, String, ActiveDelegate<JObject>, ValidateAsyncDelegate<JObject>)
Field(String, String, ActiveDelegate<T>, ValidateAsyncDelegate<T>) (Inherited from FormBuilderBase<T>)
HasField(String) (Inherited from FormBuilderBase<T>)
Message(MessageDelegate<T>, ActiveDelegate<T>, IEnumerable<String>) (Inherited from FormBuilderBase<T>)
Message(PromptAttribute, ActiveDelegate<T>, IEnumerable<String>) (Inherited from FormBuilderBase<T>)
Message(String, ActiveDelegate<T>, IEnumerable<String>) (Inherited from FormBuilderBase<T>)
OnCompletion(OnCompletionAsyncDelegate<T>) (Inherited from FormBuilderBase<T>)
Prompter(PromptAsyncDelegate<T>) (Inherited from FormBuilderBase<T>)

Applies to