from pathlib import Path from telegram import Message async def send_video(message: Message, filepath: Path, connect_timeout: int, read_timeout: int): with filepath.open('rb') as f: await message.chat.send_video( video=f, supports_streaming=True, connect_timeout=connect_timeout, read_timeout=read_timeout ) async def send_audio(message: Message, filepath: Path, title: str | None, connect_timeout: int, read_timeout: int): with filepath.open('rb') as f: await message.chat.send_audio( audio=f, title=title, connect_timeout=connect_timeout, read_timeout=read_timeout ) async def send_document(message: Message, filepath: Path, connect_timeout: int, read_timeout: int): with filepath.open('rb') as f: await message.chat.send_document( document=f, filename=filepath.name, connect_timeout=connect_timeout, read_timeout=read_timeout ) async def send_photo(message: Message, filepath: Path, connect_timeout: int, read_timeout: int): # Фото до ~20MB лучше отправлять как фото, большие — как документ if filepath.stat().st_size <= 20 * 1024 * 1024: with filepath.open('rb') as f: await message.chat.send_photo( photo=f, connect_timeout=connect_timeout, read_timeout=read_timeout ) else: await send_document(message, filepath, connect_timeout, read_timeout)