@@ -27,15 +27,15 @@ class GreenApi:
2727 media : str
2828 idInstance : str
2929 apiTokenInstance : str
30- directHost : bool #Flag for determining and using a direct host
30+ useDirectHost : bool
3131
3232 def __init__ (
3333 self ,
3434 idInstance : str ,
3535 apiTokenInstance : str ,
3636 debug_mode : bool = False ,
3737 raise_errors : bool = False ,
38- directHost : bool = False ,
38+ useDirectHost : bool = False ,
3939 host : str = "https://api.green-api.com" ,
4040 media : str = "https://media.green-api.com" ,
4141 host_timeout : float = 180 , # sec per retry
@@ -45,12 +45,8 @@ def __init__(
4545 self .media = media
4646 self .debug_mode = debug_mode
4747 self .raise_errors = raise_errors
48- self .directHost = directHost
49- if self .directHost :
50- self .host , self .media = self ._determine_host (idInstance )
51- else :
52- self .host = host
53- self .media = media
48+ self .useDirectHost = useDirectHost
49+ self .host , self .media = self ._determine_host (idInstance ) if self .useDirectHost else (host , media )
5450
5551 self .host_timeout = host_timeout
5652 self .media_timeout = media_timeout
@@ -76,14 +72,15 @@ def __init__(
7672 self .logger = logging .getLogger ("whatsapp-api-client-python" )
7773 self .__prepare_logger ()
7874
79- def _determine_host (self , idInstance : str ) -> str : #Method for determining a direct host
75+ def _determine_host (self , idInstance : str ) -> str :
8076 mapping = {
81- "1103" : (f"https://{ idInstance [: 4 ] } .api.green-api.com" , f"https://{ idInstance [: 4 ] } .media.green-api.com" ),
77+ "1103" : (f"https://1103 .api.green-api.com" , f"https://1103 .media.green-api.com" ),
8278 "1104" : (f"https://1103.api.green-api.com" , f"https://1103.media.green-api.com" ),
83- "5700" : (f"https://{ idInstance [:4 ]} .api.green-api.com" , f"https://{ idInstance [:4 ]} .media.green-api.com" ) ,
79+ "5700" : (f"https://5700.api.green-api.com" , f"https://5700.media.green-api.com" ),
80+ "7103" : ("https://7103.api.greenapi.com" , "https://7103.media.greenapi.com" ),
81+ "7105" : ("https://7105.api.greenapi.com" , "https://7105.media.greenapi.com" ),
8482 "7723" : ("https://7700.api.greenapi.com" , "https://7700.media.greenapi.com" ),
85- "7726" : ("https://api.greenapi.com" , "https://media.greenapi.com" ),
86- "7" : (f"https://{ idInstance [:4 ]} .api.greenapi.com" , f"https://{ idInstance [:4 ]} .media.greenapi.com" )
83+ "7726" : ("https://api.greenapi.com" , "https://media.greenapi.com" )
8784 }
8885 return next ((url for key , url in mapping .items () if idInstance .startswith (key )), ("https://api.green-api.com" , "https://media.green-api.com" ))
8986
@@ -231,4 +228,4 @@ def request(
231228
232229 url = url .replace ("{{partnerToken}}" , self .partnerToken )
233230
234- return super ().request (method , url , payload , files )
231+ return super ().request (method , url , payload , files )
0 commit comments