Skip to content

Commit f22d90b

Browse files
committed
create messages package
1 parent 10ae9b9 commit f22d90b

File tree

16 files changed

+282
-0
lines changed

16 files changed

+282
-0
lines changed

messages/BUILD

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
resource(name='pyproject', source='pyproject.toml')
2+
file(name='readme', source='README.md')
3+
4+
files(sources=['tests/data/*'])
5+
6+
python_distribution(
7+
name='vonage-messages',
8+
dependencies=[
9+
':pyproject',
10+
':readme',
11+
'messages/src/vonage_messages',
12+
],
13+
provides=python_artifact(),
14+
generate_setup=False,
15+
repositories=['@pypi'],
16+
)

messages/CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# 1.0.0
2+
- Initial upload

messages/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Vonage Messages Package
2+
3+
This package contains the code to use [Vonage's Messages API](https://developer.vonage.com/en/messages/overview) in Python.
4+
5+
## Usage
6+
7+
It is recommended to use this as part of the main `vonage` package. The examples below assume you've created an instance of the `vonage.Vonage` class called `vonage_client`.
8+
9+
### Send a message
10+

messages/pyproject.toml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[project]
2+
name = 'vonage-messages'
3+
version = '1.0.0'
4+
description = 'Vonage messages package'
5+
readme = "README.md"
6+
authors = [{ name = "Vonage", email = "[email protected]" }]
7+
requires-python = ">=3.8"
8+
dependencies = [
9+
"vonage-http-client>=1.2.1",
10+
"vonage-utils>=1.0.1",
11+
"pydantic>=2.6.1",
12+
]
13+
classifiers = [
14+
"Programming Language :: Python",
15+
"Programming Language :: Python :: 3",
16+
"Programming Language :: Python :: 3.8",
17+
"Programming Language :: Python :: 3.9",
18+
"Programming Language :: Python :: 3.10",
19+
"Programming Language :: Python :: 3.11",
20+
"Programming Language :: Python :: 3.12",
21+
"License :: OSI Approved :: Apache Software License",
22+
]
23+
24+
[project.urls]
25+
homepage = "https://github.com/Vonage/vonage-python-sdk"
26+
27+
[build-system]
28+
requires = ["setuptools>=61.0", "wheel"]
29+
build-backend = "setuptools.build_meta"

messages/src/vonage_messages/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python_sources()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# from .enums import ChannelType, Locale
2+
# from .errors import VerifyError
3+
# from .requests import (
4+
# EmailChannel,
5+
# SilentAuthChannel,
6+
# SmsChannel,
7+
# VerifyRequest,
8+
# VoiceChannel,
9+
# WhatsappChannel,
10+
# )
11+
# from .responses import CheckCodeResponse, StartVerificationResponse
12+
# from .verify_v2 import VerifyV2
13+
14+
# __all__ = [
15+
# 'VerifyV2',
16+
# 'VerifyError',
17+
# 'ChannelType',
18+
# 'CheckCodeResponse',
19+
# 'Locale',
20+
# 'VerifyRequest',
21+
# 'SilentAuthChannel',
22+
# 'SmsChannel',
23+
# 'WhatsappChannel',
24+
# 'VoiceChannel',
25+
# 'EmailChannel',
26+
# 'StartVerificationResponse',
27+
# ]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from enum import Enum
2+
3+
4+
class MessageType(str, Enum):
5+
TEXT = 'text'
6+
IMAGE = 'image'
7+
AUDIO = 'audio'
8+
VIDEO = 'video'
9+
FILE = 'file'
10+
TEMPLATE = 'template'
11+
STICKER = 'sticker'
12+
CUSTOM = 'custom'
13+
VCARD = 'vcard'
14+
15+
16+
class ChannelType(str, Enum):
17+
SMS = 'sms'
18+
MMS = 'mms'
19+
WHATSAPP = 'whatsapp'
20+
MESSENGER = 'messenger'
21+
VIBER = 'viber_service'
22+
23+
24+
class WebhookVersion(str, Enum):
25+
V0_1 = 'v0.1'
26+
V1 = 'v1'
27+
28+
29+
class EncodingType(str, Enum):
30+
TEXT = 'text'
31+
UNICODE = 'unicode'
32+
AUTO = 'auto'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from vonage_utils.errors import VonageError
2+
3+
4+
class MessagesError(VonageError):
5+
"""Indicates an error when using the Vonage Verify API."""
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from pydantic import validate_call
2+
from vonage_http_client.http_client import HttpClient
3+
4+
from .models.sms import BaseMessage
5+
from .responses import MessageUuid
6+
7+
8+
class Messages:
9+
"""Calls Vonage's Messages API.
10+
11+
This class provides methods to interact with Vonage's Messages API, allowing you to send messages.
12+
13+
Args:
14+
http_client (HttpClient): An instance of the HttpClient class used to make HTTP requests.
15+
"""
16+
17+
def __init__(self, http_client: HttpClient) -> None:
18+
self._http_client = http_client
19+
20+
@validate_call
21+
def send(self, message: BaseMessage) -> MessageUuid:
22+
"""Send a message using Vonage's Messages API.
23+
24+
Args:
25+
message (Message): The message to be sent.
26+
27+
Returns:
28+
MessageUuid: The unique identifier of the sent message.
29+
"""
30+
response = self._http_client.post(
31+
self._http_client.api_host,
32+
'/v1/messages',
33+
message.model_dump(by_alias=True, exclude_none=True),
34+
)
35+
36+
return MessageUuid(**response)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from typing import Optional
2+
3+
from pydantic import BaseModel, Field
4+
from vonage_utils.types.phone_number import PhoneNumber
5+
6+
from ..enums import WebhookVersion
7+
8+
9+
class BaseMessage(BaseModel):
10+
to: PhoneNumber
11+
client_ref: Optional[str] = Field(None, max_length=100)
12+
webhook_url: Optional[str] = None
13+
webhook_version: Optional[WebhookVersion] = None

0 commit comments

Comments
 (0)