# Phase 1: Message Attachments (2026-08-01)

## Goal
Page broadcasts are 80%+ image/video. Previously all `message_text=""` rows lost the actual media URL.

## Changes
1. **Schema** (`chat_messages`):
   - `attachments_json JSON NULL` — full attachment array as JSON
   - `has_attachments TINYINT(1) NOT NULL DEFAULT 0` — quick filter
2. **Poller** (`/opt/adsfb/src/live/chatPoller.ts`):
   - Added `attachments` to Graph API `fields`
   - Extract `m.attachments.data[]` → JSON.stringify → store
3. **Backfill** — re-fetched 451 convs across 14 pages, 1,692 messages with attachments found, 1,568 successfully UPDATEd (124 lost to legacy varchar(64) m_id truncation)

## Results
- **1,568 messages with attachments** in DB (up from 0)
- **By type (mime_type)**:
  - `image/jpeg`: 1,346 (85.8%)
  - `image/png` (stickers): 112 (7.1%)
  - `video/mp4`: 27 (1.7%)
  - `image/WEBP`: 17 (1.1%)
  - `application/pdf`: 6
  - `audio/opus`: 1
- **By page**:
  - SJ88 Studio: 1,118 (71.3%)
  - เฮียหนวด โซล่าเซลล์ ไฟตุ้ม: 382 (24.4%)
  - เฮียหนวด ไฟหัวเสา: 24
  - อื่นๆ: 44

## Sample URLs
Real FB CDN URLs (`scontent.fbkk36-1.fna.fbcdn.net`) with full image data:
- `https://scontent.fbkk36-1.fna.fbcdn.net/v/t1.15752-9/...` (full + preview)
- `https://scontent.fbkk36-1.fna.fbcdn.net/v/t39.1997-6/...` (stickers)

## Use Cases Now Possible
- View actual images in chat history (preview_url)
- Track broadcast quality (image vs text-only)
- Filter "messages with images" for sales lead scoring
- Detect broadcast patterns (image-stuffed conversations)

## Known Limitations
- Only first 100 messages per conversation were checked (most recent)
- Heavy broadcast conversations (>5000 msgs) only have first 100 covered
- Future polls will capture new attachments going forward

## Commit
`c3c0ebe feat(chat): Phase 1 - capture message attachments in chat_poller` (pushed to main)
