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

61 lines
1.4 KiB
Python

"""
Messages API endpoints.
"""
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.orm import Session
from app.db.session import get_db
from app.schemas.message import Message
from app.services.message_service import get_all_messages, get_message
router = APIRouter()
@router.get("/", response_model=list[Message])
async def read_messages(
skip: int = 0,
limit: int = 100,
db: Session = Depends(get_db), # noqa: B008
):
"""
Retrieve all messages.
Args:
skip: Number of messages to skip
limit: Maximum number of messages to return
db: Database session
Returns:
List of messages
"""
messages = get_all_messages(db, skip=skip, limit=limit)
return messages
@router.get("/{message_id}", response_model=Message)
async def read_message(
message_id: int,
db: Session = Depends(get_db), # noqa: B008
):
"""
Retrieve a specific message by ID.
Args:
message_id: ID of the message to retrieve
db: Database session
Returns:
The requested message
Raises:
HTTPException: If the message is not found
"""
message = get_message(db, message_id=message_id)
if message is None:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="Message not found",
)
return message