Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion verify/src/vonage_verify/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .enums import ChannelType, Locale
from .enums import ChannelType, Locale, WhatsappMode
from .errors import VerifyError
from .requests import (
EmailChannel,
Expand All @@ -21,6 +21,7 @@
'SilentAuthChannel',
'SmsChannel',
'WhatsappChannel',
'WhatsappMode',
'VoiceChannel',
'EmailChannel',
'StartVerificationResponse',
Expand Down
5 changes: 5 additions & 0 deletions verify/src/vonage_verify/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 5 additions & 1 deletion verify/src/vonage_verify/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -88,13 +88,17 @@ 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
alphanumeric characters.
"""

from_: Union[PhoneNumber, str] = Field(..., serialization_alias='from')
mode: Optional[WhatsappMode] = None
channel: ChannelType = ChannelType.WHATSAPP

@field_validator('from_')
Expand Down
21 changes: 19 additions & 2 deletions verify/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -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 *

Expand Down Expand Up @@ -43,14 +43,31 @@ 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'
with raises(VerifyError):
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,
Expand Down
Loading