From b198982f29091923a2361921340262e0b7994ecb Mon Sep 17 00:00:00 2001 From: prostraction <47314760+prostraction@users.noreply.github.com> Date: Thu, 28 Nov 2024 13:51:55 +0300 Subject: [PATCH 1/7] SW-4489 Implemetned EditMessage support --- README.md | 1 + setup.py | 2 +- .../tools/serviceMethods.py | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 164f1da..d9704f4 100644 --- a/README.md +++ b/README.md @@ -231,6 +231,7 @@ print(response.data) | `serviceMethods.getContacts` | The method is designed to get a list of contacts of the current account | [GetContacts](https://green-api.com/en/docs/api/service/GetContacts/) | | `serviceMethods.getContactInfo` | The method is designed to obtain information about the contact | [GetContactInfo](https://green-api.com/en/docs/api/service/GetContactInfo/) | | `serviceMethods.deleteMessage` | The method deletes the message from chat | [DeleteMessage](https://green-api.com/en/docs/api/service/deleteMessage/) | +| `serviceMethods.editMessage` | The method edits the message in chat | [EditMessage](https://green-api.com/en/docs/api/service/editMessage/) | | `serviceMethods.archiveChat` | The method archives the chat | [ArchiveChat](https://green-api.com/en/docs/api/service/archiveChat/) | | `serviceMethods.unarchiveChat` | The method unarchives the chat | [UnarchiveChat](https://green-api.com/en/docs/api/service/unarchiveChat/) | | `serviceMethods.setDisappearingChat` | The method is designed to change the settings of disappearing messages in chats | [SetDisappearingChat](https://green-api.com/en/docs/api/service/SetDisappearingChat/) | diff --git a/setup.py b/setup.py index fc0509d..c890ff3 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name="whatsapp-api-client-python", - version="0.0.47", + version="0.0.48", description=( "This library helps you easily create" " a Python application with WhatsApp API." diff --git a/whatsapp_api_client_python/tools/serviceMethods.py b/whatsapp_api_client_python/tools/serviceMethods.py index 1ceab7f..06834ad 100644 --- a/whatsapp_api_client_python/tools/serviceMethods.py +++ b/whatsapp_api_client_python/tools/serviceMethods.py @@ -94,6 +94,23 @@ def deleteMessage(self, chatId: str, idMessage: str) -> Response: ), request_body ) + def editMessage(self, chatId: str, idMessage: str, message: str) -> Response: + """ + The method edits a message in chat. + + https://green-api.com/en/docs/api/service/editMessage/ + """ + + request_body = locals() + request_body.pop("self") + + return self.api.request( + "POST", ( + "{{host}}/waInstance{{idInstance}}/" + "editMessage/{{apiTokenInstance}}" + ), request_body + ) + def archiveChat(self, chatId: str) -> Response: """ The method archives a chat. From d6bbdd5d4cd135d88cc9d419419e83f875361a9b Mon Sep 17 00:00:00 2001 From: prostraction <47314760+prostraction@users.noreply.github.com> Date: Thu, 28 Nov 2024 13:57:17 +0300 Subject: [PATCH 2/7] SW-4489 Documentation fix --- docs/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/README.md b/docs/README.md index f6a7f02..d8127a7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -215,6 +215,7 @@ print(response.data) | `serviceMethods.getContacts` | Метод предназначен для получения списка контактов текущего аккаунта | [GetContacts](https://green-api.com/docs/api/service/GetContacts/) | | `serviceMethods.getContactInfo` | Метод предназначен для получения информации о контакте | [GetContactInfo](https://green-api.com/docs/api/service/GetContactInfo/) | | `serviceMethods.deleteMessage` | Метод удаляет сообщение из чата | [DeleteMessage](https://green-api.com/docs/api/service/deleteMessage/) | +| `serviceMethods.editMessage` | Метод изменяет сообщение в чате | [EditMessage](https://green-api.com/docs/api/service/editMessage/) | | `serviceMethods.archiveChat` | Метод архивирует чат | [ArchiveChat](https://green-api.com/docs/api/service/archiveChat/) | | `serviceMethods.unarchiveChat` | Метод разархивирует чат | [UnarchiveChat](https://green-api.com/docs/api/service/unarchiveChat/) | | `serviceMethods.setDisappearingChat` | Метод предназначен для изменения настроек исчезающих сообщений в чатах | [SetDisappearingChat](https://green-api.com/docs/api/service/SetDisappearingChat/) | From 913de4b10c3863748ab717eee74aa3e3471fee91 Mon Sep 17 00:00:00 2001 From: prostraction <47314760+prostraction@users.noreply.github.com> Date: Thu, 28 Nov 2024 14:15:33 +0300 Subject: [PATCH 3/7] SW-3825 --- whatsapp_api_client_python/API.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/whatsapp_api_client_python/API.py b/whatsapp_api_client_python/API.py index 4449db9..62a2612 100644 --- a/whatsapp_api_client_python/API.py +++ b/whatsapp_api_client_python/API.py @@ -78,14 +78,18 @@ def request( url = url.replace("{{idInstance}}", self.idInstance) url = url.replace("{{apiTokenInstance}}", self.apiTokenInstance) + headers = { + 'User-Agent': 'GREEN-API_SDK_PY/1.0' + } + try: if not files: response = self.session.request( - method=method, url=url, json=payload, timeout=self.host_timeout + method=method, url=url, json=payload, timeout=self.host_timeout, headers=headers ) else: response = self.session.request( - method=method, url=url, data=payload, files=files, timeout=self.media_timeout + method=method, url=url, data=payload, files=files, timeout=self.media_timeout, headers=headers ) except Exception as error: error_message = f"Request was failed with error: {error}." From 7d9bcdc3ae7c2bc6fd2c0470c00c01af82cf281b Mon Sep 17 00:00:00 2001 From: prostraction <47314760+prostraction@users.noreply.github.com> Date: Thu, 28 Nov 2024 13:51:55 +0300 Subject: [PATCH 4/7] SW-4489 Implemetned EditMessage support --- README.md | 1 + .../tools/serviceMethods.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/README.md b/README.md index 164f1da..d9704f4 100644 --- a/README.md +++ b/README.md @@ -231,6 +231,7 @@ print(response.data) | `serviceMethods.getContacts` | The method is designed to get a list of contacts of the current account | [GetContacts](https://green-api.com/en/docs/api/service/GetContacts/) | | `serviceMethods.getContactInfo` | The method is designed to obtain information about the contact | [GetContactInfo](https://green-api.com/en/docs/api/service/GetContactInfo/) | | `serviceMethods.deleteMessage` | The method deletes the message from chat | [DeleteMessage](https://green-api.com/en/docs/api/service/deleteMessage/) | +| `serviceMethods.editMessage` | The method edits the message in chat | [EditMessage](https://green-api.com/en/docs/api/service/editMessage/) | | `serviceMethods.archiveChat` | The method archives the chat | [ArchiveChat](https://green-api.com/en/docs/api/service/archiveChat/) | | `serviceMethods.unarchiveChat` | The method unarchives the chat | [UnarchiveChat](https://green-api.com/en/docs/api/service/unarchiveChat/) | | `serviceMethods.setDisappearingChat` | The method is designed to change the settings of disappearing messages in chats | [SetDisappearingChat](https://green-api.com/en/docs/api/service/SetDisappearingChat/) | diff --git a/whatsapp_api_client_python/tools/serviceMethods.py b/whatsapp_api_client_python/tools/serviceMethods.py index 1ceab7f..06834ad 100644 --- a/whatsapp_api_client_python/tools/serviceMethods.py +++ b/whatsapp_api_client_python/tools/serviceMethods.py @@ -94,6 +94,23 @@ def deleteMessage(self, chatId: str, idMessage: str) -> Response: ), request_body ) + def editMessage(self, chatId: str, idMessage: str, message: str) -> Response: + """ + The method edits a message in chat. + + https://green-api.com/en/docs/api/service/editMessage/ + """ + + request_body = locals() + request_body.pop("self") + + return self.api.request( + "POST", ( + "{{host}}/waInstance{{idInstance}}/" + "editMessage/{{apiTokenInstance}}" + ), request_body + ) + def archiveChat(self, chatId: str) -> Response: """ The method archives a chat. From b70a3ea5b917d7fa0b2a20e7672a7a58d16417d9 Mon Sep 17 00:00:00 2001 From: prostraction <47314760+prostraction@users.noreply.github.com> Date: Thu, 28 Nov 2024 13:57:17 +0300 Subject: [PATCH 5/7] SW-4489 Documentation fix --- docs/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/README.md b/docs/README.md index f6a7f02..d8127a7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -215,6 +215,7 @@ print(response.data) | `serviceMethods.getContacts` | Метод предназначен для получения списка контактов текущего аккаунта | [GetContacts](https://green-api.com/docs/api/service/GetContacts/) | | `serviceMethods.getContactInfo` | Метод предназначен для получения информации о контакте | [GetContactInfo](https://green-api.com/docs/api/service/GetContactInfo/) | | `serviceMethods.deleteMessage` | Метод удаляет сообщение из чата | [DeleteMessage](https://green-api.com/docs/api/service/deleteMessage/) | +| `serviceMethods.editMessage` | Метод изменяет сообщение в чате | [EditMessage](https://green-api.com/docs/api/service/editMessage/) | | `serviceMethods.archiveChat` | Метод архивирует чат | [ArchiveChat](https://green-api.com/docs/api/service/archiveChat/) | | `serviceMethods.unarchiveChat` | Метод разархивирует чат | [UnarchiveChat](https://green-api.com/docs/api/service/unarchiveChat/) | | `serviceMethods.setDisappearingChat` | Метод предназначен для изменения настроек исчезающих сообщений в чатах | [SetDisappearingChat](https://green-api.com/docs/api/service/SetDisappearingChat/) | From e4d6977a978b82fa10bf100b0765837ff1863eaf Mon Sep 17 00:00:00 2001 From: prostraction <47314760+prostraction@users.noreply.github.com> Date: Thu, 28 Nov 2024 14:15:33 +0300 Subject: [PATCH 6/7] SW-3825 --- whatsapp_api_client_python/API.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/whatsapp_api_client_python/API.py b/whatsapp_api_client_python/API.py index 4449db9..62a2612 100644 --- a/whatsapp_api_client_python/API.py +++ b/whatsapp_api_client_python/API.py @@ -78,14 +78,18 @@ def request( url = url.replace("{{idInstance}}", self.idInstance) url = url.replace("{{apiTokenInstance}}", self.apiTokenInstance) + headers = { + 'User-Agent': 'GREEN-API_SDK_PY/1.0' + } + try: if not files: response = self.session.request( - method=method, url=url, json=payload, timeout=self.host_timeout + method=method, url=url, json=payload, timeout=self.host_timeout, headers=headers ) else: response = self.session.request( - method=method, url=url, data=payload, files=files, timeout=self.media_timeout + method=method, url=url, data=payload, files=files, timeout=self.media_timeout, headers=headers ) except Exception as error: error_message = f"Request was failed with error: {error}." From fb76f34ff98973c7223995b240323c8d0578a30e Mon Sep 17 00:00:00 2001 From: prostraction <47314760+prostraction@users.noreply.github.com> Date: Thu, 6 Feb 2025 17:42:11 +0300 Subject: [PATCH 7/7] Bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c890ff3..1c92486 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name="whatsapp-api-client-python", - version="0.0.48", + version="0.0.49", description=( "This library helps you easily create" " a Python application with WhatsApp API."