Skip to content

Commit

Permalink
[client] rename .register_phone_number args
Browse files Browse the repository at this point in the history
  • Loading branch information
david-lev committed Jan 11, 2024
1 parent 649c092 commit 3a07ee4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 37 deletions.
1 change: 1 addition & 0 deletions docs/source/content/client/client_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ Client Reference
.. automethod:: WhatsApp.get_flow
.. automethod:: WhatsApp.get_flows
.. automethod:: WhatsApp.get_flow_assets
.. automethod:: WhatsApp.register_phone_number
12 changes: 2 additions & 10 deletions pywa/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,22 +526,14 @@ def send_interactive_message(
)

def register_phone_number(
self, password: str, data_localization_region: str = None
self, pin: str, data_localization_region: str = None
) -> dict[str, bool]:
"""
Register a phone number with WhatsApp.
Return example:
{
'success': True,
}
Args:
password: The 2fa of the phone number (if 2fa is enabled set password to 111111).
if you don't remember the password read the docs in facebook: https://developers.facebook.com/docs/whatsapp/cloud-api/reference/two-step-verification#updating-verification-code
data_localization_region: the data localization region of the phone number.
Returns:
The success of the operation.
"""
Expand All @@ -551,7 +543,7 @@ def register_phone_number(
endpoint=f"/{self.phone_id}/register",
json={
**self._common_keys,
"pin": password,
"pin": pin,
**(
{"data_localization_region": data_localization_region}
if data_localization_region
Expand Down
59 changes: 32 additions & 27 deletions pywa/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,33 +1062,6 @@ def send_products(
reply_to_message_id=reply_to_message_id,
)["messages"][0]["id"]

def register_phone_number(
self, password: str | int, data_localization_region: str = None
) -> bool:
"""
Register a phone number with WhatsApp.
read more in fecebook develeopers https://developers.facebook.com/docs/whatsapp/cloud-api/reference/registration
Example:
>>> wa = WhatsApp(...)
>>> wa.register_phone_number(password='111111', data_localization_region='US')
Args:
password: The 2fa of the phone number (if 2fa is enabled set password to 111111).
if you don't remember the password read the docs in facebook: https://developers.facebook.com/docs/whatsapp/cloud-api/reference/two-step-verification#updating-verification-code
data_localization_region: the data localization region of the phone number.
Returns:
The success of the operation.
"""

return self.api.register_phone_number(
password=str(password), data_localization_region=data_localization_region
)["success"]

def mark_message_as_read(
self,
message_id: str,
Expand Down Expand Up @@ -1890,6 +1863,38 @@ def get_flow_assets(
)["data"]
)

def register_phone_number(
self, pin: int | str, data_localization_region: str | None = None
) -> bool:
"""
Register a Business Phone Number
- Read more at `developers.facebook.com <https://developers.facebook.com/docs/whatsapp/cloud-api/reference/registration>`_
Example:
>>> wa = WhatsApp(...)
>>> wa.register_phone_number(password='111111', data_localization_region='US')
Args:
pin: If your verified business phone number already has two-step verification enabled,
set this value to your number's 6-digit two-step verification PIN.
If you cannot recall your PIN, you can
`uptdate <https://developers.facebook.com/docs/whatsapp/cloud-api/reference/two-step-verification#updating-verification-code>`_ it.
data_localization_region: If included, enables
`local storage <https://developers.facebook.com/docs/whatsapp/cloud-api/overview/local-storage/>`_ on the
business phone number.
Value must be a 2-letter ISO 3166 country code (e.g. ``IN``) indicating the country where you
want data-at-rest to be stored.
Returns:
The success of the registration.
"""

return self.api.register_phone_number(
pin=str(pin), data_localization_region=data_localization_region
)["success"]


def _resolve_buttons_param(
buttons: Iterable[Button] | ButtonUrl | FlowButton | SectionList,
Expand Down

0 comments on commit 3a07ee4

Please sign in to comment.