iMessage
通过 imsg(stdio 上的 JSON-RPC)接入 iMessage:安装、配置与 chat_id 路由
状态:外部 CLI 集成。Gateway 会拉起 imsg rpc(stdio 上的 JSON-RPC)。
新手快速配置
1. 确保这台 Mac 的 Messages 已登录。
2. 安装 imsg:
- brew install steipete/tap/imsg
3. 在 OpenClaw 里配置 channels.imessage.cliPath 与 channels.imessage.dbPath。
4. 启动 gateway,并批准 macOS 弹窗(Automation + Full Disk Access)。
最小配置:
{
channels: {
imessage: {
enabled: true,
cliPath: "/usr/local/bin/imsg",
dbPath: "/Users/<you>/Library/Messages/chat.db",
},
},
}它是什么
- 基于 macOS 上的 imsg 提供 iMessage 通道能力。
- 确定性路由:回复始终回到 iMessage。
- 私信折叠到 agent 的主会话;群聊隔离为 ''agent:''。
- 如果某个多参与者线程却以 is_group=false 的形式出现,你仍然可以通过 channels.imessage.groups 按 channels.imessage.groups 把它当作群线程隔离(见下文 "类群线程")。
配置写回(Config writes)
默认允许 iMessage 把由 /config set|unset 触发的更新写回配置文件(需要 commands.config: true)。
禁用:
{
channels: { imessage: { configWrites: false } },
}依赖条件
- macOS 且 Messages 已登录。
- 给 OpenClaw 与 imsg 授予 Full Disk Access(读取 Messages DB)。
- 发送消息时需要 Automation 权限弹窗。
- channels.imessage.cliPath 可以指向任意"stdin/stdout 代理命令"(例如 wrapper 脚本:通过 SSH 去另一台 Mac 上运行 imsg rpc)。
设置(快速路径)
1. 确保 Messages 已登录。
2. 配置 iMessage 并启动 gateway。
#
使用独立的 bot macOS 用户(隔离身份)
如果你希望 bot 用 独立的 iMessage 身份 发送(并保持你的个人 Messages 干净),可以使用独立 Apple ID + 独立 macOS 用户:
1. 创建独立 Apple ID(例如 [email protected])。
- Apple 可能需要手机号用于验证/2FA。
2. 创建一个 macOS 用户(例如 openclawhome),并登录该用户。
3. 在该用户下打开 Messages,并使用 bot Apple ID 登录 iMessage。
4. 开启 Remote Login(System Settings → General → Sharing → Remote Login)。
5. 安装 imsg:
- brew install steipete/tap/imsg
6. 配置 SSH,让 ''ssh '' 能免密成功。
7. 把 channels.imessage.accounts.bot.cliPath 指向一个 SSH wrapper,在 bot 用户身份下运行 imsg。
首次运行提示:发送/接收可能需要在 bot 用户 下批准 GUI 权限(Automation + Full Disk Access)。如果 imsg rpc 看起来卡住或直接退出,请切到该用户(可用屏幕共享),先跑一次 imsg chats --limit 1 / imsg send ...,批准弹窗后再重试。
示例 wrapper(记得 ''chmod +x'',并把 '''' 替换为你的用户名):
#!/usr/bin/env bash set -euo pipefail exec /usr/bin/ssh -o BatchMode=yes -o ConnectTimeout=5 -T '<bot-macos-user>'@localhost \ "/usr/local/bin/imsg" "$@"
示例配置:
{
channels: {
imessage: {
enabled: true,
accounts: {
bot: {
name: "Bot",
enabled: true,
cliPath: "/path/to/imsg-bot",
dbPath: "/Users/<bot-macos-user>/Library/Messages/chat.db",
},
},
},
},
}单账号场景可用平铺字段(channels.imessage.cliPath、channels.imessage.dbPath),不必写 accounts。
#
远程/SSH 方案(可选)
如果你想把 iMessage 放在另一台 Mac 上,让 channels.imessage.cliPath 指向一个通过 SSH 在远端运行 imsg 的 wrapper。OpenClaw 只需要 stdio 即可。
示例 wrapper:
#!/usr/bin/env bash exec ssh -T gateway-host imsg "$@"
远程附件: 当 cliPath 指向远端主机时,Messages 数据库中的附件路径是在远端机器上的本地路径。你可以设置 channels.imessage.remoteHost 让 OpenClaw 自动通过 SCP 把附件取回:
{
channels: {
imessage: {
cliPath: "~/imsg-ssh",
remoteHost: "user@gateway-host",
includeAttachments: true,
},
},
}如果不设置 remoteHost,OpenClaw 会尝试解析你的 wrapper 脚本里的 SSH 命令做自动推断,但为可靠起见建议显式配置。
##
Tailscale 连接远端 Mac(示例)
如果 gateway 跑在 Linux 主机/VM 上,但 iMessage 必须跑在 Mac 上,Tailscale 是最简单的桥接:gateway 通过 tailnet 连接到 Mac,通过 SSH 运行 imsg,并用 SCP 拉取附件。
架构:
┌──────────────────────────────┐ SSH (imsg rpc) ┌──────────────────────────┐
│ Gateway host (Linux/VM) │──────────────────────────────────▶│ Mac with Messages + imsg │
│ - openclaw gateway │ SCP (attachments) │ - Messages signed in │
│ - channels.imessage.cliPath │◀──────────────────────────────────│ - Remote Login enabled │
└──────────────────────────────┘ └──────────────────────────┘
▲
│ Tailscale tailnet (hostname or 100.x.y.z)
▼
user@gateway-host配置示例(使用 Tailscale hostname):
{
channels: {
imessage: {
enabled: true,
cliPath: "~/.openclaw/scripts/imsg-ssh",
remoteHost: "[email protected]",
includeAttachments: true,
dbPath: "/Users/bot/Library/Messages/chat.db",
},
},
}wrapper 示例(~/.openclaw/scripts/imsg-ssh):
#!/usr/bin/env bash exec ssh -T [email protected] imsg "$@"
说明:
- 确保 Mac 已登录 Messages,并启用 Remote Login。
- 用 SSH key 确保 ssh [email protected] 免提示可用。
- remoteHost 应与 SSH 目标一致,便于 SCP 拉取附件。
多账号:使用 ''channels.imessage.accounts'' 按账号配置(可选 ''name'')。共享结构见 ''/gateway/configuration''。不要提交 ''~/.openclaw/openclaw.json''(里面通常有 token)。
访问控制(私聊 + 群聊)
私聊:
- 默认:channels.imessage.dmPolicy = "pairing"。
- 未知发送者会收到配对码;批准前消息不会处理(1 小时过期)。
- 批准:
- openclaw pairing list imessage
- ''openclaw pairing approve imessage ''''
- pairing 是 iMessage 私聊默认 token exchange。见 ''Pairing''。
群聊:
- channels.imessage.groupPolicy = open | allowlist | disabled。
- 当 allowlist 时,channels.imessage.groupAllowFrom 控制哪些发送者可触发。
- iMessage 没有原生 mention 元数据,因此 mention gating 依赖 agents.list[].groupChat.mentionPatterns(或 messages.groupChat.mentionPatterns)。
- 多 agent 时可在 agents.list[].groupChat.mentionPatterns 做每个 agent 的覆盖。
工作方式(行为)
- imsg 会流式输出消息事件;gateway 将其归一化到通用 channel envelope。
- 回复始终回到同一个 chat id 或 handle。
类群线程(`is_group=false`)
有些 iMessage 线程可能有多个参与者,但仍以 is_group=false 的形式出现(取决于 Messages 如何存储 chat 标识符)。
如果你在 channels.imessage.groups 里显式配置某个 channels.imessage.groups,OpenClaw 会把该线程当作"群"来处理(会话隔离与群策略适用)。