Skip to main content

Chat Interaction - Form Def Property 2

Index​

  1. Overview
  2. Property Behaviour
  3. Form Def Examples
    1. Header Text
    2. Paragraph
    3. Dropdown
    4. Tags
    5. Checkboxes
    6. Multiple Choice
    7. Action Buttons
    8. Text Input
    9. Multiple Listbox
    10. Number Input
    11. Table Format
    12. Tree View
    13. Multi-line Input
    14. Rich Text Editor
    15. Auto Complete Text Box
    16. Date

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: form_def.png

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: form_def_example1.png

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.

form_def_default_value.png

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:

header.png

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: paragraph.png

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: dropdown.png

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:

form_def_tags.png

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:

checkbox.png

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: radio.png

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: action_buttons.png

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: input_text.png

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:

multiple_listbox_options.png

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: number_input.png

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:

table.png

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: tree_view.png

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: multi_line.png

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: rich_text_editor.png

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: autocomplete.png

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: date_picker.png