Skip to content

Commit

Permalink
[flows] flow_name instead of flow_id while sending. flow_token
Browse files Browse the repository at this point in the history
…is now optional
  • Loading branch information
david-lev committed Jan 15, 2025
1 parent 81027da commit a917cee
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions pywa/types/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,20 +517,19 @@ class FlowButton:
Attributes:
title: Text on the CTA button. e.g ``SignUp``, Up to 20 characters, no emojis)
flow_id: Unique ID of the Flow provided by WhatsApp.
flow_token: Flow token generated by the business to serve as an identifier for data exchange.
flow_id: Unique ID of the Flow provided by WhatsApp (You can provide either ``flow_id`` or ``flow_name``).
flow_token: Flow token generated by the business to serve as an identifier (Default value: ``unused``)
flow_message_version: Version of the flow message. Default is the latest version.
flow_action_type: Type of action to be performed when the user clicks on the CTA button.
flow_action_screen: The ID of the first Screen.
Required when ``flow_action_type`` is ``FlowActionType.NAVIGATE`` (default).
flow_action_payload: The payload to send when the user clicks on the button
(optional, only when ``flow_action_type`` is ``FlowActionType.NAVIGATE``).
flow_action_type: Type of action to be performed when the user clicks on the button.
flow_action_screen: The ID of the screen to navigate to. Required when ``flow_action_type`` is ``FlowActionType.NAVIGATE`` (default).
flow_action_payload: The data to provide to the navigation screen, if the screen requires it.
mode: The mode of the flow. ``FlowStatus.PUBLISHED`` (default) or ``FlowStatus.DRAFT`` (for testing).
flow_name: Name of the Flow provided by WhatsApp (You can provide either ``flow_id`` or ``flow_name``).
"""

title: str
flow_id: str | int
flow_token: str
flow_id: str | int | None = None
flow_token: str | None = None
flow_action_type: (
Literal[FlowActionType.NAVIGATE, FlowActionType.DATA_EXCHANGE] | None
) = None
Expand All @@ -540,6 +539,7 @@ class FlowButton:
utils.Version.FLOW_MSG
)
mode: Literal[FlowStatus.PUBLISHED, FlowStatus.DRAFT] = FlowStatus.PUBLISHED
flow_name: str | None = None

def __post_init__(self):
utils.Version.FLOW_MSG.validate_min_version(str(self.flow_message_version))
Expand All @@ -550,6 +550,12 @@ def __post_init__(self):
raise ValueError(
"flow_action_screen cannot be None when flow_action_type is FlowActionType.NAVIGATE"
)
if (not self.flow_id and not self.flow_name) or (
self.flow_id and self.flow_name
):
raise ValueError(
"Either flow_id or flow_name must be provided, but not both."
)

def to_dict(self) -> dict:
return {
Expand All @@ -558,7 +564,8 @@ def to_dict(self) -> dict:
"mode": self.mode.lower(),
"flow_message_version": str(self.flow_message_version),
"flow_token": self.flow_token,
"flow_id": self.flow_id,
"flow_id" if self.flow_id else "flow_name": self.flow_id
or self.flow_name,
"flow_cta": self.title,
**(
{"flow_action": str(self.flow_action_type)}
Expand Down

0 comments on commit a917cee

Please sign in to comment.