# WhatsRust — Usage Documentation **WhatsApp in pure Rust. One 5 MB binary. 15 MB RAM. No Node.js required.** A single Rust binary that handles the full WhatsApp Web protocol: text, images, audio, video, stickers, reactions, edits, polls, status stories, groups, and chat management. No npm. No Python. No Docker. Just `cargo build` and scan the QR code. ## Install ```bash git clone https://github.com/199-biotechnologies/whatsrust cd whatsrust && cargo run ``` Scan the QR code with your phone. That's it. ```bash # Phone number pairing instead of QR WHATSAPP_PAIR_PHONE="+1234567890" cargo run # With sender allowlist + custom port WHATSAPP_ALLOWED="1234567890" WHATSRUST_PORT=8080 cargo run ``` ## Running modes | Mode | How | |------|-----| | **Daemon** | `cargo run` — REPL with 54 commands | | **CLI** | `whatsrust send 15551234567 "Hello"` — JSON to stdout | | **Library** | `WhatsAppBridge::start(config, tx, cancel)` — embed in your Rust app | | **MCP server** | `whatsrust mcp` — 30 tools for AI agents (Claude Code, etc.) | ## CLI With the daemon running, use `whatsrust` as a one-shot CLI. Every command returns JSON to stdout. ```bash # Messaging whatsrust send 15551234567 "Hello from the CLI" whatsrust image 15551234567 /tmp/photo.jpg "Check this out" whatsrust video 15551234567 /tmp/clip.mp4 whatsrust react 15551234567 MSG_ID "thumbsup" whatsrust poll 15551234567 1 "Lunch?" -- "Pizza" "Sushi" "Tacos" # Status/stories whatsrust status-text 15551234567 "Hello world" whatsrust status-image 15551234567 /tmp/photo.jpg # Chat management whatsrust pin-chat 15551234567 whatsrust mute-chat 15551234567 whatsrust archive-chat 15551234567 whatsrust mark-read 15551234567 whatsrust delete-chat 15551234567 # Groups whatsrust groups whatsrust group-info 120363012345678901@g.us whatsrust group-create "My Group" 15551234567 15559876543 ``` Output (all CLI commands): ```json {"ok": true, "id": "3EB0A1B2C3D4E5F6"} ``` ## REST API 54 REST endpoints on `localhost:7270`. JSON in, JSON out. ### Messaging | Endpoint | Body | |----------|------| | `POST /api/send` | `{jid, text, mentions?, schedule_at?}` | | `POST /api/reply` | `{jid, id, sender, text}` | | `POST /api/edit` | `{jid, id, text}` | | `POST /api/react` | `{jid, id, emoji}` | | `POST /api/revoke` | `{jid, id}` | | `POST /api/image` | `{jid, data, mime?, caption?}` | | `POST /api/video` | `{jid, data, mime?, caption?}` | | `POST /api/audio` | `{jid, data}` | | `POST /api/poll` | `{jid, question, options, selectable_count}` | | `POST /api/forward` | `{jid, msg_id}` | ### Status/stories | Endpoint | Body | |----------|------| | `POST /api/status-text` | `{recipients, text, background_argb?, font?}` | | `POST /api/status-image` | `{recipients, data, caption?}` | | `POST /api/status-video` | `{recipients, data, caption?}` | | `POST /api/status-revoke` | `{recipients, message_id}` | ### Chat management | Endpoint | Body | |----------|------| | `POST /api/pin-chat` | `{jid}` | | `POST /api/mute-chat` | `{jid}` | | `POST /api/archive-chat` | `{jid}` | | `POST /api/mark-read` | `{jid}` | | `POST /api/delete-chat` | `{jid}` | | `POST /api/delete-for-me` | `{jid, id}` | | `POST /api/star` | `{jid, id}` | Also available: SSE streaming (`GET /api/events`), groups endpoints, presence, health check, and QR. Async sends return `{ok, job_id}`. Add `?sync=true` to wait for the WhatsApp message ID. ## MCP server for AI agents Run `whatsrust mcp` to start a Model Context Protocol server with 30 tools over JSON-RPC stdio. Connect it to Claude Code, Cursor, or any MCP-compatible AI agent; the agent can send messages, manage groups, post stories, and handle chat operations through WhatsApp. Works out of the box with Claude Code — add it to your MCP config. ## Use as a library ```rust use whatsrust::bridge::{BridgeConfig, WhatsAppBridge, WhatsAppInbound}; use tokio::sync::mpsc; use tokio_util::sync::CancellationToken; let (inbound_tx, mut inbound_rx) = mpsc::channel::(256); let cancel = CancellationToken::new(); let bridge = WhatsAppBridge::start( BridgeConfig { db_path: "whatsapp.db".into(), health_port: 8080, ..Default::default() }, inbound_tx, cancel.clone(), ); // Send bridge.send_message_with_id("1234567890", "Hello from Rust").await?; // Receive while let Some(msg) = inbound_rx.recv().await { println!("{}: {}", msg.sender, msg.content.display_text()); } ``` Inbound messages arrive as `WhatsAppInbound` with sender, JID, message ID, reply context, `MessageFlags` (forwarded, view-once), and typed content. Media arrives as raw bytes — no second download step. ## Configuration | Variable | Default | What it does | |----------|---------|-------------| | `WHATSAPP_PAIR_PHONE` | *(QR mode)* | Phone number for pair-code linking | | `WHATSAPP_ALLOWED` | *(everyone)* | Comma-separated sender allowlist | | `WHATSRUST_PORT` | `7270` | API server port (0 = disabled) | | `WHATSRUST_BIND` | `127.0.0.1` | API bind address | | `WHATSRUST_API_TOKEN` | *(none)* | Bearer token for API auth | | `BACKUP_DIR` | `whatsapp.db.backups` | SQLite backup directory | | `RUST_LOG` | `info` | Log level (`debug` for protocol) | ## Features overview - **Message types:** text, image, audio/voice, video, document, sticker, location, contact card, reaction (add/remove), edit, revoke, reply/quote, forward, view-once (image/video), poll (create + encrypted vote decryption), status/story (text/image/video/revoke). - **Chat management (12 operations):** pin/unpin, mute/unmute, archive/unarchive, mark read/unread, delete chat, delete message for me, star/unstar. - **Group management:** list groups, get info, create, rename, set description, add/remove/promote/demote participants, invite links. - **Status/story posting:** text stories with custom background colors and fonts; image and video stories; revoke; privacy controls (contacts, allowlist, denylist). - **Reliability:** crash-safe SQLite outbound queue (messages survive restarts), deduplicated inbound processing, per-message exponential backoff, graduated reconnect backoff with jitter, graceful shutdown (SIGINT/SIGTERM), single-instance guard, SQLite backups. - **Anti-ban behavior:** read receipt batching, flush-before-reply, recording indicator before voice notes, configurable send pacing with randomized jitter, auto presence management. ## License MIT.