Device concepts
Device ID vs JID
Two distinct identifiers are used throughout the system:Device ID
User-defined alias or auto-generated UUID
- Used in API requests (
X-Device-Idheader) - Used in URLs (
/devices/{device_id}) - Example:
my-business-account,customer-support
JID (WhatsApp ID)
WhatsApp-assigned identifier
- Format:
[email protected] - Assigned after successful login
- Used for database queries and webhook payloads
Device instance
Each device maintains:- WhatsApp connection - Active WebSocket to WhatsApp servers
- Session storage - SQLite database with encryption keys
- Message history - Chat and message records
- Event handlers - Webhook forwarding, auto-reply, auto-read
- Media storage - Downloaded images, videos, files
Device lifecycle
Create device
Register a new device slot with a custom ID or auto-generated UUID:Initial state:
cURL
disconnectedLogin to WhatsApp
Choose authentication method:Scan QR with WhatsApp mobile app.State transitions:
- QR Code
- Pairing Code
disconnected → connecting → connectedDevice states
| State | Description | Can send messages? |
|---|---|---|
disconnected | Created but not logged in | ❌ |
connecting | Authentication in progress | ❌ |
connected | Logged in and ready | ✅ |
reconnecting | Temporary connection loss | ⚠️ Queued |
logged_out | Session invalidated | ❌ |
Default device behavior
If only one device is registered:X-Device-Idheader is optional- All requests automatically use the single device
- Simplifies single-account deployments
X-Device-Idheader is required- Missing header returns
400 DEVICE_ID_REQUIREDerror - Each device maintains independent state
Device manager
Central orchestrator (src/infrastructure/whatsapp/device_manager.go) handles:
- Device instance lifecycle
- Connection pooling
- Session persistence
- Event distribution
- Database scoping
Implementation reference
Implementation reference
src/infrastructure/whatsapp/device_manager.go (602 lines)Storage isolation
Each device has isolated storage:Next steps
Authentication
Learn about QR code and pairing code login methods
Device scoping
Understand X-Device-Id header and query parameters
Multi-device guide
Best practices for managing multiple accounts
Device API
Complete device management API reference
