diff --git a/verify/src/vonage_verify/__init__.py b/verify/src/vonage_verify/__init__.py index 90218321..34b87445 100644 --- a/verify/src/vonage_verify/__init__.py +++ b/verify/src/vonage_verify/__init__.py @@ -1,4 +1,4 @@ -from .enums import ChannelType, Locale +from .enums import ChannelType, Locale, WhatsappMode from .errors import VerifyError from .requests import ( EmailChannel, @@ -21,6 +21,7 @@ 'SilentAuthChannel', 'SmsChannel', 'WhatsappChannel', + 'WhatsappMode', 'VoiceChannel', 'EmailChannel', 'StartVerificationResponse', diff --git a/verify/src/vonage_verify/enums.py b/verify/src/vonage_verify/enums.py index 0871f945..987f0e32 100644 --- a/verify/src/vonage_verify/enums.py +++ b/verify/src/vonage_verify/enums.py @@ -9,6 +9,11 @@ class ChannelType(str, Enum): EMAIL = 'email' +class WhatsappMode(str, Enum): + ZERO_TAP = 'zero_tap' + OTP_CODE = 'otp_code' + + class Locale(str, Enum): EN_US = 'en-us' EN_GB = 'en-gb' diff --git a/verify/src/vonage_verify/requests.py b/verify/src/vonage_verify/requests.py index 2561af56..478b1c59 100644 --- a/verify/src/vonage_verify/requests.py +++ b/verify/src/vonage_verify/requests.py @@ -4,7 +4,7 @@ from pydantic import BaseModel, Field, field_validator, model_validator from vonage_utils.types import PhoneNumber -from .enums import ChannelType, Locale +from .enums import ChannelType, Locale, WhatsappMode from .errors import VerifyError @@ -88,6 +88,9 @@ class WhatsappChannel(Channel): from_ (Union[PhoneNumber, str]): A WhatsApp Business Account (WABA)-connected sender number, in the E.164 format. Don't use a leading + or 00 when entering a phone number. + mode (WhatsappMode, Optional): Defines the WhatsApp verification experience. Use + `WhatsappMode.ZERO_TAP` for automatic verification on Android apps. Defaults + to `WhatsappMode.OTP_CODE`. Raises: VerifyError: If the `from_` field is not a valid phone number or string of 3-11 @@ -95,6 +98,7 @@ class WhatsappChannel(Channel): """ from_: Union[PhoneNumber, str] = Field(..., serialization_alias='from') + mode: Optional[WhatsappMode] = None channel: ChannelType = ChannelType.WHATSAPP @field_validator('from_') diff --git a/verify/tests/test_models.py b/verify/tests/test_models.py index 88c075a5..d34358c3 100644 --- a/verify/tests/test_models.py +++ b/verify/tests/test_models.py @@ -1,5 +1,5 @@ from pytest import raises -from vonage_verify.enums import ChannelType, Locale +from vonage_verify.enums import ChannelType, Locale, WhatsappMode from vonage_verify.errors import VerifyError from vonage_verify.requests import * @@ -43,7 +43,7 @@ def test_create_whatsapp_channel(): } channel = WhatsappChannel(**params) - assert channel.model_dump() == params + assert channel.model_dump() == {**params, 'mode': None} assert channel.model_dump(by_alias=True)['from'] == 'Vonage' params['from_'] = 'this.is!invalid' @@ -51,6 +51,23 @@ def test_create_whatsapp_channel(): WhatsappChannel(**params) +def test_create_whatsapp_channel_with_mode(): + params = { + 'channel': ChannelType.WHATSAPP, + 'to': '1234567890', + 'from_': 'Vonage', + 'mode': WhatsappMode.ZERO_TAP, + } + channel = WhatsappChannel(**params) + + assert channel.mode == WhatsappMode.ZERO_TAP + assert channel.model_dump()['mode'] == WhatsappMode.ZERO_TAP + + params['mode'] = WhatsappMode.OTP_CODE + channel = WhatsappChannel(**params) + assert channel.mode == WhatsappMode.OTP_CODE + + def test_create_voice_channel(): params = { 'channel': ChannelType.VOICE,