Skip to content

Commit ac4b041

Browse files
authored
Merge pull request #98 from david-lev/flows-v6.3
Flows v6.3
2 parents 3d21648 + 1dae741 commit ac4b041

File tree

7 files changed

+145
-1
lines changed

7 files changed

+145
-1
lines changed

docs/source/content/flows/flow_json.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Here you will find all the components that make up a Flow JSON object.
4343

4444
.. autoclass:: CheckboxGroup()
4545

46+
.. autoclass:: ChipsSelector()
47+
4648
.. autoclass:: RadioButtonsGroup()
4749

4850
.. autoclass:: MediaSize()

docs/source/content/flows/overview.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Every component on the FlowJSON has a corresponding class in :mod:`pywa.types.fl
7676
:class:`TextArea`,
7777
:class:`RadioButtonsGroup`,
7878
:class:`CheckboxGroup`,
79+
:class:`ChipsSelector`,
7980
:class:`Dropdown`,
8081
:class:`OptIn`,
8182
:class:`DatePicker`,

pywa/types/flows.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"InputType",
7878
"TextArea",
7979
"CheckboxGroup",
80+
"ChipsSelector",
8081
"RadioButtonsGroup",
8182
"Footer",
8283
"OptIn",
@@ -1476,6 +1477,7 @@ class ComponentType(utils.StrEnum):
14761477
IF = "If"
14771478
SWITCH = "Switch"
14781479
NAVIGATION_LIST = "NavigationList"
1480+
CHIPS_SELECTOR = "ChipsSelector"
14791481

14801482

14811483
class _Expr(abc.ABC):
@@ -2523,6 +2525,61 @@ class Dropdown(FormComponent):
25232525
on_unselect_action: UpdateDataAction | None = None
25242526

25252527

2528+
@dataclasses.dataclass(slots=True, kw_only=True)
2529+
class ChipsSelector(FormComponent):
2530+
"""
2531+
Chips Selector component allows users to pick multiple selections from a list of options.
2532+
2533+
- Added in v6.3
2534+
- Read more at `developers.facebook.com <https://developers.facebook.com/docs/whatsapp/flows/reference/components#chips_selector>`_.
2535+
2536+
Example:
2537+
2538+
>>> ChipsSelector(
2539+
... name='options',
2540+
... data_source=[
2541+
... DataSource(id='1', title='Option 1'),
2542+
... DataSource(id='2', title='Option 2'),
2543+
... DataSource(id='3', title='Option 3'),
2544+
... ],
2545+
... label='Options',
2546+
... min_selected_items=1,
2547+
... max_selected_items=2,
2548+
... required=True,
2549+
... init_value=['1', '2']
2550+
... )
2551+
2552+
Attributes:
2553+
name: The unique name (id) for this component.
2554+
data_source: The data source of the chips selector.
2555+
label: The label of the chips selector. Limited to 80 characters.
2556+
description: The description of the chips selector. Limited to 300 characters
2557+
min_selected_items: The minimum number of items that can be selected. Minimum value is 1.
2558+
max_selected_items: The maximum number of items that can be selected. Maximum value is 20.
2559+
required: Whether the chips selector is required or not.
2560+
visible: Whether the chips selector is visible or not. Default to ``True``.
2561+
enabled: Whether the chips selector is enabled or not. Default to ``True``.
2562+
init_value: The default values (IDs of the data sources).
2563+
on_select_action: The action to perform when an item is selected.
2564+
"""
2565+
2566+
type: ComponentType = dataclasses.field(
2567+
default=ComponentType.CHIPS_SELECTOR, init=False, repr=False
2568+
)
2569+
name: str
2570+
data_source: Iterable[DataSource] | str | ScreenDataRef | ComponentRef
2571+
label: str | FlowStr | ScreenDataRef | ComponentRef
2572+
description: str | FlowStr | ScreenDataRef | ComponentRef | None = None
2573+
min_selected_items: int | str | ScreenDataRef | ComponentRef | None = None
2574+
max_selected_items: int | str | ScreenDataRef | ComponentRef | None = None
2575+
required: bool | str | ScreenDataRef | ComponentRef | None = None
2576+
visible: bool | str | Condition | ScreenDataRef | ComponentRef | None = None
2577+
enabled: bool | str | ScreenDataRef | ComponentRef | None = None
2578+
init_value: list[str] | str | ScreenDataRef | ComponentRef | None = None
2579+
on_select_action: DataExchangeAction | UpdateDataAction | None = None
2580+
on_unselect_action: UpdateDataAction | None = None
2581+
2582+
25262583
@dataclasses.dataclass(slots=True, kw_only=True)
25272584
class Footer(Component):
25282585
"""

pywa/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class Version(enum.Enum):
108108

109109
# KEY = (MIN_VERSION: str, LATEST_VERSION: str)
110110
GRAPH_API = ("17.0", "21.0")
111-
FLOW_JSON = ("2.1", "6.0")
111+
FLOW_JSON = ("2.1", "6.3")
112112
FLOW_DATA_API = ("3.0", "3.0")
113113
FLOW_MSG = ("3", "3")
114114

pywa_async/types/flows.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"InputType",
4040
"TextArea",
4141
"CheckboxGroup",
42+
"ChipsSelector",
4243
"RadioButtonsGroup",
4344
"Footer",
4445
"OptIn",

tests/data/flows/6_3/examples.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
{
2+
"chips_selector": {
3+
"version": "6.3",
4+
"screens": [
5+
{
6+
"id": "DEMO_SCREEN",
7+
"terminal": true,
8+
"title": "Demo screen",
9+
"layout": {
10+
"type": "SingleColumnLayout",
11+
"children": [
12+
{
13+
"type": "ChipsSelector",
14+
"name": "chips",
15+
"label": "Personalize your experience",
16+
"description": "Choose your interests to get personalized design ideas and solution",
17+
"max-selected-items": 2,
18+
"data-source": [
19+
{
20+
"id": "room_layout",
21+
"title": "🏡 Room layouts"
22+
},
23+
{
24+
"id": "lighting",
25+
"title": "💡 Lighting"
26+
},
27+
{
28+
"id": "renovation",
29+
"title": "🛠️ Renovation"
30+
},
31+
{
32+
"id": "furnitures",
33+
"title": "📐 Room layouts"
34+
}
35+
]
36+
},
37+
{
38+
"type": "Footer",
39+
"label": "Continue",
40+
"on-click-action": {
41+
"name": "complete",
42+
"payload": {}
43+
}
44+
}
45+
]
46+
}
47+
}
48+
]
49+
}
50+
}

tests/data/flows/6_3/examples.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from pywa.types.flows import * # noqa
2+
3+
chips_selector = FlowJSON(
4+
version="6.3",
5+
screens=[
6+
Screen(
7+
id="DEMO_SCREEN",
8+
terminal=True,
9+
title="Demo screen",
10+
layout=Layout(
11+
type=LayoutType.SINGLE_COLUMN,
12+
children=[
13+
ChipsSelector(
14+
name="chips",
15+
label="Personalize your experience",
16+
description="Choose your interests to get personalized design ideas and solution",
17+
max_selected_items=2,
18+
data_source=[
19+
DataSource(id="room_layout", title="🏡 Room layouts"),
20+
DataSource(id="lighting", title="💡 Lighting"),
21+
DataSource(id="renovation", title="🛠️ Renovation"),
22+
DataSource(id="furnitures", title="📐 Room layouts"),
23+
],
24+
),
25+
Footer(
26+
label="Continue",
27+
on_click_action=CompleteAction(),
28+
),
29+
],
30+
),
31+
),
32+
],
33+
)

0 commit comments

Comments
 (0)