Flow JSON#
Here you will find all the components that make up a Flow JSON object.
- class pywa.types.flows.FlowJSON#
Represents a WhatsApp Flow JSON.
Read more at developers.facebook.com.
- Variables:
screens (Iterable[pywa.types.flows.Screen]) β
The screens of the flow (Read more at developers.facebook.com).
version (str | float | Literal[pywa.utils.Version.FLOW_JSON]) β
The Flow JSON version. (Read more at developers.facebook.com).
data_api_version (str | float | Literal[pywa.utils.Version.FLOW_DATA_API] | None) β The version to use during communication with the WhatsApp Flows Data Endpoint. Use
utils.Version.FLOW_DATA_APIto get the latest versionrouting_model (dict[str, Iterable[str]] | None) β
Defines the rules for the screen by limiting the possible state transition. (Read more at developers.facebook.com).
data_channel_uri (str | None) β The endpoint to use to communicate with your server (When using v3.0 or higher, this field need to be set via
WhatsApp.update_flow_metadata()).
- class pywa.types.flows.Screen#
Represents a screen (page) in a WhatsApp flow.
The maximum number of components (children) per screen is 50.
Read more at developers.facebook.com.
Example
>>> Screen( ... id='START', ... title='Welcome', ... data=[ScreenData(key='welcome', example='Welcome to my store!')], ... terminal=True, ... layout=Layout(children=[Form(children=[...])]), ... refresh_on_back=True ... )
- Variables:
id (str) β Unique identifier of the screen which works as a page url.
SUCCESSis a reserved keyword and should not be used as a screen id.title (str | None) β Screen level attribute that is rendered in the top navigation bar.
data (Iterable[pywa.types.flows.ScreenData] | dict[str, dict] | None) β Declaration of dynamic data that this screen should get from the previous screen or from the flow endpoint. In the screen children and in
DataExchangeAction.payload, you can use thereforScreenDataRefto reference this data.terminal (bool | None) β The business flow is the end state machine. It means that each Flow should have a terminal state where we terminate the experience and have the Flow completed. Multiple screens can be marked as terminal. Itβs mandatory to have a
Footercomponent on the terminal screen. Multiple screens can be marked as terminal. Itβs mandatory to have aFooteron the terminal screen.refresh_on_back (bool | None) β
Whether to trigger a
FlowRequest(actionwill beFlowRequestActionType.BACK) with the flow endpoint when the user presses the back button while on this screen. The property is useful when you need to reevaluate the screen data when returning to the previous screen (Read more at developers.facebook.com).layout (pywa.types.flows.Layout) β
Associated screen UI Layout that is shown to the user (Read more at developers.facebook.com).
success (bool | None) β Defaults to true. A Flow can have multiple terminal screens with different business outcomes. This property marks whether terminating on a terminal screen should be considered a successful business outcome.
sensitive (Iterable[str] | None) β This array contains the names of the fields in the screen that contain sensitive data, and should be hidden in the response summary displayed to the user. (added in v5.1)
- class pywa.types.flows.ScreenData#
Represents a screen data that a screen should get from the previous screen or from the data endpoint.
You can use the
.refproperty or theScreenDataRefto reference this data in the screen children or in the action payloads.Read more at developers.facebook.com.
Example
>>> Screen( ... id='START', ... data=[ ... dynamic_welcome := ScreenData(key='welcome', example='Welcome to my store!') ... is_email_required := ScreenData(key='is_email_required', example=False) ... ], ... layout=Layout(children=[Form(children=[ ... TextHeading(text=dynamic_welcome.ref, ...), ... TextInput(required=is_email_required.ref, input_type=InputType.EMAIL, ...) ... ])]) ... )
- property ref: ScreenDataRef#
- The refernece for this data to use in the same screen children.
Use this property to reference this data in the screen children. Use the
ref_in(screen)()to reference this data in ANOTHER screen children.
Example
>>> FlowJSON( ... screens=[ ... Screen( ... id='START', ... data=[dynamic_welcome := ScreenData(key='welcome', example='Welcome to my store!')], ... layout=Layout(children=[TextHeading(text=dynamic_welcome.ref, ...)]) # Use the .ref here ... ) ... ], ... ... ... )
- ref_in(screen: Screen | str) ScreenDataRef#
- The key for this data to use in ANOTHER screen children.
If you want to reference this data in the same screen children, use the
ref()property.A shortcut for
ScreenDataRefwith this key and screen.You can also use
screen / data.refto reference this data in other screens.Added in v4.0.
Example
>>> FlowJSON( ... screens=[ ... start := Screen( ... id='START', ... data=[dynamic_welcome := ScreenData(key='welcome', example='Welcome to my store!')], ... layout=Layout(children=[...]) ... ), ... Screen( ... id='END', ... layout=Layout( ... children=[ ... TextHeading(text=dynamic_welcome.ref_in("START"), ...), # using the `.ref_in(screen)` method ... TextHeading(text=start/dynamic_welcome.ref, ...) # using the `screen / data.ref` syntax ... ] ... ) ... ) ... ], ... ... ... )
- Parameters:
screen β The screen id to reference this data in its children.
- update(new_value: str | int | float | bool | dict | date | DataSource | Iterable[str | int | float | bool | dict | date | DataSource | NavigationItem]) ScreenDataUpdate#
Update the value of this data. Use this inside the
UpdateDataAction.payload.Example:
>>> is_visible = ScreenData(key='is_visible', example=True) >>> UpdateDataAction(payload=[is_visible.update(False)])
- Parameters:
new_value β The new value of the data.
- Returns:
The update action for this data.
- class pywa.types.flows.ScreenDataUpdate#
Represents an update action for a screen data.
Use the
ScreenData.update()method to create an instance of this class from aScreenData.
1Screen( 2 id="DEMO_SCREEN", 3 data=[ 4 is_txt_visible := ScreenData( 5 key="is_txt_visible", 6 example=False, 7 ), 8 ], 9 layout=Layout( 10 children=[ 11 OptIn( 12 label="Show the text", 13 name="show_txt", 14 on_select_action=UpdateDataAction( 15 payload=[is_txt_visible.update(True)] # a much cleaner way 16 ), 17 on_unselect_action=UpdateDataAction( 18 payload=[ScreenDataUpdate(key="is_txt_visible", new_value=False)] # only when you don't have access to the `ScreenData` object 19 ), 20 ), 21 TextBody( 22 text="You clicked the button!", 23 visible=is_txt_visible.ref, 24 ), 25 ] 26 ) 27)
- class pywa.types.flows.Layout#
Layout is the top level component that holds the other components.
Read more at developers.facebook.com.
Before v4.0, the following components must be wrapped in a
Formand canβt be used directly in the layout:TextInput,TextArea,CheckboxGroup,RadioButtonsGroup,OptIn,DropdownandDatePicker.
- Variables:
type (pywa.types.flows.LayoutType) β The type of layout that is used to display the components (Default:
LayoutType.SINGLE_COLUMN).children (Iterable[pywa.types.flows.Form | pywa.types.flows.Component | dict[str, Any]]) β The components that are part of the layout.
- class pywa.types.flows.LayoutType#
- The type of layout that is used to display the components.
Currently, only
LayoutType.SINGLE_COLUMNis supported.
- Variables:
SINGLE_COLUMN β A vertical flexbox container that stacks the components in a single column.
- class pywa.types.flows.Form#
The form component is a container for other components that collects user input.
Before v4.0, the following components must be inside Form:
TextInput,TextArea,CheckboxGroup,RadioButtonsGroup,OptIn,DropdownandDatePicker.Read more at developers.facebook.com.
- Variables:
name (str) β The name of the form (the convention is to use
"form").children (Iterable[pywa.types.flows.Component | pywa.types.flows.FormComponent | dict[str, Any]]) β The components that are part of the form.
init_values (dict[str, Any] | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β
The initial values of the form (you can use
.init_valueproperty of each component to set the initial value instead of setting this attribute. Read more at developers.facebook.com).error_messages (dict[str, str] | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β
The error messages of the form (you can use
.error_messageproperty of each component to set the error message instead of setting this attribute. Read more at developers.facebook.com).
- class pywa.types.flows.FormComponent#
Base class for all components that must be inside a form (if FlowJSON version is below 4.0)
- property ref: ComponentRef#
- The reference variable for this component.
Use this when the reference is in the same screen. Use
.ref_in(screen)when the reference is in another screen.A shortcut for
ComponentRefwith this component name.
Example
>>> FlowJSON( ... screens=[ ... Screen( ... id='START', ... layout=Layout(children=[ ... Form(children=[ ... text_input := TextInput(name='email', ...), ... TextHeading(text="Your email is:", ...) ... TextCaption(text=text_input.ref, ...) ... ]), ... Footer(label='Submit', action=Action(payload={'email': text_input.ref})) ... ]) ... ] ... )
- ref_in(screen: Screen | str) ComponentRef#
- The component reference variable for this component in another screen.
Use
.refproperty when the reference is in the same screen.You can also use
screen/component.refto get the reference variable in another screen.Added in v4.0.
Example
>>> FlowJSON( ... screens=[ ... other := Screen( ... id='OTHER', ... layout=Layout(children=[Form(children=[email := TextInput(name='email', ...), ...])]) ... ), ... Screen( ... id='START', ... layout=Layout(children=[ ... TextCaption(text=email.ref_in('OTHER'), ...) # using the `.ref_in(screen)` method ... TextCaption(text=other/email.ref, ...) # using the screen/component.ref syntax ... ]) ... ) ... ] ... )
- Parameters:
screen β The screen that contains the component.
- class pywa.types.flows.TextHeading#
Represents text that is displayed as a heading.
Read more at developers.facebook.com.
Example
>>> TextHeading(text='Heading', visible=True)
- Variables:
text (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef) β The text of the heading. Limited to 80 characters.
visible (bool | str | pywa.types.flows.Condition | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the heading is visible or not. Default to
True,
- class pywa.types.flows.TextSubheading#
Represents text that is displayed as a subheading.
Read more at developers.facebook.com.
Example
>>> TextSubheading(text='Subheading', visible=True)
- Variables:
text (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef) β The text of the subheading. Limited to 80 characters.
visible (bool | str | pywa.types.flows.Condition | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the subheading is visible or not. Default to
True,
- class pywa.types.flows.TextBody#
Represents text that is displayed as a body.
Read more at developers.facebook.com.
Example
>>> TextBody( ... text='Body', ... font_weight=FontWeight.BOLD, ... strikethrough=True, ... visible=True ... )
- Variables:
text (str | Iterable[str | pywa.types.flows.FlowStr] | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | pywa.types.flows.FlowStr) β The text of the body. Limited to 4096 characters.
markdown (bool | None) β Whether the text is markdown or not (Added in v5.1).
font_weight (pywa.types.flows.FontWeight | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The weight of the text.
strikethrough (bool | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the text is strikethrough or not.
visible (bool | str | pywa.types.flows.Condition | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the body is visible or not. Default to
True,
- class pywa.types.flows.TextCaption#
Represents text that is displayed as a caption.
Read more at developers.facebook.com.
Example
>>> TextCaption( ... text='Caption', ... font_weight=FontWeight.ITALIC, ... strikethrough=True, ... )
- Variables:
text (str | Iterable[str | pywa.types.flows.FlowStr] | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | pywa.types.flows.FlowStr) β The text of the caption (array of strings supported since v5.1). Limited to 4096 characters.
markdown (bool | None) β Whether the text is markdown or not (Added in v5.1).
font_weight (pywa.types.flows.FontWeight | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The weight of the text.
strikethrough (bool | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether to strike through the text or not.
visible (bool | str | pywa.types.flows.Condition | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the caption is visible or not. Default to
True,
- class pywa.types.flows.RichText#
Represents text that is displayed as a rich text.
Read more at developers.facebook.com.
The goal of the component is to provide a rich formatting capabilities and introduce the way to render large texts (Terms of Condition, Policy Documents, User Agreement and etc) without facing limitations of basic text components (TextHeading, TextSubheading, TextBody and etc)
RichText component utilizes a select subset of the Markdown specification. It adheres strictly to standard Markdown syntax without introducing any custom modifications. Content created for the RichText component is fully compatible with standard Markdown documents.
Added in v5.1.
Example
>>> RichText( ... text=[ ... "# Heading 1", ... "## Heading 2", ... "Letβs make a **bold** statement", ... "Let's make this text *italic*", ... "Let's make this text ~~Strikethrough~~", ... "This text is ~~***really important***~~", ... "This is a [pywa docs](https://pywa.readthedocs.io/)", ... "This is a ordered list:", ... "1. Item 1", ... "2. Item 2", ... "This is a unordered list:", ... "- Item 1", ... "- Item 2", ... "", ... "| Tables | Are | Cool |", ... "| ------------- | ------------- | ----- |", ... "| col 3 is | right-aligned | $1600 |", ... "| col 2 is | centered | $12 |", ... ], ... )
- Variables:
text (str | Iterable[str | pywa.types.flows.FlowStr] | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | pywa.types.flows.FlowStr) β The markdown text (array of strings supported).
visible (bool | str | pywa.types.flows.Condition | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the caption is visible or not. Default to
True,
- class pywa.types.flows.FontWeight#
The text weight
- Variables:
BOLD β Bold text
ITALIC β Italic text
BOLD_ITALIC β Bold and italic text
NORMAL β Normal text
- class pywa.types.flows.TextInput#
Represents a text entry component that allows for a single line of text.
This component must be inside a
Form(if FlowJSON version is below 4.0).Read more at developers.facebook.com.
Example
>>> TextInput( ... name='email', ... label='Email', ... input_type=InputType.EMAIL, ... required=True, ... min_chars=5, ... max_chars=50, ... helper_text='Enter your email address', ... )
- Variables:
name (str) β The unique name (id) for this component.
label (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef) β The label of the text input. Limited to 20 characters.
input_type (pywa.types.flows.InputType | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The input type of the text input (for keyboard layout and validation rules).
pattern (str | re.Pattern | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The regex pattern to validate the text input. Added in v6.2.
required (bool | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the text input is required or not.
min_chars (int | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The minimum number of characters allowed in the text input.
max_chars (int | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The maximum number of characters allowed in the text input.
helper_text (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The helper text of the text input. Limited to 80 characters.
enabled (bool | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the text input is enabled or not. Default to
True.visible (bool | str | pywa.types.flows.Condition | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the text input is visible or not. Default to
True.init_value (str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The default value of the text input.
error_message (str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The error message of the text input.
- class pywa.types.flows.InputType#
The input type of the text entry component.
This is used by the WhatsApp client to determine the keyboard layout and validation rules.
- Variables:
TEXT β A single line of text (for multi-line text use
TextArea).NUMBER β A number (keyboard layout is numeric, with a decimal separator).
EMAIL β An email address (keyboard layout is alphanumeric, with a special character for the @ symbol).
PASSWORD β A password (the input is masked).
PASSCODE β A passcode (keyboard layout is numeric, the input is masked).
PHONE β A phone number (keyboard layout is numeric, with a special character for the + symbol).
- class pywa.types.flows.TextArea#
Represents a text entry component that allows for multiple lines of text.
This component must be inside a
Form(if FlowJSON version is below 4.0).Read more at developers.facebook.com.
Example
>>> TextArea( ... name='description', ... label='Description', ... required=True, ... max_length=100, ... helper_text='Enter your description', ... )
- Variables:
name (str) β The unique name (id) for this component.
label (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef) β The label of the text area. Limited to 20 characters.
required (bool | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the text area is required or not.
max_length (int | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The maximum number of characters allowed in the text area.
helper_text (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The helper text of the text area. Limited to 80 characters.
enabled (bool | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the text area is enabled or not. Default to
True.visible (bool | str | pywa.types.flows.Condition | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the text area is visible or not. Default to
True.init_value (str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The default value of the text area.
error_message (str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The error message of the text area.
- class pywa.types.flows.CheckboxGroup#
CheckboxGroup component allows users to pick multiple selections from a list of options.
This component must be inside a
Form(if FlowJSON version is below 4.0).Read more at developers.facebook.com.
Example
>>> CheckboxGroup( ... name='options', ... data_source=[ ... DataSource(id='1', title='Option 1'), ... DataSource(id='2', title='Option 2'), ... DataSource(id='3', title='Option 3'), ... ], ... label='Options', ... min_selected_items=1, ... max_selected_items=2, ... required=True, ... init_value=['1', '2'] ... )
- Variables:
name (str) β The unique name (id) for this component.
data_source (Iterable[pywa.types.flows.DataSource] | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef) β The data source of the checkbox group.
label (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The label of the checkbox group. Limited to 30 characters. Required starting from v4.0.
description (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The description of the checkbox group. Limited to 300 characters. Added in v4.0.
min_selected_items (int | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The minimum number of items that can be selected. Minimum value is 1.
max_selected_items (int | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The maximum number of items that can be selected. Maximum value is 20.
required (bool | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the checkbox group is required or not.
visible (bool | str | pywa.types.flows.Condition | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the checkbox group is visible or not. Default to
True.enabled (bool | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the checkbox group is enabled or not. Default to
True.init_value (list[str] | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The default values (IDs of the data sources).
media_size (pywa.types.flows.MediaSize | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The media size of the image. Added in v5.0.
on_select_action (pywa.types.flows.DataExchangeAction | pywa.types.flows.UpdateDataAction | None) β The action to perform when an item is selected.
on_unselect_action (pywa.types.flows.UpdateDataAction | None) β The action to perform when an item is unselected. Added in v6.0.
- class pywa.types.flows.ChipsSelector#
Chips Selector component allows users to pick multiple selections from a list of options.
Added in v6.3
Read more at developers.facebook.com.
Example
>>> ChipsSelector( ... name='options', ... data_source=[ ... DataSource(id='1', title='Option 1'), ... DataSource(id='2', title='Option 2'), ... DataSource(id='3', title='Option 3'), ... ], ... label='Options', ... min_selected_items=1, ... max_selected_items=2, ... required=True, ... init_value=['1', '2'] ... )
- Variables:
name (str) β The unique name (id) for this component.
data_source (Iterable[pywa.types.flows.DataSource] | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef) β The data source of the chips selector.
label (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef) β The label of the chips selector. Limited to 80 characters.
description (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The description of the chips selector. Limited to 300 characters
min_selected_items (int | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The minimum number of items that can be selected. Minimum value is 1.
max_selected_items (int | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The maximum number of items that can be selected. Maximum value is 20.
required (bool | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the chips selector is required or not.
visible (bool | str | pywa.types.flows.Condition | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the chips selector is visible or not. Default to
True.enabled (bool | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the chips selector is enabled or not. Default to
True.init_value (list[str] | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The default values (IDs of the data sources).
on_select_action (pywa.types.flows.DataExchangeAction | pywa.types.flows.UpdateDataAction | None) β The action to perform when an item is selected.
- class pywa.types.flows.RadioButtonsGroup#
RadioButtonsGroup component allows users to pick a single selection from a list of options.
This component must be inside a
Form(if FlowJSON version is below 4.0).Read more at developers.facebook.com.
Example
>>> RadioButtonsGroup( ... name='options', ... data_source=[ ... DataSource(id='1', title='Option 1'), ... DataSource(id='2', title='Option 2'), ... DataSource(id='3', title='Option 3'), ... ], ... label='Options', ... required=True, ... init_value='1' ... )
- Variables:
name (str) β The unique name (id) for this component.
data_source (Iterable[pywa.types.flows.DataSource] | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef) β The data source of the radio buttons group.
label (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The label of the radio buttons group. Limited to 30 characters. Required starting from v4.0.
description (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The description of the radio buttons group. Limited to 300 characters. Added in v4.0.
required (bool | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the radio buttons group is required or not.
visible (bool | str | pywa.types.flows.Condition | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the radio buttons group is visible or not. Default to
True.enabled (bool | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the radio buttons group is enabled or not. Default to
True.init_value (str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The default value (ID of the data source).
media_size (pywa.types.flows.MediaSize | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The media size of the image. Added in v5.0.
on_select_action (pywa.types.flows.DataExchangeAction | pywa.types.flows.UpdateDataAction | None) β The action to perform when an item is selected.
on_unselect_action (pywa.types.flows.UpdateDataAction | None) β The action to perform when an item is unselected. Added in v6.0.
- class pywa.types.flows.MediaSize#
The media size of the image.
- Variables:
REGULAR β Regular size
LARGE β Large size
Footer component allows users to navigate to other screens or submit the flow.
Read more at developers.facebook.com.
- Variables:
label (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef) β The label of the footer. Limited to 35 characters.
on_click_action (pywa.types.flows.CompleteAction | pywa.types.flows.DataExchangeAction | pywa.types.flows.NavigateAction) β The action to perform when the footer is clicked. Required.
left_caption (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Can set left_caption and right_caption or only center_caption, but not all 3 at once. Limited to 15 characters.
center_caption (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Can set center-caption or left-caption and right-caption, but not all 3 at once. Limited to 15 characters.
right_caption (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Can set right-caption and left-caption or only center-caption, but not all 3 at once. Limited to 15 characters.
enabled (bool | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the footer is enabled or not. Default to
True.
- class pywa.types.flows.OptIn#
OptIn component allows users to check a box to opt in for a specific purpose.
This component must be inside a
Form(if FlowJSON version is below 4.0).Max number of Opt-Ins Per Screen is 5.
Read more at developers.facebook.com.
Example
>>> OptIn( ... name='opt_in', ... label='I agree to the terms and conditions', ... required=True, ... init_value=True ... )
- Variables:
name (str) β The unique name (id) for this component.
label (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef) β The label of the opt in. Limited to 30 characters.
required (bool | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the opt in is required or not.
visible (bool | str | pywa.types.flows.Condition | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the opt in is visible or not. Default to
True.init_value (bool | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The default value of the opt in.
on_click_action (pywa.types.flows.OpenUrlAction | pywa.types.flows.DataExchangeAction | pywa.types.flows.NavigateAction | None) β The action to perform when the opt in is clicked.
- class pywa.types.flows.Dropdown#
Dropdown component allows users to pick a single selection from a list of options.
This component must be inside a
Form(if FlowJSON version is below 4.0).Read more at developers.facebook.com.
Example
>>> Dropdown( ... name='options', ... data_source=[ ... DataSource(id='1', title='Option 1'), ... DataSource(id='2', title='Option 2'), ... DataSource(id='3', title='Option 3'), ... ], ... label='Options', ... required=True, ... init_value='1' ... )
- Variables:
name (str) β The unique name (id) for this component.
label (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef) β The label of the dropdown. Limited to 30 characters.
data_source (Iterable[pywa.types.flows.DataSource] | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef) β The data source of the dropdown. minimum 1 and maximum 200 items.
enabled (bool | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the dropdown is enabled or not. Default to
True.required (bool | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the dropdown is required or not.
visible (bool | str | pywa.types.flows.Condition | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the dropdown is visible or not. Default to
True.init_value (str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The default value (ID of the data source).
on_select_action (pywa.types.flows.DataExchangeAction | pywa.types.flows.UpdateDataAction | None) β The action to perform when an item is selected.
on_unselect_action (pywa.types.flows.UpdateDataAction | None) β The action to perform when an item is unselected. Added in v6.0.
- class pywa.types.flows.EmbeddedLink#
EmbeddedLink component allows users to navigate to another screen.
Max Number of Embedded Links Per Screen is 2.
Empty or Blank value is not accepted for the text field.
Read more at developers.facebook.com.
Example
>>> EmbeddedLink( ... text='Sign up', ... on_click_action=NavigateAction( ... next=Next(name='SIGNUP_SCREEN'), ... payload={'data': 'value'} ... ) ... )
- Variables:
text (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef) β The text of the embedded link. Limited to 35 characters.
on_click_action (pywa.types.flows.DataExchangeAction | pywa.types.flows.UpdateDataAction | pywa.types.flows.NavigateAction | pywa.types.flows.OpenUrlAction) β The action to perform when the embedded link is clicked.
visible (bool | str | pywa.types.flows.Condition | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the embedded link is visible or not. Default to
True.
The NavigationList component allows users to navigate effectively between different screens in a Flow, by exploring and interacting with a list of options. Each list item can display rich content such as text, images and tags.
Read more at developers.facebook.com.
Added in v6.2
The on_click_action is required for this component and can be defined either at the component level or in each
NavigationItem.There can be at most 2
NavigationListcomponents per screen.The
NavigationListcomponents cannot be used in combination with any other components in the same screen.
Example
>>> NavigationList( ... name='navigation_list', ... list_items=[ ... NavigationItem( ... id='1', ... main_content=NavigationItemMainContent(title='Title 1', description='Description 1'), ... start=NavigationItemStart(image='base64image...'), ... end=NavigationItemEnd(title="$100", description="/ month"), ... badge='New', ... on_click_action=NavigateAction(next=Next(name='SCREEN_1')) ... ), ... ... ... ], ... )
- Variables:
name (str) β The unique name (id) for this component.
list_items (Iterable[pywa.types.flows.NavigationItem] | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | str) β The list items of the navigation list. Minimum 1 and maximum 20 items. Content will not be rendered if the limit is reached.
label (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The label of the navigation list. Limited to 80 characters.
description (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The description of the navigation list. Limited to 300 characters.
media_size (pywa.types.flows.MediaSize | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The media size of the image. Default to
REGULAR.on_click_action (pywa.types.flows.NavigateAction | pywa.types.flows.DataExchangeAction | None) β The action to perform when an item is clicked (can be defined at the component level or in each
NavigationItem).
The NavigationItem represents an item in the NavigationList component.
There can be only one item with a
badgeper list.The
endadd-on cannot be used in combination withmedia_sizeset toLARGE.The
on_click_actioncannot be defined simultaneously on component-level and on item-level.
- Variables:
main_content (pywa.types.flows.NavigationItemMainContent) β The main content of the navigation item.
start (pywa.types.flows.NavigationItemStart | None) β The start content of the navigation item (An image, limited to 100KB).
end (pywa.types.flows.NavigationItemEnd | None) β The end content of the navigation item.
badge (str | None) β The badge of the navigation item. Limited to 15 characters.
tags (Iterable[str] | None) β The tags of the navigation item. Maximum 3 tags, each limited to 15 characters.
The start content of the NavigationItem component.
- Variables:
image (str) β The image of the item content (base64 encoded, limited to 100KB).
The main content of the NavigationItem component.
The end content of the NavigationItem component.
- class pywa.types.flows.DatePicker#
DatePicker component allows users to select a date
This component must be inside a
Form(if FlowJSON version is below 4.0).Starting from FlowJSON version 5.0, you can use date/datetime python objects or a formatted date string in the format βYYYY-MM-DDβ, such as β2024-10-21β or
Read more at developers.facebook.com.
Example
>>> DatePicker( ... name='date', ... label='Appointment Date', ... min_date=datetime.date(2024, 7, 21), ... max_date=datetime.date(2024, 10, 21), ... unavailable_dates=[ ... datetime.date(2024, 7, 25), ... datetime.date(2024, 7, 26), ... ], ... helper_text='Select a date', ... required=True ... )
- Variables:
name (str) β The unique name (id) for this component.
label (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef) β The label of the date picker. Limited to 40 characters.
min_date (datetime.date | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The minimum date (date/datetime/timestamp) that can be selected.
max_date (datetime.date | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The maximum date (date/datetime/timestamp) that can be selected.
unavailable_dates (Iterable[datetime.date | str] | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The dates (dates/datetimes/timestamps) that cannot be selected.
helper_text (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The helper text of the date picker. Limited to 80 characters.
enabled (bool | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the date picker is enabled or not. Default to
True.required (bool | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the date picker is required or not.
visible (bool | str | pywa.types.flows.Condition | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the date picker is visible or not. Default to
True.init_value (datetime.date | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The default value.
error_message (str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The error message of the date picker.
on_select_action (pywa.types.flows.DataExchangeAction | None) β The action to perform when a date is selected.
- class pywa.types.flows.CalendarPicker#
CalendarPicker component allows users to select a single date or a range of dates from a full calendar interface.
Read more at developers.facebook.com.
Added in v6.1
Example
>>> CalendarPicker( ... name='date', ... label='Appointment Date', ... mode=CalendarPickerMode.SINGLE, ... min_date=datetime.date(2024, 7, 21), ... max_date=datetime.date(2024, 10, 21), ... unavailable_dates=[ ... datetime.date(2024, 7, 25), ... datetime.date(2024, 7, 26), ... ], ... helper_text='Select a date', ... required=True ... )
- Variables:
name (str) β The unique name (id) for this component.
label (dict[Literal['start-date', 'end-date'], str] | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef) β The label of the calendar picker. Limited to 40 characters.
title (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The title of the calendar picker. Only available when mode is
CalendarMode.RANGE.description (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The description of the calendar picker. Limited to 300 characters. Only available when mode is
CalendarMode.RANGE.mode (pywa.types.flows.CalendarPickerMode | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The mode of the calendar picker. Default to
CalendarMode.SINGLE.min_date (datetime.date | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The minimum date (date/datetime) that can be selected.
max_date (datetime.date | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The maximum date (date/datetime) that can be selected.
unavailable_dates (Iterable[datetime.date | str] | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The dates (dates/datetimes) that cannot be selected.
include_days (Iterable[pywa.types.flows.CalendarDay | str] | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The days of the week to include in the calendar picker. Default to all days.
min_days (int | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The minimum number of days that can be selected in the range mode.
max_days (int | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The maximum number of days that can be selected in the range mode.
helper_text (dict[Literal['start-date', 'end-date'], str] | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | pywa.types.flows.FlowStr | None) β The helper text of the calendar picker. Limited to 80 characters.
enabled (bool | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the calendar picker is enabled or not. Default to
True.required (dict[Literal['start-date', 'end-date'], bool] | bool | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the calendar picker is required or not.
visible (bool | str | pywa.types.flows.Condition | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the calendar picker is visible or not. Default to
True.init_value (dict[Literal['start-date', 'end-date'], datetime.date | str] | datetime.date | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The default value. Only available when component is outside Form component.
error_message (dict[Literal['start-date', 'end-date'], str] | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The error message of the calendar picker. Only available when component is outside Form component.
on_select_action (dict[Literal['start-date', 'end-date'], pywa.types.flows.DataExchangeAction] | pywa.types.flows.DataExchangeAction | None) β The action to perform when a date is selected.
- class pywa.types.flows.CalendarPickerMode#
The mode of the calendar picker.
- Variables:
SINGLE β Allows to select one date.
RANGE β Allows to select start and end dates.
- class pywa.types.flows.CalendarDay#
The days of the week.
- Variables:
MON β Monday
TUE β Tuesday
WED β Wednesday
THU β Thursday
FRI β Friday
SAT β Saturday
SUN β Sunday
- class pywa.types.flows.Image#
Image component that displays an image.
Read more at developers.facebook.com.
Supported images formats are JPEG PNG
Recommended image size is up to 300kb
Max number of images per screen is 3
Example
>>> Image( ... src='iVBORw0KGgoAAAANSUhEUgAAAlgAAAM...', ... width=100, ... height=100, ... scale_type=ScaleType.CONTAIN, ... aspect_ratio=1, ... alt_text='Image of a cat' ... )
- Variables:
src (str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef) β Base64 of an image.
width (int | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The width of the image.
height (int | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The height of the image.
scale_type (pywa.types.flows.ScaleType | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β
The scale type of the image. Defaule to
ScaleType.CONTAINRead more at developers.facebook.com.aspect_ratio (int | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef) β The aspect ratio of the image. Default to
1.alt_text (str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Alternative Text is for the accessibility feature, eg. Talkback and Voice over.
- class pywa.types.flows.ScaleType#
The scale type of the image.
Read more at developers.facebook.com.
- Variables:
COVER β Image is clipped to fit the image container.
CONTAIN β Image is contained within the image container with the original aspect ratio.
- class pywa.types.flows.PhotoPicker#
PhotoPicker component allows uploading media from camera or gallery
Read more at developers.facebook.com.
Added in v4.0
Only 1 PhotoPicker is allowed per screen
Using both
PhotoPickerandDocumentPickercomponents on a single screen is not allowed.
Example
>>> PhotoPicker( ... name='photo', ... label='Take a photo', ... description='We need your photo for verification', ... photo_source=PhotoSource.CAMERA, ... max_file_size_kb=10_000, # 10MB ... min_uploaded_photos=1, ... max_uploaded_photos=3, )
- Variables:
name (str) β The unique name (id) for this component.
label (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef) β The label of the photo picker. Limited to 30 characters.
description (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The description of the photo picker. Limited to 300 characters.
photo_source (pywa.types.flows.PhotoSource | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The source where the image can be selected from. Default to
PhotoSource.CAMERA_GALLERY.max_file_size_kb (int | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The maximum file size in KB. Default value: 25600 (25 MiB)
min_uploaded_photos (int | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The minimum number of photos that can be uploaded. This property determines whether the component is optional (set to 0) or required (set above 0).
max_uploaded_photos (int | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The maximum number of photos that can be uploaded. Default value: 30
enabled (bool | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the photo picker is enabled or not. Default to
True.visible (bool | str | pywa.types.flows.Condition | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the photo picker is visible or not. Default to
True.error_message (str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The error message of the photo picker.
- class pywa.types.flows.PhotoSource#
The source where the image can be selected from.
- Variables:
CAMERA_GALLERY β User can select from gallery or take a photo
CAMERA β User can select only from gallery
GALLERY β User can only take a photo
- class pywa.types.flows.DocumentPicker#
DocumentPicker component allows uploading files from the device
Read more at developers.facebook.com.
Added in v4.0
Only 1 DocumentPicker is allowed per screen
Using both
PhotoPickerandDocumentPickercomponents on a single screen is not allowed.Note: some old Android and iOS OS versions donβt understand all mime types above. As a result, a user might be able to select a file with a different mime type to the ones specified.
Example
>>> DocumentPicker( ... name='document', ... label='Upload your Driving License', ... description='We need your document for verification', ... max_file_size_kb=5_000, # 5MB ... min_uploaded_documents=1, ... max_uploaded_documents=1, ... allowed_mime_types=['application/pdf', 'image/jpeg', 'image/png'], )
- Variables:
name (str) β The unique name (id) for this component.
label (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef) β The label of the document picker. Limited to 30 characters.
description (str | pywa.types.flows.FlowStr | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The description of the document picker. Limited to 300 characters.
max_file_size_kb (int | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The maximum file size in KB. Default value: 25600 (25 MiB)
min_uploaded_documents (int | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The minimum number of documents that can be uploaded. This property determines whether the component is optional (set to 0) or required (set above 0).
max_uploaded_documents (int | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The maximum number of documents that can be uploaded. Default value: 30
allowed_mime_types (Iterable[str] | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Specifies which document mime types can be selected. If it contains βimage/jpegβ, picking photos from the gallery will be available as well. Default value: Any document from the supported mime types can be selected.
enabled (bool | str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the document picker is enabled or not. Default to
True.visible (bool | str | pywa.types.flows.Condition | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the document picker is visible or not. Default to
True.error_message (str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The error message of the document picker.
- class pywa.types.flows.If#
If component allows users to add components based on a condition.
Read more at developers.facebook.com.
It is allowed to nest up to 3
Ifcomponents.Should have at least one dynamic value (e.g. screen_data.ref / form_comp.ref) in the condition.
Should always be resolved into a boolean (i.e. no strings or number values).
Can be used with literals but should not only contain literals.
Footercan be added withinIfonly in the first level, not inside a nestedIf.If there is a
FooterwithinIf, it should exist in both branches (i.e.thenandelse). This means thatelsebecomes mandatory.If there is a
FooterwithinIfit cannot exist a footer outside, because the max count ofFooteris 1 per screen.
Example
>>> age = ScreenData(key="age", example=20) >>> opt_in = OptIn(name="opt_in", ...) >>> If( ... condition=(age.ref > 21) && opt_in.ref, ... then=[ ... TextHeading(text="Welcome to the club!"), ... TextInput( ... name='email', ... label='Email', ... ), ... ], ... else_=[ ... TextHeading(text="You are not eligible!"), ... ] ... )
- Variables:
condition (pywa.types.flows.Condition | str) β Boolean expression, You can use both dynamic and static values. See Supported Operators.
then (Iterable[pywa.types.flows.Component | dict[str, Any]]) β The components that will be rendered when
conditionisTrue.else (Iterable[pywa.types.flows.Component | dict[str, Any]] | None) β The components that will be rendered when
conditionisFalse.
- class pywa.types.flows.Switch#
Switch component allows users to add components based on a value of a screen data ref or form component ref.
Read more at developers.facebook.com.
Example
>>> age = TextInput(name='age', label='Age') >>> switch = Switch( ... value=age.ref, ... cases={ ... '10': [TextHeading(text='Under 18')], ... ... ... '20': [TextInput(name='email', label='Email')], ... }
- Variables:
value (pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | str) β The key / ref to the data that will be used to determine which components to render.
cases (dict[str, Iterable[pywa.types.flows.Component | dict[str, Any]]]) β The components that will be rendered based on the value.
- class pywa.types.flows.DataSource#
The data source of a component.
Read more at developers.facebook.com.
Example
>>> option_1 = DataSource(id='1', title='Option 1') >>> option_2 = DataSource(id='2', title='Option 2') >>> checkbox_group = CheckboxGroup(data_source=[option_1, option_2], ...)
- Variables:
id (str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef) β The ID of the data source.
title (str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef) β The title of the data source. Limited to 30 characters.
description (str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The description of the data source. Limited to 300 characters.
metadata (str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The metadata of the data source. Limited to 20 characters.
enabled (bool | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β Whether the data source is enabled or not. Default to
True.image (str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The base64 encoded image of the data source. Limited to 1MB (added in v5.0).
alt_text (str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β The alt text of the image. (added in v5.0).
color (str | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef | None) β 6-digit hex color code. (added in v5.0).
on_select_action (pywa.types.flows.UpdateDataAction | None) β The update data action to perform when the data source is selected. (added in v6.0).
on_unselect_action (pywa.types.flows.UpdateDataAction | None) β The update data action to perform when the data source is unselected. (added in v6.0).
- class pywa.types.flows.DataExchangeAction#
Data Exchange Action. Sending Data to WhatsApp Flows Data Endpoint
Read more at developers.facebook.com.
Example
>>> DataExchangeAction( ... payload={'data': 'value'} ... )
- Variables:
payload (dict[str, str | bool | Iterable[pywa.types.flows.DataSource] | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef]) β The payload of the action (Pass data to the WhatsApp Flows Data Endpoint). This payload can take data from form components or from the data of the screen.
Navigate Action. Triggers the next screen with the payload as its input.
Read more at developers.facebook.com.
Example
>>> NavigateAction( ... next=Next(name='NEXT_SCREEN'), ... payload={'data': 'value'} ... )
- Variables:
next (pywa.types.flows.Next) β The next action to perform
payload (dict[str, str | bool | Iterable[pywa.types.flows.DataSource] | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef]) β The payload of the action (Pass data to the next screen). This payload can take data from form components or from the data of the screen.
- class pywa.types.flows.CompleteAction#
Complete Action. Triggers the termination of the Flow with the provided payload
Read more at developers.facebook.com.
Example
>>> CompleteAction( ... payload={'data': 'value'} ... )
- Variables:
payload (dict[str, str | bool | pywa.types.flows.ScreenDataRef | pywa.types.flows.ComponentRef]) β The payload to include in the
FlowCompletion.response attribute.
- class pywa.types.flows.UpdateDataAction#
Update Data Action. Triggers an immediate update to the screenβs state, reflecting user input changes.
Read more at developers.facebook.com.
Example
>>> is_visible = ScreenData(key='is_visible', example=True) >>> UpdateDataAction( ... payload=[ ... is_visible.update(value=False) ... ] ... )
- Variables:
payload (Iterable[pywa.types.flows.ScreenDataUpdate] | dict[str, str | int | float | bool | dict | datetime.date | pywa.types.flows.DataSource | Iterable[str | int | float | bool | dict | datetime.date | pywa.types.flows.DataSource | pywa.types.flows.NavigationItem]]) β The data to update for the current screen.
- class pywa.types.flows.OpenUrlAction#
Open URL Action. Triggers a link to open in the deviceβs default web browser.
Read more at developers.facebook.com.
Example
>>> OpenUrlAction( ... url='https://example.com' ... )
- Variables:
url (str) β The URL to open
- class pywa.types.flows.Next#
The next action
- Variables:
name (str) β The name of the next screen or plugin
type (pywa.types.flows.NextType | str) β The type of the next action (Default:
NextType.SCREEN)
- class pywa.types.flows.NextType#
The type of the next action
- Variables:
SCREEN β Navigate to the next screen
PLUGIN β Trigger a plugin
- class pywa.types.flows.FlowStr#
Dynamic string that uses variables and math expressions. This is a helper class to avoid all the escaping and wrapping with quotes when using string concatenation.
Added in v6.0.
Example:
>>> FlowJSON( ... screens=[ ... Screen( ... id='START', ... layout=Layout(children=[ ... age := TextInput(name='age', input_type=InputType.NUMBER), ... email := TextInput(name='email', input_type=InputType.EMAIL), ... TextHeading(text=FlowStr("Your age is {age} and your email is {email}", age=age.ref, email=email.ref), ...) ... ]) ... ) ... ] ... ) >>> FlowJSON( ... screens=[ ... Screen( ... id='START', ... layout=Layout(children=[ ... bill := TextInput(name='bill', input_type=InputType.NUMBER), ... tip := TextInput(name='tip', input_type=InputType.NUMBER), ... TextHeading(text=FlowStr("Your total bill is {bill}", bill=bill.ref + (bill.ref * tip.ref / 100)), ...) ... ]) ... ) ... ] ... )
- class pywa.types.flows.ScreenDataRef#
Represents a
ScreenDatareference (converts to${data.<key>}|${screen.<screen>.data.<key>}).Example
Hint: use this class directly only if you donβt have access to the
ScreenDataobject.Hint: use the
.refproperty ofScreenDatato get reference to a ScreenData.Hint: use the
.ref_in(screen)method ofScreenDatato get the data ref from another screen (orscreen/ref).
>>> FlowJSON( ... screens=[ ... other := Screen(id='OTHER', data=[is_visible := ScreenData(key='is_visible', example=True)]), ... Screen( ... id='START', ... data=[welcome := ScreenData(key='welcome', example='Welcome to my store!')], ... layout=Layout(children=[ ... TextHeading( ... text=welcome.ref, # data in the same screen ... visible=is_visible.ref_in(other) # data from other screen ... ), ... TextBody( ... text=ScreenDataRef(key='welcome', screen='START'), # using the class directly ... ]) ... ) ... ] ... )
- Parameters:
key β The key to get from the
Screen.data attribute.screen β The screen that contains the data (needed if the data is from another screen). Added in v4.0.
- class pywa.types.flows.ComponentRef#
Represents a componenent reference variable (converts to
${form.<child>}|${screen.<screen>.form.<child>}).Example
Hint: use this class directly only if you donβt have access to the component object.
Hint: use the
.refproperty of each component to get a reference to this component.Hint: use the
.ref_in(screen)method of each component to get the component reference variable of that component with the given screen name.
>>> FlowJSON( ... screens=[ ... other := Screen( ... id='OTHER', ... layout=Layout(children=[Form(children=[email := TextInput(name='email', ...), ...])]) ... ), ... Screen( ... id='START', ... layout=Layout(children=[ ... phone := TextInput(name='phone', ...), ... TextBody(text=phone.ref, ...), # component reference from the same screen ... TextCaption(text=email.ref_in(other), ...) # component reference from another screen ... TextHeading(text=ComponentRef('phone', screen='START'), ...) # using the class directly ... ]) ... ) ... ] ... )
- Parameters:
component_name β The name of the component to get the value from.
screen β The name of the screen that contains the form. Added in v4.0.
- class pywa.types.flows.Condition#
This class automatically created when using the comparison operators on
Refobjects.Example:
>>> age = TextInput(name="age", input_type=InputType.NUMBER) >>> opt_in = OptIn(name="opt_in") >>> text = TextBody(text=..., visible=(age.ref > 20) & opt_in.ref)
Supported Operators:
Operator
Symbol
Types allowed
Python
Equal
==age.ref == 20Not Equal
!=age.ref != 20Greater
>age.ref > 20Greater Equal
>=age.ref >= 20Less
<age.ref < 20Less Equal
<=age.ref <= 20And
&&<Condition>
(age.ref > 20) & opt_in.refOr
||<Condition>
(age.ref > 20) | opt_in.refNot
!<Condition>
~opt_in.ref
- class pywa.types.flows.MathExpression#
This class automatically created when using the arithmetic operators on
Refobjects.Example:
# Display the year you born in by subtracting the age from 2025: >>> age = TextInput(name="age", input_type=InputType.NUMBER) >>> text = TextBody(text=FlowStr("You born in {year}", year=2025 - age.ref)) # Calculating tip: >>> bill = TextInput(name="bill", input_type=InputType.NUMBER) >>> tip_percent = TextInput(name="tip_percent", input_type=InputType.NUMBER) >>> total = TextBody(text=FlowStr("Total: {total}", total=bill.ref + (bill.ref * tip_percent.ref / 100)))
Supported Operators: