From 4fba53e0fe53fed8d39d5bfdf716fb1e1ba28e2a Mon Sep 17 00:00:00 2001 From: Zhan Date: Mon, 17 Mar 2025 07:52:29 +0300 Subject: [PATCH 01/10] directHost --- whatsapp_api_client_python/API.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/whatsapp_api_client_python/API.py b/whatsapp_api_client_python/API.py index 7cfe050..aa5690c 100644 --- a/whatsapp_api_client_python/API.py +++ b/whatsapp_api_client_python/API.py @@ -27,6 +27,7 @@ class GreenApi: media: str idInstance: str apiTokenInstance: str + directHost: bool #Добавил флаг для прямого хоста def __init__( self, @@ -34,6 +35,7 @@ def __init__( apiTokenInstance: str, debug_mode: bool = False, raise_errors: bool = False, + directHost: bool = False, #Добавил флаг для прямого хоста host: str = "https://api.green-api.com", media: str = "https://media.green-api.com", host_timeout: float = 180, # sec per retry @@ -43,6 +45,12 @@ def __init__( self.media = media self.debug_mode = debug_mode self.raise_errors = raise_errors + #Если флаг directHost == True, вызываю метод для определения прямого хоста + self.directHost = directHost + if self.directHost: + self.host = self._determine_host(idInstance) + else: + self.host = host # Change default values in init() if required self.host_timeout = host_timeout @@ -69,6 +77,17 @@ def __init__( self.logger = logging.getLogger("whatsapp-api-client-python") self.__prepare_logger() + def _determine_host(self, idInstance: str) -> str: #Метод для определения прямого хоста по первым цифрам idInstance + if idInstance.startswith("1103"): + return f"https://{idInstance[:4]}.api.green-api.com" + elif idInstance.startswith("11"): + return "https://api.green-api.com" + elif idInstance.startswith("55"): + return "https://api.green-api.com" + elif idInstance.startswith("7"): + return f"https://{idInstance[:4]}.api.greenapi.com" + return "https://api.green-api.com" + def request( self, method: str, From c2a53839bf9c8b76cd73575a338eab7b97f3c52b Mon Sep 17 00:00:00 2001 From: Zhan Date: Mon, 17 Mar 2025 12:28:27 +0300 Subject: [PATCH 02/10] media host --- whatsapp_api_client_python/API.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/whatsapp_api_client_python/API.py b/whatsapp_api_client_python/API.py index aa5690c..210fc0b 100644 --- a/whatsapp_api_client_python/API.py +++ b/whatsapp_api_client_python/API.py @@ -48,9 +48,10 @@ def __init__( #Если флаг directHost == True, вызываю метод для определения прямого хоста self.directHost = directHost if self.directHost: - self.host = self._determine_host(idInstance) + self.host, self.media = self._determine_host(idInstance) else: self.host = host + self.media = media # Change default values in init() if required self.host_timeout = host_timeout @@ -79,14 +80,14 @@ def __init__( def _determine_host(self, idInstance: str) -> str: #Метод для определения прямого хоста по первым цифрам idInstance if idInstance.startswith("1103"): - return f"https://{idInstance[:4]}.api.green-api.com" + return f"https://{idInstance[:4]}.api.green-api.com", f"https://{idInstance[:4]}.media.green-api.com" elif idInstance.startswith("11"): - return "https://api.green-api.com" + return "https://api.green-api.com", "https://media.green-api.com" elif idInstance.startswith("55"): - return "https://api.green-api.com" + return "https://api.green-api.com", "https://media.green-api.com" elif idInstance.startswith("7"): - return f"https://{idInstance[:4]}.api.greenapi.com" - return "https://api.green-api.com" + return f"https://{idInstance[:4]}.api.greenapi.com", f"https://{idInstance[:4]}.media.greenapi.com" + return "https://api.green-api.com", "https://media.green-api.com" def request( self, From 7e93de1de87e53611bba883cf0e5d7ca0017fb92 Mon Sep 17 00:00:00 2001 From: Zhan Date: Thu, 20 Mar 2025 14:53:32 +0300 Subject: [PATCH 03/10] mapping --- whatsapp_api_client_python/API.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/whatsapp_api_client_python/API.py b/whatsapp_api_client_python/API.py index 210fc0b..6773108 100644 --- a/whatsapp_api_client_python/API.py +++ b/whatsapp_api_client_python/API.py @@ -27,7 +27,7 @@ class GreenApi: media: str idInstance: str apiTokenInstance: str - directHost: bool #Добавил флаг для прямого хоста + directHost: bool #Flag for determining and using a direct host def __init__( self, @@ -35,7 +35,7 @@ def __init__( apiTokenInstance: str, debug_mode: bool = False, raise_errors: bool = False, - directHost: bool = False, #Добавил флаг для прямого хоста + directHost: bool = False, host: str = "https://api.green-api.com", media: str = "https://media.green-api.com", host_timeout: float = 180, # sec per retry @@ -45,7 +45,6 @@ def __init__( self.media = media self.debug_mode = debug_mode self.raise_errors = raise_errors - #Если флаг directHost == True, вызываю метод для определения прямого хоста self.directHost = directHost if self.directHost: self.host, self.media = self._determine_host(idInstance) @@ -53,7 +52,6 @@ def __init__( self.host = host self.media = media - # Change default values in init() if required self.host_timeout = host_timeout self.media_timeout = media_timeout @@ -78,16 +76,17 @@ def __init__( self.logger = logging.getLogger("whatsapp-api-client-python") self.__prepare_logger() - def _determine_host(self, idInstance: str) -> str: #Метод для определения прямого хоста по первым цифрам idInstance - if idInstance.startswith("1103"): - return f"https://{idInstance[:4]}.api.green-api.com", f"https://{idInstance[:4]}.media.green-api.com" - elif idInstance.startswith("11"): - return "https://api.green-api.com", "https://media.green-api.com" - elif idInstance.startswith("55"): - return "https://api.green-api.com", "https://media.green-api.com" - elif idInstance.startswith("7"): - return f"https://{idInstance[:4]}.api.greenapi.com", f"https://{idInstance[:4]}.media.greenapi.com" - return "https://api.green-api.com", "https://media.green-api.com" + def _determine_host(self, idInstance: str) -> str: #Method for determining a direct host + mapping = { + "1103": (f"https://{idInstance[:4]}.api.green-api.com", f"https://{idInstance[:4]}.media.green-api.com"), + "1104": (f"https://1103.api.green-api.com", f"https://1103.media.green-api.com"), + "5103": ("https://api.green-api.com", "https://media.green-api.com"), + "5700": (f"https://{idInstance[:4]}.api.green-api.com", f"https://{idInstance[:4]}.media.green-api.com") , + "7723": ("https://7700.api.greenapi.com", "https://7700.media.greenapi.com"), + "7726": ("https://api.greenapi.com", "https://media.greenapi.com"), + "7": (f"https://{idInstance[:4]}.api.greenapi.com", f"https://{idInstance[:4]}.media.greenapi.com") + } + return next((url for key, url in mapping.items() if idInstance.startswith(key)), ("https://api.green-api.com", "https://media.green-api.com")) def request( self, From 6145f2f4125d3c9495a4a8b54b359067ede236dd Mon Sep 17 00:00:00 2001 From: Zhan Date: Thu, 20 Mar 2025 15:54:40 +0300 Subject: [PATCH 04/10] mapping --- whatsapp_api_client_python/API.py | 1 - 1 file changed, 1 deletion(-) diff --git a/whatsapp_api_client_python/API.py b/whatsapp_api_client_python/API.py index 6773108..4d2d9ad 100644 --- a/whatsapp_api_client_python/API.py +++ b/whatsapp_api_client_python/API.py @@ -80,7 +80,6 @@ def _determine_host(self, idInstance: str) -> str: #Method for determining a dir mapping = { "1103": (f"https://{idInstance[:4]}.api.green-api.com", f"https://{idInstance[:4]}.media.green-api.com"), "1104": (f"https://1103.api.green-api.com", f"https://1103.media.green-api.com"), - "5103": ("https://api.green-api.com", "https://media.green-api.com"), "5700": (f"https://{idInstance[:4]}.api.green-api.com", f"https://{idInstance[:4]}.media.green-api.com") , "7723": ("https://7700.api.greenapi.com", "https://7700.media.greenapi.com"), "7726": ("https://api.greenapi.com", "https://media.greenapi.com"), From 19f6009c76373b0da9e3b53aae72c07c82e48419 Mon Sep 17 00:00:00 2001 From: prostraction <47314760+prostraction@users.noreply.github.com> Date: Sat, 22 Mar 2025 00:50:31 +0500 Subject: [PATCH 05/10] Update API.py --- whatsapp_api_client_python/API.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/whatsapp_api_client_python/API.py b/whatsapp_api_client_python/API.py index 4d2d9ad..a8db091 100644 --- a/whatsapp_api_client_python/API.py +++ b/whatsapp_api_client_python/API.py @@ -27,7 +27,7 @@ class GreenApi: media: str idInstance: str apiTokenInstance: str - directHost: bool #Flag for determining and using a direct host + useDirectHost: bool def __init__( self, @@ -35,7 +35,7 @@ def __init__( apiTokenInstance: str, debug_mode: bool = False, raise_errors: bool = False, - directHost: bool = False, + useDirectHost: bool = False, host: str = "https://api.green-api.com", media: str = "https://media.green-api.com", host_timeout: float = 180, # sec per retry @@ -45,12 +45,8 @@ def __init__( self.media = media self.debug_mode = debug_mode self.raise_errors = raise_errors - self.directHost = directHost - if self.directHost: - self.host, self.media = self._determine_host(idInstance) - else: - self.host = host - self.media = media + self.useDirectHost = useDirectHost + self.host, self.media = self._determine_host(idInstance) if self.useDirectHost else (host, media) self.host_timeout = host_timeout self.media_timeout = media_timeout @@ -76,14 +72,15 @@ def __init__( self.logger = logging.getLogger("whatsapp-api-client-python") self.__prepare_logger() - def _determine_host(self, idInstance: str) -> str: #Method for determining a direct host + def _determine_host(self, idInstance: str) -> str: mapping = { - "1103": (f"https://{idInstance[:4]}.api.green-api.com", f"https://{idInstance[:4]}.media.green-api.com"), + "1103": (f"https://1103.api.green-api.com", f"https://1103.media.green-api.com"), "1104": (f"https://1103.api.green-api.com", f"https://1103.media.green-api.com"), - "5700": (f"https://{idInstance[:4]}.api.green-api.com", f"https://{idInstance[:4]}.media.green-api.com") , + "5700": (f"https://5700.api.green-api.com", f"https://5700.media.green-api.com"), + "7103": ("https://7103.api.greenapi.com", "https://7103.media.greenapi.com"), + "7105": ("https://7105.api.greenapi.com", "https://7105.media.greenapi.com"), "7723": ("https://7700.api.greenapi.com", "https://7700.media.greenapi.com"), - "7726": ("https://api.greenapi.com", "https://media.greenapi.com"), - "7": (f"https://{idInstance[:4]}.api.greenapi.com", f"https://{idInstance[:4]}.media.greenapi.com") + "7726": ("https://api.greenapi.com", "https://media.greenapi.com") } return next((url for key, url in mapping.items() if idInstance.startswith(key)), ("https://api.green-api.com", "https://media.green-api.com")) @@ -231,4 +228,4 @@ def request( url = url.replace("{{partnerToken}}", self.partnerToken) - return super().request(method, url, payload, files) \ No newline at end of file + return super().request(method, url, payload, files) From 62d36f8977aac1f06d267ac81433dd2c213856a7 Mon Sep 17 00:00:00 2001 From: prostraction <47314760+prostraction@users.noreply.github.com> Date: Sat, 22 Mar 2025 00:52:16 +0500 Subject: [PATCH 06/10] Update API.py --- whatsapp_api_client_python/API.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/whatsapp_api_client_python/API.py b/whatsapp_api_client_python/API.py index a8db091..ebae6ee 100644 --- a/whatsapp_api_client_python/API.py +++ b/whatsapp_api_client_python/API.py @@ -74,9 +74,9 @@ def __init__( def _determine_host(self, idInstance: str) -> str: mapping = { - "1103": (f"https://1103.api.green-api.com", f"https://1103.media.green-api.com"), - "1104": (f"https://1103.api.green-api.com", f"https://1103.media.green-api.com"), - "5700": (f"https://5700.api.green-api.com", f"https://5700.media.green-api.com"), + "1103": ("https://1103.api.green-api.com", "https://1103.media.green-api.com"), + "1104": ("https://1103.api.green-api.com", "https://1103.media.green-api.com"), + "5700": ("https://5700.api.green-api.com", "https://5700.media.green-api.com"), "7103": ("https://7103.api.greenapi.com", "https://7103.media.greenapi.com"), "7105": ("https://7105.api.greenapi.com", "https://7105.media.greenapi.com"), "7723": ("https://7700.api.greenapi.com", "https://7700.media.greenapi.com"), From cd210d9e374bfb4b52e56ec169c9e703801aee01 Mon Sep 17 00:00:00 2001 From: prostraction <47314760+prostraction@users.noreply.github.com> Date: Sat, 22 Mar 2025 00:55:49 +0500 Subject: [PATCH 07/10] Update API.py --- whatsapp_api_client_python/API.py | 1 + 1 file changed, 1 insertion(+) diff --git a/whatsapp_api_client_python/API.py b/whatsapp_api_client_python/API.py index ebae6ee..d52af7b 100644 --- a/whatsapp_api_client_python/API.py +++ b/whatsapp_api_client_python/API.py @@ -48,6 +48,7 @@ def __init__( self.useDirectHost = useDirectHost self.host, self.media = self._determine_host(idInstance) if self.useDirectHost else (host, media) + # Change default values in init() if required (slow connection) self.host_timeout = host_timeout self.media_timeout = media_timeout From a06a4e741479932c931b48fc08307e849332675b Mon Sep 17 00:00:00 2001 From: prostraction <47314760+prostraction@users.noreply.github.com> Date: Sat, 22 Mar 2025 01:04:21 +0500 Subject: [PATCH 08/10] Update API.py --- whatsapp_api_client_python/API.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/whatsapp_api_client_python/API.py b/whatsapp_api_client_python/API.py index d52af7b..305d6a0 100644 --- a/whatsapp_api_client_python/API.py +++ b/whatsapp_api_client_python/API.py @@ -81,7 +81,7 @@ def _determine_host(self, idInstance: str) -> str: "7103": ("https://7103.api.greenapi.com", "https://7103.media.greenapi.com"), "7105": ("https://7105.api.greenapi.com", "https://7105.media.greenapi.com"), "7723": ("https://7700.api.greenapi.com", "https://7700.media.greenapi.com"), - "7726": ("https://api.greenapi.com", "https://media.greenapi.com") + "7": ("https://api.greenapi.com", "https://media.greenapi.com") } return next((url for key, url in mapping.items() if idInstance.startswith(key)), ("https://api.green-api.com", "https://media.green-api.com")) From 00c774cae9fa51b61d1f65622b5f0974881b6038 Mon Sep 17 00:00:00 2001 From: prostraction <47314760+prostraction@users.noreply.github.com> Date: Sat, 22 Mar 2025 01:08:00 +0500 Subject: [PATCH 09/10] Update API.py --- whatsapp_api_client_python/API.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/whatsapp_api_client_python/API.py b/whatsapp_api_client_python/API.py index 305d6a0..d48412b 100644 --- a/whatsapp_api_client_python/API.py +++ b/whatsapp_api_client_python/API.py @@ -80,7 +80,8 @@ def _determine_host(self, idInstance: str) -> str: "5700": ("https://5700.api.green-api.com", "https://5700.media.green-api.com"), "7103": ("https://7103.api.greenapi.com", "https://7103.media.greenapi.com"), "7105": ("https://7105.api.greenapi.com", "https://7105.media.greenapi.com"), - "7723": ("https://7700.api.greenapi.com", "https://7700.media.greenapi.com"), + "7726": ("https://api.greenapi.com", "https://media.greenapi.com"), + "77": ("https://7700.api.greenapi.com", "https://7700.media.greenapi.com"), "7": ("https://api.greenapi.com", "https://media.greenapi.com") } return next((url for key, url in mapping.items() if idInstance.startswith(key)), ("https://api.green-api.com", "https://media.green-api.com")) From dab35ee1ed754fb4c586e19418aed8b5e4c49a43 Mon Sep 17 00:00:00 2001 From: prostraction <47314760+prostraction@users.noreply.github.com> Date: Sat, 22 Mar 2025 02:01:53 +0500 Subject: [PATCH 10/10] Update API.py --- whatsapp_api_client_python/API.py | 1 - 1 file changed, 1 deletion(-) diff --git a/whatsapp_api_client_python/API.py b/whatsapp_api_client_python/API.py index d48412b..49a2352 100644 --- a/whatsapp_api_client_python/API.py +++ b/whatsapp_api_client_python/API.py @@ -80,7 +80,6 @@ def _determine_host(self, idInstance: str) -> str: "5700": ("https://5700.api.green-api.com", "https://5700.media.green-api.com"), "7103": ("https://7103.api.greenapi.com", "https://7103.media.greenapi.com"), "7105": ("https://7105.api.greenapi.com", "https://7105.media.greenapi.com"), - "7726": ("https://api.greenapi.com", "https://media.greenapi.com"), "77": ("https://7700.api.greenapi.com", "https://7700.media.greenapi.com"), "7": ("https://api.greenapi.com", "https://media.greenapi.com") }