forked from green-api/whatsapp-api-client-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatuses.py
More file actions
164 lines (131 loc) · 4.6 KB
/
statuses.py
File metadata and controls
164 lines (131 loc) · 4.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
from typing import List, Optional, TYPE_CHECKING
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] = None,
participants: Optional[List[str]] = None
) -> 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] = None,
participants: Optional[List[str]] = None
) -> 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