From 3a07ee42a877307047e4d841e63e692d535ed1e9 Mon Sep 17 00:00:00 2001 From: David Lev Date: Fri, 12 Jan 2024 01:34:43 +0200 Subject: [PATCH] [client] rename `.register_phone_number` args --- .../content/client/client_reference.rst | 1 + pywa/api.py | 12 +--- pywa/client.py | 59 ++++++++++--------- 3 files changed, 35 insertions(+), 37 deletions(-) diff --git a/docs/source/content/client/client_reference.rst b/docs/source/content/client/client_reference.rst index 401ac8c4..981f7feb 100644 --- a/docs/source/content/client/client_reference.rst +++ b/docs/source/content/client/client_reference.rst @@ -36,3 +36,4 @@ Client Reference .. automethod:: WhatsApp.get_flow .. automethod:: WhatsApp.get_flows .. automethod:: WhatsApp.get_flow_assets +.. automethod:: WhatsApp.register_phone_number diff --git a/pywa/api.py b/pywa/api.py index d012fe64..5edd80b3 100644 --- a/pywa/api.py +++ b/pywa/api.py @@ -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. """ @@ -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 diff --git a/pywa/client.py b/pywa/client.py index 3f3695e5..474248d7 100644 --- a/pywa/client.py +++ b/pywa/client.py @@ -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, @@ -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 `_ + + 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 `_ it. + data_localization_region: If included, enables + `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,