Panduan Cepat WA Gateway

WA Gateway Quick Start Guide

Pelajari cara menghubungkan aplikasi Anda ke WA Gateway hanya dalam 5 langkah mudah: autentikasi akun, inisialisasi sesi, tautkan nomor WhatsApp, dan kirim pesan via REST API.

Learn how to connect your application to WA Gateway in 5 straightforward steps: authenticate user, initialize session, link WhatsApp number, and dispatch messages via REST API.

Konsep Autentikasi: JWT vs Session API Token Authentication Concepts: JWT vs Session API Token

WA Gateway memisahkan autentikasi menjadi dua jenis token untuk keamanan dan pemisahan wewenang: WA Gateway separates authentication into two distinct token types for maximum security and responsibility separation:

Tipe Token Format Header Digunakan Untuk Used For Masa Berlaku
User / Admin JWT Authorization: Bearer <JWT> Login, profil, buat sesi baru, kelola kuota, webhook per sesi. (/api/auth/*, /api/user/*, /api/admin/*) Login, profile, session creation, quota management, webhook config. (/api/auth/*, /api/user/*, /api/admin/*) 7 hari (7 days)
Session API Token Authorization: Bearer <API_TOKEN> Kirim pesan WhatsApp, kirim media, broadcast, cek nomor, indikator typing. (/api/send, /api/send-media, dll.) Sending text messages, media, broadcast, typing presence, validate number. (/api/send, /api/send-media, etc.) Permanen per sesi (Permanent)
1
Login Akun & Ambil JWT Token Authenticate Account & Obtain JWT Token POST /api/auth/login

Kirimkan kredensial pengguna Anda untuk mendapatkan JWT Bearer Token yang digunakan untuk mengelola sesi dan akun. Send user credentials to receive a JWT Bearer Token required for session lifecycle management and account operations.

cURL
curl -X POST "http://localhost:3000/api/auth/login" \
  -H "Content-Type: application/json" \
  -d '{
    "username": "admin",
    "password": "yourpassword"
  }'
Response (200 OK)
{
  "success": true,
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "user": {
    "id": 1,
    "username": "admin",
    "role": "admin",
    "max_sessions": 5,
    "status": "active",
    "expires_at": null
  }
}
2
Buat Sesi WhatsApp Baru Create a New WhatsApp Session POST /api/user/sessions

Gunakan JWT dari Langkah 1 untuk membuat slot sesi WhatsApp baru. Sistem akan mengembalikan sessionId dan apiToken statis. Sistem secara otomatis memeriksa kuota max_sessions akun Anda. Use the JWT token from Step 1 to create a WhatsApp session slot. The system returns a unique sessionId and a static apiToken. The system automatically enforces your account's max_sessions quota limit.

cURL
curl -X POST "http://localhost:3000/api/user/sessions" \
  -H "Authorization: Bearer <YOUR_JWT_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Customer Support WhatsApp"
  }'
Response (200 OK)
{
  "success": true,
  "sessionId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "apiToken": "4f9d8e7c6b5a43210fedcba9876543210fedcba9876543210fedcba987654321",
  "message": "Session created. Please link your WhatsApp device via QR code or phone pairing code."
}
Simpan apiToken Anda dengan aman! Token 64-karakter ini digunakan untuk seluruh pengiriman pesan via POST /api/send. Save your apiToken securely! This 64-character token will be used to authenticate all message dispatch calls via POST /api/send.
3
Tautkan Perangkat (QR Code atau Pairing Code) Link Device (QR Code or Pairing Code)

Anda dapat menautkan nomor WhatsApp Anda dengan dua metode: memindai QR Code di layar atau meminta Pairing Code 8-digit langsung ke HP Anda. You can link your WhatsApp device via two methods: scanning a QR Code on screen or requesting an 8-digit Pairing Code directly to your phone.

Metode A: Scan QR Code

1. Trigger QR Initialization
curl -X POST "http://localhost:3000/api/user/sessions/<SESSION_ID>/connect" \
  -H "Authorization: Bearer <YOUR_JWT_TOKEN>"
2. Fetch QR Image (Data URL)
curl -X GET "http://localhost:3000/api/user/sessions/<SESSION_ID>/qr" \
  -H "Authorization: Bearer <YOUR_JWT_TOKEN>"

Metode B: 8-Digit Pairing Code

Request Pairing Code
curl -X POST "http://localhost:3000/api/user/sessions/<SESSION_ID>/pair" \
  -H "Authorization: Bearer <YOUR_JWT_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{
    "phoneNumber": "6281234567890"
  }'
Response Pairing Code
{
  "status": "pairing",
  "pairing_code": "AB12-CD34"
}
4
Kirim Pesan WhatsApp Pertama Dispatch First WhatsApp Message POST /api/send

Setelah status sesi berubah menjadi connected, gunakan Session API Token untuk mengirim pesan teks ke penerima WhatsApp. Once the session state is connected, use the Session API Token in the Authorization header to send a message.

cURL
curl -X POST "http://localhost:3000/api/send" \
  -H "Authorization: Bearer <YOUR_SESSION_API_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{
    "to": "628123456789",
    "text": "Halo! Pesan ini dikirim melalui WA Gateway REST API."
  }'
Response (200 OK)
{
  "success": true,
  "message": "Message sent",
  "messageId": "3EB04A1B2C3D4E5F6"
}

Contoh Pengiriman Media (Gambar / Dokumen)

POST /api/send-media
curl -X POST "http://localhost:3000/api/send-media" \
  -H "Authorization: Bearer <YOUR_SESSION_API_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{
    "to": "628123456789",
    "type": "image",
    "url": "https://images.unsplash.com/photo-1579202673506-ca3ce28943ef",
    "caption": "Bukti Pengiriman Invoice #INV-2026-001"
  }'
5
Konfigurasi Webhook (Menerima Pesan Masuk) Configure Webhook (Receive Incoming Messages) PATCH /api/user/sessions/:id/webhook

Atur URL server Anda untuk menerima notifikasi pesan masuk, pembaruan status koneksi, dan tanda terima pesan secara real-time. Anda juga dapat menyertakan beberapa target via chain_urls. Configure your backend URL to receive real-time HTTP POST notifications for incoming messages, connection state transitions, and delivery receipts. You can also specify multiple backup targets using chain_urls.

cURL
curl -X PATCH "http://localhost:3000/api/user/sessions/<SESSION_ID>/webhook" \
  -H "Authorization: Bearer <YOUR_JWT_TOKEN>" \
  -H "Content-Type: application/json" \
  -d '{
    "enabled": true,
    "url": "https://api.yourdomain.com/webhooks/whatsapp",
    "secret": "mySecretWebhookSignatureKey123",
    "chain_urls": [
      "https://backup.yourdomain.com/webhooks/whatsapp"
    ]
  }'
Contoh Payload Webhook Masuk (HTTP POST)
{
  "event": "incoming",
  "sessionId": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "message": {
    "id": "3EB04A1B2C3D4E5F6",
    "from": "628123456789@s.whatsapp.net",
    "fromMe": false,
    "text": "Halo admin, saya ingin menanyakan status pesanan saya.",
    "timestamp": 1788960613,
    "type": "text"
  }
}

Penanganan Error & Best Practice Error Handling & Best Practices

Seluruh error mengembalikan struktur JSON konsisten dengan status HTTP yang tepat: All errors return a consistent JSON structure accompanied by standard HTTP status codes:

Standard Error Response Structure
{
  "error": "Account suspended: Please contact the administrator.",
  "details": "Additional context if available"
}

Status Error Umum:

  • 400 Bad Request: Field mandatory tidak diisi atau nomor tidak terdaftar di WhatsApp.
  • 401 Unauthorized: Header Authorization: Bearer <token> hilang atau token kedaluwarsa.
  • 403 Forbidden: Kuota sesi habis (max_sessions), akun disuspensi admin, atau akun telah kedaluwarsa.
  • 404 Not Found: Sesi atau resource tidak ditemukan.
  • 409 Conflict: Sesi sudah terkoneksi saat mencoba mengambil QR code.

Tips Pencegahan Pemblokiran (Anti-Ban) Anti-Ban Best Practices

  • Gunakan Jeda Pengiriman (Delay): Jangan mengirim pesan beruntun tanpa jeda. Pada fitur broadcast, gunakan minimal delayMs: 3000. Apply Delivery Delays: Never blast messages without pause. In the broadcast API, use at least delayMs: 3000.
  • Pertahankan Anti-Ban Default (antiBan: true): Biarkan gateway menyimulasikan status mengetik (composing) secara alami sebelum transmisi pesan. Keep Anti-Ban Enabled (antiBan: true): Allow the gateway to simulate natural typing indicators (composing) before dispatching.
  • Validasi Nomor Tujuan: Gunakan POST /api/validate-number untuk menyaring nomor mati sebelum melakukan pengiriman massal. Validate Recipient Numbers: Use POST /api/validate-number to filter out inactive numbers before bulk dispatches.
  • Gunakan Auto-Delete Sisi Server: Aktifkan auto_delete_enabled untuk mencegah penumpukan media dan database chat di memori internal HP server Anda. Enable Server-Side Auto-Delete: Turn on auto_delete_enabled to prevent media storage bloat on the server phone.

⚠️ Pemberitahuan Batasan Tanggung Jawab Disclaimer Notice

WA Gateway beroperasi menggunakan Baileys (library pihak ketiga open-source). Penggunaan otomasi akun WhatsApp tunduk pada ketentuan layanan WhatsApp/Meta. Segala bentuk sanksi pembatasan akun atau pemblokiran (ban) bukan merupakan tanggung jawab pengembang perangkat lunak ini. Gunakan secara bijak dan patuhi regulasi telekomunikasi setempat. WA Gateway runs on top of Baileys (an open-source third-party library). Using WhatsApp automation is subject to WhatsApp/Meta's Terms of Service. Any account bans or service restrictions are solely the operator's responsibility and not the software author's. Use responsibly and adhere to telecommunication guidelines.