# Task 018 — Reply Classification

## Objective

Classify inbound email replies using OpenAI and drive lead/inbox workflows from labels.

## Scope

- Classification service calling OpenAI with `OPENAI_API_KEY`
- Run on new inbound messages (post IMAP sync)
- Store labels on `email_messages.classification`
- UI badges in inbox; suggest create lead / mark interested
- Fire `N8N_WEBHOOK_EMAIL_REPLY` with classification payload

**Out of scope:** Full insights dashboard (Task 021).

## Requirements

1. Server-only API calls; truncate long bodies.
2. Human override of classification in UI.
3. Graceful degradation when API key missing.

## Files to create or modify

| Path | Action |
|------|--------|
| `src/services/classification.service.ts` | Create |
| Inbox UI components | Show labels |
| `docs/08-ai-classification.md` | Implementation notes |
| `docs/09-n8n-integration.md` | Reply payload |
| `docs/16-changelog.md` | Entry |

## Acceptance criteria

- [ ] Sample replies classified into defined labels
- [ ] Override persists on message
- [ ] n8n webhook sent when configured

## Documentation updates required

- `docs/08-ai-classification.md`
- `docs/09-n8n-integration.md`
- `docs/16-changelog.md`
