Skip to content

Commit 51a49e1

Browse files
committed
add mark whatsapp message as read option
1 parent 4b51872 commit 51a49e1

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 3.17.1
2+
- Add "mark WhatsApp message as read" option for Messages API
3+
14
# 3.17.0
25
- Add RCS message type option for Messages API
36
- Add "revoke RCS message" option

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ client.messages.send_message({
213213
### Revoke an RCS Message
214214

215215
```python
216-
client.messages.revoke_outbound_message('asdf-1234-5678-9012')
216+
client.messages.revoke_outbound_message('MY-MESSAGE-ID')
217217
```
218218

219219
### Send an audio file via WhatsApp
@@ -232,7 +232,19 @@ client.messages.send_message({
232232
})
233233
```
234234

235-
### Send a video file via Facebook Messenger
235+
### Mark a WhatsApp Message as Read
236+
237+
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.
238+
239+
```python
240+
# Override api_host attribute for EU region
241+
client.api_host('api-eu.vonage.com')
242+
243+
# Mark message as read
244+
client.messages.mark_whatsapp_message_read('MY-MESSAGE-ID')
245+
```
246+
247+
### Send a Video File via Facebook Messenger
236248

237249
You will need to link your Facebook business page to your Vonage account in the Vonage developer dashboard. (Click on the sidebar
238250
"External Accounts" option to do this.)

src/vonage/messages.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def send_message(self, params: dict):
5151
auth_type=self._auth_type,
5252
)
5353

54-
def revoke_outbound_message(self, message_uuid: str) -> None:
54+
def revoke_outbound_rcs_message(self, message_uuid: str) -> None:
5555
"""Revoke an outbound RCS message.
5656
5757
Args:
@@ -64,6 +64,25 @@ def revoke_outbound_message(self, message_uuid: str) -> None:
6464
auth_type=self._auth_type,
6565
)
6666

67+
def mark_whatsapp_message_read(self, message_uuid: str) -> None:
68+
"""Mark a WhatsApp message as read.
69+
70+
Note: to use this method, update the `api_host` attribute of the `vonage.Client` instance
71+
to the API endpoint corresponding to the region where the WhatsApp number is hosted.
72+
73+
For example, to use the EU API endpoint, set the `api_host`
74+
attribute to 'https://api-eu.vonage.com'.
75+
76+
Args:
77+
message_uuid (str): The UUID of the message to mark as read.
78+
"""
79+
return self._client.patch(
80+
self._client.api_host(),
81+
f'/v1/messages/{message_uuid}',
82+
params={'status': 'read'},
83+
auth_type=self._auth_type,
84+
)
85+
6786
def validate_send_message_input(self, params):
6887
self._check_input_is_dict(params)
6988
self._check_valid_message_channel(params)

tests/test_messages_send_message.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ def test_revoke_rcs_message(messages, dummy_data):
5050
'no_content.json',
5151
)
5252

53-
assert messages.revoke_outbound_message('abcd-ef01-2345-6789') is None
53+
assert messages.revoke_outbound_rcs_message('abcd-ef01-2345-6789') is None
5454
assert request_user_agent() == dummy_data.user_agent
5555
assert b'"status": "revoked"' in request_body()
56+
57+
58+
@responses.activate
59+
def test_mark_whatsapp_message_read(messages, dummy_data):
60+
stub(
61+
responses.PATCH,
62+
'https://api.nexmo.com/v1/messages/abcd-ef01-2345-6789',
63+
'no_content.json',
64+
)
65+
66+
assert messages.mark_whatsapp_message_read('abcd-ef01-2345-6789') is None
67+
assert request_user_agent() == dummy_data.user_agent
68+
assert b'"status": "read"' in request_body()

0 commit comments

Comments
 (0)