Koleksi devices menyimpan device WhatsApp terdaftar per store. Handler memakai token atau instance untuk resolve device sebelum operasi.
Model
models/mongo_device.go:3 — DeviceStruct:
| Field | BSON key | Tipe | Catatan |
|---|---|---|---|
ID | id | string | Primary key (UUID) |
StoreId | store_id | string | Tenant scope |
AgentID | agent_id | string | ID AI agent (kosong = no bot) |
Idpaket | idpaket | int | ID paket langganan |
Iduser | iduser | string | User ID owner (non-standard naming) |
Token | token | string | Token device — dipakai untuk auth di handler |
Webhook | webhook | string | URL webhook WA gateway |
Status | status | bool | Active flag |
Role | role | string | Role device |
Tenant variants
| Tenant | Model | Struct | Catatan |
|---|---|---|---|
| default | mongo_device.go | DeviceStruct | 9 field |
| admin | mongo_device_admin.go | DeviceStructAdmin | Field tambahan |
| crm | mongo_device_crm.go | DeviceCrmStruct | Field tambahan |
Cara akses di handler
By token
handlers/chat_submit.go:40-43:
filterGetDevice := bson.M{"token": payload.Token}
orderPaket, err := GetDevicebyFilter(filterGetDevice)By instance ID
handlers/chat_callback.go:101-109:
device, err := GetDevice(payload.InstanceID)
// filter: bson.M{"id": deviceId}Field kritis
Token
Dipakai sebagai auth credential di handler send. Frontend mengirim token di payload, handler resolve device via GetDevicebyFilter({"token": token}). Jika tidak ditemukan → error.
AgentID
Menentukan apakah bot dispatch aktif. chat_callback.go:1365:
if device.AgentID == "" {
return nil, errors.New("agent ID kosong")
}Jika AgentID kosong, submitBot return error — pesan masuk tidak dispatch ke chatbot engine.
StoreId
Tenant scope. Dipakai di CS rotator (chat_service.go:36 GetRotator(ctx, storeID, instance)).
Catatan
IduserdanIdpaketmemakai naming non-standard (camelCase, no underscore) — berbeda daristore_idyang snake_caseStatusadalahbool, bukan string — berbeda darichat_inbox.Statusyangint- Tidak ada field
phone/number— device diidentifikasi viaid(instance) atautoken Webhookadalah URL yang dipanggil WA gateway untukcallback_message— tapi routecallback_messageskip auth, jadi webhook URL tidak butuh token
Kembali ke
- Schema Index — daftar semua koleksi
- Auth & JWT — cara
tokendipakai - CS Rotator — cara
store_iddipakai