Skip to content

Commit

Permalink
test message models
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkahan committed Apr 10, 2024
1 parent 989be78 commit 847df22
Show file tree
Hide file tree
Showing 22 changed files with 1,165 additions and 73 deletions.
37 changes: 11 additions & 26 deletions messages/src/vonage_messages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
# from .enums import ChannelType, Locale
# from .errors import VerifyError
# from .requests import (
# EmailChannel,
# SilentAuthChannel,
# SmsChannel,
# VerifyRequest,
# VoiceChannel,
# WhatsappChannel,
# )
# from .responses import CheckCodeResponse, StartVerificationResponse
# from .verify_v2 import VerifyV2
from . import models
from .enums import ChannelType, EncodingType, MessageType, WebhookVersion
from .messages import Messages

# __all__ = [
# 'VerifyV2',
# 'VerifyError',
# 'ChannelType',
# 'CheckCodeResponse',
# 'Locale',
# 'VerifyRequest',
# 'SilentAuthChannel',
# 'SmsChannel',
# 'WhatsappChannel',
# 'VoiceChannel',
# 'EmailChannel',
# 'StartVerificationResponse',
# ]
__all__ = [
'models',
'Messages',
'ChannelType',
'MessageType',
'WebhookVersion',
'EncodingType',
]
5 changes: 0 additions & 5 deletions messages/src/vonage_messages/errors.py

This file was deleted.

4 changes: 2 additions & 2 deletions messages/src/vonage_messages/messages.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pydantic import validate_call
from vonage_http_client.http_client import HttpClient

from .models.sms import BaseMessage
from .models import BaseMessage
from .responses import MessageUuid


Expand All @@ -22,7 +22,7 @@ def send(self, message: BaseMessage) -> MessageUuid:
"""Send a message using Vonage's Messages API.
Args:
message (Message): The message to be sent.
message (BaseMessage): The message to be sent.
Returns:
MessageUuid: The unique identifier of the sent message.
Expand Down
2 changes: 1 addition & 1 deletion messages/src/vonage_messages/models/BUILD
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python_sources()
python_sources(name='models')
2 changes: 1 addition & 1 deletion messages/src/vonage_messages/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .message import BaseMessage
from .base_message import BaseMessage
from .messenger import (
MessengerAudio,
MessengerFile,
Expand Down
12 changes: 6 additions & 6 deletions messages/src/vonage_messages/models/messenger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pydantic import BaseModel, Field, model_validator

from ..enums import ChannelType, MessageType
from .message import BaseMessage
from .base_message import BaseMessage


class MessengerResource(BaseModel):
Expand All @@ -30,24 +30,24 @@ class BaseMessenger(BaseMessage):

class MessengerText(BaseMessenger):
text: str = Field(..., max_length=640)
type: MessageType = MessageType.TEXT
message_type: MessageType = MessageType.TEXT


class MessengerImage(BaseMessenger):
image: MessengerResource
type: MessageType = MessageType.IMAGE
message_type: MessageType = MessageType.IMAGE


class MessengerAudio(BaseMessenger):
audio: MessengerResource
type: MessageType = MessageType.AUDIO
message_type: MessageType = MessageType.AUDIO


class MessengerVideo(BaseMessenger):
video: MessengerResource
type: MessageType = MessageType.VIDEO
message_type: MessageType = MessageType.VIDEO


class MessengerFile(BaseMessenger):
file: MessengerResource
type: MessageType = MessageType.FILE
message_type: MessageType = MessageType.FILE
2 changes: 1 addition & 1 deletion messages/src/vonage_messages/models/mms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from vonage_utils.types.phone_number import PhoneNumber

from ..enums import ChannelType, MessageType
from .message import BaseMessage
from .base_message import BaseMessage


class MmsResource(BaseModel):
Expand Down
2 changes: 1 addition & 1 deletion messages/src/vonage_messages/models/sms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from vonage_utils.types.phone_number import PhoneNumber

from ..enums import ChannelType, EncodingType, MessageType
from .message import BaseMessage
from .base_message import BaseMessage


class SmsOptions(BaseModel):
Expand Down
4 changes: 2 additions & 2 deletions messages/src/vonage_messages/models/viber.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pydantic import BaseModel, Field, field_validator

from ..enums import ChannelType, MessageType
from .message import BaseMessage
from .base_message import BaseMessage


class ViberAction(BaseModel):
Expand Down Expand Up @@ -77,7 +77,7 @@ def validate_file_size(cls, value):

class ViberVideo(BaseViber):
video: ViberVideoResource
viber_service: Optional[ViberVideoOptions] = None
viber_service: ViberVideoOptions
message_type: MessageType = MessageType.VIDEO


Expand Down
28 changes: 14 additions & 14 deletions messages/src/vonage_messages/models/whatsapp.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import Literal, Optional, Union
from typing import List, Literal, Optional, Union

from pydantic import BaseModel, ConfigDict, Field
from vonage_utils.types.phone_number import PhoneNumber

from ..enums import ChannelType, MessageType
from .message import BaseMessage
from .base_message import BaseMessage


class WhatsappContext(BaseModel):
Expand All @@ -13,13 +13,13 @@ class WhatsappContext(BaseModel):

class BaseWhatsapp(BaseMessage):
from_: Union[PhoneNumber, str] = Field(..., serialization_alias='from')
context: WhatsappContext
context: Optional[WhatsappContext] = None
channel: ChannelType = ChannelType.WHATSAPP


class WhatsappText(BaseWhatsapp):
text: str = Field(..., max_length=4096)
type: MessageType = MessageType.TEXT
message_type: MessageType = MessageType.TEXT


class WhatsappImageResource(BaseModel):
Expand All @@ -29,7 +29,7 @@ class WhatsappImageResource(BaseModel):

class WhatsappImage(BaseWhatsapp):
image: WhatsappImageResource
type: MessageType = MessageType.IMAGE
message_type: MessageType = MessageType.IMAGE


class WhatsappAudioResource(BaseModel):
Expand All @@ -38,7 +38,7 @@ class WhatsappAudioResource(BaseModel):

class WhatsappAudio(BaseWhatsapp):
audio: WhatsappAudioResource
type: MessageType = MessageType.AUDIO
message_type: MessageType = MessageType.AUDIO


class WhatsappVideoResource(BaseModel):
Expand All @@ -48,7 +48,7 @@ class WhatsappVideoResource(BaseModel):

class WhatsappVideo(BaseWhatsapp):
video: WhatsappVideoResource
type: MessageType = MessageType.VIDEO
message_type: MessageType = MessageType.VIDEO


class WhatsappFileResource(BaseModel):
Expand All @@ -59,25 +59,25 @@ class WhatsappFileResource(BaseModel):

class WhatsappFile(BaseWhatsapp):
file: WhatsappFileResource
type: MessageType = MessageType.FILE
message_type: MessageType = MessageType.FILE


class WhatsappTemplateResource(BaseModel):
name: str
parameters: Optional[list] = None
parameters: Optional[List[str]] = None

model_config = ConfigDict(extra='allow')


class WhatsappTemplateSettings(BaseModel):
locale: str = 'en_US'
locale: Optional[str] = 'en_US'
policy: Optional[Literal['deterministic']] = None


class WhatsappTemplate(BaseWhatsapp):
template: WhatsappTemplateResource
whatsapp: WhatsappTemplateSettings
type: MessageType = MessageType.TEMPLATE
whatsapp: WhatsappTemplateSettings = WhatsappTemplateSettings()
message_type: MessageType = MessageType.TEMPLATE


class WhatsappStickerUrl(BaseModel):
Expand All @@ -90,9 +90,9 @@ class WhatsappStickerId(BaseModel):

class WhatsappSticker(BaseWhatsapp):
sticker: Union[WhatsappStickerUrl, WhatsappStickerId]
type: MessageType = MessageType.STICKER
message_type: MessageType = MessageType.STICKER


class WhatsappCustom(BaseWhatsapp):
custom: Optional[dict] = None
type: MessageType = MessageType.CUSTOM
message_type: MessageType = MessageType.CUSTOM
4 changes: 4 additions & 0 deletions messages/tests/BUILD
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
python_tests(dependencies=['messages', 'testutils'])

python_sources(
name="tests0",
)
File renamed without changes.
Loading

0 comments on commit 847df22

Please sign in to comment.