omp packages

whatsapp-pi1.1.1

WhatsApp integration extension for Pi

castelloes Published 2 days ago MIT ~2.3K downloads/mo

Untested on omp

This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

WhatsApp logo

WhatsApp-Pi

GitHub npm version

WhatsApp-Pi connects Pi Coding Agent to WhatsApp. Chat with your Pi agent from an allowed contact or group, browse local conversation history, and let Pi send messages or reactions.

Community

Join the WhatsApp-Pi group on WhatsApp to connect with the community, ask questions, and share ideas.

Contents

Features

  • Pair a WhatsApp account with a QR code; credentials persist locally.
  • Choose which contacts and groups can trigger the agent. Manage numbers, aliases, and group JIDs in Pi’s /whatsapp menu.
  • Browse recents and message history, then reply from the TUI.
  • Send WhatsApp messages and reactions with Pi tools. Sending is connection-aware, with stable message IDs, bounded pre-transmission retries, and explicit uncertain outcomes.
  • Process incoming images for vision, transcribe voice notes locally with Whisper.cpp, and download documents for agent access. PDFs get a bounded text preview when readable.
  • Optionally bind an agent instance to one group with --whatsapp-group <jid>.

Requirements

  • Pi Coding Agent and a configured model provider. Use /login in Pi or configure the provider’s API key.
  • Node.js 22.19+ when installing current Pi through npm or developing locally.
  • For voice-note transcription: FFmpeg and a built Whisper.cpp whisper-cli. Other features do not require the Whisper CLI.

Install Pi using the official instructions, then install this extension:

pi install npm:whatsapp-pi

Connect WhatsApp

  1. Start Pi and run /whatsapp.
  2. Choose Connect / Reconnect WhatsApp and scan the QR code if prompted.
  3. Add the contact or group that should be able to trigger Pi under Allowed Contacts or Allowed Groups.
  4. Send a message from that chat. Pi replies in the same conversation.

You can also open Recents, select a conversation, and choose Allow Contact or Allow Group. A group JID looks like 120363012345@g.us; an allowed group’s menu can print its JID.

Windows Terminal 1.22 or later displays a smaller pairing QR code. If your terminal cannot display it, set WHATSAPP_PI_QR_TEXT=1 to use the text QR instead.

After pairing, pi --whatsapp-pi-online starts with automatic connection when saved credentials are available. To bind this Pi instance to one group, pass its JID with --whatsapp-group <jid>.

Troubleshooting the first connection

  • If the QR code is unreadable, try the text QR setting above or enlarge your terminal.
  • If Pi does not reply, check the connection and confirm that the sending contact or group is allowed. Check that your model provider is configured in Pi.
  • Messages sent to yourself may show delivery ticks without triggering Pi. Try an allowed chat from another account.

Voice-note transcription (optional)

The build scripts fetch and compile Whisper.cpp. Run from a local checkout:

# Linux/macOS (requires CMake and a C++ build toolchain)
npm install
./scripts/build-whisper-cli.sh

# Windows PowerShell (requires Git, CMake, and a C++ build toolchain)
npm install
./scripts/build-whisper-cli.ps1

The extension searches vendor/whisper.cpp/build/bin (and the Windows Release subdirectory). Set WHISPER_CLI_PATH to use a CLI at another location. FFmpeg converts WhatsApp audio to 16 kHz mono WAV before transcription. Transcription runs locally without a transcription API key and currently uses Portuguese. On the first voice note, the extension downloads the Whisper base model (about 142 MB) to ~/.pi/agent/extensions/whatsapp-pi/whisper/models/; subsequent transcriptions reuse it.

Permissions and local data

Only incoming messages from allowed contacts and groups are sent to the Pi agent. The /whatsapp Recents view is for browsing history; a message appearing there does not trigger the agent. Sending a message to yourself may show WhatsApp delivery ticks without triggering Pi.

The extension stores WhatsApp credentials, configuration, recents, logs, and media locally under:

~/.pi/agent/extensions/whatsapp-pi/

On first initialization, existing data from ~/.pi/agent/extension/whatsapp-pi/ and ~/.pi/whatsapp-pi/ is copied into the current storage location where files do not already exist. Documents are kept with local media. Keep this directory private because it includes authentication credentials and conversation data.

Pi menu

Run /whatsapp to manage the connection and allowed chats:

  • Connect / Reconnect, Disconnect, and Logoff (Delete Session) manage the linked WhatsApp session.
  • Allowed Contacts and Allowed Groups control which chats can trigger the agent; entries support aliases and history views.
  • Recents lists conversations, opens message history, allows a sender, or starts a manual reply. In message detail, press R to reply.
  • Send Message from a contact, group, or recent conversation sends a one-off message without invoking the agent.

Isolated chats and reply routing

Each allowed contact or group gets a separate background Pi session and working directory. Subsequent messages resume that session, including after a restart. Group members share one session. Removing a chat from the allow list does not delete its session or files.

This is conversation-context isolation, not a security sandbox. Sessions can access the same filesystem, credentials, network, and WhatsApp history. Background sessions load Pi's built-in and WhatsApp tools, but do not automatically load other extensions or their input policies. Allow only trusted chats.

Automatic replies are routed only when the originating conversation can be identified safely. A successful send means WhatsApp accepted it, not that the recipient received or read it. If a send returns an unknown delivery outcome, do not automatically retry: the first send may still arrive.

See the routing reference for session recovery, replay protection, and message handling.

Pi tools

Tool Purpose
send_wa_message Send text to a known recipient, or omit jid for the uniquely owned current conversation. Idle manual calls retain last-conversation/operator fallback.
send_wa_media Explicit local document/image/audio/voice-note/video sending with validation, bounded conversion and optional native quote.
send_reaction React to a retained, unambiguous message key; optional fromMe/participant hints and compound emoji are supported.
list_wa_conversations Read recent conversation summaries, with filters for incoming and allowed chats.
get_wa_conversation_history Read recent messages for a sender number or JID.
check_wa_new_messages Find conversations whose latest message is incoming, optionally since a timestamp, with an optional local scope.
request_wa_history Explicitly request up to 100 older messages for an allowed/bound chat, or read retained request status locally.

The three inbox read tools use the selected local archive projection. They never fetch network history or mark messages as read. Defaults remain 20 items; scope selects a known local profile/account or legacy-unassigned. list_wa_conversations returns available scope IDs. get_wa_conversation_history also accepts an opaque cursor and returns nextCursor for older local pages, including equal-timestamp records.

Sending files and native replies

Use the send_wa_media tool to send a local document, image, audio file, voice note, or video. Provide a path and type, and optionally a recipient JID, caption, or quote:

{"path":"reports/example.pdf","type":"document","jid":"15550000001@s.whatsapp.net","caption":"Requested report"}

Files must be inside the current Pi workspace or the extension's media directory. The limit is 25 MiB; some file types require FFmpeg. Mentioning a path in a message does not upload it. Native quotes require an available, unambiguous message in the current account's chat.

See the media reference for supported formats, conversion, file restrictions, and quote behavior.

Local archive and history

Conversation history is stored locally and remains available while disconnected. Account partitions keep history separate; the Local history scope menu can select a known account or the read-only legacy view. Retention is limited to 1,000 records per conversation, 30 days, and 100 MiB per account partition. View-once content is excluded, and disappearing-message expiry takes precedence.

The inbox tools read local history without fetching messages or marking them as read. To request older messages from WhatsApp, use request_wa_history while connected to an allowed or bound chat; availability depends on WhatsApp and the linked device. Full initial history sync is opt-in with --whatsapp-history-full.

On Windows, archive access depends on inherited Windows ACLs. Restrict them if other local users must not read conversation history. Stop the extension and preserve the archive before attempting recovery or rollback.

See the archive reference for retention, migration, history requests, and rollback limitations.

Run with Docker

Docker Engine and the Docker Compose plugin are required. From a checkout:

docker compose up -d --build
docker attach $(docker compose ps -q whatsapp-pi)

The container runs Pi's interactive terminal. Configure a model provider with /login, or set ANTHROPIC_API_KEY or OPENAI_API_KEY in your host environment before starting Compose. For OAuth logins that redirect to localhost, copy the full redirect URL from the browser and paste it into Pi's login prompt; the callback server runs inside the container. Keep that URL private. To pass another provider's environment variable, add it to the environment list in compose.yaml and recreate the container.

In Pi, run /whatsapp, connect and scan the QR code, then add the contacts or groups allowed to trigger the agent. The startup flag reconnects automatically on subsequent starts after pairing. Detach without stopping Pi using Docker's default Ctrl-p, Ctrl-q sequence; reattach using the docker attach command above. Use docker compose stop and docker compose start to stop and restart it.

The pi-data volume contains Pi settings, provider credentials, WhatsApp authentication, conversation data, and media. The workspace volume is the agent's working directory. Both persist when the container is recreated; protect them as sensitive data and avoid docker compose down --volumes unless you intend to delete them. Do not run multiple instances against the same Pi data volume. Pi can read and modify the workspace, so allow only trusted chats and mount only files the agent should access.

The Compose file also runs Portainer CE for container management. Open https://localhost:9444 after the first start and create the administrator account. Portainer mounts the Docker socket and therefore has administrator-level access to Docker; it is bound to localhost only.

The image uses Ubuntu 24.04, Node.js 22, Pi 1.5.2 and pi-web-access 0.48.0. It installs the published extension with pi install npm:whatsapp-pi; rebuilding does not include unpublished checkout changes. To update the extension later, run docker compose exec whatsapp-pi pi update npm:whatsapp-pi and restart the service. The startup script restores the pinned pi-web-access version if the persisted installation differs. FFmpeg and a static whisper-cli build are included; the Whisper model (~142 MB) downloads on the first audio message and is stored in the pi-data volume. The WhatsApp service publishes no inbound ports; the container needs outbound access to WhatsApp and the model provider.

Railway

Deploy the repository using its Dockerfile, without overriding the start command. When started without a terminal, the container runs Pi inside a whatsapp-pi tmux session.

  1. Attach a Railway volume at /home/ubuntu/.pi to persist Pi settings, WhatsApp credentials and conversation data. Railway mounts volumes as root; set RAILWAY_RUN_UID=0 in the service variables so the container can write to it. This runs Pi as root inside the container, so allow only trusted chats and do not expose the terminal publicly.
  2. Set a model provider variable such as ANTHROPIC_API_KEY or OPENAI_API_KEY and redeploy. Keep one instance of the service.
  3. Install the Railway CLI, then run railway login, railway link, and railway ssh --service whatsapp-pi.
  4. In the container, run whatsapp-pi-attach. This attaches with a UTF-8 locale so the QR code displays correctly even if the SSH shell's locale is not UTF-8. Use /whatsapp to pair the account and allow the chats that can trigger Pi.
  5. Detach without stopping Pi with Ctrl-b, then d. Run exit to close the SSH shell; use the same SSH and tmux commands to reconnect.

Railway supports one volume per service; /workspace is not persisted by the volume above. The service needs no public domain or HTTP health check. If it exits, check its deploy logs with railway logs --service whatsapp-pi --latest --lines 100. If the tmux session cannot be found over SSH, check that SSH and the container process use the same user. On an older image without whatsapp-pi-attach, use LC_ALL=C.UTF-8 tmux -u attach -t whatsapp-pi instead.

Run on Ubuntu at login

The optional systemd user service installer requires tmux, systemd, and an installed pi command. From a checkout:

sudo apt install tmux
./scripts/install-whatsapp-pi-service.sh

Useful commands:

tmux attach -t whatsapp-pi
systemctl --user status whatsapp-pi.service
systemctl --user disable --now whatsapp-pi.service

Develop

git clone https://github.com/RaphaCastelloes/whatsapp-pi.git
cd whatsapp-pi
npm install
npm test
npm run lint
npm run typecheck

For a local extension checkout, run pi -e whatsapp-pi.ts. On Windows, ./scripts/launch-pi.ps1 starts the local entry point. Add --verbose to print detailed Baileys and audio timing logs.

License

MIT. See LICENSE.