D
Engineering

devices

Schema collection devices dan admin_devices — perangkat WhatsApp dengan token dan webhook.

Collection: devices

Menyimpan data perangkat WhatsApp yang terhubung ke engine.

Struktur Dokumen

json
{
  "_id": "uuid-string",
  "store_id": "uuid-string",
  "name": "Device 1",
  "sender": "+6281234567890",
  "token": "random-token-string",
  "webhook_url": "https://backend.dazo.id/webhook",
  "status": "active",
  "created_at": "2026-01-01T00:00:00.000000Z",
  "updated_at": "2026-06-25T14:30:00.000000Z"
}

Field

FieldTypeDeskripsi
_idstring (UUID)Primary key
store_idstring (UUID)Foreign key ke stores._id
namestringNama device
senderstringNomor WhatsApp (format +62)
tokenstringToken untuk autentikasi ke engine
webhook_urlstringURL webhook untuk receive message
statusstringStatus: active, inactive, disconnected

Collection: admin_devices

Menyimpan data device yang dikelola oleh admin (bukan store owner).

Struktur Dokumen

json
{
  "_id": "uuid-string",
  "name": "Admin Device 1",
  "sender": "+6281234567890",
  "token": "random-token-string",
  "webhook_url": "https://backend.dazo.id/webhook",
  "status": "active",
  "created_by": "admin@dazo.id",
  "created_at": "2026-01-01T00:00:00.000000Z",
  "updated_at": "2026-06-25T14:30:00.000000Z"
}

Field

FieldTypeDeskripsi
_idstring (UUID)Primary key
namestringNama device
senderstringNomor WhatsApp
tokenstringToken untuk autentikasi
webhook_urlstringURL webhook
statusstringStatus: active, inactive, disconnected
created_bystringEmail admin yang membuat

Provisioning Flow

  1. Admin buat device → DeviceController::store()
  2. Generate random token
  3. Simpan ke MongoDB (admin_devices)
  4. cURL POST ke engine WhatsApp: {$url_engine}/new
  5. Engine spawn instance WhatsApp baru
  6. Engine mengembalikan QR code untuk pairing

Query Umum

javascript
// Device aktif
db.devices.find({ status: "active" })

// Device by store
db.devices.find({ store_id: "uuid-store" })

// Admin device aktif
db.admin_devices.find({ status: "active" })