# WhatsApp Group Tickets Implementation Plan

> **For agentic workers:** Implement task-by-task.

**Goal:** Direct vs Group toggle on New ticket; create WA group; sync chat to ticket.

**Architecture:** Migration on tickets; Baileys `groupCreate` + send to `@g.us`; internal inbound routes by `groupJid`; staff modal picks staff with phones.

**Tech Stack:** Postgres, Fastify, Baileys worker, React modal.

## Global Constraints

- Connected WhatsApp only; max 3 staff; staff must have `users.phone`
- Always new ticket; group subject editable with Silicon Support default
- Fix inbound so group messages do not create fake 1:1 tickets

---

### Task 1: Schema + shared types

- Migration `024_ticket_wa_group.sql`
- Types on `Ticket` / Message display fields as needed

### Task 2: WhatsApp worker create group + send to group

- `POST /group/create` → `{ channelId, subject, phones[] }` → `{ groupJid }`
- `/send` accept group JID or `isGroup`

### Task 3: API create group ticket + inbound routing

- Extend `POST /tickets` with `mode: 'group'`, `staff_user_ids`, `group_subject`
- Internal messages: if `groupJid` match ticket, append there
- Outbound reply uses `wa_group_jid` when set

### Task 4: Frontend modal + ticket UI badge

- Toggle Direct/Group; staff multi-select; subject field
- Show group badge / subject on ticket header

### Task 5: Docs

- CHANGELOG, README, NewKnowledgeBase, TestSprite PRD
