Bot WhatsApp dengan arsitektur hibrida: Golang menangani socket WhatsApp secara langsung (via whatsmeow), sedangkan logic fitur diproses menggunakan JavaScript melalui engine github.com/dop251/goja.
Tidak ada HTTP/REST API antara Go dan JS — semua eksekusi terjadi secara native di dalam satu proses Go.
┌─────────────────────────────────────────────────────┐
│ GojaBot (1 Binary Go) │
│ │
│ ┌──────────────┐ ┌──────────────────────────┐ │
│ │ WhatsApp │ │ Goja JS Engine │ │
│ │ Socket │─────▶│ │ │
│ │ (whatsmeow) │ │ handler.js │ │
│ │ │ │ ├── serialize() │ │
│ │ • Connect │ │ ├── loadPlugins() │ │
│ │ • Receive │◀─────│ └── handleMessage() │ │
│ │ • Send │ │ │ │
│ │ • Upload │ │ plugins/ │ │
│ │ • Download │ │ ├── ping.js │ │
│ │ │ │ ├── menu.js │ │
│ └──────────────┘ │ ├── sticker.js │ │
│ │ └── owner.js │ │
│ ┌──────────────┐ └──────────────────────────┘ │
│ │ SQLite │ │
│ │ (Sessions) │ ┌──────────────────────────┐ │
│ └──────────────┘ │ MongoDB │ │
│ │ • Local: group metadata │ │
│ ┌──────────────┐ │ • Cloud: user data │ │
│ │ AntiSpam │ └──────────────────────────┘ │
│ │ (sync.Map) │ │
│ └──────────────┘ │
└─────────────────────────────────────────────────────┘
- Go menerima pesan masuk dari WhatsApp socket (whatsmeow event handler)
- Go memeriksa anti-spam (hanya 1 bot merespon jika ada multiple instances)
- Go mengkonversi
events.Message→map[string]interface{}(serialize) - Goja menerima object JS yang sudah di-serialize
- JS
handler.js→serialize()→ enrichment (prefix, command parsing, owner check) - JS mencari plugin yang cocok di registry (no switch-case)
- JS plugin memanggil
conn.sendMessage(),conn.sendSticker(), dll - Go mengeksekusi whatsmeow API (upload, send, download) dan return hasilnya
- Seluruh proses terjadi di shared memory — zero serialization overhead
┌─────────────────┐ shared memory ┌─────────────────┐
│ Go Runtime │◀──────────────────▶│ Goja JS VM │
│ │ │ │
│ whatsmeow. │ conn.sendMessage │ handler.js │
│ Client. │◀──────────────────│ plugin.handler() │
│ SendMessage() │ │ │
│ │ conn.download │ │
│ whatsmeow. │ Media() │ │
│ Client. │◀──────────────────│ sticker.js │
│ Download() │ → ArrayBuffer │ │
│ │──────────────────▶│ │
└─────────────────┘ └─────────────────┘
Key points:
goja.Runtime.Set("conn", obj)→ membuat objectconnaccessible di JS- Go function di-wrap sebagai
func(goja.FunctionCall) goja.Value - JS
ArrayBuffer↔ Go[]byte— transfer langsung via shared memory _rawMsgmenyimpan reference keevents.MessageGo struct di JS object- Ketika JS memanggil
conn.downloadMedia(msg._rawMsg), Goja mengembalikan reference Go asli
gojabot/
├── main.go # Entry point, pairing code, whatsmeow init
├── goja_engine.go # Bridge Go↔Goja: bindings, serialize, CommonJS
├── antispam.go # Anti-spam multi-bot (sync.Map)
├── jadibot.go # Sub-bot manager (session persistence)
├── mongodb.go # MongoDB dual-DB manager (local + cloud)
├── .env # Konfigurasi
├── js/
│ ├── handler.js # Serialize + plugin loader + router
│ └── plugins/
│ ├── ping.js # Cek kecepatan respon
│ ├── menu.js # Daftar fitur (auto-generated)
│ ├── sticker.js # Image/video → stiker
│ └── owner.js # Kontak owner (vCard)
└── README.md
- Go 1.21+
- ImageMagick (
apt install imagemagick) - MongoDB (opsional, untuk fitur database)
# Clone / masuk ke direktoricd /root/gojabot
# Build binary
go build -o gojabot .# Edit konfigurasi
nano .env
# Jalankan
./gojabotPada startup pertama, bot akan menampilkan pairing code di terminal:
══════════════════════════════════════
🔑 PAIRING CODE: ABCD-EFGH
══════════════════════════════════════
Masukkan kode di atas pada WhatsApp:
Settings → Linked Devices → Link a Device
══════════════════════════════════════
BOT_NAME=GojaBotBOT_PREFIX=.OWNER_NUMBER=6288294961496,6281953678883,6289518562932OWNER_NAME=OwnerANTISPAM_TTL_MS=5000BOT_INSTANCE_ID=bot-mainMONGO_LOCAL_URI=mongodb://localhost:27017MONGO_LOCAL_DB=gojabot_localMONGO_CLOUD_URI=your_cloud_uriMONGO_CLOUD_DB=gojabot_cloudBuat file .js di folder js/plugins/. Format:
'use strict';module.exports={name: 'nama_plugin',command: ['cmd1','cmd2'],// Array command yang trigger plugin inicategory: 'tools',// Kategori untuk menudescription: 'Deskripsi plugin',isOwner: false,// true = hanya ownerisGroup: false,// true = hanya di grupisPrivate: false,// true = hanya di private chathandler: function(msg,{ conn, db, plugins, args, text, prefix }){// msg.from → JID chat (grup atau private)// msg.sender → JID pengirim// msg.pushName → Nama pengirim// msg.body → Isi pesan// msg.command → Nama command (tanpa prefix)// msg.args → Array argumen// msg.text → Teks setelah command// msg.isGroup → Boolean// msg.isOwner → Boolean// msg.quoted → Quoted message object atau null// msg.messageType → 'conversation', 'image', 'video', dll// msg._rawMsg → Reference ke raw Go event (untuk downloadMedia)conn.sendMessage(msg.from,'Hello from plugin!');},};| Fungsi | Deskripsi |
|---|---|
conn.sendMessage(jid, text) | Kirim pesan teks |
conn.reply(jid, text, quotedID) | Reply ke pesan |
conn.sendImage(jid, bytes, caption) | Kirim gambar |
conn.sendSticker(jid, bytes) | Kirim stiker (auto-convert WebP) |
conn.sendContact(jid, name, phone) | Kirim vCard |
conn.downloadMedia(rawMsg) | Download media → ArrayBuffer |
db.getGroup(jid) | Ambil data grup dari MongoDB |
db.upsertGroup(jid, data) | Update/insert data grup |
db.getUser(jid) | Ambil data user dari MongoDB |
db.upsertUser(jid, data) | Update/insert data user |
db.isUserBanned(jid) | Cek status ban user |
log(level, message) | Log ke terminal Go |
Sistem JadiBot memungkinkan user lain "meminjamkan" nomor mereka sebagai bot tambahan:
- Setiap jadibot punya
whatsmeow.Client+GojaEnginesendiri - Session tersimpan di SQLite (device keys) + JSON (metadata)
- Auto-restore saat startup
- Anti-spam shared: hanya 1 bot merespon per command
- Menggunakan
sync.Mapuntuk lock-free concurrent access Claim(messageID, botID)→ atomic first-come-first-served- TTL-based auto-cleanup
- Shared antar bot utama dan semua jadibot instances
| Package | Kegunaan |
|---|---|
go.mau.fi/whatsmeow | WhatsApp Web API (socket langsung) |
github.com/dop251/goja | JavaScript engine embedded di Go |
go.mongodb.org/mongo-driver | Native MongoDB driver |
modernc.org/sqlite | Pure Go SQLite (tanpa CGO) |
github.com/joho/godotenv | Load .env configuration |
| ImageMagick (system) | Konversi image → WebP untuk sticker |