D
Engineering

devices

Koleksi devices — device WhatsApp terdaftar. Field id, store_id, agent_id, token, status. Dipakai untuk resolve device di callback dan send.

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:

FieldBSON keyTipeCatatan
IDidstringPrimary key (UUID)
StoreIdstore_idstringTenant scope
AgentIDagent_idstringID AI agent (kosong = no bot)
IdpaketidpaketintID paket langganan
IduseriduserstringUser ID owner (non-standard naming)
TokentokenstringToken device — dipakai untuk auth di handler
WebhookwebhookstringURL webhook WA gateway
StatusstatusboolActive flag
RolerolestringRole device

Tenant variants

TenantModelStructCatatan
defaultmongo_device.goDeviceStruct9 field
adminmongo_device_admin.goDeviceStructAdminField tambahan
crmmongo_device_crm.goDeviceCrmStructField tambahan

Cara akses di handler

By token

handlers/chat_submit.go:40-43:

go
filterGetDevice := bson.M{"token": payload.Token}
orderPaket, err := GetDevicebyFilter(filterGetDevice)

By instance ID

handlers/chat_callback.go:101-109:

go
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:

go
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

  • Iduser dan Idpaket memakai naming non-standard (camelCase, no underscore) — berbeda dari store_id yang snake_case
  • Status adalah bool, bukan string — berbeda dari chat_inbox.Status yang int
  • Tidak ada field phone / number — device diidentifikasi via id (instance) atau token
  • Webhook adalah URL yang dipanggil WA gateway untuk callback_message — tapi route callback_message skip auth, jadi webhook URL tidak butuh token

Kembali ke