Skip to content

Commit

Permalink
Merge pull request #51 from filipporomani/patch-1
Browse files Browse the repository at this point in the history
add mark_as_read
  • Loading branch information
Kalebu authored Jan 12, 2023
2 parents b933f95 + 0638368 commit eb75b06
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ Unofficial python wrapper to [WhatsApp Cloud API](https://developers.facebook.co
## Features supported

1. Sending messages
2. Sending Media (images, audio, video and documents)
3. Sending location
4. Sending interactive buttons
5. Sending template messages
6. Parsing messages and media received
2. Marking messages as read
3. Sending Media (images, audio, video and documents)
4. Sending location
5. Sending interactive buttons
6. Sending template messages
7. Parsing messages and media received

## Getting started

Expand Down Expand Up @@ -89,6 +90,14 @@ Use this method to send text message to a WhatsApp number.
>>> messenger.send_message('Your message ', 'Mobile eg: 255757xxxxx')
```

## Marking messages as read

Use this method to mark a previously sent text message as read.

```python
>>> messenger.mark_as_read('Message ID')
```

## Sending Images

When sending media(image, video, audio, gif and document ), you can either specify a link containing the media or specify object id, you can do this using the same method.
Expand Down
22 changes: 22 additions & 0 deletions heyoo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(self, token=None, phone_number_id=None):
self.token = token
self.phone_number_id = phone_number_id
self.base_url = "https://graph.facebook.com/v14.0"
self.v15_base_url = "https://graph.facebook.com/v15.0"
self.url = f"{self.base_url}/{phone_number_id}/messages"

self.headers = {
Expand Down Expand Up @@ -488,6 +489,27 @@ def delete_media(self, media_id: str):
logging.info(f"Status code: {r.status_code}")
logging.info(f"Response: {r.json()}")
return None

def mark_as_read(self, message_id: str):
"""
Marks a message as read
Args:
message_id[str]: Id of the message to be marked as read
"""
headers = {
'Authorization': f'Bearer {self.token}',
'Content-Type': 'application/json',
}

json_data = {
'messaging_product': 'whatsapp',
'status': 'read',
'message_id': message_id,
}
response = requests.post(
f'{self.v15_base_url}/{self.phone_number_id}/messages', headers=headers, json=json_data).json()
return response["success"]

def create_button(self, button):
"""
Expand Down

0 comments on commit eb75b06

Please sign in to comment.