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,80 @@
|
|
|
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 Receiving:
|
|
10
|
+
def __init__(self, api: "GreenApi"):
|
|
11
|
+
self.api = api
|
|
12
|
+
|
|
13
|
+
def receiveNotification(self) -> Response:
|
|
14
|
+
"""
|
|
15
|
+
The method is aimed for receiving one incoming notification
|
|
16
|
+
from the notifications queue.
|
|
17
|
+
|
|
18
|
+
https://green-api.com/telegram/docs/api/receiving/technology-http-api/ReceiveNotification/
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
return self.api.request(
|
|
22
|
+
"GET", (
|
|
23
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
24
|
+
"receiveNotification/{{apiTokenInstance}}"
|
|
25
|
+
)
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
async def receiveNotificationAsync(self) -> Response:
|
|
29
|
+
return await self.api.requestAsync(
|
|
30
|
+
"GET", "{{host}}/waInstance{{idInstance}}/receiveNotification/{{apiTokenInstance}}"
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
def deleteNotification(self, receiptId: int) -> Response:
|
|
34
|
+
"""
|
|
35
|
+
The method is aimed for deleting an incoming notification from
|
|
36
|
+
the notification queue.
|
|
37
|
+
|
|
38
|
+
https://green-api.com/telegram/docs/api/receiving/technology-http-api/DeleteNotification/
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
url = (
|
|
42
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
43
|
+
"deleteNotification/{{apiTokenInstance}}"
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
return self.api.request("DELETE", f"{url}/{receiptId}")
|
|
47
|
+
|
|
48
|
+
async def deleteNotificationAsync(self, receiptId: int) -> Response:
|
|
49
|
+
return await self.api.requestAsync(
|
|
50
|
+
"DELETE",
|
|
51
|
+
"{{host}}/waInstance{{idInstance}}/deleteNotification/{{apiTokenInstance}}/",
|
|
52
|
+
receiptId
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
def downloadFile(self, chatId: str, idMessage: str) -> Response:
|
|
56
|
+
"""
|
|
57
|
+
The method is aimed for downloading incoming and outgoing files.
|
|
58
|
+
|
|
59
|
+
https://green-api.com/telegram/docs/api/receiving/files/DownloadFile/
|
|
60
|
+
"""
|
|
61
|
+
|
|
62
|
+
request_body = locals()
|
|
63
|
+
request_body.pop("self")
|
|
64
|
+
|
|
65
|
+
return self.api.request(
|
|
66
|
+
"POST", (
|
|
67
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
68
|
+
"downloadFile/{{apiTokenInstance}}"
|
|
69
|
+
), request_body
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
async def downloadFileAsync(self, chatId: str, idMessage: str) -> Response:
|
|
73
|
+
request_body = locals()
|
|
74
|
+
request_body.pop("self")
|
|
75
|
+
|
|
76
|
+
return await self.api.requestAsync(
|
|
77
|
+
"POST",
|
|
78
|
+
"{{host}}/waInstance{{idInstance}}/downloadFile/{{apiTokenInstance}}",
|
|
79
|
+
request_body
|
|
80
|
+
)
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import mimetypes
|
|
2
|
+
import pathlib
|
|
3
|
+
from typing import Dict, List, Optional, TYPE_CHECKING, Union
|
|
4
|
+
|
|
5
|
+
import aiofiles
|
|
6
|
+
|
|
7
|
+
from ..response import Response
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from ..API import GreenApi
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Sending:
|
|
14
|
+
def __init__(self, api: "GreenApi"):
|
|
15
|
+
self.api = api
|
|
16
|
+
|
|
17
|
+
def sendMessage(
|
|
18
|
+
self,
|
|
19
|
+
chatId: str,
|
|
20
|
+
message: str,
|
|
21
|
+
) -> Response:
|
|
22
|
+
"""
|
|
23
|
+
The method is aimed for sending a text message to a personal or
|
|
24
|
+
a group chat.
|
|
25
|
+
|
|
26
|
+
https://green-api.com/telegram/docs/api/sending/SendMessage/
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
request_body = self.__handle_parameters(locals())
|
|
30
|
+
|
|
31
|
+
return self.api.request(
|
|
32
|
+
"POST", (
|
|
33
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
34
|
+
"sendMessage/{{apiTokenInstance}}"
|
|
35
|
+
), request_body
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
async def sendMessageAsync(
|
|
39
|
+
self,
|
|
40
|
+
chatId: str,
|
|
41
|
+
message: str,
|
|
42
|
+
) -> Response:
|
|
43
|
+
request_body = self.__handle_parameters(locals())
|
|
44
|
+
|
|
45
|
+
return await self.api.requestAsync(
|
|
46
|
+
"POST",
|
|
47
|
+
"{{host}}/waInstance{{idInstance}}/sendMessage/{{apiTokenInstance}}",
|
|
48
|
+
request_body
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
def sendFileByUpload(
|
|
52
|
+
self,
|
|
53
|
+
chatId: str,
|
|
54
|
+
path: str,
|
|
55
|
+
fileName: Optional[str] = None,
|
|
56
|
+
caption: Optional[str] = None,
|
|
57
|
+
) -> Response:
|
|
58
|
+
"""
|
|
59
|
+
The method is aimed for sending a file uploaded by form
|
|
60
|
+
(form-data).
|
|
61
|
+
|
|
62
|
+
https://green-api.com/telegram/docs/api/sending/SendFileByUpload/
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
request_body = self.__handle_parameters(locals())
|
|
66
|
+
|
|
67
|
+
file_name = pathlib.Path(path).name
|
|
68
|
+
content_type = mimetypes.guess_type(file_name)[0]
|
|
69
|
+
|
|
70
|
+
files = {"file": (file_name, open(path, "rb"), content_type)}
|
|
71
|
+
|
|
72
|
+
request_body.pop("path")
|
|
73
|
+
|
|
74
|
+
return self.api.request(
|
|
75
|
+
"POST", (
|
|
76
|
+
"{{media}}/waInstance{{idInstance}}/"
|
|
77
|
+
"sendFileByUpload/{{apiTokenInstance}}"
|
|
78
|
+
), request_body, files
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
async def sendFileByUploadAsync(
|
|
82
|
+
self,
|
|
83
|
+
chatId: str,
|
|
84
|
+
path: str,
|
|
85
|
+
fileName: Optional[str] = None,
|
|
86
|
+
caption: Optional[str] = None,
|
|
87
|
+
) -> Response:
|
|
88
|
+
request_body = self.__handle_parameters(locals())
|
|
89
|
+
|
|
90
|
+
file_name = pathlib.Path(path).name
|
|
91
|
+
content_type = mimetypes.guess_type(file_name)[0]
|
|
92
|
+
|
|
93
|
+
async with aiofiles.open(path, "rb") as file:
|
|
94
|
+
file_data = await file.read()
|
|
95
|
+
files = {"file": (file_name, file_data, content_type)}
|
|
96
|
+
|
|
97
|
+
request_body.pop("path")
|
|
98
|
+
|
|
99
|
+
return await self.api.requestAsync(
|
|
100
|
+
"POST",
|
|
101
|
+
"{{media}}/waInstance{{idInstance}}/sendFileByUpload/{{apiTokenInstance}}",
|
|
102
|
+
request_body,
|
|
103
|
+
files=files
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
def sendFileByUrl(
|
|
107
|
+
self,
|
|
108
|
+
chatId: str,
|
|
109
|
+
urlFile: str,
|
|
110
|
+
fileName: str,
|
|
111
|
+
caption: Optional[str] = None,
|
|
112
|
+
) -> Response:
|
|
113
|
+
"""
|
|
114
|
+
The method is aimed for sending a file uploaded by URL.
|
|
115
|
+
|
|
116
|
+
https://green-api.com/telegram/docs/api/sending/SendFileByUrl/
|
|
117
|
+
"""
|
|
118
|
+
|
|
119
|
+
request_body = self.__handle_parameters(locals())
|
|
120
|
+
|
|
121
|
+
return self.api.request(
|
|
122
|
+
"POST", (
|
|
123
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
124
|
+
"sendFileByUrl/{{apiTokenInstance}}"
|
|
125
|
+
), request_body
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
async def sendFileByUrlAsync(
|
|
129
|
+
self,
|
|
130
|
+
chatId: str,
|
|
131
|
+
urlFile: str,
|
|
132
|
+
fileName: str,
|
|
133
|
+
caption: Optional[str] = None,
|
|
134
|
+
) -> Response:
|
|
135
|
+
request_body = self.__handle_parameters(locals())
|
|
136
|
+
|
|
137
|
+
return await self.api.requestAsync(
|
|
138
|
+
"POST",
|
|
139
|
+
"{{host}}/waInstance{{idInstance}}/sendFileByUrl/{{apiTokenInstance}}",
|
|
140
|
+
request_body
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
def uploadFile(self, path: str) -> Response:
|
|
144
|
+
"""
|
|
145
|
+
The method is designed to upload a file to the cloud storage,
|
|
146
|
+
which can be sent using the sendFileByUrl method.
|
|
147
|
+
|
|
148
|
+
https://green-api.com/telegram/docs/api/sending/UploadFile/
|
|
149
|
+
"""
|
|
150
|
+
|
|
151
|
+
file_name = pathlib.Path(path).name
|
|
152
|
+
content_type = mimetypes.guess_type(file_name)[0]
|
|
153
|
+
|
|
154
|
+
with open(path, "rb") as file:
|
|
155
|
+
return self.api.raw_request(
|
|
156
|
+
method="POST",
|
|
157
|
+
url=(
|
|
158
|
+
f"{self.api.media}/waInstance{self.api.idInstance}/"
|
|
159
|
+
f"uploadFile/{self.api.apiTokenInstance}"
|
|
160
|
+
),
|
|
161
|
+
data=file.read(),
|
|
162
|
+
headers={"Content-Type": content_type,
|
|
163
|
+
"GA-Filename": file_name}
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
async def uploadFileAsync(self, path: str) -> Response:
|
|
167
|
+
file_name = pathlib.Path(path).name
|
|
168
|
+
content_type = mimetypes.guess_type(file_name)[0]
|
|
169
|
+
|
|
170
|
+
async with aiofiles.open(path, "rb") as file:
|
|
171
|
+
return await self.api.raw_request_async(
|
|
172
|
+
method="POST",
|
|
173
|
+
url=(
|
|
174
|
+
f"{self.api.media}/waInstance{self.api.idInstance}/"
|
|
175
|
+
f"uploadFile/{self.api.apiTokenInstance}"
|
|
176
|
+
),
|
|
177
|
+
data=file.read(),
|
|
178
|
+
headers={"Content-Type": content_type,
|
|
179
|
+
"GA-Filename": file_name}
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
def sendLocation(
|
|
183
|
+
self,
|
|
184
|
+
chatId: str,
|
|
185
|
+
latitude: float,
|
|
186
|
+
longitude: float,
|
|
187
|
+
) -> Response:
|
|
188
|
+
"""
|
|
189
|
+
The method is aimed for sending location message.
|
|
190
|
+
|
|
191
|
+
https://green-api.com/telegram/docs/api/sending/SendLocation/
|
|
192
|
+
"""
|
|
193
|
+
|
|
194
|
+
request_body = self.__handle_parameters(locals())
|
|
195
|
+
|
|
196
|
+
return self.api.request(
|
|
197
|
+
"POST", (
|
|
198
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
199
|
+
"sendLocation/{{apiTokenInstance}}"
|
|
200
|
+
), request_body
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
async def sendLocationAsync(
|
|
204
|
+
self,
|
|
205
|
+
chatId: str,
|
|
206
|
+
latitude: float,
|
|
207
|
+
longitude: float,
|
|
208
|
+
) -> Response:
|
|
209
|
+
request_body = self.__handle_parameters(locals())
|
|
210
|
+
|
|
211
|
+
return await self.api.requestAsync(
|
|
212
|
+
"POST",
|
|
213
|
+
"{{host}}/waInstance{{idInstance}}/sendLocation/{{apiTokenInstance}}",
|
|
214
|
+
request_body
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
def sendContact(
|
|
218
|
+
self,
|
|
219
|
+
chatId: str,
|
|
220
|
+
contact: Dict[str, Union[int, str]],
|
|
221
|
+
) -> Response:
|
|
222
|
+
"""
|
|
223
|
+
The method is aimed for sending a contact message.
|
|
224
|
+
|
|
225
|
+
https://green-api.com/telegram/docs/api/sending/SendContact/
|
|
226
|
+
"""
|
|
227
|
+
|
|
228
|
+
request_body = self.__handle_parameters(locals())
|
|
229
|
+
|
|
230
|
+
return self.api.request(
|
|
231
|
+
"POST", (
|
|
232
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
233
|
+
"sendContact/{{apiTokenInstance}}"
|
|
234
|
+
), request_body
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
async def sendContactAsync(
|
|
238
|
+
self,
|
|
239
|
+
chatId: str,
|
|
240
|
+
contact: Dict[str, Union[int, str]],
|
|
241
|
+
) -> Response:
|
|
242
|
+
request_body = self.__handle_parameters(locals())
|
|
243
|
+
|
|
244
|
+
return await self.api.requestAsync(
|
|
245
|
+
"POST",
|
|
246
|
+
"{{host}}/waInstance{{idInstance}}/sendContact/{{apiTokenInstance}}",
|
|
247
|
+
request_body
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def sendPoll(
|
|
252
|
+
self,
|
|
253
|
+
chatId: str,
|
|
254
|
+
message: str,
|
|
255
|
+
options: List[Dict[str, str]],
|
|
256
|
+
multipleAnswers: Optional[bool] = None,
|
|
257
|
+
isAnonymous: Optional[bool] = None
|
|
258
|
+
) -> Response:
|
|
259
|
+
"""
|
|
260
|
+
This method is intended for sending messages with a poll to a
|
|
261
|
+
private or group chat.
|
|
262
|
+
|
|
263
|
+
https://green-api.com/telegram/docs/api/sending/SendPoll/
|
|
264
|
+
"""
|
|
265
|
+
|
|
266
|
+
request_body = self.__handle_parameters(locals())
|
|
267
|
+
|
|
268
|
+
return self.api.request(
|
|
269
|
+
"POST", (
|
|
270
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
271
|
+
"sendPoll/{{apiTokenInstance}}"
|
|
272
|
+
), request_body
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
async def sendPollAsync(
|
|
276
|
+
self,
|
|
277
|
+
chatId: str,
|
|
278
|
+
message: str,
|
|
279
|
+
options: List[Dict[str, str]],
|
|
280
|
+
multipleAnswers: Optional[bool] = None,
|
|
281
|
+
isAnonymous: Optional[bool] = None
|
|
282
|
+
) -> Response:
|
|
283
|
+
request_body = self.__handle_parameters(locals())
|
|
284
|
+
|
|
285
|
+
return await self.api.requestAsync(
|
|
286
|
+
"POST",
|
|
287
|
+
"{{host}}/waInstance{{idInstance}}/sendPoll/{{apiTokenInstance}}",
|
|
288
|
+
request_body
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
@classmethod
|
|
293
|
+
def __handle_parameters(cls, parameters: dict) -> dict:
|
|
294
|
+
handled_parameters = parameters.copy()
|
|
295
|
+
handled_parameters.pop("self")
|
|
296
|
+
|
|
297
|
+
for key, value in parameters.items():
|
|
298
|
+
if value is None:
|
|
299
|
+
handled_parameters.pop(key)
|
|
300
|
+
|
|
301
|
+
return handled_parameters
|
|
@@ -0,0 +1,264 @@
|
|
|
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 ServiceMethods:
|
|
9
|
+
def __init__(self, api: "GreenApi"):
|
|
10
|
+
self.api = api
|
|
11
|
+
|
|
12
|
+
def checkAccount(self, phoneNumber: int) -> Response:
|
|
13
|
+
"""
|
|
14
|
+
The method checks Account account availability on a phone
|
|
15
|
+
number.
|
|
16
|
+
|
|
17
|
+
https://green-api.com/telegram/docs/api/service/CheckAccount/
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
request_body = locals()
|
|
21
|
+
request_body.pop("self")
|
|
22
|
+
|
|
23
|
+
return self.api.request(
|
|
24
|
+
"POST", (
|
|
25
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
26
|
+
"checkAccount/{{apiTokenInstance}}"
|
|
27
|
+
), request_body
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
async def checkAccountAsync(self, phoneNumber: int) -> Response:
|
|
31
|
+
request_body = locals()
|
|
32
|
+
request_body.pop("self")
|
|
33
|
+
|
|
34
|
+
return await self.api.requestAsync(
|
|
35
|
+
"POST",
|
|
36
|
+
"{{host}}/waInstance{{idInstance}}/checkAccount/{{apiTokenInstance}}",
|
|
37
|
+
request_body
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
def getAvatar(self, chatId: str) -> Response:
|
|
41
|
+
"""
|
|
42
|
+
The method returns a user or a group chat avatar.
|
|
43
|
+
|
|
44
|
+
https://green-api.com/telegram/docs/api/service/GetAvatar/
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
request_body = locals()
|
|
48
|
+
request_body.pop("self")
|
|
49
|
+
|
|
50
|
+
return self.api.request(
|
|
51
|
+
"POST", (
|
|
52
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
53
|
+
"getAvatar/{{apiTokenInstance}}"
|
|
54
|
+
), request_body
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
async def getAvatarAsync(self, chatId: str) -> Response:
|
|
58
|
+
request_body = locals()
|
|
59
|
+
request_body.pop("self")
|
|
60
|
+
|
|
61
|
+
return await self.api.requestAsync(
|
|
62
|
+
"POST",
|
|
63
|
+
"{{host}}/waInstance{{idInstance}}/getAvatar/{{apiTokenInstance}}",
|
|
64
|
+
request_body
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
def getContacts(self) -> Response:
|
|
68
|
+
"""
|
|
69
|
+
The method is aimed for getting a list of the current account
|
|
70
|
+
contacts.
|
|
71
|
+
|
|
72
|
+
https://green-api.com/telegram/docs/api/service/GetContacts/
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
return self.api.request(
|
|
76
|
+
"GET", (
|
|
77
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
78
|
+
"getContacts/{{apiTokenInstance}}"
|
|
79
|
+
)
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
async def getContactsAsync(self) -> Response:
|
|
83
|
+
return await self.api.requestAsync(
|
|
84
|
+
"GET", "{{host}}/waInstance{{idInstance}}/getContacts/{{apiTokenInstance}}"
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
def getContactInfo(self, chatId: str) -> Response:
|
|
88
|
+
"""
|
|
89
|
+
The method is aimed for getting information on a contact.
|
|
90
|
+
|
|
91
|
+
https://green-api.com/telegram/docs/api/service/GetContactInfo/
|
|
92
|
+
"""
|
|
93
|
+
|
|
94
|
+
request_body = locals()
|
|
95
|
+
request_body.pop("self")
|
|
96
|
+
|
|
97
|
+
return self.api.request(
|
|
98
|
+
"POST", (
|
|
99
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
100
|
+
"getContactInfo/{{apiTokenInstance}}"
|
|
101
|
+
), request_body
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
async def getContactInfoAsync(self, chatId: str) -> Response:
|
|
105
|
+
request_body = locals()
|
|
106
|
+
request_body.pop("self")
|
|
107
|
+
|
|
108
|
+
return await self.api.requestAsync(
|
|
109
|
+
"POST",
|
|
110
|
+
"{{host}}/waInstance{{idInstance}}/getContactInfo/{{apiTokenInstance}}",
|
|
111
|
+
request_body
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
def deleteMessage(self, chatId: str, idMessage: str, onlySenderDelete: Optional[bool] = None) -> Response:
|
|
115
|
+
"""
|
|
116
|
+
The method deletes a message from a chat.
|
|
117
|
+
|
|
118
|
+
https://green-api.com/telegram/docs/api/service/deleteMessage/
|
|
119
|
+
"""
|
|
120
|
+
|
|
121
|
+
request_body = locals()
|
|
122
|
+
if onlySenderDelete is None:
|
|
123
|
+
request_body.pop("onlySenderDelete")
|
|
124
|
+
request_body.pop("self")
|
|
125
|
+
print(request_body)
|
|
126
|
+
|
|
127
|
+
return self.api.request(
|
|
128
|
+
"POST", (
|
|
129
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
130
|
+
"deleteMessage/{{apiTokenInstance}}"
|
|
131
|
+
), request_body
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
async def deleteMessageAsync(self, chatId: str, idMessage: str, onlySenderDelete: Optional[bool] = None) -> Response:
|
|
135
|
+
request_body = locals()
|
|
136
|
+
if onlySenderDelete is None:
|
|
137
|
+
request_body.pop("onlySenderDelete")
|
|
138
|
+
request_body.pop("self")
|
|
139
|
+
|
|
140
|
+
return await self.api.requestAsync(
|
|
141
|
+
"POST",
|
|
142
|
+
"{{host}}/waInstance{{idInstance}}/deleteMessage/{{apiTokenInstance}}",
|
|
143
|
+
request_body
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
def editMessage(self, chatId: str, idMessage: str, message: str) -> Response:
|
|
147
|
+
"""
|
|
148
|
+
The method edits a message in chat.
|
|
149
|
+
|
|
150
|
+
https://green-api.com/telegram/docs/api/service/editMessage/
|
|
151
|
+
"""
|
|
152
|
+
|
|
153
|
+
request_body = locals()
|
|
154
|
+
request_body.pop("self")
|
|
155
|
+
|
|
156
|
+
return self.api.request(
|
|
157
|
+
"POST", (
|
|
158
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
159
|
+
"editMessage/{{apiTokenInstance}}"
|
|
160
|
+
), request_body
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
async def editMessageAsync(self, chatId: str, idMessage: str, message: str) -> Response:
|
|
164
|
+
request_body = locals()
|
|
165
|
+
request_body.pop("self")
|
|
166
|
+
|
|
167
|
+
return await self.api.requestAsync(
|
|
168
|
+
"POST",
|
|
169
|
+
"{{host}}/waInstance{{idInstance}}/editMessage/{{apiTokenInstance}}",
|
|
170
|
+
request_body
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
def archiveChat(self, chatId: str) -> Response:
|
|
174
|
+
"""
|
|
175
|
+
The method archives a chat.
|
|
176
|
+
|
|
177
|
+
https://green-api.com/telegram/docs/api/service/archiveChat/
|
|
178
|
+
"""
|
|
179
|
+
|
|
180
|
+
request_body = locals()
|
|
181
|
+
request_body.pop("self")
|
|
182
|
+
|
|
183
|
+
return self.api.request(
|
|
184
|
+
"POST", (
|
|
185
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
186
|
+
"archiveChat/{{apiTokenInstance}}"
|
|
187
|
+
), request_body
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
async def archiveChatAsync(self, chatId: str) -> Response:
|
|
191
|
+
request_body = locals()
|
|
192
|
+
request_body.pop("self")
|
|
193
|
+
|
|
194
|
+
return await self.api.requestAsync(
|
|
195
|
+
"POST",
|
|
196
|
+
"{{host}}/waInstance{{idInstance}}/archiveChat/{{apiTokenInstance}}",
|
|
197
|
+
request_body
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
def unarchiveChat(self, chatId: str) -> Response:
|
|
201
|
+
"""
|
|
202
|
+
The method unarchives a chat.
|
|
203
|
+
|
|
204
|
+
https://green-api.com/telegram/docs/api/service/unarchiveChat/
|
|
205
|
+
"""
|
|
206
|
+
|
|
207
|
+
request_body = locals()
|
|
208
|
+
request_body.pop("self")
|
|
209
|
+
|
|
210
|
+
return self.api.request(
|
|
211
|
+
"POST", (
|
|
212
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
213
|
+
"unarchiveChat/{{apiTokenInstance}}"
|
|
214
|
+
), request_body
|
|
215
|
+
)
|
|
216
|
+
|
|
217
|
+
async def unarchiveChatAsync(self, chatId: str) -> Response:
|
|
218
|
+
request_body = locals()
|
|
219
|
+
request_body.pop("self")
|
|
220
|
+
|
|
221
|
+
return await self.api.requestAsync(
|
|
222
|
+
"POST",
|
|
223
|
+
"{{host}}/waInstance{{idInstance}}/unarchiveChat/{{apiTokenInstance}}",
|
|
224
|
+
request_body
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
def sendTyping(
|
|
228
|
+
self, chatId: str, typingTime: Optional[int] = None, typingType: Optional[str] = None,
|
|
229
|
+
) -> Response:
|
|
230
|
+
"""
|
|
231
|
+
The method is used to send a notification about typing or recording audio in a chat.
|
|
232
|
+
|
|
233
|
+
https://green-api.com/telegram/docs/api/service/SendTyping/
|
|
234
|
+
"""
|
|
235
|
+
|
|
236
|
+
request_body = locals()
|
|
237
|
+
if typingTime is None:
|
|
238
|
+
request_body.pop("typingTime")
|
|
239
|
+
if typingType is None:
|
|
240
|
+
request_body.pop("typingType")
|
|
241
|
+
request_body.pop("self")
|
|
242
|
+
|
|
243
|
+
return self.api.request(
|
|
244
|
+
"POST", (
|
|
245
|
+
"{{host}}/waInstance{{idInstance}}/"
|
|
246
|
+
"sendTyping/{{apiTokenInstance}}"
|
|
247
|
+
), request_body
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
async def sendTypingAsync(
|
|
251
|
+
self, chatId: str, typingTime: Optional[int] = None, typingType: Optional[str] = None,
|
|
252
|
+
) -> Response:
|
|
253
|
+
request_body = locals()
|
|
254
|
+
if typingTime is None:
|
|
255
|
+
request_body.pop("typingTime")
|
|
256
|
+
if typingType is None:
|
|
257
|
+
request_body.pop("typingType")
|
|
258
|
+
request_body.pop("self")
|
|
259
|
+
|
|
260
|
+
return await self.api.requestAsync(
|
|
261
|
+
"POST",
|
|
262
|
+
"{{host}}/waInstance{{idInstance}}/sendTyping/{{apiTokenInstance}}",
|
|
263
|
+
request_body
|
|
264
|
+
)
|