Chat Interaction - Form Def Property 2
Indexβ
Overviewβ
The form_def input property in the chat interaction activity is a JSON string which defines default values for the form which the user will fill out. Using the form_def property in the chat interaction activity, you can pre-define what values will be displayed to the user to any type of form you create in the Pia Form Editor screen.
The form_def property in chat interaction activity is displayed as below in the package editor:
Here is an example of a basic package that uses form_def property:
# Orchestrator package
conditions:
- name: 'client_filter'
optMode: 'OptOut'
category: 'Testing'
- name: 'chat'
option_button: 'Test Package'
option_text: 'This is a text package.'
option_category: 'Test Category'
steps:
- task: inline_powershell
alias: form_def_builder
inputs:
script: |
$formDef = @{
StaffGroup = "Pia All Staffs"
}
return @{FormDef = $formDef}
- task: chat_interaction
inputs:
text: 'Form Definition test'
form_name: 'text_form'
form_display_mode: 'Embed'
form_def: =form_def_builder.FormDef
In the above example, form_def has been used to pass the field value in a text form. When the package runs in the Pia chatbot, the user will see a text form with the given value:
Property Behaviourβ
The main purpose of the form_def property in the chat interaction activity is to pass values to the form. You can use the inline_powershell activity to generate these values dynamically.
The form_def property is not a mandatory field in the chat interaction activity. In the form template, you may set a default value for any fields you create. The default value for a form can be defined in the form editor by clicking on the edit icon for each field type.
When specifying the form_def property on the chat interaction activity, any default values you set in the form_def for a field will override the default values in the form template for that field.
If the form field is missing both the form_def and the default value, then it will either show blank fields or the text 'Place holder Option' based on what type of field it is.
Examplesβ
Header Textβ
Example of passing Header text field options via form_def property, JSON format:Β
- task: chat_interaction
inputs:
text: 'Direct Header test'
form_name: 'header_form'
form_def: '{"header": "Sample Header"}'
form_display_mode: 'Embed'
Example of passing Header text field options via dynamic inline powershell:
# Orchestrator package
conditions:
- name: 'client_filter'
optMode: 'OptOut'
category: 'Testing'
- name: 'chat'
option_button: 'Test Package'
option_text: 'This is a Test Package'
option_category: 'Testing Category'
steps:
- task: inline_powershell
alias: header_inline
inputs:
script: |
$headerText = "Sample Header"
$formDef = @{header = $headerText}
return @{formDef = $formDef}
- task: chat_interaction
inputs:
text: 'Inline Header test'
form_name: 'header_form'
form_def: =header_inline.formDef
form_display_mode: 'Embed'
Here is the output in Pia chatbot:
Paragraphβ
Example of passing Paragraph text via form_def property, JSON format:Β
- task: chat_interaction
inputs:
text: 'Test'
form_name: 'paragraph_form'
form_def: '{"test_paragraph": "This is a test paragraph."}'
form_display_mode: 'Embed'
Example of passing Header text field options via dynamic inline powershell:
# Orchestrator package
conditions:
- name: 'client_filter'
optMode: 'OptOut'
category: 'Testing'
- name: 'chat'
option_button: 'Test Package'
option_text: 'This is a Test Package'
option_category: 'Testing Category'
steps:
- task: inline_powershell
alias: paragraph_inline
inputs:
script: |
$paragraphText = "This is a test paragraph."
$formDef = @{test_paragraph = $paragraphText}
return @{formDef = $formDef}
- task: chat_interaction
inputs:
text: 'Inline Paragraph test'
form_def: =paragraph_inline.formDef
form_display_mode: 'Embed'
Here is the output in Pia chatbot:
Dropdownβ
Example of passing drop-down field options via form_def property, JSON format:Β
- task: chat_interaction
inputs:
text: 'Pick a user'
form_name: 'dropdown_form'
form_def: '{ "dropdown": [{ "text": "Option A", "value": "opt_1", "selected": true },
{ "text": "Option B", "value": "opt_2", "selected": false }] }'
form_display_mode: 'Embed'
Example of passing dropdown field options via dynamic inline powershell:
# Orchestrator package
conditions:
- name: 'client_filter'
optMode: 'OptOut'
category: 'Testing'
- name: 'chat'
option_button: 'Test Package'
option_text: 'This is a test package.'
option_category: 'Test Category'
steps:
- task: inline_powershell
alias: form_def_builder
inputs:
script: |
$dropdownSelect = @()
$dropdownSelect += @{text="Option A"; value ="opt_1"; selected = $true;}
$dropdownSelect += @{text="Option B"; value ="opt_2"; selected = $false;}
$formDef = @{
dropdown= $dropdownSelect
}
return @{FormDef = $formDef}
- task: chat_interaction
inputs:
text: 'Form Definition test'
form_name: 'dropdown_form'
form_display_mode: 'Embed'
form_def: =form_def_builder.FormDef
Here is the output in Pia chatbot:
Tagsβ
Example of passing tags field options via form_def property, JSON format:Β
- task: chat_interaction
Β inputs:
Β Β Β text: 'Pick a User:'
Β Β Β form_name: 'pick_user_form'
Β Β Β form_def: '{ "user_selection": [{ "text": "Option A", "value": "opt_1", "selected": true },{ "text": "Option B", "value": "opt_2", "selected": true }] }'
Example of passing tags field options via dynamic inline powershell:
# Orchestrator package
conditions:
- name: 'client_filter'
optMode: 'OptOut'
category: 'Testing'
- name: 'chat'
option_button: 'Form Def Test'
option_text: 'This is a Test Package'
option_category: 'Test Category'
steps:
- task: inline_powershell
alias: form_def_builder
inputs:
script: |
$dropdownSelect = @()
$dropdownSelect += @{text="Cloud Only"; value ="CO"; selected = $true;}
$dropdownSelect += @{text="Cloud Hybrid"; value ="CH"; selected = $true;}
$formDef = @{
dropdownSelect = $dropdownSelect
}
return @{FormDef = $formDef}
- task: chat_interaction
inputs:
text: 'Form Definition test'
form_name: 'text_form'
form_display_mode: 'Embed'
form_def: =form_def_builder.FormDef
Here, a Tags field is used in the chat interaction activity with the reference name "dropdownSelect". When the package runs in the Pia Chatbot, the user will be shown a drop-down form with two options to select from as defined in the package:
Checkboxesβ
Example of passing checkbox field options via form_def property, JSON format:Β
- task: chat_interaction
inputs:
text: 'Select an Option'
form_name: 'checkbox_form_test'
form_def: |
{
"checkbox":[
{"text":"Option A", "value": "option_a", "selected": true},
{"text":"Option B", "value": "option_b", "selected": false}
]
}
form_display_mode: 'Embed'
Example of passing checkbox field options via dynamic inline powershell:
# Orchestrator package
conditions:
- name: 'client_filter'
optMode: 'OptOut'
category: 'Testing'
- name: 'chat'
option_button: 'Test Package'
option_text: 'This is a test package'
option_category: 'Test'
steps:
- task: inline_powershell
alias: checkbox_inline
inputs:
script: |
$checkboxOptions = @()
$checkboxOptions += @{text = "Option A"; value = "option_a"; selected = $true;}
$checkboxOptions += @{text = "Option B"; value = "option_b"; selected = $false;}
$formDef = @{checkbox = $checkboxOptions}
return @{formDef = $formDef}
- task: chat_interaction
inputs:
text: 'Select an Option'
form_name: 'checkbox_form_test'
form_def: =checkbox_inline.formDef
form_display_mode: 'Embed'
Here is the output in Pia chatbot:
Multiple Choiceβ
Example of passing multiple choice field options via form_def property, JSON format:Β
- task: chat_interaction
inputs:
text: 'Select an Option'
form_name: 'multiple_choice'
form_def: |
{
"multiple_choice_form":[
{"text":"Option A", "value": "option_a", "selected": true},
{"text":"Option B", "value": "option_b", "selected": false}
]
}
form_display_mode: 'Embed'
Example of passing multiple choice field options via dynamic inline powershell:
# Orchestrator package
conditions:
- name: 'client_filter'
optMode: 'OptOut'
category: 'Testing'
- name: 'chat'
option_button: '1'
option_text: 'This is a test package'
option_category: 'Test'
steps:
- task: inline_powershell
alias: radio_inline
inputs:
script: |
$radioOptions = @()
$radioOptions += @{text = "Option A"; value = "option_a"; selected = $true;}
$radioOptions += @{text = "Option B"; value = "option_b"; selected = $false;}
$formDef = @{multiple_choice_form = $radioOptions}
return @{formDef = $formDef}
- task: chat_interaction
inputs:
text: 'Select an Option'
form_name: 'multiple_choice'
form_def: =radio_inline.formDef
form_display_mode: 'Embed'
Here is the output in Pia chatbot:
Action Buttonsβ
Example of passing action button options via form_def property, JSON format:Β
- task: chat_interaction
inputs:
text: 'Action Button Test'
form_name: 'action_button_test'
form_def: |
{
"actionButton":[
{"text":"Test Option A", "value": "option_a"},
{"text":"Test Option B", "value": "option_b"}
]
}
form_display_mode: 'Embed'
Example of passing action button options via dynamic inline powershell:
# Orchestrator package
conditions:
- name: 'client_filter'
optMode: 'OptOut'
category: 'Testing'
- name: 'chat'
option_button: 'Test Package'
option_text: 'This is a test package'
option_category: 'Test Category'
steps:
- task: inline_powershell
alias: action_buttons_inline
inputs:
script: |
$actionButtonOptions = @()
$actionButtonOptions += @{text = "Option A"; value = "option_a";}
$actionButtonOptions += @{text = "Option B"; value = "option_b"; }
$formDef = @{actionButton = $actionButtonOptions}
return @{formDef = $formDef}
- task: chat_interaction
inputs:
text: 'Action Button Test'
form_name: 'action_button_test'
form_def: =action_buttons_inline.formDef
form_display_mode: 'Embed'
Here is the output in Pia chatbot:
Text Inputβ
Example of passing text input value via form_def property, JSON format:Β
- task: chat_interaction
inputs:
text: 'Form Def Test'
form_name: 'text_input_form'
form_def: '{"text_input": "This is a test value"}'
form_display_mode: 'Embed'
Example of passing text input value via dynamic inline powershell:
# Orchestrator package
conditions:
- name: 'client_filter'
optMode: 'OptOut'
category: 'Testing'
- name: 'chat'
option_button: 'Test'
option_text: 'This is a Test Package'
option_category: 'Testing Category'
steps:
- task: inline_powershell
alias: inputtext_inline
inputs:
script: |
$inputText = "This is a test value"
$formDef = @{text_input = $inputText}
return @{formDef = $formDef}
- task: chat_interaction
inputs:
text: 'Test'
form_name: 'text_input_form'
form_def: =inputtext_inline.formDef
form_display_mode: 'Embed'
Here is the output in Pia chatbot:
Multiple Listboxβ
Example of passing multiple listbox options via form_def property, JSON format:Β
- task: chat_interaction
inputs:
text: 'Select an Option'
form_name: 'multiple_listbox'
form_def: |
{
"listbox_form":[
{"text":"Option A", "value": "option_a", "selected": true},
{"text":"Option B", "value": "option_b", "selected": true},
{"text":"Option C", "value": "option_c", "selected": false},
{"text":"Option D", "value": "option_d", "selected": false}
]
}
form_display_mode: 'Embed'
Example of passing multiple listbox options via dynamic inline powershell:
# Orchestrator package
conditions:
- name: 'client_filter'
optMode: 'OptOut'
category: 'Testing'
- name: 'chat'
option_button: 'Test'
option_text: 'This is a Test Package'
option_category: 'Testing Category'
steps:
- task: inline_powershell
alias: listbox_inline
inputs:
script: |
$listboxOptions = @()
$listboxOptions += @{text = "Option A"; value = "option_a"; selected = $true;}
$listboxOptions += @{text = "Option B"; value = "option_b"; selected = $true;}
$listboxOptions += @{text = "Option C"; value = "option_c"; selected = $false;}
$listboxOptions += @{text = "Option D"; value = "option_d"; selected = $false;}
$formDef = @{listbox_form = $listboxOptions}
return @{formDef = $formDef}
- task: chat_interaction
inputs:
text: 'Select an Option'
form_name: 'multiple_listbox'
form_def: =listbox_inline.formDef
form_display_mode: 'Embed'
Here is the output in Pia chatbot:
Number Inputβ
Example of passing number input value via form_def property, JSON format:Β
- task: chat_interaction
inputs:
text: 'Form Def Test'
form_name: 'number_input'
form_def: '{"number_input": "11"}'
form_display_mode: 'Embed'
Example of passing number input value via dynamic inline powershell:
# Orchestrator package
conditions:
- name: 'client_filter'
optMode: 'OptOut'
category: 'Testing'
- name: 'chat'
option_button: 'Test'
option_text: 'This is a Test Package'
option_category: 'Testing Category'
steps:
- task: inline_powershell
alias: numbertext_inline
inputs:
script: |
$inputNum = "11"
$formDef = @{number_input = $inputNum}
return @{formDef = $formDef}
- task: chat_interaction
inputs:
text: 'Test'
form_name: 'number_input'
form_def: =numbertext_inline.formDef
form_display_mode: 'Embed'
Here is the output in Pia chatbot:
Table Formatβ
Example of passing table format values via form_def property, JSON format:Β
- task: chat_interaction
inputs:
text: 'Here is your output:'
form_name: 'table_form'
form_def: |
{"table_values":[{"user":"Test User 1","position":"Manager"},
{"user":"Test User 2 ","position":"Manager"}]
}
form_display_mode: 'Embed'
Example of passing table format values via dynamic inline powershell:
# Orchestrator package
conditions:
- name: 'client_filter'
optMode: 'OptOut'
category: 'Testing'
- name: 'chat'
option_button: 'Test'
option_text: 'This is a Test Package'
option_category: 'Testing Category'
steps:
- task: inline_powershell
alias: table_inline
inputs:
script: |
$tableOptions = @()
$tableOptions += [pscustomobject]@{ user = "Test User 1"; position = "Manager"}
$tableOptions += [pscustomobject]@{ user = "Test User 2 "; position = "Manager" }
$formDef = @{table_values = $tableOptions}
return @{formDef = $formDef}
- task: chat_interaction
inputs:
text: 'Here is your output:'
form_name: 'table_form'
form_def: =table_inline.formDef
form_display_mode: 'Embed'
Here is the output in Pia chatbot:
Tree Viewβ
Example of passing tree view values via form_def property, JSON format:Β
steps:
- task: chat_interaction
inputs:
text: 'Test'
form_name: 'tree_view'
form_def: '{"tree_view_options": [
{
"children": [],
"isExpanded": false,
"text": "Folder 1",
"value": "option_a"
},
{
"children": [
{
"children": [],
"isExpanded": false,
"text": "Folder 2.1",
"value": "option_b1"
},
{
"children": [],
"isExpanded": false,
"text": "Folder 2.2",
"value": "option_b2"
},
{
"children": [],
"isExpanded": false,
"text": "Folder 2.3",
"value": "option_b3"
},
{
"children": [],
"isExpanded": false,
"text": "Folder 2.4",
"value": "option_b4"
}
],
"isExpanded": false,
"text": "Folder 2",
"value": "option_b"
},
{
"children": [],
"isExpanded": false,
"text": "Folder 3",
"value": "option_c"
},
]
}'
form_display_mode: 'Embed'
Example of passing tree view values via dynamic inline powershell:
# Orchestrator package
conditions:
- name: 'client_filter'
optMode: 'OptOut'
category: 'Testing'
- name: 'chat'
option_button: 'Test'
option_text: 'This is a Test Package'
option_category: 'Testing Category'
steps:
- task: inline_powershell
alias: tree_inline
inputs:
script: |
$treeView = @()
$treeView += @{text = "Folder 1"; value = "folder_a"; isExpanded = $false; children=@();}
$treeView += @{text = "Folder 2"; value = "folder_b"; isExpanded = $false; children = @(
[pscustomobject]@{text = "Folder 2.1"; value = "folder_b1"; isExpanded = $false; children = @();},
[pscustomobject]@{text = "Folder 2.2"; value = "folder_b2"; isExpanded = $false; children = @();},
[pscustomobject]@{text = "Folder 2.3"; value = "folder_b3"; isExpanded = $false; children = @();}
)}
$treeView += @{text = "Folder 3"; value = "folder_c"; isExpanded = $false; children=@();}
$formDef = @{tree_view_options = $treeView}
return @{formDef = $formDef}
- task: chat_interaction
inputs:
text: 'Inline TreeView test'
form_name: 'tree_view'
form_def: =tree_inline.formDef
form_display_mode: 'Embed'
Here is the output in Pia chatbot:
Multi Line Inputβ
Example of passing Multi Line Input values via form_def property, JSON format:Β
steps:
- task: chat_interaction
inputs:
text: 'Test'
form_name: 'multiline_input_form'
form_def: '{"multiline_input":"This is a test multi-line input value."}'
form_display_mode: 'Embed'
Example of passing Multi Line Input values via dynamic inline powershell:
# Orchestrator package
conditions:
- name: 'client_filter'
optMode: 'OptOut'
category: 'Testing'
- name: 'chat'
option_button: 'Test Package'
option_text: 'This is a Test Package'
option_category: 'Testing Category'
steps:
- task: inline_powershell
alias: multiline_inline
inputs:
script: |
$multiLine = "This is a test multi-line input value."
$formDef = @{multiline_input = $multiLine}
return @{formDef = $formDef}
- task: chat_interaction
inputs:
text: 'Inline Multiline test'
form_name: 'multiline_input_form'
form_def: =multiline_inline.formDef
form_display_mode: 'Embed'
Here is the output in Pia chatbot:
Rich Text Editorβ
Example of passing rich text editor values via form_def property, JSON format:Β
steps:
- task: chat_interaction
inputs:
text: 'Test'
form_name: 'rich_text_editor_form'
form_def: '{"input_richtext":"Inline RichText Editor test Value."}'
form_display_mode: 'Embed'
Example of passing rich text editor values via dynamic inline powershell:
# Orchestrator package
conditions:
- name: 'client_filter'
optMode: 'OptOut'
category: 'Testing'
- name: 'chat'
option_button: 'Test'
option_text: 'This is a Test Package'
option_category: 'Testing Category'
steps:
- task: inline_powershell
alias: richtext_inline
inputs:
script: |
$richText = "Inline RichText Editor test Value."
$formDef = @{input_richtext = $richText}
return @{formDef = $formDef}
- task: chat_interaction
inputs:
text: 'Inline RichText Editor test'
form_name: 'rich_text_editor_form'
form_def: =richtext_inline.formDef
form_display_mode: 'Embed'
Here is the output in Pia chatbot:
Auto Complete Text Boxβ
Example of passing auto complete text box values via form_def property, JSON format:Β
steps:
- task: chat_interaction
inputs:
text: 'Test'
form_name: 'auto_complete_form'
form_def: '{"auto_complete": ["Test Value 1", "Test Value 2", "Test Value 3"]}'
form_display_mode: 'Embed'
Example of passing auto complete text box values via dynamic inline powershell:
# Orchestrator package
conditions:
- name: 'client_filter'
optMode: 'OptOut'
category: 'Testing'
- name: 'chat'
option_button: 'Test'
option_text: 'This is a Test Package'
option_category: 'Testing Category'
steps:
- task: inline_powershell
alias: autocomplete_inline
inputs:
script: |
$autoComplete = @("Test Value 1", "Test Value 2", "Test Value 3")
$formDef = @{auto_complete = $autoComplete}
return @{formDef = $formDef}
- task: chat_interaction
inputs:
text: 'Inline Auto Complete test'
form_name: 'auto_complete_form'
form_def: =autocomplete_inline.formDef
form_display_mode: 'Embed'
Here is the output in Pia chatbot:
Dateβ
Example of passing date field values via form_def property, JSON format:Β
- task: chat_interaction
inputs:
text: 'Test'
form_name: 'date_form'
form_def: '{"date_picker": "12/04/2023"}'
form_display_mode: 'Embed'
Example of passing date field values via dynamic inline powershell:
# Orchestrator package
conditions:
- name: 'client_filter'
optMode: 'OptOut'
category: 'Testing'
- name: 'chat'
option_button: '1'
option_text: 'This is a Test Package'
option_category: 'Testing Category'
steps:
- task: inline_powershell
alias: date_inline
inputs:
script: |
$datePicker = "12/04/2023"
$formDef = @{date_picker = $datePicker}
return @{formDef = $formDef}
- task: chat_interaction
inputs:
text: 'Pick a date to continue:'
form_name: 'date_form'
form_def: =date_inline.formDef
form_display_mode: 'Embed'
Here is the output in Pia chatbot: