dikasterion/backend/app/utils/notifications.py

35 lines
1.0 KiB
Python

import logging
import os
from datetime import datetime
# Simple logger for MVP - writes to file instead of sending actual emails
logger = logging.getLogger("notifications")
logger.setLevel(logging.INFO)
# Create file handler
if not os.path.exists("logs"):
os.makedirs("logs")
file_handler = logging.FileHandler("logs/notifications.log")
file_handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(message)s')
file_handler.setFormatter(formatter)
logger.addHandler(file_handler)
async def notify_user(user, subject: str, message: str):
"""Notify user via email/Telegram (MVP: log to file)"""
log_entry = f"""
=== NOTIFICATION ===
To: {user.username} ({user.email or 'no email'})
Subject: {subject}
Message: {message}
===================
"""
logger.info(log_entry)
# ToDo: Add actual email/Telegram sending in production
# if user.email and os.getenv("SMTP_HOST"):
# await send_email(user.email, subject, message)
# if os.getenv("TELEGRAM_BOT_TOKEN"):
# await send_telegram(user.id, message)