From f59c10e875d9a5e0bd9fc7a831deb34ff87264d2 Mon Sep 17 00:00:00 2001 From: dephea Date: Tue, 23 Apr 2024 08:29:19 +0300 Subject: [PATCH 1/9] Added status methods --- examples/sendTextStatus.py | 15 ++ whatsapp_api_client_python/API.py | 4 +- whatsapp_api_client_python/tools/statuses.py | 149 +++++++++++++++++++ 3 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 examples/sendTextStatus.py create mode 100644 whatsapp_api_client_python/tools/statuses.py diff --git a/examples/sendTextStatus.py b/examples/sendTextStatus.py new file mode 100644 index 0000000..7c5eb8d --- /dev/null +++ b/examples/sendTextStatus.py @@ -0,0 +1,15 @@ +from whatsapp_api_client_python import API + +greenAPI = API.GreenAPI( + "1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345" +) + + +def main(): + response = greenAPI.statuses.sendTextStatus("I sent this status using Green Api Python SDK!", "#54c774", "NORICAN_REGULAR") + + print(response.data) + + +if __name__ == '__main__': + main() diff --git a/whatsapp_api_client_python/API.py b/whatsapp_api_client_python/API.py index 815886b..0562028 100644 --- a/whatsapp_api_client_python/API.py +++ b/whatsapp_api_client_python/API.py @@ -16,7 +16,8 @@ receiving, sending, serviceMethods, - webhooks + webhooks, + statuses ) @@ -56,6 +57,7 @@ def __init__( self.sending = sending.Sending(self) self.serviceMethods = serviceMethods.ServiceMethods(self) self.webhooks = webhooks.Webhooks(self) + self.statuses = statuses.Statuses(self) self.logger = logging.getLogger("whatsapp-api-client-python") self.__prepare_logger() diff --git a/whatsapp_api_client_python/tools/statuses.py b/whatsapp_api_client_python/tools/statuses.py new file mode 100644 index 0000000..3833b14 --- /dev/null +++ b/whatsapp_api_client_python/tools/statuses.py @@ -0,0 +1,149 @@ +from typing import Dict, List, Optional, TYPE_CHECKING, Union + +from ..response import Response + +if TYPE_CHECKING: + from ..API import GreenApi + +class Statuses: + def __init__(self, api: "GreenApi"): + self.api = api + + def sendTextStatus(self, + message: str, + backgroundColor: Optional[str] = None, + font: Optional[str] = None, + participants: Optional[List[str]] = None) -> Response: + """ + The method is aimed for sending a text status. + + https://green-api.com/en/docs/api/statuses/SendTextStatus/ + """ + + request_body = self.__handle_parameters(locals()) + + return self.api.request( + "POST", ( + "{{host}}/waInstance{{idInstance}}/" + "sendTextStatus/{{apiTokenInstance}}" + ), request_body + ) + + def sendVoiceStatus(self, + urlFile: str, + fileName: str, + backgroundColor: Optional[str], + participants: Optional[List[str]]) -> Response: + """ + The method is aimed for sending a voice status. + + https://green-api.com/en/docs/api/statuses/SendVoiceStatus/ + """ + + request_body = self.__handle_parameters(locals()) + + return self.api.request( + "POST", ( + "{{host}}/waInstance{{idInstance}}/" + "sendVoiceStatus/{{apiTokenInstance}}" + ), request_body + ) + + def sendMediaStatus(self, + urlFile: str, + fileName: str, + caption: Optional[str], + participants: Optional[List[str]]) -> Response: + """ + The method is aimed for sending a pictures or video status. + + https://green-api.com/en/docs/api/statuses/SendMediaStatus/ + """ + + request_body = self.__handle_parameters(locals()) + + return self.api.request( + "POST", ( + "{{host}}/waInstance{{idInstance}}/" + "sendMediaStatus/{{apiTokenInstance}}" + ), request_body + ) + + def deleteStatus(self, + idMessage: str) -> Response: + """ + The method is aimed for deleting a certain status. + + https://green-api.com/en/docs/api/statuses/DeleteStatus/ + """ + + request_body = self.__handle_parameters(locals()) + + return self.api.request( + "POST", ( + "{{host}}/waInstance{{idInstance}}/" + "deleteStatus/{{apiTokenInstance}}" + ), request_body + ) + + def getStatusStatistic(self, + idMessage: str) -> Response: + """ + The method returns an array of recipients marked sent/delivered/read for a given status. + + https://green-api.com/en/docs/api/statuses/GetStatusStatistic/ + """ + url = ( + "{{host}}/waInstance{{idInstance}}/" + "getStatusStatistic/{{apiTokenInstance}}" + ) + + return self.api.request("GET", f"{url}?idMessage={idMessage}") + + def getIncomingStatuses(self, + minutes: Optional[int]=None) -> Response: + """ + The method returns the incoming statuses of the account + If no argument passed, the incoming statuses for the past 24 hours are returned. + + https://green-api.com/en/docs/api/statuses/GetIncomingStatuses/ + """ + url = ( + "{{host}}/waInstance{{idInstance}}/" + "getIncomingStatuses/{{apiTokenInstance}}" + ) + + if minutes: + return self.api.request("GET", f"{url}?minutes={minutes}") + else: + return self.api.request("GET", f"{url}") + + def getOutgoingStatuses(self, + minutes: Optional[int]=None) -> Response: + """ + The method returns the outgoing statuses of the account + If no argument passed, the outgoing statuses for the past 24 hours are returned. + + https://green-api.com/en/docs/api/statuses/GetOutgoingStatuses/ + """ + url = ( + "{{host}}/waInstance{{idInstance}}/" + "getOutgoingStatuses/{{apiTokenInstance}}" + ) + + if minutes: + return self.api.request("GET", f"{url}?minutes={minutes}") + else: + return self.api.request("GET", f"{url}") + + @classmethod + def __handle_parameters(cls, parameters: dict) -> dict: + handled_parameters = parameters.copy() + + handled_parameters.pop("self") + + for key, value in parameters.items(): + if value is None: + handled_parameters.pop(key) + + return handled_parameters \ No newline at end of file From baf2ec27fcee8b437012f4cdaf4f2a13708b414f Mon Sep 17 00:00:00 2001 From: dephea Date: Tue, 23 Apr 2024 08:45:24 +0300 Subject: [PATCH 2/9] added status documentation --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 164f1da..6a01dd2 100644 --- a/README.md +++ b/README.md @@ -169,6 +169,18 @@ response = greenAPI.sending.sendPoll( print(response.data) ``` +### Sending a text status + +Link to example: [sendTextStatus.py]( +https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendTextStatus.py +). + +``` +response = greenAPI.statuses.sendTextStatus("I sent this status using Green Api Python SDK!", "#54c774", "NORICAN_REGULAR") + +print(response.data) +``` + ## Examples list | Description | Module | @@ -179,6 +191,7 @@ print(response.data) | Example of a group creation and sending a message to the group | [createGroupAndSendMessage.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/createGroupAndSendMessage.py) | | Example of incoming webhooks receiving | [receiveNotification.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/receiveNotification.py) | | Example of sending a polling message | [sendPoll.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendPoll.py) | +| Example of sending a text status | [sendTextStatus.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendTextStatus.py) | ## The full list of the library methods @@ -204,6 +217,13 @@ print(response.data) | `groups.removeAdmin` | The method deprives the participant of group chat administration rights | [RemoveAdmin](https://green-api.com/en/docs/api/groups/RemoveAdmin/) | | `groups.setGroupPicture` | The method sets the avatar of the group | [SetGroupPicture](https://green-api.com/en/docs/api/groups/SetGroupPicture/) | | `groups.leaveGroup` | The method logs the user of the current account out of the group chat | [LeaveGroup](https://green-api.com/en/docs/api/groups/LeaveGroup/) | +| `statuses.sendTextStatus` | The method is aimed for sending a text status | [SendTextStatus](https://green-api.com/en/docs/api/statuses/SendTextStatus/) | +| `statuses.sendVoiceStatus` | The method is aimed for sending a voice status | [SendVoiceStatus](https://green-api.com/en/docs/api/statuses/SendVoiceStatus/) | +| `statuses.sendMediaStatus` | The method is aimed for sending a pictures or video status | [SendMediaStatus](https://green-api.com/en/docs/api/statuses/SendMediaStatus/) | +| `statuses.deleteStatus` | The method is aimed for deleting a certain status | [DeleteStatus](https://green-api.com/en/docs/api/statuses/DeleteStatus/) | +| `statuses.getStatusStatistic` | The method returns an array of recipients marked sent/delivered/read for a given status | [GetStatusStatistic](https://green-api.com/en/docs/api/statuses/GetStatusStatistic/) | +| `statuses.getOutgoingStatuses` | The method returns the outgoing statuses of the account | [GetOutgoingStatuses](https://green-api.com/en/docs/api/statuses/GetOutgoingStatuses/) | +| `statuses.getIncomingStatuses` | The method returns the incoming statuses of the account | [GetIncomingStatuses](https://green-api.com/en/docs/api/statuses/GetIncomingStatuses/) | | `journals.getChatHistory` | The method returns the chat message history | [GetChatHistory](https://green-api.com/en/docs/api/journals/GetChatHistory/) | | `journals.getMessage` | The method returns a chat message | [GetMessage](https://green-api.com/en/docs/api/journals/GetMessage/) | | `journals.lastIncomingMessages` | The method returns the most recent incoming messages of the account | [LastIncomingMessages](https://green-api.com/en/docs/api/journals/LastIncomingMessages/) | From 076b3385d74606fe309d2e6e69905731a336bd0c Mon Sep 17 00:00:00 2001 From: dephea Date: Tue, 23 Apr 2024 08:46:52 +0300 Subject: [PATCH 3/9] small fix --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6a01dd2..4d4c6ec 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,9 @@ https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sen ). ``` -response = greenAPI.statuses.sendTextStatus("I sent this status using Green Api Python SDK!", "#54c774", "NORICAN_REGULAR") +response = greenAPI.statuses.sendTextStatus("I sent this status using Green Api Python SDK!", + "#54c774", + "NORICAN_REGULAR") print(response.data) ``` From e46d663fffaa5ffeaea8daf008e949219edda08e Mon Sep 17 00:00:00 2001 From: dephea Date: Tue, 23 Apr 2024 15:56:18 +0300 Subject: [PATCH 4/9] remove unused import --- whatsapp_api_client_python/tools/statuses.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/whatsapp_api_client_python/tools/statuses.py b/whatsapp_api_client_python/tools/statuses.py index 3833b14..cb12170 100644 --- a/whatsapp_api_client_python/tools/statuses.py +++ b/whatsapp_api_client_python/tools/statuses.py @@ -1,4 +1,4 @@ -from typing import Dict, List, Optional, TYPE_CHECKING, Union +from typing import List, Optional, TYPE_CHECKING from ..response import Response From 3aafb310a73c0de23a10ecf995102f70f0392a33 Mon Sep 17 00:00:00 2001 From: dephea Date: Sat, 27 Apr 2024 08:46:39 +0300 Subject: [PATCH 5/9] added test cases --- README.md | 8 ++-- tests/test_methods.py | 13 ++++++ whatsapp_api_client_python/tools/statuses.py | 42 +++++++++++++------- 3 files changed, 46 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 4d4c6ec..737c5cc 100644 --- a/README.md +++ b/README.md @@ -176,9 +176,11 @@ https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sen ). ``` -response = greenAPI.statuses.sendTextStatus("I sent this status using Green Api Python SDK!", - "#54c774", - "NORICAN_REGULAR") +response = greenAPI.statuses.sendTextStatus( + "I sent this status using Green Api Python SDK!", + "#54c774", + "NORICAN_REGULAR" +) print(response.data) ``` diff --git a/tests/test_methods.py b/tests/test_methods.py index 3865f06..5861b7b 100644 --- a/tests/test_methods.py +++ b/tests/test_methods.py @@ -21,6 +21,7 @@ def test_methods(self, mock_request): *self.account_methods, *self.device_methods, *self.group_methods, + *self.status_methods, *self.log_methods, *self.queue_methods, *self.read_mark_methods, @@ -68,6 +69,18 @@ def group_methods(self) -> typing.List[Response]: api.groups.leaveGroup("") ] + @property + def status_methods(self) -> typing.List[Response]: + return [ + api.statuses.sendTextStatus(""), + api.statuses.sendVoiceStatus("", ""), + api.statuses.sendMediaStatus("", ""), + api.statuses.deleteStatus(""), + api.statuses.getStatusStatistic(""), + api.statuses.getIncomingStatuses(), + api.statuses.getOutgoingStatuses() + ] + @property def log_methods(self) -> typing.List[Response]: return [ diff --git a/whatsapp_api_client_python/tools/statuses.py b/whatsapp_api_client_python/tools/statuses.py index cb12170..878b0d6 100644 --- a/whatsapp_api_client_python/tools/statuses.py +++ b/whatsapp_api_client_python/tools/statuses.py @@ -9,11 +9,13 @@ class Statuses: def __init__(self, api: "GreenApi"): self.api = api - def sendTextStatus(self, + def sendTextStatus( + self, message: str, backgroundColor: Optional[str] = None, font: Optional[str] = None, - participants: Optional[List[str]] = None) -> Response: + participants: Optional[List[str]] = None + ) -> Response: """ The method is aimed for sending a text status. @@ -29,11 +31,13 @@ def sendTextStatus(self, ), request_body ) - def sendVoiceStatus(self, + def sendVoiceStatus( + self, urlFile: str, fileName: str, backgroundColor: Optional[str], - participants: Optional[List[str]]) -> Response: + participants: Optional[List[str]] + ) -> Response: """ The method is aimed for sending a voice status. @@ -49,11 +53,13 @@ def sendVoiceStatus(self, ), request_body ) - def sendMediaStatus(self, + def sendMediaStatus( + self, urlFile: str, fileName: str, caption: Optional[str], - participants: Optional[List[str]]) -> Response: + participants: Optional[List[str]] + ) -> Response: """ The method is aimed for sending a pictures or video status. @@ -69,8 +75,10 @@ def sendMediaStatus(self, ), request_body ) - def deleteStatus(self, - idMessage: str) -> Response: + def deleteStatus( + self, + idMessage: str + ) -> Response: """ The method is aimed for deleting a certain status. @@ -86,8 +94,10 @@ def deleteStatus(self, ), request_body ) - def getStatusStatistic(self, - idMessage: str) -> Response: + def getStatusStatistic( + self, + idMessage: str + ) -> Response: """ The method returns an array of recipients marked sent/delivered/read for a given status. @@ -100,8 +110,10 @@ def getStatusStatistic(self, return self.api.request("GET", f"{url}?idMessage={idMessage}") - def getIncomingStatuses(self, - minutes: Optional[int]=None) -> Response: + def getIncomingStatuses( + self, + minutes: Optional[int]=None + ) -> Response: """ The method returns the incoming statuses of the account If no argument passed, the incoming statuses for the past 24 hours are returned. @@ -118,8 +130,10 @@ def getIncomingStatuses(self, else: return self.api.request("GET", f"{url}") - def getOutgoingStatuses(self, - minutes: Optional[int]=None) -> Response: + def getOutgoingStatuses( + self, + minutes: Optional[int]=None + ) -> Response: """ The method returns the outgoing statuses of the account If no argument passed, the outgoing statuses for the past 24 hours are returned. From ebe9afcf00bd98e86e75d9bda14f39c013ecc8e7 Mon Sep 17 00:00:00 2001 From: dephea Date: Thu, 2 May 2024 07:30:40 +0300 Subject: [PATCH 6/9] fix optional params --- whatsapp_api_client_python/tools/statuses.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/whatsapp_api_client_python/tools/statuses.py b/whatsapp_api_client_python/tools/statuses.py index 878b0d6..5b914e0 100644 --- a/whatsapp_api_client_python/tools/statuses.py +++ b/whatsapp_api_client_python/tools/statuses.py @@ -35,8 +35,8 @@ def sendVoiceStatus( self, urlFile: str, fileName: str, - backgroundColor: Optional[str], - participants: Optional[List[str]] + backgroundColor: Optional[str] = None, + participants: Optional[List[str]] = None ) -> Response: """ The method is aimed for sending a voice status. @@ -57,8 +57,8 @@ def sendMediaStatus( self, urlFile: str, fileName: str, - caption: Optional[str], - participants: Optional[List[str]] + caption: Optional[str] = None, + participants: Optional[List[str]] = None ) -> Response: """ The method is aimed for sending a pictures or video status. @@ -112,7 +112,7 @@ def getStatusStatistic( def getIncomingStatuses( self, - minutes: Optional[int]=None + minutes: Optional[int] = None ) -> Response: """ The method returns the incoming statuses of the account @@ -132,7 +132,7 @@ def getIncomingStatuses( def getOutgoingStatuses( self, - minutes: Optional[int]=None + minutes: Optional[int] = None ) -> Response: """ The method returns the outgoing statuses of the account From a0cbd794b0bf503957c1de294013742da09b0cc5 Mon Sep 17 00:00:00 2001 From: dephea Date: Thu, 6 Jun 2024 09:13:03 +0300 Subject: [PATCH 7/9] Small fixes --- examples/sendTextStatus.py | 5 ++++- whatsapp_api_client_python/tools/statuses.py | 17 +++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/examples/sendTextStatus.py b/examples/sendTextStatus.py index 7c5eb8d..444f095 100644 --- a/examples/sendTextStatus.py +++ b/examples/sendTextStatus.py @@ -6,7 +6,10 @@ def main(): - response = greenAPI.statuses.sendTextStatus("I sent this status using Green Api Python SDK!", "#54c774", "NORICAN_REGULAR") + response = greenAPI.statuses.sendTextStatus( + "I sent this status using Green Api Python SDK!", + "#54c774", + "NORICAN_REGULAR") print(response.data) diff --git a/whatsapp_api_client_python/tools/statuses.py b/whatsapp_api_client_python/tools/statuses.py index 5b914e0..14bfedf 100644 --- a/whatsapp_api_client_python/tools/statuses.py +++ b/whatsapp_api_client_python/tools/statuses.py @@ -5,6 +5,7 @@ if TYPE_CHECKING: from ..API import GreenApi + class Statuses: def __init__(self, api: "GreenApi"): self.api = api @@ -30,7 +31,7 @@ def sendTextStatus( "sendTextStatus/{{apiTokenInstance}}" ), request_body ) - + def sendVoiceStatus( self, urlFile: str, @@ -52,14 +53,14 @@ def sendVoiceStatus( "sendVoiceStatus/{{apiTokenInstance}}" ), request_body ) - + def sendMediaStatus( self, urlFile: str, fileName: str, caption: Optional[str] = None, participants: Optional[List[str]] = None - ) -> Response: + ) -> Response: """ The method is aimed for sending a pictures or video status. @@ -74,7 +75,7 @@ def sendMediaStatus( "sendMediaStatus/{{apiTokenInstance}}" ), request_body ) - + def deleteStatus( self, idMessage: str @@ -93,7 +94,7 @@ def deleteStatus( "deleteStatus/{{apiTokenInstance}}" ), request_body ) - + def getStatusStatistic( self, idMessage: str @@ -109,7 +110,7 @@ def getStatusStatistic( ) return self.api.request("GET", f"{url}?idMessage={idMessage}") - + def getIncomingStatuses( self, minutes: Optional[int] = None @@ -129,7 +130,7 @@ def getIncomingStatuses( return self.api.request("GET", f"{url}?minutes={minutes}") else: return self.api.request("GET", f"{url}") - + def getOutgoingStatuses( self, minutes: Optional[int] = None @@ -160,4 +161,4 @@ def __handle_parameters(cls, parameters: dict) -> dict: if value is None: handled_parameters.pop(key) - return handled_parameters \ No newline at end of file + return handled_parameters From d0260af7b637c15f2ebe68676a84b656ef4c7219 Mon Sep 17 00:00:00 2001 From: prostraction Date: Sun, 23 Feb 2025 01:16:33 +0500 Subject: [PATCH 8/9] Added examples, small fixes --- .../partherMethods/DeleteInstanceAccount.py | 1 - examples/statusesMethods/deleteStatus.py | 13 +++++++++++++ examples/statusesMethods/getStatuses.py | 19 +++++++++++++++++++ examples/statusesMethods/sendMediaStatus.py | 17 +++++++++++++++++ .../{ => statusesMethods}/sendTextStatus.py | 1 - examples/statusesMethods/sendVoiceStatus.py | 17 +++++++++++++++++ whatsapp_api_client_python/API.py | 1 - whatsapp_api_client_python/tools/partner.py | 19 ++++++++++++------- whatsapp_api_client_python/tools/statuses.py | 2 +- 9 files changed, 79 insertions(+), 11 deletions(-) create mode 100644 examples/statusesMethods/deleteStatus.py create mode 100644 examples/statusesMethods/getStatuses.py create mode 100644 examples/statusesMethods/sendMediaStatus.py rename examples/{ => statusesMethods}/sendTextStatus.py (99%) create mode 100644 examples/statusesMethods/sendVoiceStatus.py diff --git a/examples/partherMethods/DeleteInstanceAccount.py b/examples/partherMethods/DeleteInstanceAccount.py index a6b48e0..f48d013 100644 --- a/examples/partherMethods/DeleteInstanceAccount.py +++ b/examples/partherMethods/DeleteInstanceAccount.py @@ -9,6 +9,5 @@ def main(): response = greenAPI.partner.deleteInstanceAccount(1103123456) print(response.data) - if __name__ == '__main__': main() diff --git a/examples/statusesMethods/deleteStatus.py b/examples/statusesMethods/deleteStatus.py new file mode 100644 index 0000000..5290a76 --- /dev/null +++ b/examples/statusesMethods/deleteStatus.py @@ -0,0 +1,13 @@ +from whatsapp_api_client_python import API + +greenAPI = API.GreenAPI( + "1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345" +) + + +def main(): + response = greenAPI.statuses.deleteStatus('BAE54F518532FCB1') + print(response.data) + +if __name__ == '__main__': + main() diff --git a/examples/statusesMethods/getStatuses.py b/examples/statusesMethods/getStatuses.py new file mode 100644 index 0000000..9e93c04 --- /dev/null +++ b/examples/statusesMethods/getStatuses.py @@ -0,0 +1,19 @@ +from whatsapp_api_client_python import API + +greenAPI = API.GreenAPI( + "1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345" +) + + +def main(): + response = greenAPI.statuses.getIncomingStatuses(1400) # minutes argument is Optional + print(response.data) + + response = greenAPI.statuses.getOutgoingStatuses(1400) # minutes argument is Optional + print(response.data) + + response = greenAPI.statuses.getStatusStatistic('BAE54F518532FCB1') + print(response.data) + +if __name__ == '__main__': + main() diff --git a/examples/statusesMethods/sendMediaStatus.py b/examples/statusesMethods/sendMediaStatus.py new file mode 100644 index 0000000..f8e9ee5 --- /dev/null +++ b/examples/statusesMethods/sendMediaStatus.py @@ -0,0 +1,17 @@ +from whatsapp_api_client_python import API + +greenAPI = API.GreenAPI( + "1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345" +) + + +def main(): + response = greenAPI.statuses.sendMediaStatus( + "https://example.com/file.mp4", + "test.mp4" + "#54c774") + + print(response.data) + +if __name__ == '__main__': + main() diff --git a/examples/sendTextStatus.py b/examples/statusesMethods/sendTextStatus.py similarity index 99% rename from examples/sendTextStatus.py rename to examples/statusesMethods/sendTextStatus.py index 444f095..8fdaefc 100644 --- a/examples/sendTextStatus.py +++ b/examples/statusesMethods/sendTextStatus.py @@ -13,6 +13,5 @@ def main(): print(response.data) - if __name__ == '__main__': main() diff --git a/examples/statusesMethods/sendVoiceStatus.py b/examples/statusesMethods/sendVoiceStatus.py new file mode 100644 index 0000000..7a8abf5 --- /dev/null +++ b/examples/statusesMethods/sendVoiceStatus.py @@ -0,0 +1,17 @@ +from whatsapp_api_client_python import API + +greenAPI = API.GreenAPI( + "1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345" +) + + +def main(): + response = greenAPI.statuses.sendVoiceStatus( + "https://example.com/file.mp3", + "test.mp3" + "#54c774") + + print(response.data) + +if __name__ == '__main__': + main() diff --git a/whatsapp_api_client_python/API.py b/whatsapp_api_client_python/API.py index ef931a6..7cfe050 100644 --- a/whatsapp_api_client_python/API.py +++ b/whatsapp_api_client_python/API.py @@ -178,7 +178,6 @@ def __prepare_session(self) -> None: self.session.mount("http://", HTTPAdapter(max_retries=retry)) self.session.mount("https://", HTTPAdapter(max_retries=retry)) - class GreenAPI(GreenApi): pass diff --git a/whatsapp_api_client_python/tools/partner.py b/whatsapp_api_client_python/tools/partner.py index 73d3435..a003213 100644 --- a/whatsapp_api_client_python/tools/partner.py +++ b/whatsapp_api_client_python/tools/partner.py @@ -44,7 +44,7 @@ def deleteInstanceAccount(self, idInstance: int) -> Response: https://green-api.com/en/docs/partners/deleteInstanceAccount/ """ - request_body = self.handle_parameters(locals()) + request_body = self.__handle_parameters(locals()) return self.api.request( "POST", ( @@ -52,10 +52,15 @@ def deleteInstanceAccount(self, idInstance: int) -> Response: "deleteInstanceAccount/{{partnerToken}}" ), request_body ) + + @classmethod + def __handle_parameters(cls, parameters: dict) -> dict: + handled_parameters = parameters.copy() + + handled_parameters.pop("self") + + for key, value in parameters.items(): + if value is None: + handled_parameters.pop(key) - def handle_parameters(self, parameters: dict) -> dict: - return { - key: value - for key, value in parameters.items() - if value is not None and key != "self" - } \ No newline at end of file + return handled_parameters \ No newline at end of file diff --git a/whatsapp_api_client_python/tools/statuses.py b/whatsapp_api_client_python/tools/statuses.py index 14bfedf..1c1c883 100644 --- a/whatsapp_api_client_python/tools/statuses.py +++ b/whatsapp_api_client_python/tools/statuses.py @@ -161,4 +161,4 @@ def __handle_parameters(cls, parameters: dict) -> dict: if value is None: handled_parameters.pop(key) - return handled_parameters + return handled_parameters \ No newline at end of file From 5821c4ce01ccfa6fc7fb9d69b3aa798e244b538c Mon Sep 17 00:00:00 2001 From: prostraction Date: Sun, 23 Feb 2025 01:20:07 +0500 Subject: [PATCH 9/9] Fixed documentation --- README.md | 4 +--- docs/README.md | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c77946e..cd41d8b 100644 --- a/README.md +++ b/README.md @@ -171,9 +171,7 @@ print(response.data) ### Sending a text status -Link to example: [sendTextStatus.py]( -https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendTextStatus.py -). +Link to example: [sendTextStatus.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/statusesMethods/sendTextStatus.py). ``` response = greenAPI.statuses.sendTextStatus( diff --git a/docs/README.md b/docs/README.md index a8704ce..3c47657 100644 --- a/docs/README.md +++ b/docs/README.md @@ -153,6 +153,20 @@ response = greenAPI.sending.sendPoll( print(response.data) ``` +## Отправка текстового статуса + +Ссылка на пример: [sendPoll.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/statusesMethods/sendTextStatus.py). + +``` +response = greenAPI.statuses.sendTextStatus( + "I sent this status using Green Api Python SDK!", + "#54c774", + "NORICAN_REGULAR" +) + +print(response.data) +``` + ## Список примеров | Описание | Модуль |