彼得·斯坦伯格 – WhatsApp 命令行界面:同步、搜索、发送
Wacli – WhatsApp CLI

原始链接: https://github.com/steipete/wacli

## WACLI:WhatsApp 命令行界面 WACLI 是一个基于 whatsmeow 构建的第三方 CLI 工具,提供本地 WhatsApp 消息历史同步、离线搜索以及消息/联系人管理功能。它利用 WhatsApp Web 协议,与 WhatsApp 无关联。 主要功能包括:同步消息(首次认证通过二维码,然后持续同步)、搜索消息历史(包括表情反应和媒体)、发送文本和文件(可覆盖文件名)以及管理群组。 可以通过 Homebrew 或本地构建进行安装。数据默认存储在 `~/.wacli` 目录。 “历史回填”功能尝试检索较早的消息,需要您的主设备在线,但属于尽力而为,可能无法返回完整历史。 WACLI 提供人类可读和 JSON 输出选项,并受到 `whatsapp-cli` 项目的启发。详细设计说明可在 `docs/spec.md` 中找到。

## WhatsApp 命令行界面与自动化问题 (Hacker News 讨论) 一个新的 WhatsApp 命令行界面 (CLI) “Wacli” 已经发布 (github.com/steipete),在 Hacker News 上引发了讨论。虽然它提供了对 WhatsApp 的程序化访问,但对话很快集中在**因违反 WhatsApp 严格政策而导致账号被封禁的风险**上,WhatsApp 严禁未经授权的自动化。 多位评论者,包括一个 WhatsApp 代理平台创始人,警告说,过量或快速发送消息可能会触发封禁,因为 WhatsApp 官方不支持此类自动化。人们担心潜在的滥用行为,以及 Meta 即使通过其官方 API 也会主动阻止一些自动化尝试。 讨论还涉及 Meta 最近为实现互操作性所做的努力(受欧盟法规驱动),以及在这些限制下构建开源解决方案的挑战。有人建议使用 Telegram 和 Matrix 等替代方案,并强调 Matrix 的开源性质和更轻松的机器人集成。然而,人们对 WhatsApp 等封闭平台上的隐私和安全问题仍然担忧。 最终,该讨论强调了自动化需求与避免违反 WhatsApp 服务条款之间的矛盾,许多人建议为自动化任务使用单独的账号。Wacli 的创建者也以 PSPDFKit 和 OpenClaw 而闻名,引发了关于其可信度的争论。
相关文章

原文

WhatsApp CLI built on top of whatsmeow, focused on:

  • Best-effort local sync of message history + continuous capture
  • Fast offline search
  • Sending messages
  • Contact + group management

This is a third-party tool that uses the WhatsApp Web protocol via whatsmeow and is not affiliated with WhatsApp.

Core implementation is in place. See docs/spec.md for the full design notes.

  • Messages: search/list includes display text for reactions, replies, and media types.
  • Send: wacli send file --filename to override the display name.
  • Auth: optional WACLI_DEVICE_LABEL / WACLI_DEVICE_PLATFORM env overrides.

Choose one of the following options.
If you install via Homebrew, you can skip the local build step.

Option A: Install via Homebrew (tap)

  • brew install steipete/tap/wacli
  • go build -tags sqlite_fts5 -o ./dist/wacli ./cmd/wacli

Run (local build only):

Default store directory is ~/.wacli (override with --store DIR).

# 1) Authenticate (shows QR), then bootstrap sync
pnpm wacli auth
# or: ./dist/wacli auth (after pnpm build)

# 2) Keep syncing (never shows QR; requires prior auth)
pnpm wacli sync --follow

# Diagnostics
pnpm wacli doctor

# Search messages
pnpm wacli messages search "meeting"

# Backfill older messages for a chat (best-effort; requires your primary device online)
pnpm wacli history backfill --chat [email protected] --requests 10 --count 50

# Download media for a message (after syncing)
./wacli media download --chat [email protected] --id <message-id>

# Send a message
pnpm wacli send text --to 1234567890 --message "hello"

# Send a file
./wacli send file --to 1234567890 --file ./pic.jpg --caption "hi"
# Or override display name
./wacli send file --to 1234567890 --file /tmp/abc123 --filename report.pdf

# List groups and manage participants
pnpm wacli groups list
pnpm wacli groups rename --jid [email protected] --name "New name"

This project is heavily inspired by (and learns from) the excellent whatsapp-cli by Vicente Reig:

  • wacli auth: interactive login (shows QR code), then immediately performs initial data sync.
  • wacli sync: non-interactive sync loop (never shows QR; errors if not authenticated).
  • Output is human-readable by default; pass --json for machine-readable output.

Defaults to ~/.wacli (override with --store DIR).

  • WACLI_DEVICE_LABEL: set the linked device label (shown in WhatsApp).
  • WACLI_DEVICE_PLATFORM: override the linked device platform (defaults to CHROME if unset or invalid).

Backfilling older history

wacli sync stores whatever WhatsApp Web sends opportunistically. To try to fetch older messages, use on-demand history sync requests to your primary device (your phone).

Important notes:

  • This is best-effort: WhatsApp may not return full history.
  • Your primary device must be online.
  • Requests are per chat (DM or group). wacli uses the oldest locally stored message in that chat as the anchor.
  • Recommended --count is 50 per request.
pnpm wacli history backfill --chat [email protected] --requests 10 --count 50

Backfill all chats (script)

This loops through chats already known in your local DB:

pnpm -s wacli -- --json chats list --limit 100000 \
  | jq -r '.[].JID' \
  | while read -r jid; do
      pnpm -s wacli -- history backfill --chat "$jid" --requests 3 --count 50
    done

See LICENSE.

联系我们 contact @ memedata.com