gptme-whatsapp

v0.1.0 WhatsApp integration for gptme agents via whatsapp-web.js packages/gptme-whatsapp View on GitHub

gptme-whatsapp

WhatsApp integration for gptme agents. Enables agents (like Sven) to communicate via WhatsApp using whatsapp-web.js.

Supports both gptme and Claude Code as agent backends.

Architecture

WhatsApp (user's phone)
    ↕
whatsapp-web.js (Node.js bridge)
    ↕  spawns (per message)
gptme -p "<msg>" ...   OR   claude -p "<msg>" ...
    ↕
Response sent back to WhatsApp

Conversation history is maintained per-sender via named conversations (gptme) or --resume (Claude Code).

Setup

Prerequisites

1. Install Node.js dependencies

cd packages/gptme-whatsapp/node
npm install

Or use the Python helper:

pip install -e .
gptme-whatsapp-setup install

2. First run (QR code scan)

cd node
GPTME_AGENT=sven AGENT_WORKSPACE=/home/sven/sven node index.js

A QR code will print in the terminal. Scan it with the WhatsApp phone (Settings > Linked Devices > Link a device). Auth persists in .wwebjs_auth/ — no rescanning needed after.

3. Configure backend and allowed contacts

With gptme (default):

GPTME_AGENT=sven ALLOWED_CONTACTS=447700900000 node index.js

With Claude Code:

# First, generate the system prompt
cd /home/sven/sven
./scripts/build-system-prompt.sh > state/system-prompt.txt

# Then run the bridge
BACKEND=claude-code GPTME_AGENT=sven ALLOWED_CONTACTS=447700900000 node index.js

Phone numbers in international format without +. If not set, all contacts are accepted.

4. Systemd service

Generate a service file:

gptme-whatsapp-setup service \
  --agent sven \
  --workspace /home/sven/sven \
  --contacts 447700900000 \
  --backend claude-code \
  --node-path /home/sven/.nvm/versions/node/v24.13.1/bin \
  > ~/.config/systemd/user/sven-whatsapp.service

systemctl --user daemon-reload
systemctl --user enable --now sven-whatsapp.service

Environment Variables

Variable Default Description
GPTME_AGENT sven Agent name (used in conversation naming)
BACKEND gptme Agent backend: gptme or claude-code
AGENT_WORKSPACE ~/<agent> Path to agent's workspace
ALLOWED_CONTACTS "" (all) Comma-separated phone numbers (no +)
GPTME_CMD gptme Path to gptme binary
CLAUDE_CMD claude Path to claude binary
SYSTEM_PROMPT_FILE <workspace>/state/system-prompt.txt System prompt file for Claude Code backend

How it works

  1. whatsapp-web.js connects to WhatsApp Web protocol (no official API needed)
  2. On incoming message from an allowed contact, spawns the configured backend:
    • gptme: gptme -p "<message>" --name "whatsapp-sven-<sender>" --non-interactive -y
    • Claude Code: claude -p "<message>" --output-format text --resume "whatsapp-sven-<sender>"
  3. The conversation name/resume ID persists history between messages
  4. Response is sent back via WhatsApp

Notes