diff --git a/pywa/api.py b/pywa/api.py index 58f21153..d012fe64 100644 --- a/pywa/api.py +++ b/pywa/api.py @@ -525,6 +525,41 @@ def send_interactive_message( }, ) + def register_phone_number( + self, password: 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. + """ + + return self._make_request( + method="POST", + endpoint=f"/{self.phone_id}/register", + json={ + **self._common_keys, + "pin": password, + **( + {"data_localization_region": data_localization_region} + if data_localization_region + else {} + ), + }, + ) + def send_contacts( self, to: str, diff --git a/pywa/client.py b/pywa/client.py index 9c9f909d..3f3695e5 100644 --- a/pywa/client.py +++ b/pywa/client.py @@ -1062,6 +1062,33 @@ 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,