-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
379 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
python_sources() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
from .message import BaseMessage | ||
from .messenger import ( | ||
MessengerAudio, | ||
MessengerFile, | ||
MessengerImage, | ||
MessengerOptions, | ||
MessengerResource, | ||
MessengerText, | ||
MessengerVideo, | ||
) | ||
from .mms import MmsAudio, MmsImage, MmsResource, MmsVcard, MmsVideo | ||
from .sms import Sms, SmsOptions | ||
from .viber import ( | ||
ViberAction, | ||
ViberFile, | ||
ViberFileOptions, | ||
ViberFileResource, | ||
ViberImage, | ||
ViberImageOptions, | ||
ViberImageResource, | ||
ViberText, | ||
ViberTextOptions, | ||
ViberVideo, | ||
ViberVideoOptions, | ||
ViberVideoResource, | ||
) | ||
from .whatsapp import ( | ||
WhatsappAudio, | ||
WhatsappAudioResource, | ||
WhatsappContext, | ||
WhatsappCustom, | ||
WhatsappFile, | ||
WhatsappFileResource, | ||
WhatsappImage, | ||
WhatsappImageResource, | ||
WhatsappSticker, | ||
WhatsappStickerId, | ||
WhatsappStickerUrl, | ||
WhatsappTemplate, | ||
WhatsappTemplateResource, | ||
WhatsappTemplateSettings, | ||
WhatsappText, | ||
WhatsappVideo, | ||
WhatsappVideoResource, | ||
) | ||
|
||
__all__ = [ | ||
'BaseMessage', | ||
'MessengerAudio', | ||
'MessengerFile', | ||
'MessengerImage', | ||
'MessengerOptions', | ||
'MessengerResource', | ||
'MessengerText', | ||
'MessengerVideo', | ||
'MmsAudio', | ||
'MmsImage', | ||
'MmsResource', | ||
'MmsVcard', | ||
'MmsVideo', | ||
'Sms', | ||
'SmsOptions', | ||
'ViberAction', | ||
'ViberFile', | ||
'ViberFileOptions', | ||
'ViberFileResource', | ||
'ViberImage', | ||
'ViberImageOptions', | ||
'ViberImageResource', | ||
'ViberText', | ||
'ViberTextOptions', | ||
'ViberVideo', | ||
'ViberVideoOptions', | ||
'ViberVideoResource', | ||
'WhatsappAudio', | ||
'WhatsappAudioResource', | ||
'WhatsappContext', | ||
'WhatsappCustom', | ||
'WhatsappFile', | ||
'WhatsappFileResource', | ||
'WhatsappImage', | ||
'WhatsappImageResource', | ||
'WhatsappSticker', | ||
'WhatsappStickerId', | ||
'WhatsappStickerUrl', | ||
'WhatsappTemplate', | ||
'WhatsappTemplateResource', | ||
'WhatsappTemplateSettings', | ||
'WhatsappText', | ||
'WhatsappVideo', | ||
'WhatsappVideoResource', | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from typing import Literal, Optional | ||
|
||
from pydantic import BaseModel, Field, model_validator | ||
|
||
from ..enums import ChannelType, MessageType | ||
from .message import BaseMessage | ||
|
||
|
||
class MessengerResource(BaseModel): | ||
url: str | ||
|
||
|
||
class MessengerOptions(BaseModel): | ||
category: Optional[Literal['response', 'update', 'message_tag']] = None | ||
tag: Optional[str] = None | ||
|
||
@model_validator(mode='after') | ||
def check_tag_if_category_message_tag(self): | ||
if self.category == 'message_tag' and not self.tag: | ||
raise ValueError('"tag" is required when "category" == "message_tag"') | ||
return self | ||
|
||
|
||
class BaseMessenger(BaseMessage): | ||
to: str = Field(..., min_length=1, max_length=50) | ||
from_: str = Field(..., min_length=1, max_length=50, serialization_alias='from') | ||
messenger: Optional[MessengerOptions] = None | ||
channel: ChannelType = ChannelType.MESSENGER | ||
|
||
|
||
class MessengerText(BaseMessenger): | ||
text: str = Field(..., max_length=640) | ||
type: MessageType = MessageType.TEXT | ||
|
||
|
||
class MessengerImage(BaseMessenger): | ||
image: MessengerResource | ||
type: MessageType = MessageType.IMAGE | ||
|
||
|
||
class MessengerAudio(BaseMessenger): | ||
audio: MessengerResource | ||
type: MessageType = MessageType.AUDIO | ||
|
||
|
||
class MessengerVideo(BaseMessenger): | ||
video: MessengerResource | ||
type: MessageType = MessageType.VIDEO | ||
|
||
|
||
class MessengerFile(BaseMessenger): | ||
file: MessengerResource | ||
type: MessageType = MessageType.FILE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from typing import Optional, Union | ||
|
||
from pydantic import BaseModel, Field | ||
from vonage_utils.types.phone_number import PhoneNumber | ||
|
||
from ..enums import ChannelType, MessageType | ||
from .message import BaseMessage | ||
|
||
|
||
class MmsResource(BaseModel): | ||
url: str | ||
caption: Optional[str] = Field(None, min_length=1, max_length=2000) | ||
|
||
|
||
class BaseMms(BaseMessage): | ||
to: PhoneNumber | ||
from_: Union[PhoneNumber, str] = Field(..., serialization_alias='from') | ||
ttl: Optional[int] = Field(None, ge=300, le=259200) | ||
channel: ChannelType = ChannelType.MMS | ||
|
||
|
||
class MmsImage(BaseMms): | ||
image: MmsResource | ||
message_type: MessageType = MessageType.IMAGE | ||
|
||
|
||
class MmsVcard(BaseMms): | ||
vcard: MmsResource | ||
message_type: MessageType = MessageType.VCARD | ||
|
||
|
||
class MmsAudio(BaseMms): | ||
audio: MmsResource | ||
message_type: MessageType = MessageType.AUDIO | ||
|
||
|
||
class MmsVideo(BaseMms): | ||
video: MmsResource | ||
message_type: MessageType = MessageType.VIDEO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
from typing import Literal, Optional | ||
|
||
from pydantic import BaseModel, Field, field_validator | ||
|
||
from ..enums import ChannelType, MessageType | ||
from .message import BaseMessage | ||
|
||
|
||
class ViberAction(BaseModel): | ||
url: str | ||
text: str = Field(..., max_length=30) | ||
|
||
|
||
class ViberOptions(BaseModel): | ||
category: Literal['transaction', 'promotion'] = None | ||
ttl: Optional[int] = Field(None, ge=30, le=259200) | ||
type: Optional[Literal['string', 'template']] = None | ||
|
||
|
||
class BaseViber(BaseMessage): | ||
from_: str = Field(..., min_length=1, max_length=50, serialization_alias='from') | ||
viber_service: Optional[ViberOptions] = None | ||
channel: ChannelType = ChannelType.VIBER | ||
|
||
|
||
class ViberTextOptions(ViberOptions): | ||
action: Optional[ViberAction] = None | ||
|
||
|
||
class ViberText(BaseViber): | ||
text: str = Field(..., max_length=1000) | ||
viber_service: Optional[ViberTextOptions] = None | ||
message_type: MessageType = MessageType.TEXT | ||
|
||
|
||
class ViberImageResource(BaseModel): | ||
url: str | ||
caption: Optional[str] = None | ||
|
||
|
||
class ViberImageOptions(ViberOptions): | ||
action: Optional[ViberAction] = None | ||
|
||
|
||
class ViberImage(BaseViber): | ||
image: ViberImageResource | ||
viber_service: Optional[ViberImageOptions] = None | ||
message_type: MessageType = MessageType.IMAGE | ||
|
||
|
||
class ViberVideoResource(BaseModel): | ||
url: str | ||
thumb_url: str = Field(..., max_length=1000) | ||
caption: Optional[str] = Field(None, max_length=1000) | ||
|
||
|
||
class ViberVideoOptions(ViberOptions): | ||
duration: str | ||
file_size: str | ||
|
||
@field_validator('duration') | ||
@classmethod | ||
def validate_duration(cls, value): | ||
value_int = int(value) | ||
if not 1 <= value_int <= 600: | ||
raise ValueError('"Duration" must be a number between 1 and 600.') | ||
return value | ||
|
||
@field_validator('file_size') | ||
@classmethod | ||
def validate_file_size(cls, value): | ||
value_int = int(value) | ||
if not 1 <= value_int <= 200: | ||
raise ValueError('"File size" must be a number between 1 and 200.') | ||
return value | ||
|
||
|
||
class ViberVideo(BaseViber): | ||
video: ViberVideoResource | ||
viber_service: Optional[ViberVideoOptions] = None | ||
message_type: MessageType = MessageType.VIDEO | ||
|
||
|
||
class ViberFileResource(BaseModel): | ||
url: str | ||
name: Optional[str] = Field(None, max_length=25) | ||
|
||
|
||
class ViberFileOptions(ViberOptions): | ||
pass | ||
|
||
|
||
class ViberFile(BaseViber): | ||
file: ViberFileResource | ||
viber_service: Optional[ViberFileOptions] = None | ||
message_type: MessageType = MessageType.FILE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
from typing import 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 | ||
|
||
|
||
class WhatsappContext(BaseModel): | ||
message_uuid: str | ||
|
||
|
||
class BaseWhatsapp(BaseMessage): | ||
from_: Union[PhoneNumber, str] = Field(..., serialization_alias='from') | ||
context: WhatsappContext | ||
channel: ChannelType = ChannelType.WHATSAPP | ||
|
||
|
||
class WhatsappText(BaseWhatsapp): | ||
text: str = Field(..., max_length=4096) | ||
type: MessageType = MessageType.TEXT | ||
|
||
|
||
class WhatsappImageResource(BaseModel): | ||
url: str | ||
caption: Optional[str] = Field(None, min_length=1, max_length=3000) | ||
|
||
|
||
class WhatsappImage(BaseWhatsapp): | ||
image: WhatsappImageResource | ||
type: MessageType = MessageType.IMAGE | ||
|
||
|
||
class WhatsappAudioResource(BaseModel): | ||
url: str = Field(..., min_length=10, max_length=2000) | ||
|
||
|
||
class WhatsappAudio(BaseWhatsapp): | ||
audio: WhatsappAudioResource | ||
type: MessageType = MessageType.AUDIO | ||
|
||
|
||
class WhatsappVideoResource(BaseModel): | ||
url: str | ||
caption: Optional[str] = None | ||
|
||
|
||
class WhatsappVideo(BaseWhatsapp): | ||
video: WhatsappVideoResource | ||
type: MessageType = MessageType.VIDEO | ||
|
||
|
||
class WhatsappFileResource(BaseModel): | ||
url: str | ||
caption: Optional[str] = None | ||
name: Optional[str] = None | ||
|
||
|
||
class WhatsappFile(BaseWhatsapp): | ||
file: WhatsappFileResource | ||
type: MessageType = MessageType.FILE | ||
|
||
|
||
class WhatsappTemplateResource(BaseModel): | ||
name: str | ||
parameters: Optional[list] = None | ||
|
||
model_config = ConfigDict(extra='allow') | ||
|
||
|
||
class WhatsappTemplateSettings(BaseModel): | ||
locale: str = 'en_US' | ||
policy: Optional[Literal['deterministic']] = None | ||
|
||
|
||
class WhatsappTemplate(BaseWhatsapp): | ||
template: WhatsappTemplateResource | ||
whatsapp: WhatsappTemplateSettings | ||
type: MessageType = MessageType.TEMPLATE | ||
|
||
|
||
class WhatsappStickerUrl(BaseModel): | ||
url: str | ||
|
||
|
||
class WhatsappStickerId(BaseModel): | ||
id: str | ||
|
||
|
||
class WhatsappSticker(BaseWhatsapp): | ||
sticker: Union[WhatsappStickerUrl, WhatsappStickerId] | ||
type: MessageType = MessageType.STICKER | ||
|
||
|
||
class WhatsappCustom(BaseWhatsapp): | ||
custom: Optional[dict] = None | ||
type: MessageType = MessageType.CUSTOM |