iMessage
iMessage(旧版:imsg)
Section titled “iMessage(旧版:imsg)”状态:旧版外部 CLI 集成。Gateway(网关) 会生成 imsg rpc 并通过 stdio 上的 JSON-RPC 进行通信(无单独的守护进程/端口)。
新设置的首选 iMessage 路径。
iMessage 私信默认为配对模式。
完整的 iMessage 字段参考。
Install and verify imsg
Terminal window brew install steipete/tap/imsgimsg rpc --helpConfigure OpenClaw
{channels: {imessage: {enabled: true,cliPath: "/usr/local/bin/imsg",dbPath: "/Users//Library/Messages/chat.db”, }, }, }
Start gateway
Terminal window openclaw gatewayApprove first 私信 pairing (default dmPolicy)
Terminal window openclaw pairing list imessageopenclaw pairing approve imessage配对请求将在 1 小时后过期。
要求和权限(macOS)
Section titled “要求和权限(macOS)”
- 必须在运行
imsg 的 Mac 上登录 Messages(信息)。
- 运行 OpenClaw/
imsg 的进程上下文需要“完全磁盘访问权限”(访问 Messages 数据库)。
- 通过 Messages.app 发送消息需要“自动化”权限。
访问控制和路由
Section titled “访问控制和路由”channels.imessage.dmPolicy 控制私信:
pairing(默认)
allowlist
open(要求 allowFrom 包含 "*")
disabled
允许列表字段:channels.imessage.allowFrom。
允许列表条目可以是句柄或聊天目标(chat_id:*,chat_guid:*,chat_identifier:*)。
channels.imessage.groupPolicy 控制群组处理:
allowlist(配置时的默认值)
open
disabled
群组发送者白名单:channels.imessage.groupAllowFrom。
运行时回退:如果 groupAllowFrom 未设置,iMessage 群组发送者检查将在可用时回退到 allowFrom。
运行时说明:如果 channels.imessage 完全缺失,运行时将回退到 groupPolicy="allowlist" 并记录警告(即使设置了 channels.defaults.groupPolicy)。
群组的提及限制:
- iMessage 没有原生的提及元数据
- 提及检测使用正则模式(
agents.list[].groupChat.mentionPatterns,回退 messages.groupChat.mentionPatterns)
- 如果没有配置模式,则无法强制执行提及限制
来自授权发送者的控制命令可以在群组中绕过提及限制。
- 私信使用直接路由;群组使用群组路由。
- 使用默认的
session.dmScope=main,iMessage 私信会合并到代理主会话中。
- 群组会话是隔离的(`agent:
:imessage:group:
`)。
- 回复使用原始渠道/目标元数据路由回 iMessage。
类群组线程行为:
一些多参与者的 iMessage 线程可能会带有 `is_group=false` 到达。如果该 `chat_id` 在 `channels.imessage.groups` 下进行了显式配置,OpenClaw 会将其视为群组流量(群组限制 + 群组会话隔离)。
ACP 会话绑定
Section titled “ACP 会话绑定”
旧版 iMessage 聊天也可以绑定到 ACP 会话。
快速操作流程:
- 在私信或允许的群组聊天中运行
/acp spawn codex --bind here。
- 该同一 iMessage 对话中的未来消息将路由到生成的 ACP 会话。
/new 和 /reset 会就地重置同一个绑定的 ACP 会话。
/acp close 关闭 ACP 会话并移除绑定。
通过顶层的 bindings[] 条目支持配置的持久绑定,包含 type: "acp" 和 match.channel: "imessage"。
match.peer.id 可以使用:
- 规范化的私信句柄,例如
+15555550123 或 [email protected]
- `chat_id:
`(推荐用于稳定的群组绑定)
- `chat_guid:
`
- `chat_identifier:
`
示例:
{ agents: { list: [ { id: "codex", runtime: { type: "acp", acp: { agent: "codex", backend: "acpx", mode: "persistent" }, }, }, ], }, bindings: [ { type: "acp", agentId: "codex", match: { channel: "imessage", accountId: "default", peer: { kind: "group", id: "chat_id:123" }, }, acp: { label: "codex-group" }, }, ],}
有关共享 ACP 绑定行为,请参阅 ACP Agents。
专用机器人 macOS 用户(独立的 iMessage 身份)
使用专用的 Apple ID 和 macOS 用户,以便将机器人流量与您的个人信息资料隔离。
典型流程:
- 创建/登录专用的 macOS 用户。
- 在该用户中使用机器人 Apple ID 登录信息。
- 在该用户中安装
imsg。
- 创建 SSH 包装器,以便 OpenClaw 可以在该用户上下文中运行
imsg。
- 将 `channels.imessage.accounts.
.cliPath和.dbPath` 指向该用户配置文件。
首次运行可能需要在机器人用户会话中进行 GUI 批准(Automation + Full Disk Access)。
通过 Tailscale 远程连接 Mac(示例)
常见拓扑结构:
- 网关运行在 Linux/VM 上- iMessage + `imsg` 运行在您 tailnet 中的 Mac 上- `cliPath` 包装器使用 SSH 运行 `imsg`- `remoteHost` 启用 SCP 附件获取
示例:
{ channels: { imessage: { enabled: true, cliPath: "~/.openclaw/scripts/imsg-ssh", includeAttachments: true, dbPath: "/Users/bot/Library/Messages/chat.db", }, },}
#!/usr/bin/env bash
使用 SSH 密钥,以便 SSH 和 SCP 都是非交互式的。确保首先信任主机密钥(例如 `ssh [email protected]`),以便填充 `known_hosts`。
多账号模式
iMessage 支持在 channels.imessage.accounts 下进行针对每个账号的配置。
每个账号都可以覆盖诸如 cliPath、dbPath、allowFrom、groupPolicy、mediaMaxMb、历史记录设置和附件根目录允许列表等字段。
媒体、分块和传递目标
Section titled “媒体、分块和传递目标”附件和媒体
- 接收附件摄取是可选的:
channels.imessage.includeAttachments
- 当设置
remoteHost 时,可以通过 SCP 获取远程附件路径
- 附件路径必须匹配允许的根目录:
channels.imessage.attachmentRoots (本地)
channels.imessage.remoteAttachmentRoots (远程 SCP 模式)
- 默认根目录模式:
/Users/*/Library/Messages/Attachments
- SCP 使用严格的主机密钥检查 (
StrictHostKeyChecking=yes)
- 发出媒体大小使用
channels.imessage.mediaMaxMb (默认 16 MB)
发出分块
- 文本分块限制:
channels.imessage.textChunkLimit (默认 4000) - 分块模式:channels.imessage.chunkMode - length (默认) - newline (段落优先分割)
地址格式
首选的显式目标:
- `chat_id:123` (推荐用于稳定路由)- `chat_guid:...`- `chat_identifier:...`
也支持 Handle 目标:
- `imessage:+1555...`- `sms:+1555...`
Terminal window imsg chats --limit 20
iMessage 默认允许渠道发起的配置写入(针对 commands.config: true 时的 /config set|unset)。
禁用:
{ channels: { imessage: { configWrites: false, }, },}
imsg not found or RPC unsupported
验证二进制文件和 RPC 支持:
Terminal window imsg rpc --helpopenclaw channels status --probe
如果探测报告不支持 RPC,请更新 `imsg`。
私信 are ignored
检查:
channels.imessage.dmPolicy
channels.imessage.allowFrom
- 配对批准(
openclaw pairing list imessage)
Group messages are ignored
检查:
channels.imessage.groupPolicy
channels.imessage.groupAllowFrom
channels.imessage.groups 允许列表行为
- 提及模式配置(
agents.list[].groupChat.mentionPatterns)
远程附件失败
检查:
channels.imessage.remoteHost
channels.imessage.remoteAttachmentRoots
- 来自 Gateway(网关) 主机的 SSH/SCP 密钥认证
- Gateway(网关) 主机的
~/.ssh/known_hosts 中存在主机密钥
- 运行 Messages 的 Mac 上的远程路径可读性
错过了 macOS 权限提示
在相同的用户/会话上下文中,以交互式 GUI 终端重新运行并批准提示:
Terminal window imsg chats --limit 1imsg send
“test”
确认为运行 OpenClaw/`imsg` 的进程上下文授予了完全磁盘访问权限 + 自动化权限。
配置参考指针
Section titled “配置参考指针”