Skip to content

Commit

Permalink
add RCS support, revoke RCS message, mark WhatsApp as read
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkahan committed Aug 22, 2024
1 parent 1bff284 commit 0cde800
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 10 deletions.
37 changes: 35 additions & 2 deletions messages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This message can now be sent with
vonage_client.messages.send(message)
```

All possible message types from every message channel have their own message model. They are named following this rule: {Channel}{MessageType}, e.g. `Sms`, `MmsImage`, `MessengerAudio`, `WhatsappSticker`, `ViberVideo`, etc.
All possible message types from every message channel have their own message model. They are named following this rule: {Channel}{MessageType}, e.g. `Sms`, `MmsImage`, `RcsFile`, `MessengerAudio`, `WhatsappSticker`, `ViberVideo`, etc.

The different message models are listed at the bottom of the page.

Expand Down Expand Up @@ -64,14 +64,47 @@ message = Sms(
vonage_client.messages.send(message)
```

### Mark a WhatsApp Message as Read

Note: to use this method, update the `api_host` attribute of the `vonage_http_client.HttpClientOptions` object to the API endpoint corresponding to the region where the WhatsApp number is hosted.

For example, to use the EU API endpoint, set the `api_host` attribute to 'api-eu.vonage.com'.

```python
from vonage import Vonage, Auth, HttpClientOptions

auth = Auth(application_id='MY-APP-ID', private_key='MY-PRIVATE-KEY')
options = HttpClientOptions(api_host='api-eu.vonage.com')

vonage_client = Vonage(auth, options)
vonage_client.messages.mark_whatsapp_message_read('MESSAGE_UUID')
```

### Revoke an RCS Message

Note: as above, to use this method you need to update the `api_host` attribute of the `vonage_http_client.HttpClientOptions` object to the API endpoint corresponding to the region where the WhatsApp number is hosted.

For example, to use the EU API endpoint, set the `api_host` attribute to 'api-eu.vonage.com'.

```python
from vonage import Vonage, Auth, HttpClientOptions

auth = Auth(application_id='MY-APP-ID', private_key='MY-PRIVATE-KEY')
options = HttpClientOptions(api_host='api-eu.vonage.com')

vonage_client = Vonage(auth, options)
vonage_client.messages.revoke_rcs_message('MESSAGE_UUID')
```

## Message Models

To send a message, instantiate a message model of the correct type as described above. This is a list of message models that can be used:

```
Sms
MmsImage, MmsVcard, MmsAudio, MmsVideo
RcsText, RcsImage, RcsVideo, RcsFile, RcsCustom
WhatsappText, WhatsappImage, WhatsappAudio, WhatsappVideo, WhatsappFile, WhatsappTemplate, WhatsappSticker, WhatsappCustom
MessengerText, MessengerImage, MessengerAudio, MessengerVideo, MessengerFile
ViberText, ViberImage, ViberVideo, ViberFile
```
```
4 changes: 2 additions & 2 deletions messages/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[project]
name = 'vonage-messages'
version = '1.1.1'
version = '1.2.0'
description = 'Vonage messages package'
readme = "README.md"
authors = [{ name = "Vonage", email = "devrel@vonage.com" }]
requires-python = ">=3.8"
dependencies = [
"vonage-http-client>=1.3.1",
"vonage-http-client>=1.4.0",
"vonage-utils>=1.1.1",
"pydantic>=2.7.1",
]
Expand Down
4 changes: 2 additions & 2 deletions messages/src/vonage_messages/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def mark_whatsapp_message_read(self, message_uuid: str) -> None:
corresponding to the region where the WhatsApp number is hosted.
For example, to use the EU API endpoint, set the `api_host`
attribute to 'https://api-eu.vonage.com'.
attribute to 'api-eu.vonage.com'.
Args:
message_uuid (str): The unique identifier of the WhatsApp message to mark as read.
Expand All @@ -74,7 +74,7 @@ def revoke_rcs_message(self, message_uuid: str) -> None:
corresponding to the region where the RCS number is hosted.
For example, to use the EU API endpoint, set the `api_host`
attribute to 'https://api-eu.vonage.com'.
attribute to 'api-eu.vonage.com'.
Args:
message_uuid (str): The unique identifier of the RCS message to revoke.
Expand Down
4 changes: 2 additions & 2 deletions messages/tests/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ def test_http_client_property():
def test_mark_whatsapp_message_read():
responses.add(
responses.PATCH,
'https://api-eu.vonage.com/v1/messages/1234567890',
'https://api-eu.vonage.com/v1/messages/asdf',
)
messages = Messages(
HttpClient(get_mock_jwt_auth(), HttpClientOptions(api_host='api-eu.vonage.com'))
)
messages.http_client.http_client_options.api_host = 'api-eu.vonage.com'
messages.mark_whatsapp_message_read('1234567890')
messages.mark_whatsapp_message_read('asdf')


@responses.activate
Expand Down
5 changes: 5 additions & 0 deletions vonage/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 3.99.2a0
- Add support for the [RCS messaging channel](https://developer.vonage.com/en/messages/concepts/rcs) of the Vonage Messages API
- Add method to revoke an RCS message
- Add method to mark a WhatsApp message as read

# 3.99.0a12
- Add support for the [Vonage Account API](https://developer.vonage.com/en/account/overview).
- Update package metadata for the `vonage-application` package.
Expand Down
2 changes: 1 addition & 1 deletion vonage/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies = [
"vonage-http-client>=1.4.0",
"vonage-account>=1.0.0",
"vonage-application>=1.0.0",
"vonage-messages>=1.1.1",
"vonage-messages>=1.2.0",
"vonage-number-insight>=1.0.0",
"vonage-sms>=1.1.1",
"vonage-users>=1.1.2",
Expand Down
2 changes: 1 addition & 1 deletion vonage/src/vonage/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '3.99.0a12'
__version__ = '3.99.2a0'

0 comments on commit 0cde800

Please sign in to comment.