
- 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
34 lines
972 B
Python
34 lines
972 B
Python
"""
|
|
SQLAlchemy models for WhatsApp messages.
|
|
"""
|
|
|
|
from sqlalchemy import Boolean, Column, DateTime, Integer, String, Text
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.db.base_class import Base
|
|
|
|
|
|
class Message(Base):
|
|
"""
|
|
Model for storing WhatsApp messages.
|
|
"""
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
|
|
# WhatsApp message details
|
|
sender_phone = Column(String(20), index=True, nullable=False)
|
|
sender_name = Column(String(255), index=True, nullable=False)
|
|
message_body = Column(Text, nullable=False)
|
|
|
|
# Metadata
|
|
timestamp = Column(DateTime, default=func.now(), nullable=False, index=True)
|
|
|
|
# Tracking fields
|
|
analyzed = Column(Boolean, default=False, index=True)
|
|
last_analyzed_at = Column(DateTime, nullable=True)
|
|
|
|
def __repr__(self) -> str:
|
|
"""
|
|
String representation of the message.
|
|
"""
|
|
return f"<Message {self.id}: {self.sender_name} ({self.sender_phone}) at {self.timestamp}>"
|