Skip to content

Commit

Permalink
add mark whatsapp message as read option
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkahan committed Aug 20, 2024
1 parent 4b51872 commit 51a49e1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 3.17.1
- Add "mark WhatsApp message as read" option for Messages API

# 3.17.0
- Add RCS message type option for Messages API
- Add "revoke RCS message" option
Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ client.messages.send_message({
### Revoke an RCS Message

```python
client.messages.revoke_outbound_message('asdf-1234-5678-9012')
client.messages.revoke_outbound_message('MY-MESSAGE-ID')
```

### Send an audio file via WhatsApp
Expand All @@ -232,7 +232,19 @@ client.messages.send_message({
})
```

### Send a video file via Facebook Messenger
### Mark a WhatsApp Message as Read

To mark a WhatsApp message as read, you must override the default `vonage.Client.api_host` attribute. Override it to correspond to the region where the WhatsApp number you're using is hosted.

```python
# Override api_host attribute for EU region
client.api_host('api-eu.vonage.com')

# Mark message as read
client.messages.mark_whatsapp_message_read('MY-MESSAGE-ID')
```

### Send a Video File via Facebook Messenger

You will need to link your Facebook business page to your Vonage account in the Vonage developer dashboard. (Click on the sidebar
"External Accounts" option to do this.)
Expand Down
21 changes: 20 additions & 1 deletion src/vonage/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def send_message(self, params: dict):
auth_type=self._auth_type,
)

def revoke_outbound_message(self, message_uuid: str) -> None:
def revoke_outbound_rcs_message(self, message_uuid: str) -> None:
"""Revoke an outbound RCS message.
Args:
Expand All @@ -64,6 +64,25 @@ def revoke_outbound_message(self, message_uuid: str) -> None:
auth_type=self._auth_type,
)

def mark_whatsapp_message_read(self, message_uuid: str) -> None:
"""Mark a WhatsApp message as read.
Note: to use this method, update the `api_host` attribute of the `vonage.Client` instance
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 'https://api-eu.vonage.com'.
Args:
message_uuid (str): The UUID of the message to mark as read.
"""
return self._client.patch(
self._client.api_host(),
f'/v1/messages/{message_uuid}',
params={'status': 'read'},
auth_type=self._auth_type,
)

def validate_send_message_input(self, params):
self._check_input_is_dict(params)
self._check_valid_message_channel(params)
Expand Down
15 changes: 14 additions & 1 deletion tests/test_messages_send_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ def test_revoke_rcs_message(messages, dummy_data):
'no_content.json',
)

assert messages.revoke_outbound_message('abcd-ef01-2345-6789') is None
assert messages.revoke_outbound_rcs_message('abcd-ef01-2345-6789') is None
assert request_user_agent() == dummy_data.user_agent
assert b'"status": "revoked"' in request_body()


@responses.activate
def test_mark_whatsapp_message_read(messages, dummy_data):
stub(
responses.PATCH,
'https://api.nexmo.com/v1/messages/abcd-ef01-2345-6789',
'no_content.json',
)

assert messages.mark_whatsapp_message_read('abcd-ef01-2345-6789') is None
assert request_user_agent() == dummy_data.user_agent
assert b'"status": "read"' in request_body()

0 comments on commit 51a49e1

Please sign in to comment.