From 8a985186fb648daff9945d45ba4cf703325ca5fc Mon Sep 17 00:00:00 2001 From: Filippo Romani Date: Wed, 11 Jan 2023 18:03:06 +0100 Subject: [PATCH 1/3] add mark_as_read Messages can now be marked as read by using the mark_as_read function. Required arguments: message_id, the id of the message to be marked as read Return: True or False depending on operation success. --- heyoo/__init__.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/heyoo/__init__.py b/heyoo/__init__.py index 47e2c55..b91578c 100644 --- a/heyoo/__init__.py +++ b/heyoo/__init__.py @@ -488,6 +488,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'https://graph.facebook.com/v15.0/{self.phone_number_id}/messages', headers=headers, json=json_data).json() + return response["success"] def create_button(self, button): """ From cb6626d9706a19b1dcae0350c992314d80aac863 Mon Sep 17 00:00:00 2001 From: Filippo Romani Date: Wed, 11 Jan 2023 18:06:36 +0100 Subject: [PATCH 2/3] Update README.md --- README.md | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f6ce513..460c938 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. From 06383683e669d296efead8f30c4b27bea6adf6d8 Mon Sep 17 00:00:00 2001 From: Filippo Romani Date: Thu, 12 Jan 2023 12:36:17 +0100 Subject: [PATCH 3/3] fix: move URL to init() --- heyoo/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/heyoo/__init__.py b/heyoo/__init__.py index b91578c..8f94e85 100644 --- a/heyoo/__init__.py +++ b/heyoo/__init__.py @@ -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 = { @@ -507,7 +508,7 @@ def mark_as_read(self, message_id: str): 'message_id': message_id, } response = requests.post( - f'https://graph.facebook.com/v15.0/{self.phone_number_id}/messages', headers=headers, json=json_data).json() + f'{self.v15_base_url}/{self.phone_number_id}/messages', headers=headers, json=json_data).json() return response["success"] def create_button(self, button):