telegram-api-client-python 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- telegram-api-client-python/API.py +323 -0
- telegram-api-client-python/__init__.py +0 -0
- telegram-api-client-python/response.py +18 -0
- telegram-api-client-python/tools/__init__.py +0 -0
- telegram-api-client-python/tools/account.py +261 -0
- telegram-api-client-python/tools/groups.py +274 -0
- telegram-api-client-python/tools/journals.py +126 -0
- telegram-api-client-python/tools/marking.py +38 -0
- telegram-api-client-python/tools/partner.py +87 -0
- telegram-api-client-python/tools/queues.py +111 -0
- telegram-api-client-python/tools/receiving.py +80 -0
- telegram-api-client-python/tools/sending.py +301 -0
- telegram-api-client-python/tools/serviceMethods.py +264 -0
- telegram-api-client-python/tools/webhooks.py +97 -0
- telegram_api_client_python-1.0.0.dist-info/METADATA +319 -0
- telegram_api_client_python-1.0.0.dist-info/RECORD +19 -0
- telegram_api_client_python-1.0.0.dist-info/WHEEL +5 -0
- telegram_api_client_python-1.0.0.dist-info/licenses/LICENSE +392 -0
- telegram_api_client_python-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import List, TYPE_CHECKING
|
|
3
|
+
|
|
4
|
+
import aiofiles
|
|
5
|
+
|
|
6
|
+
from ..response import Response
|
|
7
|
+
|
|
8
|
+
if TYPE_CHECKING:
|
|
9
|
+
from ..API import GreenApi
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Groups:
|
|
13
|
+
def __init__(self, api: "GreenApi"):
|
|
14
|
+
self.api = api
|
|
15
|
+
|
|
16
|
+
def createGroup(self, groupName: str, chatIds: List[str]) -> Response:
|
|
17
|
+
"""
|
|
18
|
+
The method is aimed for creating a group chat.
|
|
19
|
+
|
|
20
|
+
https://green-api.com/telegram/docs/api/groups/CreateGroup/
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
request_body = self.__handle_parameters(locals())
|
|
24
|
+
|
|
25
|
+
return self.api.request(
|
|
26
|
+
"POST", (
|
|
27
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
28
|
+
"createGroup/{{apiTokenInstance}}"
|
|
29
|
+
), request_body
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
async def createGroupAsync(self, groupName: str, chatIds: List[str]) -> Response:
|
|
34
|
+
request_body = self.__handle_parameters(locals())
|
|
35
|
+
|
|
36
|
+
return await self.api.requestAsync(
|
|
37
|
+
"POST",
|
|
38
|
+
"{{host}}/waInstance{{idInstance}}/createGroup/{{apiTokenInstance}}",
|
|
39
|
+
request_body
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
def updateGroupName(self, chatId: str, groupName: str) -> Response:
|
|
43
|
+
"""
|
|
44
|
+
The method changes a group chat name.
|
|
45
|
+
|
|
46
|
+
https://green-api.com/telegram/docs/api/groups/UpdateGroupName/
|
|
47
|
+
"""
|
|
48
|
+
|
|
49
|
+
request_body = self.__handle_parameters(locals())
|
|
50
|
+
|
|
51
|
+
return self.api.request(
|
|
52
|
+
"POST", (
|
|
53
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
54
|
+
"updateGroupName/{{apiTokenInstance}}"
|
|
55
|
+
), request_body
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
async def updateGroupNameAsync(self, chatId: str, groupName: str) -> Response:
|
|
59
|
+
request_body = self.__handle_parameters(locals())
|
|
60
|
+
|
|
61
|
+
return await self.api.requestAsync(
|
|
62
|
+
"POST",
|
|
63
|
+
"{{host}}/waInstance{{idInstance}}/updateGroupName/{{apiTokenInstance}}",
|
|
64
|
+
request_body
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
def getGroupData(self, chatId: str) -> Response:
|
|
68
|
+
"""
|
|
69
|
+
The method gets group chat data.
|
|
70
|
+
|
|
71
|
+
https://green-api.com/telegram/docs/api/groups/GetGroupData/
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
request_body = self.__handle_parameters(locals())
|
|
75
|
+
|
|
76
|
+
return self.api.request(
|
|
77
|
+
"POST", (
|
|
78
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
79
|
+
"getGroupData/{{apiTokenInstance}}"
|
|
80
|
+
), request_body
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
async def getGroupDataAsync(self, chatId: str) -> Response:
|
|
84
|
+
request_body = self.__handle_parameters(locals())
|
|
85
|
+
|
|
86
|
+
return await self.api.requestAsync(
|
|
87
|
+
"POST",
|
|
88
|
+
"{{host}}/waInstance{{idInstance}}/getGroupData/{{apiTokenInstance}}",
|
|
89
|
+
request_body
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
def addGroupParticipant(
|
|
93
|
+
self, chatId: str, participantChatId: str
|
|
94
|
+
) -> Response:
|
|
95
|
+
"""
|
|
96
|
+
The method adds a participant to a group chat.
|
|
97
|
+
|
|
98
|
+
https://green-api.com/telegram/docs/api/groups/AddGroupParticipant/
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
request_body = self.__handle_parameters(locals())
|
|
102
|
+
|
|
103
|
+
return self.api.request(
|
|
104
|
+
"POST", (
|
|
105
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
106
|
+
"addGroupParticipant/{{apiTokenInstance}}"
|
|
107
|
+
), request_body
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
async def addGroupParticipantAsync(
|
|
111
|
+
self, chatId: str, participantChatId: str
|
|
112
|
+
) -> Response:
|
|
113
|
+
request_body = self.__handle_parameters(locals())
|
|
114
|
+
|
|
115
|
+
return await self.api.requestAsync(
|
|
116
|
+
"POST",
|
|
117
|
+
"{{host}}/waInstance{{idInstance}}/addGroupParticipant/{{apiTokenInstance}}",
|
|
118
|
+
request_body
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
def removeGroupParticipant(
|
|
122
|
+
self, chatId: str, participantChatId: str
|
|
123
|
+
) -> Response:
|
|
124
|
+
"""
|
|
125
|
+
The method removes a participant from a group chat.
|
|
126
|
+
|
|
127
|
+
https://green-api.com/telegram/docs/api/groups/RemoveGroupParticipant/
|
|
128
|
+
"""
|
|
129
|
+
|
|
130
|
+
request_body = self.__handle_parameters(locals())
|
|
131
|
+
|
|
132
|
+
return self.api.request(
|
|
133
|
+
"POST", (
|
|
134
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
135
|
+
"removeGroupParticipant/{{apiTokenInstance}}"
|
|
136
|
+
), request_body
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
async def removeGroupParticipantAsync(
|
|
140
|
+
self, chatId: str, participantChatId: str
|
|
141
|
+
) -> Response:
|
|
142
|
+
request_body = self.__handle_parameters(locals())
|
|
143
|
+
|
|
144
|
+
return await self.api.requestAsync(
|
|
145
|
+
"POST",
|
|
146
|
+
"{{host}}/waInstance{{idInstance}}/removeGroupParticipant/{{apiTokenInstance}}",
|
|
147
|
+
request_body
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
def setGroupAdmin(self, chatId: str, participantChatId: str) -> Response:
|
|
151
|
+
"""
|
|
152
|
+
The method sets a group chat participant as an administrator.
|
|
153
|
+
|
|
154
|
+
https://green-api.com/telegram/docs/api/groups/SetGroupAdmin/
|
|
155
|
+
"""
|
|
156
|
+
|
|
157
|
+
request_body = self.__handle_parameters(locals())
|
|
158
|
+
|
|
159
|
+
return self.api.request(
|
|
160
|
+
"POST", (
|
|
161
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
162
|
+
"setGroupAdmin/{{apiTokenInstance}}"
|
|
163
|
+
), request_body
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
async def setGroupAdminAsync(self, chatId: str, participantChatId: str) -> Response:
|
|
167
|
+
request_body = self.__handle_parameters(locals())
|
|
168
|
+
|
|
169
|
+
return await self.api.requestAsync(
|
|
170
|
+
"POST",
|
|
171
|
+
"{{host}}/waInstance{{idInstance}}/setGroupAdmin/{{apiTokenInstance}}",
|
|
172
|
+
request_body
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
def removeAdmin(self, chatId: str, participantChatId: str) -> Response:
|
|
176
|
+
"""
|
|
177
|
+
The method removes a participant from group chat administration
|
|
178
|
+
rights.
|
|
179
|
+
|
|
180
|
+
https://green-api.com/telegram/docs/api/groups/RemoveAdmin/
|
|
181
|
+
"""
|
|
182
|
+
|
|
183
|
+
request_body = self.__handle_parameters(locals())
|
|
184
|
+
|
|
185
|
+
return self.api.request(
|
|
186
|
+
"POST", (
|
|
187
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
188
|
+
"removeAdmin/{{apiTokenInstance}}"
|
|
189
|
+
), request_body
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
async def removeAdminAsync(self, chatId: str, participantChatId: str) -> Response:
|
|
193
|
+
request_body = self.__handle_parameters(locals())
|
|
194
|
+
|
|
195
|
+
return await self.api.requestAsync(
|
|
196
|
+
"POST",
|
|
197
|
+
"{{host}}/waInstance{{idInstance}}/removeAdmin/{{apiTokenInstance}}",
|
|
198
|
+
request_body
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
def setGroupPicture(self, chatId: str, path: str) -> Response:
|
|
202
|
+
"""
|
|
203
|
+
The method sets a group picture.
|
|
204
|
+
|
|
205
|
+
https://green-api.com/telegram/docs/api/groups/SetGroupPicture/
|
|
206
|
+
"""
|
|
207
|
+
|
|
208
|
+
request_body = self.__handle_parameters(locals())
|
|
209
|
+
|
|
210
|
+
file_name = Path(path).name
|
|
211
|
+
files = {"file": (file_name, open(path, "rb"), "image/jpeg")}
|
|
212
|
+
|
|
213
|
+
request_body.pop("path")
|
|
214
|
+
|
|
215
|
+
return self.api.request(
|
|
216
|
+
"POST", (
|
|
217
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
218
|
+
"setGroupPicture/{{apiTokenInstance}}"
|
|
219
|
+
), request_body, files
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
async def setGroupPictureAsync(self, chatId: str, path: str) -> Response:
|
|
223
|
+
request_body = self.__handle_parameters(locals())
|
|
224
|
+
|
|
225
|
+
request_body.pop("path")
|
|
226
|
+
file_name = Path(path).name
|
|
227
|
+
|
|
228
|
+
async with aiofiles.open(path, "rb") as file:
|
|
229
|
+
file_data = await file.read()
|
|
230
|
+
files = {"file": (file_name, file_data, "image/jpeg")}
|
|
231
|
+
|
|
232
|
+
return await self.api.requestAsync(
|
|
233
|
+
"POST",
|
|
234
|
+
"{{host}}/waInstance{{idInstance}}/setGroupPicture/{{apiTokenInstance}}",
|
|
235
|
+
request_body,
|
|
236
|
+
files=files
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
def leaveGroup(self, chatId: str) -> Response:
|
|
240
|
+
"""
|
|
241
|
+
The method makes the current account user leave the group chat.
|
|
242
|
+
|
|
243
|
+
https://green-api.com/telegram/docs/api/groups/LeaveGroup/
|
|
244
|
+
"""
|
|
245
|
+
|
|
246
|
+
request_body = self.__handle_parameters(locals())
|
|
247
|
+
|
|
248
|
+
return self.api.request(
|
|
249
|
+
"POST", (
|
|
250
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
251
|
+
"leaveGroup/{{apiTokenInstance}}"
|
|
252
|
+
), request_body
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
async def leaveGroupAsync(self, chatId: str) -> Response:
|
|
256
|
+
request_body = self.__handle_parameters(locals())
|
|
257
|
+
|
|
258
|
+
return await self.api.requestAsync(
|
|
259
|
+
"POST",
|
|
260
|
+
"{{host}}/waInstance{{idInstance}}/leaveGroup/{{apiTokenInstance}}",
|
|
261
|
+
request_body
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
@classmethod
|
|
265
|
+
def __handle_parameters(cls, parameters: dict) -> dict:
|
|
266
|
+
handled_parameters = parameters.copy()
|
|
267
|
+
|
|
268
|
+
handled_parameters.pop("self")
|
|
269
|
+
|
|
270
|
+
for key, value in parameters.items():
|
|
271
|
+
if value is None:
|
|
272
|
+
handled_parameters.pop(key)
|
|
273
|
+
|
|
274
|
+
return handled_parameters
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
from typing import Optional, TYPE_CHECKING
|
|
2
|
+
|
|
3
|
+
from ..response import Response
|
|
4
|
+
|
|
5
|
+
if TYPE_CHECKING:
|
|
6
|
+
from ..API import GreenApi
|
|
7
|
+
|
|
8
|
+
class Journals:
|
|
9
|
+
def __init__(self, api: "GreenApi"):
|
|
10
|
+
self.api = api
|
|
11
|
+
|
|
12
|
+
def getChatHistory(
|
|
13
|
+
self, chatId: str, count: Optional[int] = None
|
|
14
|
+
) -> Response:
|
|
15
|
+
"""
|
|
16
|
+
The method returns the chat message history.
|
|
17
|
+
|
|
18
|
+
https://green-api.com/telegram/docs/api/journals/GetChatHistory/
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
request_body = locals()
|
|
22
|
+
if count is None:
|
|
23
|
+
request_body.pop("count")
|
|
24
|
+
request_body.pop("self")
|
|
25
|
+
|
|
26
|
+
return self.api.request(
|
|
27
|
+
"POST", (
|
|
28
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
29
|
+
"getChatHistory/{{apiTokenInstance}}"
|
|
30
|
+
), request_body
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
async def getChatHistoryAsync(
|
|
34
|
+
self, chatId: str, count: Optional[int] = None
|
|
35
|
+
) -> Response:
|
|
36
|
+
request_body = locals()
|
|
37
|
+
if count is None:
|
|
38
|
+
request_body.pop("count")
|
|
39
|
+
request_body.pop("self")
|
|
40
|
+
|
|
41
|
+
return await self.api.requestAsync(
|
|
42
|
+
"POST",
|
|
43
|
+
"{{host}}/waInstance{{idInstance}}/getChatHistory/{{apiTokenInstance}}",
|
|
44
|
+
request_body
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
def getMessage(self, chatId: str, idMessage: str) -> Response:
|
|
48
|
+
"""
|
|
49
|
+
The method returns the chat message.
|
|
50
|
+
|
|
51
|
+
https://green-api.com/telegram/docs/api/journals/GetMessage/
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
request_body = locals()
|
|
55
|
+
request_body.pop("self")
|
|
56
|
+
|
|
57
|
+
return self.api.request(
|
|
58
|
+
"POST", (
|
|
59
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
60
|
+
"getMessage/{{apiTokenInstance}}"
|
|
61
|
+
), request_body
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
async def getMessageAsync(self, chatId: str, idMessage: str) -> Response:
|
|
65
|
+
request_body = locals()
|
|
66
|
+
request_body.pop("self")
|
|
67
|
+
|
|
68
|
+
return await self.api.requestAsync(
|
|
69
|
+
"POST",
|
|
70
|
+
"{{host}}/waInstance{{idInstance}}/getMessage/{{apiTokenInstance}}",
|
|
71
|
+
request_body
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
def lastIncomingMessages(self, minutes: Optional[int] = None) -> Response:
|
|
75
|
+
"""
|
|
76
|
+
The method returns the last incoming messages of the account.
|
|
77
|
+
|
|
78
|
+
https://green-api.com/telegram/docs/api/journals/LastIncomingMessages/
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
append_minutes = ""
|
|
82
|
+
if minutes is not None:
|
|
83
|
+
append_minutes = f"?minutes={minutes}"
|
|
84
|
+
|
|
85
|
+
return self.api.request(
|
|
86
|
+
"GET", (
|
|
87
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
88
|
+
"lastIncomingMessages/{{apiTokenInstance}}"+append_minutes
|
|
89
|
+
)
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
async def lastIncomingMessagesAsync(self, minutes: Optional[int] = None) -> Response:
|
|
93
|
+
params = {"minutes": minutes} if minutes else {}
|
|
94
|
+
|
|
95
|
+
return await self.api.requestAsync(
|
|
96
|
+
"GET",
|
|
97
|
+
"{{host}}/waInstance{{idInstance}}/lastIncomingMessages/{{apiTokenInstance}}",
|
|
98
|
+
params
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
def lastOutgoingMessages(self, minutes: Optional[int] = None) -> Response:
|
|
102
|
+
"""
|
|
103
|
+
The method returns the last outgoing messages of the account.
|
|
104
|
+
|
|
105
|
+
https://green-api.com/telegram/docs/api/journals/LastOutgoingMessages/
|
|
106
|
+
"""
|
|
107
|
+
|
|
108
|
+
append_minutes = ""
|
|
109
|
+
if minutes is not None:
|
|
110
|
+
append_minutes = f"?minutes={minutes}"
|
|
111
|
+
|
|
112
|
+
return self.api.request(
|
|
113
|
+
"GET", (
|
|
114
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
115
|
+
"lastOutgoingMessages/{{apiTokenInstance}}"+append_minutes
|
|
116
|
+
)
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
async def lastOutgoingMessagesAsync(self, minutes: Optional[int] = None) -> Response:
|
|
120
|
+
params = {"minutes": minutes} if minutes else {}
|
|
121
|
+
|
|
122
|
+
return await self.api.requestAsync(
|
|
123
|
+
"GET",
|
|
124
|
+
"{{host}}/waInstance{{idInstance}}/lastOutgoingMessages/{{apiTokenInstance}}",
|
|
125
|
+
params
|
|
126
|
+
)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING
|
|
2
|
+
|
|
3
|
+
from ..response import Response
|
|
4
|
+
|
|
5
|
+
if TYPE_CHECKING:
|
|
6
|
+
from ..API import GreenApi
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Marking:
|
|
10
|
+
def __init__(self, api: "GreenApi"):
|
|
11
|
+
self.api = api
|
|
12
|
+
|
|
13
|
+
def readChat(self, chatId: str) -> Response:
|
|
14
|
+
"""
|
|
15
|
+
The method is aimed for marking messages in a chat as read.
|
|
16
|
+
|
|
17
|
+
https://green-api.com/telegram/docs/api/marks/ReadChat/
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
request_body = locals()
|
|
21
|
+
request_body.pop("self")
|
|
22
|
+
|
|
23
|
+
return self.api.request(
|
|
24
|
+
"POST", (
|
|
25
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
26
|
+
"readChat/{{apiTokenInstance}}"
|
|
27
|
+
), request_body
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
async def readChatAsync(self, chatId: str) -> Response:
|
|
31
|
+
request_body = locals()
|
|
32
|
+
request_body.pop("self")
|
|
33
|
+
|
|
34
|
+
return await self.api.requestAsync(
|
|
35
|
+
"POST",
|
|
36
|
+
"{{host}}/waInstance{{idInstance}}/readChat/{{apiTokenInstance}}",
|
|
37
|
+
request_body
|
|
38
|
+
)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
from typing import Dict, TYPE_CHECKING, Union
|
|
2
|
+
|
|
3
|
+
from ..response import Response
|
|
4
|
+
|
|
5
|
+
if TYPE_CHECKING:
|
|
6
|
+
from ..API import GreenApiPartner
|
|
7
|
+
|
|
8
|
+
class Partner:
|
|
9
|
+
def __init__(self, api: "GreenApiPartner"):
|
|
10
|
+
self.api = api
|
|
11
|
+
|
|
12
|
+
def getInstances(self) -> Response:
|
|
13
|
+
"""
|
|
14
|
+
The method is aimed for getting all the account instances created by the partner.
|
|
15
|
+
|
|
16
|
+
https://green-api.com/telegram/docs/partners/getInstances/
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
return self.api.request(
|
|
20
|
+
"GET", (
|
|
21
|
+
"{{host}}/partner/"
|
|
22
|
+
"getInstances/{{partnerToken}}"
|
|
23
|
+
)
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
async def getInstancesAsync(self) -> Response:
|
|
27
|
+
return await self.api.requestAsync(
|
|
28
|
+
"GET", "{{host}}/partner/getInstances/{{partnerToken}}"
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
def createInstance(self, requestBody: Dict[str, Union[int, str]]) -> Response:
|
|
32
|
+
"""
|
|
33
|
+
The method is aimed for creating a messenger account instance on the partner's part.
|
|
34
|
+
|
|
35
|
+
https://green-api.com/telegram/docs/partners/createInstance/
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
return self.api.request(
|
|
39
|
+
"POST", (
|
|
40
|
+
"{{host}}/partner/"
|
|
41
|
+
"createInstance/{{partnerToken}}"
|
|
42
|
+
), requestBody
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
async def createInstanceAsync(self, requestBody: Dict[str, Union[int, str]]) -> Response:
|
|
46
|
+
return await self.api.requestAsync(
|
|
47
|
+
"POST",
|
|
48
|
+
"{{host}}/partner/createInstance/{{partnerToken}}",
|
|
49
|
+
requestBody
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
def deleteInstanceAccount(self, idInstance: int) -> Response:
|
|
53
|
+
"""
|
|
54
|
+
The method is aimed for deleting an instance of the partners's account.
|
|
55
|
+
|
|
56
|
+
https://green-api.com/telegram/docs/partners/deleteInstanceAccount/
|
|
57
|
+
"""
|
|
58
|
+
|
|
59
|
+
request_body = self.__handle_parameters(locals())
|
|
60
|
+
|
|
61
|
+
return self.api.request(
|
|
62
|
+
"POST", (
|
|
63
|
+
"{{host}}/partner/"
|
|
64
|
+
"deleteInstanceAccount/{{partnerToken}}"
|
|
65
|
+
), request_body
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
async def deleteInstanceAccountAsync(self, idInstance: int) -> Response:
|
|
69
|
+
request_body = self.__handle_parameters(locals())
|
|
70
|
+
|
|
71
|
+
return await self.api.requestAsync(
|
|
72
|
+
"POST",
|
|
73
|
+
"{{host}}/partner/deleteInstanceAccount/{{partnerToken}}",
|
|
74
|
+
request_body
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
@classmethod
|
|
78
|
+
def __handle_parameters(cls, parameters: dict) -> dict:
|
|
79
|
+
handled_parameters = parameters.copy()
|
|
80
|
+
|
|
81
|
+
handled_parameters.pop("self")
|
|
82
|
+
|
|
83
|
+
for key, value in parameters.items():
|
|
84
|
+
if value is None:
|
|
85
|
+
handled_parameters.pop(key)
|
|
86
|
+
|
|
87
|
+
return handled_parameters
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING
|
|
2
|
+
|
|
3
|
+
from ..response import Response
|
|
4
|
+
|
|
5
|
+
if TYPE_CHECKING:
|
|
6
|
+
from ..API import GreenApi
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Queues:
|
|
10
|
+
def __init__(self, api: "GreenApi"):
|
|
11
|
+
self.api = api
|
|
12
|
+
|
|
13
|
+
def showMessagesQueue(self) -> Response:
|
|
14
|
+
"""
|
|
15
|
+
The method is aimed for getting a list of messages in the queue
|
|
16
|
+
to be sent.
|
|
17
|
+
|
|
18
|
+
https://green-api.com/telegram/docs/api/queues/ShowMessagesQueue/
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
return self.api.request(
|
|
22
|
+
"GET", (
|
|
23
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
24
|
+
"showMessagesQueue/{{apiTokenInstance}}"
|
|
25
|
+
)
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
async def showMessagesQueueAsync(self) -> Response:
|
|
29
|
+
return await self.api.requestAsync(
|
|
30
|
+
"GET", "{{host}}/waInstance{{idInstance}}/showMessagesQueue/{{apiTokenInstance}}"
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
def getMessagesCount(self) -> Response:
|
|
34
|
+
"""
|
|
35
|
+
The method is aimed for getting a list of messages in the queue
|
|
36
|
+
to be sent.
|
|
37
|
+
|
|
38
|
+
https://green-api.com/telegram/docs/api/queues/GetMessagesCount/
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
return self.api.request(
|
|
42
|
+
"GET", (
|
|
43
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
44
|
+
"getMessagesCount/{{apiTokenInstance}}"
|
|
45
|
+
)
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
async def getMessagesCountAsync(self) -> Response:
|
|
49
|
+
return await self.api.requestAsync(
|
|
50
|
+
"GET", "{{host}}/waInstance{{idInstance}}/getMessagesCountAsync/{{apiTokenInstance}}"
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
def clearMessagesQueue(self) -> Response:
|
|
54
|
+
"""
|
|
55
|
+
The method is aimed for clearing the queue of messages to be
|
|
56
|
+
sent.
|
|
57
|
+
|
|
58
|
+
https://green-api.com/telegram/docs/api/queues/ClearMessagesQueue/
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
return self.api.request(
|
|
62
|
+
"GET", (
|
|
63
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
64
|
+
"clearMessagesQueue/{{apiTokenInstance}}"
|
|
65
|
+
)
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
async def clearMessagesQueueAsync(self) -> Response:
|
|
69
|
+
return await self.api.requestAsync(
|
|
70
|
+
"GET", "{{host}}/waInstance{{idInstance}}/clearMessagesQueue/{{apiTokenInstance}}"
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
def getWebhooksCount(self) -> Response:
|
|
74
|
+
"""
|
|
75
|
+
The method is aimed for getting a list of messages in the queue
|
|
76
|
+
to be sent.
|
|
77
|
+
|
|
78
|
+
https://green-api.com/telegram/docs/api/queues/GetWebhooksCount/
|
|
79
|
+
"""
|
|
80
|
+
|
|
81
|
+
return self.api.request(
|
|
82
|
+
"GET", (
|
|
83
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
84
|
+
"getWebhooksCount/{{apiTokenInstance}}"
|
|
85
|
+
)
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
async def getWebhooksCountAsync(self) -> Response:
|
|
89
|
+
return await self.api.requestAsync(
|
|
90
|
+
"GET", "{{host}}/waInstance{{idInstance}}/getWebhooksCountAsync/{{apiTokenInstance}}"
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
def clearWebhooksQueue(self) -> Response:
|
|
94
|
+
"""
|
|
95
|
+
The method is aimed for clearing the queue of messages to be
|
|
96
|
+
sent.
|
|
97
|
+
|
|
98
|
+
https://green-api.com/telegram/docs/api/queues/clearWebhooksQueue/
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
return self.api.request(
|
|
102
|
+
"GET", (
|
|
103
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
104
|
+
"clearWebhooksQueue/{{apiTokenInstance}}"
|
|
105
|
+
)
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
async def clearWebhooksQueueAsync(self) -> Response:
|
|
109
|
+
return await self.api.requestAsync(
|
|
110
|
+
"GET", "{{host}}/waInstance{{idInstance}}/clearWebhooksQueue/{{apiTokenInstance}}"
|
|
111
|
+
)
|