wa-bot-notif
Service notifikasi WhatsApp, Go + whatsmeow.
Overview
Service notifikasi WhatsApp yang dibangun pakai Go dan whatsmeow. Isinya HTTP API kecil untuk kirim pesan, cek kontak, dan health check.
API
| Method | Path | Auth | Deskripsi |
|---|---|---|---|
POST | /send | Bearer | Kirim pesan WhatsApp |
GET | /contacts | Bearer | List kontak yang sudah di-sync |
GET | /messages | Bearer | Cache pesan terbaru (runtime memory) |
GET | /healthz | - | Selalu return 200 OK |
GET | /readyz | - | 200 saat WA terhubung, 503 kalau tidak |
POST /send
Request body:
{ "message": "hello", "userId": "628xxx", "groupId": "[email protected]" }
Urutan prioritas target: userId → groupId → fallback ke env GROUP_JID.
Response:
{ "success": true, "sent_to": "<jid>", "timestamp": "<RFC3339>" }
Config
| Variabel | Default | Wajib | Deskripsi |
|---|---|---|---|
AUTH_TOKEN | - | ✅ | Bearer token untuk semua endpoint yang butuh auth |
PORT | 5000 | - | Port listen HTTP (1-65535) |
GROUP_JID | - | - | Target kirim default kalau request tidak menyertakan userId/groupId |
AUTH_DB_DSN | file:auth.db?_foreign_keys=on | - | DSN SQLite untuk sesi WhatsApp |
LOGS_DB_DSN | file:logs.db?_foreign_keys=on | - | DSN SQLite untuk audit log |
LOG_LEVEL | info | - | Level Zerolog: trace, debug, info, warn, error |
Copy
.env.examplejadi.env, lalu isiAUTH_TOKENdanGROUP_JIDsebelum run pertama kali.
Jalan di Lokal
Prasyarat
- Go 1.25+
- CGO toolchain
- SQLite dev headers
- macOS: Xcode Command Line Tools
- Debian/Ubuntu:
build-essential libsqlite3-dev
Menjalankan service
GOTOOLCHAIN=auto go run ./cmd/api
Cek saat development
GOTOOLCHAIN=auto go test ./...
GOTOOLCHAIN=auto go vet ./...
GOTOOLCHAIN=auto gofmt -l .
Docker
cp .env.example .env
# isi AUTH_TOKEN
docker compose -f deploy/docker-compose.yml up --build -d
docker compose -f deploy/docker-compose.yml logs -f api
File SQLite-nya disimpan persisten lewat Docker volume wa_bot_notif_data.
Deployment shared-network
Di deployment shared-network, service-nya bisa diakses di http://wa-bot-notif-api:5000 lewat network homelab_integration:
docker network create homelab_integration
Setelah itu, set INTEGRATION_NETWORK=homelab_integration di .env.
Struktur Project
.
├── cmd/api/ — entry point
├── internal/
│ ├── config/ — env config loading + validation
│ ├── httpapi/ — HTTP handlers
│ ├── storage/ — SQLite audit log store
│ └── wa/ — WhatsApp connection manager
├── deploy/ — Docker Compose
├── docs/ai/ — AI agent guidance and planning docs
├── Dockerfile
└── go.mod
Bacaan Lanjutan
Dokumentasi AI
AGENTS.md: entrypoint agentdocs/ai/README.md: index lengkap dokumentasi AI
Deployment
docs/deploy.md: runbook deployment lengkap (lokal, Docker, homelab, WireGuard)
Ditulis ulang dari TypeScript/Bun ke Go
Versi pertamanya TypeScript di atas Bun. Yang jalan sekarang adalah rewrite
penuh ke Go pakai whatsmeow, dan file lamanya dihapus, bukan dibiarkan
nongkrong di sebelah yang baru.
Ada beberapa hal yang sekalian di-fix waktu rewrite itu, bukan cuma dipindah bahasanya:
- Error yang ditelan diam-diam. Pola
_ = ...dihttpapi/server.gomembuang nilai error tanpa dicek. Sekarang semuanya di-handle. - Perbandingan token yang bocor lewat timing. Bearer auth pakai
crypto/subtle.ConstantTimeCompare, bukan==. Perbandingan string biasa berhenti di karakter pertama yang beda, jadi lama-tidaknya jawaban keluar ikut memberi tahu seberapa banyak tebakan yang sudah benar. - Index yang belum ada.
logs.timestampdanunauthorized_logs.ipbesertatimestamp-nya sekarang di-index. - Log yang tumbuh terus. Storage log-nya dikasih retensi 30 hari lewat goroutine sendiri.
Structured logging-nya pakai zerolog, menggantikan log bawaan.