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

77 lines
1.5 KiB
Python

"""
Pydantic schemas for WhatsApp messages.
"""
from datetime import datetime
from pydantic import BaseModel, Field
class MessageBase(BaseModel):
"""
Base schema for WhatsApp messages.
"""
sender_phone: str = Field(..., description="Phone number of the message sender")
sender_name: str = Field(..., description="Name of the message sender")
message_body: str = Field(..., description="Content of the message")
class MessageCreate(MessageBase):
"""
Schema for creating a new message.
"""
pass
class Message(MessageBase):
"""
Schema for a message.
"""
id: int
timestamp: datetime
analyzed: bool
last_analyzed_at: datetime | None = None
class Config:
"""
Pydantic config for the Message schema.
"""
from_attributes = True
# WhatsApp webhook specific schemas
class WhatsAppTextMessage(BaseModel):
"""
Schema for a WhatsApp text message.
"""
from_: str = Field(..., alias="from")
id: str
timestamp: str
text: dict
type: str
class WhatsAppValue(BaseModel):
"""
Schema for WhatsApp webhook value object.
"""
messaging_product: str
metadata: dict
contacts: list
messages: list[WhatsAppTextMessage]
class WhatsAppWebhookEntry(BaseModel):
"""
Schema for a WhatsApp webhook entry.
"""
id: str
changes: list[dict]
class WhatsAppWebhook(BaseModel):
"""
Schema for a WhatsApp webhook.
"""
object: str
entry: list[WhatsAppWebhookEntry]