- POST /api/whatsapp/webhook handles Meta verification (hub.challenge) - Inbound text messages create tickets via create_ticket() - Auto-reply confirmation sent back via Meta Graph API - WhatsApp messages logged with ticket linkage in whatsapp_log - Added WHATSAPP_PHONE_NUMBER_ID, WHATSAPP_ACCESS_TOKEN, WHATSAPP_VERIFY_TOKEN config - Kept /mock-log debug endpoint for backward compatibility - Graceful degradation: logs message even if ticket/reply fails
26 lines
981 B
Python
26 lines
981 B
Python
"""WhatsApp log model for inbound webhook messages."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
|
|
from sqlalchemy import DateTime, Integer, String, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.core.database import Base
|
|
|
|
|
|
class WhatsAppLog(Base):
|
|
__tablename__ = "whatsapp_log"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
from_number: Mapped[str] = mapped_column(String(50), nullable=False)
|
|
message_text: Mapped[str] = mapped_column(Text, nullable=False)
|
|
wa_message_id: Mapped[str | None] = mapped_column(String(100), nullable=True)
|
|
ticket_id: Mapped[int | None] = mapped_column(Integer, nullable=True)
|
|
ticket_number: Mapped[str | None] = mapped_column(String(30), nullable=True)
|
|
received_at: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<WhatsAppLog {self.id}: from={self.from_number} ticket={self.ticket_number}>"
|