multibotkit 0.1.10__tar.gz → 0.1.12__tar.gz
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.
- {multibotkit-0.1.10 → multibotkit-0.1.12}/PKG-INFO +1 -1
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/dispatchers/telegram.py +9 -2
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/helpers/telegram.py +202 -206
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit.egg-info/PKG-INFO +1 -1
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit.egg-info/requires.txt +1 -1
- {multibotkit-0.1.10 → multibotkit-0.1.12}/setup.py +2 -2
- {multibotkit-0.1.10 → multibotkit-0.1.12}/LICENSE +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/README.md +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/__init__.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/dispatchers/__init__.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/dispatchers/base_dispatcher.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/dispatchers/fb.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/dispatchers/viber.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/dispatchers/vk.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/helpers/__init__.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/helpers/base_helper.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/helpers/fb.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/helpers/viber.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/helpers/vk.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/schemas/__init__.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/schemas/fb/__init__.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/schemas/fb/incoming.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/schemas/fb/outgoing.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/schemas/telegram/__init__.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/schemas/telegram/incoming.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/schemas/telegram/outgoing.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/schemas/viber/__init__.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/schemas/viber/incoming.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/schemas/viber/outgoing.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/schemas/vk/__init__.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/schemas/vk/incoming.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/schemas/vk/outgoing.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/states/__init__.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/states/managers/__init__.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/states/managers/base.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/states/managers/memory.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/states/managers/mongo.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/states/managers/redis.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit/states/state.py +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit.egg-info/SOURCES.txt +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit.egg-info/dependency_links.txt +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/multibotkit.egg-info/top_level.txt +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/pyproject.toml +0 -0
- {multibotkit-0.1.10 → multibotkit-0.1.12}/setup.cfg +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import inspect
|
|
1
2
|
from datetime import datetime
|
|
2
3
|
from multibotkit.dispatchers.base_dispatcher import BaseDispatcher
|
|
3
4
|
from multibotkit.schemas.telegram.incoming import Update
|
|
@@ -21,14 +22,20 @@ class TelegramDispatcher(BaseDispatcher):
|
|
|
21
22
|
state_func_result = True
|
|
22
23
|
if state_func is not None:
|
|
23
24
|
try:
|
|
24
|
-
|
|
25
|
+
if inspect.iscoroutinefunction(state_func):
|
|
26
|
+
state_func_result = await state_func(state_object)
|
|
27
|
+
else:
|
|
28
|
+
state_func_result = state_func(state_object)
|
|
25
29
|
except Exception:
|
|
26
30
|
continue
|
|
27
31
|
|
|
28
32
|
func_result = True
|
|
29
33
|
if func is not None:
|
|
30
34
|
try:
|
|
31
|
-
|
|
35
|
+
if inspect.iscoroutinefunction(func):
|
|
36
|
+
func_result = await func(event)
|
|
37
|
+
else:
|
|
38
|
+
func_result = func(event)
|
|
32
39
|
except Exception:
|
|
33
40
|
continue
|
|
34
41
|
|
|
@@ -24,8 +24,9 @@ from multibotkit.schemas.telegram.outgoing import (
|
|
|
24
24
|
ReplyKeyboardMarkup,
|
|
25
25
|
SetWebhookParams,
|
|
26
26
|
WebhookInfo,
|
|
27
|
-
MediaGroup,
|
|
28
|
-
|
|
27
|
+
MediaGroup,
|
|
28
|
+
ReplyKeyboardRemove,
|
|
29
|
+
Sticker,
|
|
29
30
|
)
|
|
30
31
|
|
|
31
32
|
|
|
@@ -71,10 +72,12 @@ class TelegramHelper(BaseHelper):
|
|
|
71
72
|
chat_id: int,
|
|
72
73
|
text: str,
|
|
73
74
|
disable_web_page_preview: Optional[bool] = None,
|
|
74
|
-
reply_markup: Optional[
|
|
75
|
+
reply_markup: Optional[
|
|
76
|
+
Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove]
|
|
77
|
+
] = None,
|
|
75
78
|
parse_mode: str = "HTML",
|
|
76
79
|
reply_to_message_id: Optional[int] = None,
|
|
77
|
-
allow_sending_without_reply: Optional[bool] = None
|
|
80
|
+
allow_sending_without_reply: Optional[bool] = None,
|
|
78
81
|
):
|
|
79
82
|
url = self.tg_base_url + "sendMessage"
|
|
80
83
|
message = Message(
|
|
@@ -83,7 +86,7 @@ class TelegramHelper(BaseHelper):
|
|
|
83
86
|
disable_web_page_preview=disable_web_page_preview,
|
|
84
87
|
reply_markup=reply_markup,
|
|
85
88
|
reply_to_message_id=reply_to_message_id,
|
|
86
|
-
allow_sending_without_reply=allow_sending_without_reply
|
|
89
|
+
allow_sending_without_reply=allow_sending_without_reply,
|
|
87
90
|
)
|
|
88
91
|
|
|
89
92
|
data = message.dict(exclude_none=True)
|
|
@@ -96,10 +99,12 @@ class TelegramHelper(BaseHelper):
|
|
|
96
99
|
chat_id: int,
|
|
97
100
|
text: str,
|
|
98
101
|
disable_web_page_preview: Optional[bool] = None,
|
|
99
|
-
reply_markup: Optional[
|
|
102
|
+
reply_markup: Optional[
|
|
103
|
+
Union[InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyKeyboardRemove]
|
|
104
|
+
] = None,
|
|
100
105
|
parse_mode: str = "HTML",
|
|
101
106
|
reply_to_message_id: Optional[int] = None,
|
|
102
|
-
allow_sending_without_reply: Optional[bool] = None
|
|
107
|
+
allow_sending_without_reply: Optional[bool] = None,
|
|
103
108
|
):
|
|
104
109
|
url = self.tg_base_url + "sendMessage"
|
|
105
110
|
message = Message(
|
|
@@ -108,7 +113,7 @@ class TelegramHelper(BaseHelper):
|
|
|
108
113
|
disable_web_page_preview=disable_web_page_preview,
|
|
109
114
|
reply_markup=reply_markup,
|
|
110
115
|
reply_to_message_id=reply_to_message_id,
|
|
111
|
-
allow_sending_without_reply=allow_sending_without_reply
|
|
116
|
+
allow_sending_without_reply=allow_sending_without_reply,
|
|
112
117
|
)
|
|
113
118
|
|
|
114
119
|
data = message.dict(exclude_none=True)
|
|
@@ -140,26 +145,36 @@ class TelegramHelper(BaseHelper):
|
|
|
140
145
|
r = await self._perform_async_request(url, data)
|
|
141
146
|
return r
|
|
142
147
|
|
|
143
|
-
def sync_edit_message_caption(
|
|
148
|
+
def sync_edit_message_caption(
|
|
149
|
+
self,
|
|
150
|
+
chat_id: int,
|
|
151
|
+
message_id: int,
|
|
152
|
+
caption: str,
|
|
153
|
+
parse_mode: Optional[str] = "HTML",
|
|
154
|
+
):
|
|
144
155
|
url = self.tg_base_url + "editMessageCaption"
|
|
145
156
|
data = {
|
|
146
157
|
"chat_id": chat_id,
|
|
147
158
|
"message_id": message_id,
|
|
148
159
|
"caption": caption,
|
|
149
|
-
"parse_mode":
|
|
160
|
+
"parse_mode": parse_mode,
|
|
150
161
|
}
|
|
151
162
|
r = self._perform_sync_request(url, data)
|
|
152
163
|
return r
|
|
153
164
|
|
|
154
165
|
async def async_edit_message_caption(
|
|
155
|
-
self,
|
|
166
|
+
self,
|
|
167
|
+
chat_id: int,
|
|
168
|
+
message_id: int,
|
|
169
|
+
caption: str,
|
|
170
|
+
parse_mode: Optional[str] = "HTML",
|
|
156
171
|
):
|
|
157
172
|
url = self.tg_base_url + "editMessageCaption"
|
|
158
173
|
data = {
|
|
159
174
|
"chat_id": chat_id,
|
|
160
175
|
"message_id": message_id,
|
|
161
176
|
"caption": caption,
|
|
162
|
-
"parse_mode":
|
|
177
|
+
"parse_mode": parse_mode,
|
|
163
178
|
}
|
|
164
179
|
r = await self._perform_async_request(url, data)
|
|
165
180
|
return r
|
|
@@ -199,7 +214,7 @@ class TelegramHelper(BaseHelper):
|
|
|
199
214
|
data = {"chat_id": chat_id, "message_id": message_id, "reply_markup": {}}
|
|
200
215
|
r = await self._perform_async_request(url, data)
|
|
201
216
|
return r
|
|
202
|
-
|
|
217
|
+
|
|
203
218
|
def sync_edit_message_media(
|
|
204
219
|
self,
|
|
205
220
|
media: Union[str, IO],
|
|
@@ -208,21 +223,20 @@ class TelegramHelper(BaseHelper):
|
|
|
208
223
|
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
|
209
224
|
chat_id: Optional[int] = None,
|
|
210
225
|
message_id: Optional[int] = None,
|
|
211
|
-
inline_message_id: Optional[Union[int, str]] = None
|
|
226
|
+
inline_message_id: Optional[Union[int, str]] = None,
|
|
227
|
+
parse_mode: Optional[str] = "HTML",
|
|
212
228
|
):
|
|
213
229
|
if type(media) == str:
|
|
214
230
|
if media.startswith("http://") or media.startswith("https://"):
|
|
215
231
|
media_obj = InputMedia(
|
|
216
|
-
type=media_type,
|
|
217
|
-
media=media,
|
|
218
|
-
caption=caption
|
|
232
|
+
type=media_type, media=media, caption=caption, parse_mode=parse_mode
|
|
219
233
|
)
|
|
220
234
|
data_obj = EditMessageMediaModel(
|
|
221
235
|
chat_id=chat_id,
|
|
222
236
|
message_id=message_id,
|
|
223
237
|
inline_message_id=inline_message_id,
|
|
224
238
|
media=media_obj,
|
|
225
|
-
reply_markup=reply_markup
|
|
239
|
+
reply_markup=reply_markup,
|
|
226
240
|
)
|
|
227
241
|
|
|
228
242
|
url = self.tg_base_url + "editMessageMedia"
|
|
@@ -230,7 +244,7 @@ class TelegramHelper(BaseHelper):
|
|
|
230
244
|
|
|
231
245
|
r = self._perform_sync_request(url, data)
|
|
232
246
|
return r
|
|
233
|
-
|
|
247
|
+
|
|
234
248
|
ends = [".jpg", ".jpeg", ".gif", ".png"]
|
|
235
249
|
for end in ends:
|
|
236
250
|
if media.endswith(end):
|
|
@@ -239,14 +253,15 @@ class TelegramHelper(BaseHelper):
|
|
|
239
253
|
media_obj = InputMedia(
|
|
240
254
|
type=media_type,
|
|
241
255
|
media=f"attach://{media}",
|
|
242
|
-
caption=caption
|
|
256
|
+
caption=caption,
|
|
257
|
+
parse_mode=parse_mode,
|
|
243
258
|
)
|
|
244
259
|
data_obj = EditMessageMediaModel(
|
|
245
260
|
chat_id=chat_id,
|
|
246
261
|
message_id=message_id,
|
|
247
262
|
inline_message_id=inline_message_id,
|
|
248
263
|
media=media_obj,
|
|
249
|
-
reply_markup=reply_markup
|
|
264
|
+
reply_markup=reply_markup,
|
|
250
265
|
)
|
|
251
266
|
|
|
252
267
|
url = self.tg_base_url + "editMessageMedia"
|
|
@@ -256,20 +271,20 @@ class TelegramHelper(BaseHelper):
|
|
|
256
271
|
data["reply_markup"] = json.dumps(data["reply_markup"])
|
|
257
272
|
files = {media: opened_media}
|
|
258
273
|
|
|
259
|
-
r = self._perform_sync_request(
|
|
274
|
+
r = self._perform_sync_request(
|
|
275
|
+
url, data, use_json=False, files=files
|
|
276
|
+
)
|
|
260
277
|
return r
|
|
261
|
-
|
|
278
|
+
|
|
262
279
|
media_obj = InputMedia(
|
|
263
|
-
type=media_type,
|
|
264
|
-
media=media,
|
|
265
|
-
caption=caption
|
|
280
|
+
type=media_type, media=media, caption=caption, parse_mode=parse_mode
|
|
266
281
|
)
|
|
267
282
|
data_obj = EditMessageMediaModel(
|
|
268
283
|
chat_id=chat_id,
|
|
269
284
|
message_id=message_id,
|
|
270
285
|
inline_message_id=inline_message_id,
|
|
271
286
|
media=media_obj,
|
|
272
|
-
reply_markup=reply_markup
|
|
287
|
+
reply_markup=reply_markup,
|
|
273
288
|
)
|
|
274
289
|
|
|
275
290
|
url = self.tg_base_url + "editMessageMedia"
|
|
@@ -277,18 +292,19 @@ class TelegramHelper(BaseHelper):
|
|
|
277
292
|
|
|
278
293
|
r = self._perform_sync_request(url, data)
|
|
279
294
|
return r
|
|
280
|
-
|
|
295
|
+
|
|
281
296
|
media_obj = InputMedia(
|
|
282
297
|
type=media_type,
|
|
283
298
|
media="attach://media",
|
|
284
|
-
caption=caption
|
|
299
|
+
caption=caption,
|
|
300
|
+
parse_mode=parse_mode,
|
|
285
301
|
)
|
|
286
302
|
data_obj = EditMessageMediaModel(
|
|
287
303
|
chat_id=chat_id,
|
|
288
304
|
message_id=message_id,
|
|
289
305
|
inline_message_id=inline_message_id,
|
|
290
306
|
media=media_obj,
|
|
291
|
-
reply_markup=reply_markup
|
|
307
|
+
reply_markup=reply_markup,
|
|
292
308
|
)
|
|
293
309
|
|
|
294
310
|
url = self.tg_base_url + "editMessageMedia"
|
|
@@ -300,7 +316,6 @@ class TelegramHelper(BaseHelper):
|
|
|
300
316
|
|
|
301
317
|
r = self._perform_sync_request(url, data, use_json=False, files=files)
|
|
302
318
|
return r
|
|
303
|
-
|
|
304
319
|
|
|
305
320
|
async def async_edit_message_media(
|
|
306
321
|
self,
|
|
@@ -310,21 +325,20 @@ class TelegramHelper(BaseHelper):
|
|
|
310
325
|
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
|
311
326
|
chat_id: Optional[int] = None,
|
|
312
327
|
message_id: Optional[int] = None,
|
|
313
|
-
inline_message_id: Optional[Union[int, str]] = None
|
|
328
|
+
inline_message_id: Optional[Union[int, str]] = None,
|
|
329
|
+
parse_mode: Optional[str] = "HTML",
|
|
314
330
|
):
|
|
315
331
|
if type(media) == str:
|
|
316
332
|
if media.startswith("http://") or media.startswith("https://"):
|
|
317
333
|
media_obj = InputMedia(
|
|
318
|
-
type=media_type,
|
|
319
|
-
media=media,
|
|
320
|
-
caption=caption
|
|
334
|
+
type=media_type, media=media, caption=caption, parse_mode=parse_mode
|
|
321
335
|
)
|
|
322
336
|
data_obj = EditMessageMediaModel(
|
|
323
337
|
chat_id=chat_id,
|
|
324
338
|
message_id=message_id,
|
|
325
339
|
inline_message_id=inline_message_id,
|
|
326
340
|
media=media_obj,
|
|
327
|
-
reply_markup=reply_markup
|
|
341
|
+
reply_markup=reply_markup,
|
|
328
342
|
)
|
|
329
343
|
|
|
330
344
|
url = self.tg_base_url + "editMessageMedia"
|
|
@@ -332,7 +346,7 @@ class TelegramHelper(BaseHelper):
|
|
|
332
346
|
|
|
333
347
|
r = await self._perform_async_request(url, data)
|
|
334
348
|
return r
|
|
335
|
-
|
|
349
|
+
|
|
336
350
|
ends = [".jpg", ".jpeg", ".gif", ".png"]
|
|
337
351
|
for end in ends:
|
|
338
352
|
if media.endswith(end):
|
|
@@ -341,14 +355,15 @@ class TelegramHelper(BaseHelper):
|
|
|
341
355
|
media_obj = InputMedia(
|
|
342
356
|
type=media_type,
|
|
343
357
|
media=f"attach://{media}",
|
|
344
|
-
caption=caption
|
|
358
|
+
caption=caption,
|
|
359
|
+
parse_mode=parse_mode,
|
|
345
360
|
)
|
|
346
361
|
data_obj = EditMessageMediaModel(
|
|
347
362
|
chat_id=chat_id,
|
|
348
363
|
message_id=message_id,
|
|
349
364
|
inline_message_id=inline_message_id,
|
|
350
365
|
media=media_obj,
|
|
351
|
-
reply_markup=reply_markup
|
|
366
|
+
reply_markup=reply_markup,
|
|
352
367
|
)
|
|
353
368
|
|
|
354
369
|
url = self.tg_base_url + "editMessageMedia"
|
|
@@ -358,20 +373,20 @@ class TelegramHelper(BaseHelper):
|
|
|
358
373
|
data["reply_markup"] = json.dumps(data["reply_markup"])
|
|
359
374
|
files = {media: opened_media}
|
|
360
375
|
|
|
361
|
-
r = await self._perform_async_request(
|
|
376
|
+
r = await self._perform_async_request(
|
|
377
|
+
url, data, use_json=False, files=files
|
|
378
|
+
)
|
|
362
379
|
return r
|
|
363
|
-
|
|
380
|
+
|
|
364
381
|
media_obj = InputMedia(
|
|
365
|
-
type=media_type,
|
|
366
|
-
media=media,
|
|
367
|
-
caption=caption
|
|
382
|
+
type=media_type, media=media, caption=caption, parse_mode=parse_mode
|
|
368
383
|
)
|
|
369
384
|
data_obj = EditMessageMediaModel(
|
|
370
385
|
chat_id=chat_id,
|
|
371
386
|
message_id=message_id,
|
|
372
387
|
inline_message_id=inline_message_id,
|
|
373
388
|
media=media_obj,
|
|
374
|
-
reply_markup=reply_markup
|
|
389
|
+
reply_markup=reply_markup,
|
|
375
390
|
)
|
|
376
391
|
|
|
377
392
|
url = self.tg_base_url + "editMessageMedia"
|
|
@@ -379,18 +394,19 @@ class TelegramHelper(BaseHelper):
|
|
|
379
394
|
|
|
380
395
|
r = await self._perform_async_request(url, data)
|
|
381
396
|
return r
|
|
382
|
-
|
|
397
|
+
|
|
383
398
|
media_obj = InputMedia(
|
|
384
399
|
type=media_type,
|
|
385
400
|
media="attach://media",
|
|
386
|
-
caption=caption
|
|
401
|
+
caption=caption,
|
|
402
|
+
parse_mode=parse_mode,
|
|
387
403
|
)
|
|
388
404
|
data_obj = EditMessageMediaModel(
|
|
389
405
|
chat_id=chat_id,
|
|
390
406
|
message_id=message_id,
|
|
391
407
|
inline_message_id=inline_message_id,
|
|
392
408
|
media=media_obj,
|
|
393
|
-
reply_markup=reply_markup
|
|
409
|
+
reply_markup=reply_markup,
|
|
394
410
|
)
|
|
395
411
|
|
|
396
412
|
url = self.tg_base_url + "editMessageMedia"
|
|
@@ -403,7 +419,6 @@ class TelegramHelper(BaseHelper):
|
|
|
403
419
|
r = await self._perform_async_request(url, data, use_json=False, files=files)
|
|
404
420
|
return r
|
|
405
421
|
|
|
406
|
-
|
|
407
422
|
def sync_send_photo(
|
|
408
423
|
self,
|
|
409
424
|
chat_id: int,
|
|
@@ -414,7 +429,7 @@ class TelegramHelper(BaseHelper):
|
|
|
414
429
|
protect_content: Optional[bool] = None,
|
|
415
430
|
reply_to_message_id: Optional[int] = None,
|
|
416
431
|
allow_sending_without_reply: Optional[bool] = None,
|
|
417
|
-
reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup]] = None
|
|
432
|
+
reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup]] = None,
|
|
418
433
|
):
|
|
419
434
|
if type(photo) == str:
|
|
420
435
|
if photo.startswith("http://") or photo.startswith("https://"):
|
|
@@ -427,15 +442,15 @@ class TelegramHelper(BaseHelper):
|
|
|
427
442
|
protect_content=protect_content,
|
|
428
443
|
reply_to_message_id=reply_to_message_id,
|
|
429
444
|
allow_sending_without_reply=allow_sending_without_reply,
|
|
430
|
-
reply_markup=reply_markup
|
|
445
|
+
reply_markup=reply_markup,
|
|
431
446
|
)
|
|
432
447
|
|
|
433
448
|
url = self.tg_base_url + "sendPhoto"
|
|
434
449
|
data = photo_obj.dict(exclude_none=True)
|
|
435
|
-
|
|
450
|
+
|
|
436
451
|
r = self._perform_sync_request(url, data)
|
|
437
452
|
return r
|
|
438
|
-
|
|
453
|
+
|
|
439
454
|
ends = [".jpg", ".jpeg", ".gif", ".png"]
|
|
440
455
|
for end in ends:
|
|
441
456
|
if photo.endswith(end):
|
|
@@ -449,7 +464,7 @@ class TelegramHelper(BaseHelper):
|
|
|
449
464
|
protect_content=protect_content,
|
|
450
465
|
reply_to_message_id=reply_to_message_id,
|
|
451
466
|
allow_sending_without_reply=allow_sending_without_reply,
|
|
452
|
-
reply_markup=reply_markup
|
|
467
|
+
reply_markup=reply_markup,
|
|
453
468
|
)
|
|
454
469
|
|
|
455
470
|
url = self.tg_base_url + "sendPhoto"
|
|
@@ -457,10 +472,12 @@ class TelegramHelper(BaseHelper):
|
|
|
457
472
|
if "reply_markup" in data.keys():
|
|
458
473
|
data["reply_markup"] = json.dumps(data["reply_markup"])
|
|
459
474
|
files = {photo: opened_photo}
|
|
460
|
-
|
|
461
|
-
r = self._perform_sync_request(
|
|
475
|
+
|
|
476
|
+
r = self._perform_sync_request(
|
|
477
|
+
url, data, use_json=False, files=files
|
|
478
|
+
)
|
|
462
479
|
return r
|
|
463
|
-
|
|
480
|
+
|
|
464
481
|
photo_obj = Photo(
|
|
465
482
|
chat_id=chat_id,
|
|
466
483
|
photo=photo,
|
|
@@ -470,15 +487,15 @@ class TelegramHelper(BaseHelper):
|
|
|
470
487
|
protect_content=protect_content,
|
|
471
488
|
reply_to_message_id=reply_to_message_id,
|
|
472
489
|
allow_sending_without_reply=allow_sending_without_reply,
|
|
473
|
-
reply_markup=reply_markup
|
|
490
|
+
reply_markup=reply_markup,
|
|
474
491
|
)
|
|
475
492
|
|
|
476
493
|
url = self.tg_base_url + "sendPhoto"
|
|
477
494
|
data = photo_obj.dict(exclude_none=True)
|
|
478
|
-
|
|
495
|
+
|
|
479
496
|
r = self._perform_sync_request(url, data)
|
|
480
497
|
return r
|
|
481
|
-
|
|
498
|
+
|
|
482
499
|
photo_obj = Photo(
|
|
483
500
|
chat_id=chat_id,
|
|
484
501
|
photo="attach://image",
|
|
@@ -488,7 +505,7 @@ class TelegramHelper(BaseHelper):
|
|
|
488
505
|
protect_content=protect_content,
|
|
489
506
|
reply_to_message_id=reply_to_message_id,
|
|
490
507
|
allow_sending_without_reply=allow_sending_without_reply,
|
|
491
|
-
reply_markup=reply_markup
|
|
508
|
+
reply_markup=reply_markup,
|
|
492
509
|
)
|
|
493
510
|
|
|
494
511
|
url = self.tg_base_url + "sendPhoto"
|
|
@@ -496,7 +513,7 @@ class TelegramHelper(BaseHelper):
|
|
|
496
513
|
if "reply_markup" in data.keys():
|
|
497
514
|
data["reply_markup"] = json.dumps(data["reply_markup"])
|
|
498
515
|
files = {"image": photo}
|
|
499
|
-
|
|
516
|
+
|
|
500
517
|
r = self._perform_sync_request(url, data, use_json=False, files=files)
|
|
501
518
|
return r
|
|
502
519
|
|
|
@@ -510,7 +527,7 @@ class TelegramHelper(BaseHelper):
|
|
|
510
527
|
protect_content: Optional[bool] = None,
|
|
511
528
|
reply_to_message_id: Optional[int] = None,
|
|
512
529
|
allow_sending_without_reply: Optional[bool] = None,
|
|
513
|
-
reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup]] = None
|
|
530
|
+
reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup]] = None,
|
|
514
531
|
):
|
|
515
532
|
if type(photo) == str:
|
|
516
533
|
if photo.startswith("http://") or photo.startswith("https://"):
|
|
@@ -523,14 +540,14 @@ class TelegramHelper(BaseHelper):
|
|
|
523
540
|
protect_content=protect_content,
|
|
524
541
|
reply_to_message_id=reply_to_message_id,
|
|
525
542
|
allow_sending_without_reply=allow_sending_without_reply,
|
|
526
|
-
reply_markup=reply_markup
|
|
543
|
+
reply_markup=reply_markup,
|
|
527
544
|
)
|
|
528
545
|
|
|
529
546
|
url = self.tg_base_url + "sendPhoto"
|
|
530
547
|
data = photo_obj.dict(exclude_none=True)
|
|
531
548
|
r = await self._perform_async_request(url, data)
|
|
532
549
|
return r
|
|
533
|
-
|
|
550
|
+
|
|
534
551
|
ends = [".jpg", ".jpeg", ".gif", ".png"]
|
|
535
552
|
for end in ends:
|
|
536
553
|
if photo.endswith(end):
|
|
@@ -545,7 +562,7 @@ class TelegramHelper(BaseHelper):
|
|
|
545
562
|
protect_content=protect_content,
|
|
546
563
|
reply_to_message_id=reply_to_message_id,
|
|
547
564
|
allow_sending_without_reply=allow_sending_without_reply,
|
|
548
|
-
reply_markup=reply_markup
|
|
565
|
+
reply_markup=reply_markup,
|
|
549
566
|
)
|
|
550
567
|
|
|
551
568
|
url = self.tg_base_url + "sendPhoto"
|
|
@@ -553,9 +570,11 @@ class TelegramHelper(BaseHelper):
|
|
|
553
570
|
if "reply_markup" in data.keys():
|
|
554
571
|
data["reply_markup"] = json.dumps(data["reply_markup"])
|
|
555
572
|
files = {photo: content}
|
|
556
|
-
r = await self._perform_async_request(
|
|
573
|
+
r = await self._perform_async_request(
|
|
574
|
+
url, data, use_json=False, files=files
|
|
575
|
+
)
|
|
557
576
|
return r
|
|
558
|
-
|
|
577
|
+
|
|
559
578
|
photo_obj = Photo(
|
|
560
579
|
chat_id=chat_id,
|
|
561
580
|
photo=photo,
|
|
@@ -565,14 +584,14 @@ class TelegramHelper(BaseHelper):
|
|
|
565
584
|
protect_content=protect_content,
|
|
566
585
|
reply_to_message_id=reply_to_message_id,
|
|
567
586
|
allow_sending_without_reply=allow_sending_without_reply,
|
|
568
|
-
reply_markup=reply_markup
|
|
587
|
+
reply_markup=reply_markup,
|
|
569
588
|
)
|
|
570
589
|
|
|
571
590
|
url = self.tg_base_url + "sendPhoto"
|
|
572
591
|
data = photo_obj.dict(exclude_none=True)
|
|
573
592
|
r = await self._perform_async_request(url, data)
|
|
574
593
|
return r
|
|
575
|
-
|
|
594
|
+
|
|
576
595
|
photo_obj = Photo(
|
|
577
596
|
chat_id=chat_id,
|
|
578
597
|
photo="attach://image",
|
|
@@ -582,7 +601,7 @@ class TelegramHelper(BaseHelper):
|
|
|
582
601
|
protect_content=protect_content,
|
|
583
602
|
reply_to_message_id=reply_to_message_id,
|
|
584
603
|
allow_sending_without_reply=allow_sending_without_reply,
|
|
585
|
-
reply_markup=reply_markup
|
|
604
|
+
reply_markup=reply_markup,
|
|
586
605
|
)
|
|
587
606
|
|
|
588
607
|
url = self.tg_base_url + "sendPhoto"
|
|
@@ -592,7 +611,6 @@ class TelegramHelper(BaseHelper):
|
|
|
592
611
|
files = {"image": photo}
|
|
593
612
|
r = await self._perform_async_request(url, data, use_json=False, files=files)
|
|
594
613
|
return r
|
|
595
|
-
|
|
596
614
|
|
|
597
615
|
def sync_send_document(
|
|
598
616
|
self,
|
|
@@ -605,7 +623,7 @@ class TelegramHelper(BaseHelper):
|
|
|
605
623
|
protect_content: Optional[bool] = None,
|
|
606
624
|
reply_to_message_id: Optional[int] = None,
|
|
607
625
|
allow_sending_without_reply: Optional[bool] = None,
|
|
608
|
-
reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup]] = None
|
|
626
|
+
reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup]] = None,
|
|
609
627
|
):
|
|
610
628
|
files = {}
|
|
611
629
|
document_str = None
|
|
@@ -615,7 +633,10 @@ class TelegramHelper(BaseHelper):
|
|
|
615
633
|
ends = [".pdf", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx"]
|
|
616
634
|
for end in ends:
|
|
617
635
|
if document.endswith(end):
|
|
618
|
-
files["document"] = (
|
|
636
|
+
files["document"] = (
|
|
637
|
+
file_name if file_name else document,
|
|
638
|
+
open(document, "rb"),
|
|
639
|
+
)
|
|
619
640
|
document_str = "attach://document"
|
|
620
641
|
if document_str is None:
|
|
621
642
|
document_str = document
|
|
@@ -632,7 +653,7 @@ class TelegramHelper(BaseHelper):
|
|
|
632
653
|
protect_content=protect_content,
|
|
633
654
|
reply_to_message_id=reply_to_message_id,
|
|
634
655
|
allow_sending_without_reply=allow_sending_without_reply,
|
|
635
|
-
reply_markup=reply_markup
|
|
656
|
+
reply_markup=reply_markup,
|
|
636
657
|
)
|
|
637
658
|
|
|
638
659
|
url = self.tg_base_url + "sendDocument"
|
|
@@ -643,7 +664,7 @@ class TelegramHelper(BaseHelper):
|
|
|
643
664
|
if len(files.keys()):
|
|
644
665
|
r = self._perform_sync_request(url, data, use_json=False, files=files)
|
|
645
666
|
return r
|
|
646
|
-
|
|
667
|
+
|
|
647
668
|
r = self._perform_sync_request(url, data)
|
|
648
669
|
return r
|
|
649
670
|
|
|
@@ -658,17 +679,20 @@ class TelegramHelper(BaseHelper):
|
|
|
658
679
|
protect_content: Optional[bool] = None,
|
|
659
680
|
reply_to_message_id: Optional[int] = None,
|
|
660
681
|
allow_sending_without_reply: Optional[bool] = None,
|
|
661
|
-
reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup]] = None
|
|
682
|
+
reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup]] = None,
|
|
662
683
|
):
|
|
663
684
|
files = {}
|
|
664
685
|
document_str = None
|
|
665
|
-
|
|
686
|
+
|
|
666
687
|
if type(document) == str:
|
|
667
688
|
if not (document.startswith("http://") or document.startswith("https://")):
|
|
668
689
|
ends = [".pdf", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx"]
|
|
669
690
|
for end in ends:
|
|
670
691
|
if document.endswith(end):
|
|
671
|
-
files["document"] = (
|
|
692
|
+
files["document"] = (
|
|
693
|
+
file_name if file_name else document,
|
|
694
|
+
open(document, "rb"),
|
|
695
|
+
)
|
|
672
696
|
document_str = "attach://document"
|
|
673
697
|
if document_str is None:
|
|
674
698
|
document_str = document
|
|
@@ -685,23 +709,24 @@ class TelegramHelper(BaseHelper):
|
|
|
685
709
|
protect_content=protect_content,
|
|
686
710
|
reply_to_message_id=reply_to_message_id,
|
|
687
711
|
allow_sending_without_reply=allow_sending_without_reply,
|
|
688
|
-
reply_markup=reply_markup
|
|
712
|
+
reply_markup=reply_markup,
|
|
689
713
|
)
|
|
690
714
|
|
|
691
715
|
url = self.tg_base_url + "sendDocument"
|
|
692
716
|
data = document_obj.dict(exclude_none=True)
|
|
693
|
-
|
|
717
|
+
|
|
694
718
|
if "reply_markup" in data.keys():
|
|
695
719
|
data["reply_markup"] = json.dumps(data["reply_markup"])
|
|
696
720
|
|
|
697
721
|
if len(files.keys()):
|
|
698
|
-
r = await self._perform_async_request(
|
|
722
|
+
r = await self._perform_async_request(
|
|
723
|
+
url, data, use_json=False, files=files
|
|
724
|
+
)
|
|
699
725
|
return r
|
|
700
|
-
|
|
726
|
+
|
|
701
727
|
r = await self._perform_async_request(url, data)
|
|
702
728
|
return r
|
|
703
729
|
|
|
704
|
-
|
|
705
730
|
@retry(
|
|
706
731
|
retry=retry_if_exception_type(httpx.HTTPError),
|
|
707
732
|
reraise=True,
|
|
@@ -711,14 +736,12 @@ class TelegramHelper(BaseHelper):
|
|
|
711
736
|
def sync_get_file(self, file_id: str):
|
|
712
737
|
|
|
713
738
|
url = self.tg_base_url + "getFile"
|
|
714
|
-
data = {
|
|
715
|
-
"file_id": file_id
|
|
716
|
-
}
|
|
739
|
+
data = {"file_id": file_id}
|
|
717
740
|
r = self._perform_sync_request(url, data)
|
|
718
741
|
|
|
719
742
|
file_path = r["result"]["file_path"]
|
|
720
743
|
download_url = f"https://api.telegram.org/file/bot{self.token}/{file_path}"
|
|
721
|
-
|
|
744
|
+
|
|
722
745
|
io_object = BytesIO()
|
|
723
746
|
with httpx.stream(method="GET", url=download_url) as result:
|
|
724
747
|
for data in result.iter_bytes():
|
|
@@ -736,9 +759,7 @@ class TelegramHelper(BaseHelper):
|
|
|
736
759
|
async def async_get_file(self, file_id: str):
|
|
737
760
|
|
|
738
761
|
url = self.tg_base_url + "getFile"
|
|
739
|
-
data = {
|
|
740
|
-
"file_id": file_id
|
|
741
|
-
}
|
|
762
|
+
data = {"file_id": file_id}
|
|
742
763
|
r = await self._perform_async_request(url, data)
|
|
743
764
|
|
|
744
765
|
file_path = r["result"]["file_path"]
|
|
@@ -753,74 +774,52 @@ class TelegramHelper(BaseHelper):
|
|
|
753
774
|
|
|
754
775
|
return io_object
|
|
755
776
|
|
|
756
|
-
def sync_send_media_group(
|
|
757
|
-
self,
|
|
758
|
-
chat_id: int,
|
|
759
|
-
photos: Union[List[str], List[IO]]
|
|
760
|
-
):
|
|
777
|
+
def sync_send_media_group(self, chat_id: int, photos: Union[List[str], List[IO]]):
|
|
761
778
|
files = {}
|
|
762
779
|
photos_list = []
|
|
763
780
|
|
|
764
781
|
if type(photos[-1]) == str:
|
|
765
782
|
if photos[-1].startswith("http://") or photos[-1].startswith("https://"):
|
|
766
783
|
for photo in photos:
|
|
767
|
-
photos_list.append(
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
media_group = MediaGroup(
|
|
772
|
-
chat_id=chat_id,
|
|
773
|
-
media=photos_list
|
|
774
|
-
)
|
|
784
|
+
photos_list.append(InputMediaPhoto(media=photo))
|
|
785
|
+
|
|
786
|
+
media_group = MediaGroup(chat_id=chat_id, media=photos_list)
|
|
775
787
|
url = self.tg_base_url + "sendMediaGroup"
|
|
776
788
|
data = media_group.dict(exclude_none=True)
|
|
777
789
|
r = self._perform_sync_request(url, data)
|
|
778
790
|
return r
|
|
779
|
-
|
|
791
|
+
|
|
780
792
|
ends = [".jpg", ".jpeg", ".gif", ".png"]
|
|
781
793
|
for end in ends:
|
|
782
794
|
if photos[-1].endswith(end):
|
|
783
795
|
for photo in photos:
|
|
784
|
-
photos_list.append(
|
|
785
|
-
InputMediaPhoto(media=f"attach://{photo}")
|
|
786
|
-
)
|
|
796
|
+
photos_list.append(InputMediaPhoto(media=f"attach://{photo}"))
|
|
787
797
|
content = open(photo, "rb")
|
|
788
798
|
files[photo] = content
|
|
789
|
-
|
|
790
|
-
media_group = MediaGroup(
|
|
791
|
-
chat_id=chat_id,
|
|
792
|
-
media=photos_list
|
|
793
|
-
)
|
|
799
|
+
|
|
800
|
+
media_group = MediaGroup(chat_id=chat_id, media=photos_list)
|
|
794
801
|
url = self.tg_base_url + "sendMediaGroup"
|
|
795
802
|
data = media_group.dict(exclude_none=True)
|
|
796
803
|
data["media"] = json.dumps(data["media"])
|
|
797
|
-
r = self._perform_sync_request(
|
|
804
|
+
r = self._perform_sync_request(
|
|
805
|
+
url, data, use_json=False, files=files
|
|
806
|
+
)
|
|
798
807
|
return r
|
|
799
808
|
|
|
800
809
|
for photo in photos:
|
|
801
|
-
photos_list.append(
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
media_group = MediaGroup(
|
|
806
|
-
chat_id=chat_id,
|
|
807
|
-
media=photos_list
|
|
808
|
-
)
|
|
810
|
+
photos_list.append(InputMediaPhoto(media=photo))
|
|
811
|
+
|
|
812
|
+
media_group = MediaGroup(chat_id=chat_id, media=photos_list)
|
|
809
813
|
url = self.tg_base_url + "sendMediaGroup"
|
|
810
814
|
data = media_group.dict(exclude_none=True)
|
|
811
815
|
r = self._perform_sync_request(url, data)
|
|
812
816
|
return r
|
|
813
817
|
|
|
814
818
|
for i in range(len(photos)):
|
|
815
|
-
photos_list.append(
|
|
816
|
-
InputMediaPhoto(media=f"attach://image_{i}")
|
|
817
|
-
)
|
|
819
|
+
photos_list.append(InputMediaPhoto(media=f"attach://image_{i}"))
|
|
818
820
|
files[f"image_{i}"] = photos[i]
|
|
819
|
-
|
|
820
|
-
media_group = MediaGroup(
|
|
821
|
-
chat_id=chat_id,
|
|
822
|
-
media=photos_list
|
|
823
|
-
)
|
|
821
|
+
|
|
822
|
+
media_group = MediaGroup(chat_id=chat_id, media=photos_list)
|
|
824
823
|
url = self.tg_base_url + "sendMediaGroup"
|
|
825
824
|
data = media_group.dict(exclude_none=True)
|
|
826
825
|
data["media"] = json.dumps(data["media"])
|
|
@@ -828,9 +827,7 @@ class TelegramHelper(BaseHelper):
|
|
|
828
827
|
return r
|
|
829
828
|
|
|
830
829
|
async def async_send_media_group(
|
|
831
|
-
self,
|
|
832
|
-
chat_id: int,
|
|
833
|
-
photos: Union[List[str], List[IO]]
|
|
830
|
+
self, chat_id: int, photos: Union[List[str], List[IO]]
|
|
834
831
|
):
|
|
835
832
|
files = {}
|
|
836
833
|
photos_list = []
|
|
@@ -838,64 +835,46 @@ class TelegramHelper(BaseHelper):
|
|
|
838
835
|
if type(photos[-1]) == str:
|
|
839
836
|
if photos[-1].startswith("http://") or photos[-1].startswith("https://"):
|
|
840
837
|
for photo in photos:
|
|
841
|
-
photos_list.append(
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
media_group = MediaGroup(
|
|
846
|
-
chat_id=chat_id,
|
|
847
|
-
media=photos_list
|
|
848
|
-
)
|
|
838
|
+
photos_list.append(InputMediaPhoto(media=photo))
|
|
839
|
+
|
|
840
|
+
media_group = MediaGroup(chat_id=chat_id, media=photos_list)
|
|
849
841
|
url = self.tg_base_url + "sendMediaGroup"
|
|
850
842
|
data = media_group.dict(exclude_none=True)
|
|
851
843
|
r = await self._perform_async_request(url, data)
|
|
852
844
|
return r
|
|
853
|
-
|
|
845
|
+
|
|
854
846
|
ends = [".jpg", ".jpeg", ".gif", ".png"]
|
|
855
847
|
for end in ends:
|
|
856
848
|
if photos[-1].endswith(end):
|
|
857
849
|
for photo in photos:
|
|
858
|
-
photos_list.append(
|
|
859
|
-
InputMediaPhoto(media=f"attach://{photo}")
|
|
860
|
-
)
|
|
850
|
+
photos_list.append(InputMediaPhoto(media=f"attach://{photo}"))
|
|
861
851
|
async with aiofiles.open(photo, "rb") as opened_photo:
|
|
862
852
|
content = await opened_photo.read()
|
|
863
853
|
files[photo] = content
|
|
864
|
-
|
|
865
|
-
media_group = MediaGroup(
|
|
866
|
-
chat_id=chat_id,
|
|
867
|
-
media=photos_list
|
|
868
|
-
)
|
|
854
|
+
|
|
855
|
+
media_group = MediaGroup(chat_id=chat_id, media=photos_list)
|
|
869
856
|
url = self.tg_base_url + "sendMediaGroup"
|
|
870
857
|
data = media_group.dict(exclude_none=True)
|
|
871
858
|
data["media"] = json.dumps(data["media"])
|
|
872
|
-
r = await self._perform_async_request(
|
|
859
|
+
r = await self._perform_async_request(
|
|
860
|
+
url, data, use_json=False, files=files
|
|
861
|
+
)
|
|
873
862
|
return r
|
|
874
863
|
|
|
875
864
|
for photo in photos:
|
|
876
|
-
photos_list.append(
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
media_group = MediaGroup(
|
|
881
|
-
chat_id=chat_id,
|
|
882
|
-
media=photos_list
|
|
883
|
-
)
|
|
865
|
+
photos_list.append(InputMediaPhoto(media=photo))
|
|
866
|
+
|
|
867
|
+
media_group = MediaGroup(chat_id=chat_id, media=photos_list)
|
|
884
868
|
url = self.tg_base_url + "sendMediaGroup"
|
|
885
869
|
data = media_group.dict(exclude_none=True)
|
|
886
870
|
r = await self._perform_async_request(url, data)
|
|
887
871
|
return r
|
|
888
872
|
|
|
889
873
|
for i in range(len(photos)):
|
|
890
|
-
photos_list.append(
|
|
891
|
-
InputMediaPhoto(media=f"attach://image_{i}")
|
|
892
|
-
)
|
|
874
|
+
photos_list.append(InputMediaPhoto(media=f"attach://image_{i}"))
|
|
893
875
|
files[f"image_{i}"] = photos[i]
|
|
894
|
-
|
|
895
|
-
media_group = MediaGroup(
|
|
896
|
-
chat_id=chat_id,
|
|
897
|
-
media=photos_list
|
|
898
|
-
)
|
|
876
|
+
|
|
877
|
+
media_group = MediaGroup(chat_id=chat_id, media=photos_list)
|
|
899
878
|
url = self.tg_base_url + "sendMediaGroup"
|
|
900
879
|
data = media_group.dict(exclude_none=True)
|
|
901
880
|
data["media"] = json.dumps(data["media"])
|
|
@@ -917,24 +896,29 @@ class TelegramHelper(BaseHelper):
|
|
|
917
896
|
protect_content: Optional[bool] = None,
|
|
918
897
|
reply_to_message_id: Optional[int] = None,
|
|
919
898
|
allow_sending_without_reply: Optional[bool] = None,
|
|
920
|
-
reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup]] = None
|
|
899
|
+
reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup]] = None,
|
|
921
900
|
):
|
|
922
901
|
files = {}
|
|
923
902
|
animation_str = None
|
|
924
903
|
|
|
925
904
|
if type(animation) == str:
|
|
926
|
-
if not (
|
|
905
|
+
if not (
|
|
906
|
+
animation.startswith("http://") or animation.startswith("https://")
|
|
907
|
+
):
|
|
927
908
|
ends = [".gif"]
|
|
928
909
|
for end in ends:
|
|
929
910
|
if animation.endswith(end):
|
|
930
|
-
files["animation"] = (
|
|
911
|
+
files["animation"] = (
|
|
912
|
+
file_name if file_name else "file.gif",
|
|
913
|
+
open(animation, "rb"),
|
|
914
|
+
)
|
|
931
915
|
animation_str = "attach://animation"
|
|
932
916
|
if animation_str is None:
|
|
933
917
|
animation_str = animation
|
|
934
918
|
else:
|
|
935
919
|
animation_str = "attach://animation"
|
|
936
920
|
files["animation"] = (file_name if file_name else "file.gif", animation)
|
|
937
|
-
|
|
921
|
+
|
|
938
922
|
animation_obj = Animation(
|
|
939
923
|
chat_id=chat_id,
|
|
940
924
|
animation=animation_str,
|
|
@@ -948,7 +932,7 @@ class TelegramHelper(BaseHelper):
|
|
|
948
932
|
protect_content=protect_content,
|
|
949
933
|
reply_to_message_id=reply_to_message_id,
|
|
950
934
|
allow_sending_without_reply=allow_sending_without_reply,
|
|
951
|
-
reply_markup=reply_markup
|
|
935
|
+
reply_markup=reply_markup,
|
|
952
936
|
)
|
|
953
937
|
|
|
954
938
|
url = self.tg_base_url + "sendAnimation"
|
|
@@ -959,7 +943,7 @@ class TelegramHelper(BaseHelper):
|
|
|
959
943
|
if len(files.keys()):
|
|
960
944
|
r = self._perform_sync_request(url, data, use_json=False, files=files)
|
|
961
945
|
return r
|
|
962
|
-
|
|
946
|
+
|
|
963
947
|
r = self._perform_sync_request(url, data)
|
|
964
948
|
return r
|
|
965
949
|
|
|
@@ -978,17 +962,22 @@ class TelegramHelper(BaseHelper):
|
|
|
978
962
|
protect_content: Optional[bool] = None,
|
|
979
963
|
reply_to_message_id: Optional[int] = None,
|
|
980
964
|
allow_sending_without_reply: Optional[bool] = None,
|
|
981
|
-
reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup]] = None
|
|
965
|
+
reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup]] = None,
|
|
982
966
|
):
|
|
983
967
|
files = {}
|
|
984
968
|
animation_str = None
|
|
985
969
|
|
|
986
970
|
if type(animation) == str:
|
|
987
|
-
if not (
|
|
971
|
+
if not (
|
|
972
|
+
animation.startswith("http://") or animation.startswith("https://")
|
|
973
|
+
):
|
|
988
974
|
ends = [".gif"]
|
|
989
975
|
for end in ends:
|
|
990
976
|
if animation.endswith(end):
|
|
991
|
-
files["animation"] = (
|
|
977
|
+
files["animation"] = (
|
|
978
|
+
file_name if file_name else "file.gif",
|
|
979
|
+
open(animation, "rb"),
|
|
980
|
+
)
|
|
992
981
|
animation_str = "attach://animation"
|
|
993
982
|
if animation_str is None:
|
|
994
983
|
animation_str = animation
|
|
@@ -1009,7 +998,7 @@ class TelegramHelper(BaseHelper):
|
|
|
1009
998
|
protect_content=protect_content,
|
|
1010
999
|
reply_to_message_id=reply_to_message_id,
|
|
1011
1000
|
allow_sending_without_reply=allow_sending_without_reply,
|
|
1012
|
-
reply_markup=reply_markup
|
|
1001
|
+
reply_markup=reply_markup,
|
|
1013
1002
|
)
|
|
1014
1003
|
|
|
1015
1004
|
url = self.tg_base_url + "sendAnimation"
|
|
@@ -1018,9 +1007,11 @@ class TelegramHelper(BaseHelper):
|
|
|
1018
1007
|
data["reply_markup"] = json.dumps(data["reply_markup"])
|
|
1019
1008
|
|
|
1020
1009
|
if len(files.keys()):
|
|
1021
|
-
r = await self._perform_async_request(
|
|
1010
|
+
r = await self._perform_async_request(
|
|
1011
|
+
url, data, use_json=False, files=files
|
|
1012
|
+
)
|
|
1022
1013
|
return r
|
|
1023
|
-
|
|
1014
|
+
|
|
1024
1015
|
r = await self._perform_async_request(url, data)
|
|
1025
1016
|
return r
|
|
1026
1017
|
|
|
@@ -1039,7 +1030,7 @@ class TelegramHelper(BaseHelper):
|
|
|
1039
1030
|
protect_content: Optional[bool] = None,
|
|
1040
1031
|
reply_to_message_id: Optional[int] = None,
|
|
1041
1032
|
allow_sending_without_reply: Optional[bool] = None,
|
|
1042
|
-
reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup]] = None
|
|
1033
|
+
reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup]] = None,
|
|
1043
1034
|
):
|
|
1044
1035
|
files = {}
|
|
1045
1036
|
audio_str = None
|
|
@@ -1049,7 +1040,10 @@ class TelegramHelper(BaseHelper):
|
|
|
1049
1040
|
ends = [".mp3"]
|
|
1050
1041
|
for end in ends:
|
|
1051
1042
|
if audio.endswith(end):
|
|
1052
|
-
files["audio"] = (
|
|
1043
|
+
files["audio"] = (
|
|
1044
|
+
file_name if file_name else audio,
|
|
1045
|
+
open(audio, "rb"),
|
|
1046
|
+
)
|
|
1053
1047
|
audio_str = "attach://animation"
|
|
1054
1048
|
if audio_str is None:
|
|
1055
1049
|
audio_str = audio
|
|
@@ -1070,7 +1064,7 @@ class TelegramHelper(BaseHelper):
|
|
|
1070
1064
|
protect_content=protect_content,
|
|
1071
1065
|
reply_to_message_id=reply_to_message_id,
|
|
1072
1066
|
allow_sending_without_reply=allow_sending_without_reply,
|
|
1073
|
-
reply_markup=reply_markup
|
|
1067
|
+
reply_markup=reply_markup,
|
|
1074
1068
|
)
|
|
1075
1069
|
|
|
1076
1070
|
url = self.tg_base_url + "sendAudio"
|
|
@@ -1079,21 +1073,23 @@ class TelegramHelper(BaseHelper):
|
|
|
1079
1073
|
data["reply_markup"] = json.dumps(data["reply_markup"])
|
|
1080
1074
|
|
|
1081
1075
|
if len(files.keys()):
|
|
1082
|
-
r = await self._perform_async_request(
|
|
1076
|
+
r = await self._perform_async_request(
|
|
1077
|
+
url, data, use_json=False, files=files
|
|
1078
|
+
)
|
|
1083
1079
|
return r
|
|
1084
|
-
|
|
1080
|
+
|
|
1085
1081
|
r = await self._perform_async_request(url, data)
|
|
1086
1082
|
return r
|
|
1087
1083
|
|
|
1088
1084
|
async def async_send_sticker(
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1085
|
+
self,
|
|
1086
|
+
chat_id: int,
|
|
1087
|
+
sticker: str,
|
|
1088
|
+
disable_notification: Optional[bool] = None,
|
|
1089
|
+
protect_content: Optional[bool] = None,
|
|
1090
|
+
reply_to_message_id: Optional[int] = None,
|
|
1091
|
+
allow_sending_without_reply: Optional[bool] = None,
|
|
1092
|
+
reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup]] = None,
|
|
1097
1093
|
):
|
|
1098
1094
|
sticker_obj = Sticker(
|
|
1099
1095
|
chat_id=chat_id,
|
|
@@ -1102,7 +1098,7 @@ class TelegramHelper(BaseHelper):
|
|
|
1102
1098
|
protect_content=protect_content,
|
|
1103
1099
|
reply_to_message_id=reply_to_message_id,
|
|
1104
1100
|
allow_sending_without_reply=allow_sending_without_reply,
|
|
1105
|
-
reply_markup=reply_markup
|
|
1101
|
+
reply_markup=reply_markup,
|
|
1106
1102
|
)
|
|
1107
1103
|
|
|
1108
1104
|
url = self.tg_base_url + "sendSticker"
|
|
@@ -1114,14 +1110,14 @@ class TelegramHelper(BaseHelper):
|
|
|
1114
1110
|
return r
|
|
1115
1111
|
|
|
1116
1112
|
def sync_send_sticker(
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1113
|
+
self,
|
|
1114
|
+
chat_id: int,
|
|
1115
|
+
sticker: str,
|
|
1116
|
+
disable_notification: Optional[bool] = None,
|
|
1117
|
+
protect_content: Optional[bool] = None,
|
|
1118
|
+
reply_to_message_id: Optional[int] = None,
|
|
1119
|
+
allow_sending_without_reply: Optional[bool] = None,
|
|
1120
|
+
reply_markup: Optional[Union[InlineKeyboardMarkup, ReplyKeyboardMarkup]] = None,
|
|
1125
1121
|
):
|
|
1126
1122
|
sticker_obj = Sticker(
|
|
1127
1123
|
chat_id=chat_id,
|
|
@@ -1130,7 +1126,7 @@ class TelegramHelper(BaseHelper):
|
|
|
1130
1126
|
protect_content=protect_content,
|
|
1131
1127
|
reply_to_message_id=reply_to_message_id,
|
|
1132
1128
|
allow_sending_without_reply=allow_sending_without_reply,
|
|
1133
|
-
reply_markup=reply_markup
|
|
1129
|
+
reply_markup=reply_markup,
|
|
1134
1130
|
)
|
|
1135
1131
|
|
|
1136
1132
|
url = self.tg_base_url + "sendSticker"
|
|
@@ -1142,8 +1138,8 @@ class TelegramHelper(BaseHelper):
|
|
|
1142
1138
|
return r
|
|
1143
1139
|
|
|
1144
1140
|
def sync_get_sticker_set(
|
|
1145
|
-
|
|
1146
|
-
|
|
1141
|
+
self,
|
|
1142
|
+
sticker_set: str,
|
|
1147
1143
|
):
|
|
1148
1144
|
url = self.tg_base_url + "getStickerSet"
|
|
1149
1145
|
data = {"name": sticker_set}
|
|
@@ -1151,8 +1147,8 @@ class TelegramHelper(BaseHelper):
|
|
|
1151
1147
|
return r
|
|
1152
1148
|
|
|
1153
1149
|
async def async_get_sticker_set(
|
|
1154
|
-
|
|
1155
|
-
|
|
1150
|
+
self,
|
|
1151
|
+
sticker_set: str,
|
|
1156
1152
|
):
|
|
1157
1153
|
url = self.tg_base_url + "getStickerSet"
|
|
1158
1154
|
data = {"name": sticker_set}
|
|
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
|
|
|
5
5
|
|
|
6
6
|
setuptools.setup(
|
|
7
7
|
name="multibotkit",
|
|
8
|
-
version="0.1.
|
|
8
|
+
version="0.1.12",
|
|
9
9
|
author="Appvelox LLC",
|
|
10
10
|
author_email="team@appvelox.ru",
|
|
11
11
|
description="Functional library for developing multiplatform chatbots",
|
|
@@ -19,7 +19,7 @@ setuptools.setup(
|
|
|
19
19
|
"License :: OSI Approved :: MIT License",
|
|
20
20
|
"Operating System :: OS Independent",
|
|
21
21
|
],
|
|
22
|
-
install_requires=["httpx>=0.23.0", "pydantic
|
|
22
|
+
install_requires=["httpx>=0.23.0", "pydantic<2", "tenacity>=8.0.1", "aiofiles>=22.1.0"],
|
|
23
23
|
extras_require={
|
|
24
24
|
"mongo": ["motor>=3.0.0"],
|
|
25
25
|
"redis": ["aioredis>=2.0.1"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|