Community编程与开发github.com

imsg

使用 OpenClaw 智能体的 imsg CLI 实现 iMessage/SMS 私信、群组消息、回复、表情反应、投票、监听以及私有 API 操作。

imsg 是什么?

imsg 是一个针对 macOS Messages.app 的 CLI 工具,能让 AI 智能体(如 OpenClaw 智能体)直接操作用户本地的 iMessage/SMS 账户。它支持查看消息历史、选择正确的私信或群组、发送消息和文件、回复、添加表情反应、投票,以及通过私有 API 实现更高级的功能,如富文本回复、消息效果、编辑/撤回、群组管理(创建、改名、增减成员)等。该技能适用于 macOS 14+ 系统,需要为运行进程授予完全磁盘访问权限以及 Messages.app 和辅助功能权限。对于 Linux 系统,仅支持读取复制的 chat.db 文件,无法执行发送或状态变更等操作。imsg 提供公开的 Messages 自动化(如发送、表情反应、监听)和私有桥接接口(如发送回复、投票、群组管理),开发者应根据所需功能选择最低能力级别的命令,并在执行发送或可见状态变更前确认操作内容。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/clawdbot/clawdbot/tree/main/skills/imsg

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

imsg 是做什么的?

当 OpenClaw 智能体需要通过用户本地的 macOS Messages.app 账户执行操作时,使用 imsg:查看 iMessage/SMS 历史、选择正确的私信或群组、发送消息/文件、回复、添加表情反应、投票,或使用私有 API 的 iMessage 功能。

不要将此技能用于 Telegram、Signal、WhatsApp、Discord、Slack,或用于在当前 OpenClaw 对话中回复(当配置的通道已处理回复时)。

智能体流程

  1. 先确定对话对象。
  2. 选择私信、现有群组或新群组。
  3. 选择能执行请求操作的最低能力命令。
  4. 在发送或更改可见状态前进行确认,除非用户已提供精确的收件人、内容和操作。
  5. 使用稳定标识符执行操作:对于普通发送/监听/历史查看,首选 --chat-id;对于桥接操作,使用 --chat 聊天 GUID。

当多个聊天或句柄可能匹配时,切勿仅凭随意的名称推断收件人。在发送前显示匹配的显示名称、句柄、群组成员以及消息文本/操作。

主机要求

  • macOS 14+,且 Messages.app 已登录(用于发送/表情反应/桥接操作)。
  • 运行 imsg 或 OpenClaw 的进程上下文具有完全磁盘访问权限;否则读取操作会因无法访问 Messages 数据库而失败。
  • 使用公开 send 时需要 Messages.app 的自动化权限。
  • 运行公开 imsg react 的进程上下文需要辅助功能权限;因为它使用系统事件的 UI 自动化。桥接的 tapback 使用私有 API 替代。
  • 可选:需要通讯录权限以解析联系人名称。
  • 发送短信需要用户 iPhone 到本 Mac 的“短信转发”功能。
  • Linux 仅能读取复制的 chat.db;无法发送、添加表情反应、启动 Messages.app、标记已读或输入文字。

确定目标

使用 --json 进行读取操作。输出为换行分隔的 JSON;当 jq 可用时,使用 jq -s,或直接逐行处理每个对象。

imsg chats --limit 25 --json | jq -s
imsg search --query "dinner" --match contains --json | jq -s
imsg history --chat-id 42 --limit 20 --attachments --json | jq -s
imsg group --chat-id 42 --json

目标规则:

  • 私信到电话号码/邮箱:当用户提供了确切的句柄,或经过唯一且无歧义的聊天匹配后,使用 imsg send --to。
  • 现有私信线程:imsg send --chat-id <id> 比重新解析名称更安全。
  • 现有群组:使用 imsg group --chat-id <id> --json 检查;使用 --chat-id 发送,使用 group 中的聊天 GUID 进行桥接操作。
  • 新群组:仅当用户明确要求创建群组或没有现有群组匹配时,才使用 chat-create。
  • 群组名称有歧义时:确认参与者,而不仅仅是显示名称。
  • 短信:仅当用户要求或不希望使用 iMessage 回退时,才使用 --service sms。短信中继需要“短信转发”功能。

不要将 jq 作为此技能的硬性前提条件;它只是示例中方便的格式化工具。

能力选择

当足够时,优先使用公开的 Messages 自动化:

  • 读取/列出/搜索/监听:chats、group、history、search、watch
  • 基本文本/文件发送:send
  • 对聊天中最近一条收到的消息添加标准 tapback:react

仅当公开自动化无法满足时,才使用私有 API 桥接:

  • 富回复、文本格式化、效果、主题、多部分发送
  • 原生 Apple Messages 投票及投票操作
  • 按消息 GUID 的 tapback 或 tapback 移除
  • 编辑、取消发送、删除、无论如何设置已读
  • 已读回执、输入指示器、桥接事件监听
  • 群组创建/名称/头像/成员/退出/删除/标记操作
  • 账户、whois、昵称检查

进行桥接操作前,请检查:

imsg status --json

如果主机支持桥接操作但 Messages 尚未注入,请在运行 imsg launch 前询问用户。它会杀死并重新启动 Messages.app 以注入桥接,因此将其视为可见状态变更:

imsg launch
imsg status --json

如果 SIP、库验证、私有权限检查或缺少选择器仍然阻止了该能力,请勿让用户随意禁用 SIP。解释请求的私有 API 操作在此主机上不可用,并提供最接近的非桥接操作(如果存在)。

私信场景

精确句柄,基本发送:

imsg send --to "+14155551212" --text "出发了" --service auto

已知私信线程:

imsg send --chat-id 42 --text "出发了"
imsg send --chat-id 42 --file /path/to/photo.jpg

仅当用户要求时强制指定通道:

imsg send --to "+14155551212" --text "绿色气泡" --service sms
imsg send --to "+14155551212" --text "仅 iMessage" --service imessage --no-sms-fallback

线程回复、格式化、效果或附件回复:

imsg send-rich --chat 'iMessage;-;+15551234567' \
  --reply-to <message-guid> --text "回复文本"
imsg send-rich --chat 'iMessage;-;+15551234567' --text '你好世界' \
  --format '[{"start":0,"length":5,"styles":["bold"]}]'
imsg send-rich --chat 'iMessage;-;+15551234567' --text "轰" --effect impact
imsg send-attachment --chat 'iMessage;-;+15551234567' \
  --reply-to <message-guid> --file /path/to/file.jpg

格式化范围基于 UTF-16 位置。支持的样式包括 bold、italic、underline、strikethrough;可使用 --format-file 传入生成的 JSON。

群组场景

操作前先检查:

imsg group --chat-id 42 --json
imsg history --chat-id 42 --limit 20 --json | jq -s

向现有群组发送消息:

imsg send --chat-id 42 --text "我没问题"

在现有群组中进行桥接回复或投票:

imsg send-rich --chat 'iMessage;+;chat0000' \
  --reply-to <message-guid> --text "在线程中回复"
imsg poll send --chat 'iMessage;+;chat0000' \
  --question "晚饭?" --option "披萨" --option "寿司"

仅在用户明确要求时才创建或修改群组:

imsg chat-create --addresses '+15551111111,+15552222222' --name '团队' --text '大家早上好'
imsg chat-name --chat 'iMessage;+;chat0000' --name '已重命名'
imsg chat-photo --chat 'iMessage;+;chat0000' --file /path/to/group.jpg
imsg chat-add-member --chat 'iMessage;+;chat0000' --address +15553333333
imsg chat-remove-member --chat 'iMessage;+;chat0000' --address +15553333333
imsg chat-leave --chat 'iMessage;+;chat0000'
imsg chat-delete --chat 'iMessage;+;chat0000'
imsg chat-mark --chat 'iMessage;+;chat0000' --read

群组变更非常明显。在更改成员、名称、头像、已读状态、退出或删除群组前,请确认确切的群组和参与者列表。

表情反应和回复

公开的 react 有限制:它仅对聊天中最近一条收到的消息添加反应。

imsg react --chat-id 42 --reaction like
imsg react --chat-id 42 --reaction love
imsg react --chat-id 42 --reaction dislike
imsg react --chat-id 42 --reaction laugh
imsg react --chat-id 42 --reaction emphasis
imsg react --chat-id 42 --reaction question

若需针对特定消息 GUID 或移除反应,请使用桥接的 tapback:

imsg tapback --chat 'iMessage;-;+15551234567' --message <message-guid> --kind love
imsg tapback --chat 'iMessage;-;+15551234567' --message <message-guid> --kind love --remove

对于线程回复,请使用 send-rich --reply-to <message-guid>。如果用户说“那个”或“上一条”,请确认所引用的消息。

投票

原生 Apple Messages 投票需要桥接。创建时需要至少两个 --option 值。投票时需要 --option-id、--option-index 或 --option 其中之一。

Messages 仅在投票气泡上显示选项;--question 标题不会向收件人显示。设置 --question(必填)以及至少两个 --option 值。

imsg poll send --chat 'iMessage;-;+15551234567' \
  --question "晚饭?" --option "披萨" --option "寿司"
imsg poll send --chat 'iMessage;+;chat0000' --reply-to <message-guid> \
  --question "批准?" --option "是" --option "否"
imsg poll vote --chat 'iMessage;+;chat0000' \
  --poll <poll-message-guid> --option-id <option-id>

使用以下命令查找投票 ID 和选项:

imsg history --chat-id 42 --limit 20 --json | jq -s '.[] | select(.poll != null) | {guid, poll}'

投票行是 poll 事件,而非 tapback;无需 watch --reactions 即可看到。

监听和长期运行智能体

对于短期的单次等待,使用 watch:

imsg watch --chat-id 42 --since-rowid 9000 --json
imsg watch --chat-id 42 --attachments --convert-attachments --json
imsg watch --chat-id 42 --reactions --json
imsg watch --chat-id 42 --bb-events --json

--since-rowid 是排他性的。不带此参数时,watch 从最新行开始。watch 使用文件系统事件以及低频轮询回退,因此可以补上错过的 SQLite 侧车事件。轮询对象不含 --reactions。

对于守护进程或多聊天集成,请使用 imsg rpc。它通过 stdin/stdout 使用 JSON-RPC 2.0 协议。在使用新的桥接或轮询方法前,请通过 imsg status --json 检查 rpc_methods。

安全规则

  • 在每次发送前确认收件人、聊天和内容,除非用户的请求已包含精确值。
  • 确认可见状态变更:已读回执、输入指示器、编辑、取消发送、删除、投票、tapback、群组成员、群组名称/头像、退出/删除聊天。
  • 未批准时切勿向未知号码或歧义的联系人名称匹配发送消息。
  • 确认附件存在且是预期的文件。
  • 优先使用 E.164 格式的电话号码;仅在需要处理本地格式时才使用 --region US 或其他区域。
  • 不要仅仅因为桥接操作可用就使用它们;仅当所请求的行为需要时才使用。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

1password

Set up and use 1Password CLI for sign-in, desktop integration, and reading or injecting secrets.

acp-router

Route plain-language requests for Claude Code, Cursor, Copilot, OpenClaw ACP, OpenCode, Gemini CLI, Grok Build, Qwen, Kiro, Kimi, iFlow, Factory Droid, Kilocode, or explicit ACP harness work into either OpenClaw ACP runtime sessions or direct acpx-driven sessions ("telephone game" flow). For coding-agent thread requests, read this skill first, then use only `sessions_spawn` for thread creation. Codex chat binding defaults to the native Codex app-server plugin unless ACP is explicit or background spawn needs ACP.

add-model-provider

Add and live-prove a model provider with non-interactive config one-liners, without exposing credentials.

agent-transcript

Requested GitHub PR/issue agent transcripts: redact, trim, preview, and insert safely.

apple-notes

Create, view, edit, delete, search, move, or export Apple Notes via the memo CLI on macOS.

apple-reminders

List, add, edit, complete, or delete Apple Reminders and reminder lists via remindctl.

auto-qa

Run OpenClaw-wide autonomous QA and live/stress campaigns across independent subsystem lanes, with verified fixes and a resumable evidence report.

autoreview

Structured code review through the shared OpenClaw agent-skills installation.

bear-notes

Create, search, and manage Bear notes via grizzly CLI.

blacksmith-testbox

Run Blacksmith Testbox for CI-parity checks, secrets, hosted services, migrations, or builds local cannot reproduce.

block-kit

Use proactively for structured or interactive Slack replies, and when asked to author or validate native Slack Block Kit JSON.

blogwatcher

Monitor blogs and RSS/Atom feeds for updates using the blogwatcher CLI.

blucli

BluOS CLI (blu) for discovery, playback, grouping, and volume.

bluebubbles

Send and manage iMessages via BlueBubbles, including attachments, tapbacks, edits, replies, and groups.

browser-automation

Use when controlling web pages with the OpenClaw browser tool, especially multi-step flows, login checks, tab management, or recovery from stale refs/timeouts.

camsnap

Capture frames or clips from RTSP/ONVIF cameras and local webcams, including USB pan/tilt/zoom control.

canvas

Present HTML on connected OpenClaw node canvases, navigate/eval/snapshot, and debug canvas host URLs.

channel-message-flows

Use when running QA Lab channel message flow evidence.

clawdtributor

Clawtributor PRs here, last week or another window: discover conversation refs, recheck GitHub, rank by impact.

clawhub

Search ClawHub for plugins by default, or skills and agent Templates when requested; add Templates; install, verify, update, uninstall, publish, or sync skills.

相关技能