Automated Action ef749e4878 Implement WhatsApp Message Analytics Service
- Set up FastAPI application structure
- Implement SQLite database with SQLAlchemy
- Create WhatsApp webhook endpoints
- Implement message storage and analysis
- Integrate Gemini 2.5 Pro for message analysis
- Add email delivery of insights
- Configure APScheduler for weekend analysis
- Add linting with Ruff
2025-05-22 13:29:12 +00:00

68 lines
2.0 KiB
Python

"""
Configuration settings for the application.
"""
from pathlib import Path
from pydantic import AnyHttpUrl, EmailStr, validator
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
"""
Application settings.
"""
API_V1_STR: str = "/api/v1"
PROJECT_NAME: str = "WhatsApp Message Analytics Service"
PROJECT_DESCRIPTION: str = "A service that processes WhatsApp messages and provides insights"
PROJECT_VERSION: str = "0.1.0"
# CORS configuration
BACKEND_CORS_ORIGINS: list[str | AnyHttpUrl] = []
@validator("BACKEND_CORS_ORIGINS", pre=True)
def assemble_cors_origins(self, v: str | list[str]) -> list[str] | str:
"""
Parse and validate CORS origins.
"""
if isinstance(v, str) and not v.startswith("["):
return [i.strip() for i in v.split(",")]
elif isinstance(v, list | str):
return v
raise ValueError(v)
# Database configuration
DB_DIR: Path = Path("/app") / "storage" / "db"
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
# WhatsApp API configuration
WHATSAPP_VERIFY_TOKEN: str = "your_verify_token"
# Email configuration
SMTP_TLS: bool = True
SMTP_PORT: int | None = 587
SMTP_HOST: str | None = "smtp.gmail.com"
SMTP_USER: str | None = ""
SMTP_PASSWORD: str | None = ""
EMAILS_FROM_EMAIL: EmailStr | None = "your-email@example.com"
EMAILS_FROM_NAME: str | None = "WhatsApp Message Analytics"
EMAIL_RECIPIENTS: list[EmailStr] = []
# Gemini API configuration
GEMINI_API_KEY: str = "your_gemini_api_key"
# Scheduler configuration
ENABLE_SCHEDULER: bool = True
ANALYSIS_CRON_DAY_OF_WEEK: str = "sun" # Run on Sundays
ANALYSIS_CRON_HOUR: int = 6 # Run at 6 AM
ANALYSIS_CRON_MINUTE: int = 0 # Run at 0 minutes
class Config:
"""
Configuration for the settings class.
"""
case_sensitive = True
env_file = ".env"
settings = Settings()