Skip to content

Commit

Permalink
Fixed EditMessage, DeleteMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
prostraction committed Feb 12, 2025
1 parent c7dedac commit c98513f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
20 changes: 20 additions & 0 deletions examples/serviceMethods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from whatsapp_api_client_python import API

greenAPI = API.GreenAPI(
"1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345"
)


def main():
# DeleteMessage for sender
response = greenAPI.serviceMethods.deleteMessage("[email protected]", "BAE52A7F04F452F9", True)

# DeleteMessage for all (default)
response = greenAPI.serviceMethods.deleteMessage("[email protected]", "BAE5558FFC7565C2")

# EditMessage
response = greenAPI.serviceMethods.editMessage("[email protected]", "BAE5F793F61411D0", "New text")
print(response.data) # new idMessage

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name="whatsapp-api-client-python",
version="0.0.49",
version="0.0.50",
description=(
"This library helps you easily create"
" a Python application with WhatsApp API."
Expand Down
5 changes: 4 additions & 1 deletion whatsapp_api_client_python/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class Response:
def __init__(self, code: Optional[int], text: str):
self.code = code
if self.code == 200:
self.data = loads(text)
try:
self.data = loads(text)
except:

Check failure on line 15 in whatsapp_api_client_python/response.py

View workflow job for this annotation

GitHub Actions / 3.8

Ruff (E722)

whatsapp_api_client_python/response.py:15:13: E722 Do not use bare `except`

Check failure on line 15 in whatsapp_api_client_python/response.py

View workflow job for this annotation

GitHub Actions / 3.11

Ruff (E722)

whatsapp_api_client_python/response.py:15:13: E722 Do not use bare `except`

Check failure on line 15 in whatsapp_api_client_python/response.py

View workflow job for this annotation

GitHub Actions / 3.12

Ruff (E722)

whatsapp_api_client_python/response.py:15:13: E722 Do not use bare `except`
self.data = "[]"
else:
self.error = text
5 changes: 4 additions & 1 deletion whatsapp_api_client_python/tools/serviceMethods.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,18 @@ def getContactInfo(self, chatId: str) -> Response:
), request_body
)

def deleteMessage(self, chatId: str, idMessage: str) -> Response:
def deleteMessage(self, chatId: str, idMessage: str, onlySenderDelete: Optional[bool] = None) -> Response:
"""
The method deletes a message from a chat.
https://green-api.com/en/docs/api/service/deleteMessage/
"""

request_body = locals()
if onlySenderDelete is None:
request_body.pop("onlySenderDelete")
request_body.pop("self")
print(request_body)

return self.api.request(
"POST", (
Expand Down

0 comments on commit c98513f

Please sign in to comment.