Skip to content

Commit

Permalink
[flows] change types and update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
david-lev committed Sep 19, 2024
1 parent 49a12b2 commit 245770b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
2 changes: 2 additions & 0 deletions docs/source/content/flows/flow_json.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Here you will find all the components that make up a Flow JSON object.

.. autoclass:: TextCaption()

.. autoclass:: RichText()

.. autoclass:: FontWeight()

.. autoclass:: TextInput()
Expand Down
47 changes: 36 additions & 11 deletions pywa/types/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"TextSubheading",
"TextBody",
"TextCaption",
"RichText",
"FontWeight",
"TextInput",
"InputType",
Expand Down Expand Up @@ -1479,7 +1480,7 @@ class TextHeading(TextComponent):
>>> TextHeading(text='Heading', visible=True)
Attributes:
text: The text of the heading. Limited to 4096 characters. Can be dynamic.
text: The text of the heading. Limited to 80 characters. Can be dynamic.
visible: Whether the heading is visible or not. Default to ``True``, Can be dynamic.
"""

Expand All @@ -1502,7 +1503,7 @@ class TextSubheading(TextComponent):
>>> TextSubheading(text='Subheading', visible=True)
Attributes:
text: The text of the subheading. Limited to 60 characters. Can be dynamic.
text: The text of the subheading. Limited to 80 characters. Can be dynamic.
visible: Whether the subheading is visible or not. Default to ``True``, Can be dynamic.
"""

Expand Down Expand Up @@ -1530,7 +1531,8 @@ class TextBody(TextComponent):
... )
Attributes:
text: The text of the body. Limited to 80 characters. Can be dynamic.
text: The text of the body. Limited to 4096 characters. Can be dynamic.
markdown: Whether the text is markdown or not (Added in v5.1).
font_weight: The weight of the text. Can be dynamic.
strikethrough: Whether the text is strikethrough or not. Can be dynamic.
visible: Whether the body is visible or not. Default to ``True``, Can be dynamic.
Expand All @@ -1539,8 +1541,8 @@ class TextBody(TextComponent):
type: ComponentType = dataclasses.field(
default=ComponentType.TEXT_BODY, init=False, repr=False
)
text: str | list[str] | DataKey | FormRef
markdown: bool | str | DataKey | FormRef | None = None
text: str | Iterable[str] | DataKey | FormRef
markdown: bool | None = None
font_weight: FontWeight | str | DataKey | FormRef | None = None
strikethrough: bool | str | DataKey | FormRef | None = None
visible: bool | str | DataKey | FormRef | None = None
Expand All @@ -1563,7 +1565,8 @@ class TextCaption(TextComponent):
Attributes:
text: The text of the caption. Limited to 4096 characters. Can be dynamic.
text: The text of the caption (array of strings supported since v5.1). Limited to 4096 characters. Can be dynamic.
markdown: Whether the text is markdown or not (Added in v5.1).
font_weight: The weight of the text. Can be dynamic.
strikethrough: Whether to strike through the text or not. Can be dynamic.
visible: Whether the caption is visible or not. Default to ``True``, Can be dynamic.
Expand All @@ -1572,8 +1575,8 @@ class TextCaption(TextComponent):
type: ComponentType = dataclasses.field(
default=ComponentType.TEXT_CAPTION, init=False, repr=False
)
text: str | list[str] | DataKey | FormRef
markdown: bool | str | DataKey | FormRef | None = None
text: str | Iterable[str] | DataKey | FormRef
markdown: bool | None = None
font_weight: FontWeight | str | DataKey | FormRef | None = None
strikethrough: bool | str | DataKey | FormRef | None = None
visible: bool | str | DataKey | FormRef | None = None
Expand All @@ -1585,23 +1588,45 @@ class RichText(TextComponent):
Represents text that is displayed as a rich text.
- Read more at `developers.facebook.com <https://developers.facebook.com/docs/whatsapp/flows/reference/flowjson/components#richtext>`_.
- 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=['**bold**'],
... 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",
... "![image](data:image/png;base64,<base64 content>)",
... "| Tables | Are | Cool |",
... "| ------------- | ------------- | ----- |",
... "| col 3 is | right-aligned | $1600 |",
... "| col 2 is | centered | $12 |",
... ],
... )
Attributes:
text:
text: The markdown text (array of strings supported). Limited to 4096 characters. Can be dynamic.
visible: Whether the caption is visible or not. Default to ``True``, Can be dynamic.
"""

type: ComponentType = dataclasses.field(
default=ComponentType.RICH_TEXT, init=False, repr=False
)
text: str | list[str] | DataKey | FormRef
text: str | Iterable[str] | DataKey | FormRef
visible: bool | str | DataKey | FormRef | None = None


Expand Down
3 changes: 2 additions & 1 deletion pywa_async/types/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"TextSubheading",
"TextBody",
"TextCaption",
"RichText",
"FontWeight",
"TextInput",
"InputType",
Expand All @@ -51,9 +52,9 @@
"DataSource",
"Action",
"FlowActionType",
"FlowRequestActionType",
"ActionNext",
"ActionNextType",
"RichText"
]

from pywa.types.flows import * # noqa MUST BE IMPORTED FIRST
Expand Down

0 comments on commit 245770b

Please sign in to comment.