from telegram import Bot from src.config import DATA_PARTIAL_DIR from src.database import upsert_recording from src.logger import logger from src.scenarios import get_audio_filename async def save_voice_message( bot: Bot, file_id: str, user_id: int, scenario_id: str, replica_index: int, ) -> None: """Сохраняет голосовое сообщение в data_partial/.""" # Создаём директорию если нужно scenario_dir = DATA_PARTIAL_DIR / scenario_id scenario_dir.mkdir(parents=True, exist_ok=True) # Скачиваем файл file = await bot.get_file(file_id) filename = get_audio_filename(replica_index, user_id) filepath = scenario_dir / filename await file.download_to_drive(filepath) # Записываем в БД upsert_recording(user_id, scenario_id, replica_index) logger.debug(f"Saved voice: {filepath}")