Skip to content

Commit

Permalink
Merge pull request #34 from yehuda-lev/master
Browse files Browse the repository at this point in the history
[client] Added register_phone_number
  • Loading branch information
david-lev authored Jan 11, 2024
2 parents fc47b0d + 35b38e0 commit 649c092
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pywa/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 27 additions & 0 deletions pywa/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 649c092

Please sign in to comment.