-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
30 lines (22 loc) · 717 Bytes
/
utils.py
File metadata and controls
30 lines (22 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import asyncio
import os
from aiogram import Bot
from aiogram.types import FSInputFile
async def send_safe_message(bot: Bot, chat_id, message):
while True:
try:
await bot.send_message(chat_id, message)
break
except:
await asyncio.sleep(1)
async def send_safe_document(bot: Bot, chat_id, file_path):
while True:
try:
await bot.send_document(chat_id, FSInputFile(file_path))
break
except:
await asyncio.sleep(1)
async def send_file_and_cleanup(bot: Bot, chat_id, file_path, response_text=None):
await send_safe_document(bot, chat_id, file_path)
os.remove(file_path)
return response_text