@anura-gate/watcher-whatsapp
v0.6.0
Published
GATE Watcher — Self-hosted daemon for WhatsApp Web integration. Credentials never leave your machine.
Maintainers
Readme
GATE Watcher — WhatsApp Web
Self-hosted daemon that connects to WhatsApp Web and pushes all message events to GATE cloud for security processing. Your WhatsApp session tokens never leave your machine.
How it works
Your Machine (Watcher) GATE Cloud
┌─────────────────────┐ ┌──────────────────┐
│ WhatsApp Web session │───────>│ Security pipeline │
│ (tokens stay HERE) │<───────│ (redact, policy, │
│ │ poll │ audit, forward) │
└─────────────────────┘ └──────────────────┘Quick Start (CLI)
The fastest way — runs standalone with QR in your terminal.
cd watcher
npm install
# Create .env (or pass env vars directly)
cp .env.example .env
# Fill in GATE_URL, GATE_KEY, GATE_INTEGRATION_ID
npm startScan the QR code with your phone. Done.
Embed in Your App (SDK)
For production use — import the class, handle the QR however you want.
npm install @anura-gate/watcher-whatsappconst { GateWatcher } = require("@anura-gate/watcher-whatsapp");
const watcher = new GateWatcher({
gateUrl: "https://your-gate.vercel.app",
gateKey: "gk-xxx",
integrationId: "int_xxx",
});
// Render QR however you want — web page, API response, email, etc.
watcher.on("qr", (qr) => {
// Example: send to frontend via WebSocket
io.emit("whatsapp-qr", qr);
});
watcher.on("ready", () => {
console.log("WhatsApp connected!");
});
// Every incoming message after GATE security processing
watcher.on("message", (msg, result) => {
console.log(`From: ${msg.from}, Text: ${msg.body}`);
console.log(`Security actions: ${result.securityActions}`);
console.log(`Blocked: ${result.blocked}`);
});
// Outbound actions executed by the watcher
watcher.on("action_result", ({ action, success, error }) => {
console.log(`${action}: ${success ? "done" : error}`);
});
await watcher.start();
// Later...
await watcher.stop();SDK Events
| Event | Args | Description |
|---|---|---|
| qr | (qrString) | QR code string — render it however you want |
| authenticated | — | WhatsApp session authenticated |
| ready | — | Client ready, heartbeat + polling started |
| message | (msg, result) | Incoming message processed by GATE |
| message_sent | (msg, result) | Outgoing message processed by GATE |
| action | (action) | Outbound action received from queue |
| action_result | ({ actionId, action, success, result, error }) | Outbound action completed |
| gate_error | ({ path, status, error }) | GATE API call failed |
| limit_reached | (type) | Plan limit hit (e.g. "watcher_agents") |
| disconnected | (reason) | WhatsApp disconnected |
| stopped | — | Watcher fully shut down |
SDK Options
| Option | Required | Default | Description |
|---|---|---|---|
| gateUrl | Yes | — | GATE cloud URL |
| gateKey | Yes | — | Virtual key (gk-xxx) |
| integrationId | Yes | — | Integration ID (int_xxx) |
| authDir | No | ./.wwebjs_auth | Path to store WhatsApp session |
| heartbeatInterval | No | 30000 | ms between heartbeats |
| pollInterval | No | 3000 | ms between outbound polls |
| puppeteer | No | { headless: true } | Puppeteer launch options |
Advanced: Access whatsapp-web.js directly
const client = watcher.getWhatsAppClient();
const chats = await client.getChats();Setup
- Go to GATE Dashboard → Integrations → Add Integration
- Select WhatsApp Web, copy the Integration ID
- Copy your Virtual Key from the Keys page
- Set the three env vars and run
Security model
- WhatsApp session tokens stored in
.wwebjs_auth/on YOUR machine - GATE cloud never sees or stores your credentials
- All message content passes through GATE's security pipeline
- Billing, limits, and security enforced server-side
