Skip to content

Commit

Permalink
Merge pull request #83 from david-lev/flows-v6
Browse files Browse the repository at this point in the history
Flows v6
  • Loading branch information
david-lev authored Nov 24, 2024
2 parents 2fc79c6 + b720adc commit 651b4ad
Show file tree
Hide file tree
Showing 18 changed files with 2,120 additions and 303 deletions.
20 changes: 18 additions & 2 deletions docs/source/content/flows/flow_json.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ Here you will find all the components that make up a Flow JSON object.

.. autoclass:: DatePicker()

.. autoclass:: CalendarPicker()

.. autoclass:: CalendarPickerMode()

.. autoclass:: CalendarDay()

.. autoclass:: Image()

.. autoclass:: ScaleType()
Expand All @@ -65,9 +71,15 @@ Here you will find all the components that make up a Flow JSON object.

.. autoclass:: DataSource()

.. autoclass:: Action()
.. autoclass:: DataExchangeAction()

.. autoclass:: NavigateAction()

.. autoclass:: FlowActionType()
.. autoclass:: CompleteAction()

.. autoclass:: UpdateDataAction()

.. autoclass:: OpenUrlAction()

.. autoclass:: ActionNext()

Expand All @@ -76,3 +88,7 @@ Here you will find all the components that make up a Flow JSON object.
.. autoclass:: ScreenDataRef()

.. autoclass:: ComponentRef()

.. autoclass:: Condition()

.. autoclass:: MathExpression()
18 changes: 12 additions & 6 deletions docs/source/content/flows/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ Every component on the FlowJSON, has a corresponding class in :mod:`pywa.types.f
:class:`CheckboxGroup`,
:class:`Dropdown`,
:class:`OptIn`,
:class:`DatePicker`,
:class:`CalendarPicker`,
:class:`PhotoPicker`,
:class:`DocumentPicker`
* - Navigation
Expand All @@ -88,6 +90,12 @@ Every component on the FlowJSON, has a corresponding class in :mod:`pywa.types.f
* - Conditional Component Rendering
- :class:`If`,
:class:`Switch`
* - Actions
- :class:`DataExchangeAction`,
:class:`NavigateAction`,
:class:`CompleteAction`,
:class:`UpdateDataAction`,
:class:`OpenUrlAction`

==================

Expand All @@ -102,7 +110,7 @@ Every component on the FlowJSON, has a corresponding class in :mod:`pywa.types.f
.. code-block:: python
:caption: simple_sign_up_flow.py
:linenos:
:emphasize-lines: 16, 22, 28, 40-42
:emphasize-lines: 16, 22, 28, 39-41
from pywa.types.flows import *
Expand Down Expand Up @@ -140,8 +148,7 @@ Every component on the FlowJSON, has a corresponding class in :mod:`pywa.types.f
Footer(
label="Done",
enabled=True,
on_click_action=Action(
name=FlowActionType.COMPLETE,
on_click_action=CompleteAction(
payload={
"first_name": first_name.ref,
"last_name": last_name.ref,
Expand Down Expand Up @@ -244,7 +251,7 @@ Every component on the FlowJSON, has a corresponding class in :mod:`pywa.types.f
.. code-block:: python
:caption: dynamic_sign_up_flow.py
:linenos:
:emphasize-lines: 3, 11-13, 21, 26, 28, 32, 34, 38, 45-47
:emphasize-lines: 3, 11-13, 21, 26, 28, 32, 34, 38, 44-46
dynamic_flow = FlowJSON(
Expand Down Expand Up @@ -288,8 +295,7 @@ Every component on the FlowJSON, has a corresponding class in :mod:`pywa.types.f
),
Footer(
label="Done",
on_click_action=Action(
name=FlowActionType.COMPLETE,
on_click_action=CompleteAction(
payload={
"first_name": last_name.ref,
"last_name": last_name.ref,
Expand Down
18 changes: 8 additions & 10 deletions pywa/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(
self._validate_updates = validate_updates
self._continue_handling = continue_handling
self._skip_duplicate_updates = skip_duplicate_updates
self._updates_ids_in_process = set[
self._updates_in_process = set[
str | int
]() # TODO use threading.Lock | asyncio.Lock

Expand Down Expand Up @@ -191,7 +191,7 @@ def webhook_update_handler(
if res:
return res, status
self._call_handlers(update_dict)
return self._after_calling_update(update_hash)
return self._after_handling_update(update_hash)

def _check_and_prepare_update(
self, update: bytes, hmac_header: str = None
Expand Down Expand Up @@ -223,25 +223,23 @@ def _check_and_prepare_update(
)
return "Error, invalid update", 400, None, None

update_hash: str | int | None = None
update_hash = hmac_header or hash(update)
_logger.debug(
"Webhook ('%s') received an update: %s",
self._webhook_endpoint,
update_dict,
)
if self._skip_duplicate_updates and (
update_hash := (hmac_header or hash(update))
):
if update_hash in self._updates_ids_in_process:
if self._skip_duplicate_updates:
if update_hash in self._updates_in_process:
return "ok", 200, None, None
self._updates_ids_in_process.add(update_hash)
self._updates_in_process.add(update_hash)

return None, None, update_dict, update_hash

def _after_calling_update(self, update_hash: str | None) -> tuple[str, int]:
def _after_handling_update(self, update_hash: str) -> tuple[str, int]:
if self._skip_duplicate_updates:
try:
self._updates_ids_in_process.remove(update_hash)
self._updates_in_process.remove(update_hash)
except KeyError:
pass
return "ok", 200
Expand Down
Loading

0 comments on commit 651b4ad

Please sign in to comment.