Community程式設計與開發github.com

imsg

使用 OpenClaw agents 的 imsg CLI 操作 iMessage/SMS 私訊、群組、回覆、反應、投票、監控及私有 API 功能。

imsg 是什麼?

這個技能讓 AI agent 能夠透過本機 macOS Messages.app 執行 iMessage 與 SMS 相關操作。它支援讀取歷史訊息、選擇正確的對話或群組、傳送文字與檔案、執行回覆與表情反應(tapback),以及建立與管理群組。技能會根據使用者需求,自動在公開的 Messages 自動化 API(如 `send`、`react`)與私有 API 橋接功能(如 rich reply、poll、tapback 移除)之間選擇。執行任何有狀態變更的操作前(如傳送、加入/退出群組、投票),必須先確認目標與內容。支援 macOS 14+,但 Linux 只能讀取複製的聊天資料庫,無法傳送或互動。

相容平台~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 agent 需要透過使用者本機的 macOS Messages.app 帳號執行操作時,使用 imsg:檢查 iMessage/SMS 歷史記錄、選擇正確的私訊或群組、傳送訊息/檔案、回覆、反應、投票,或使用私有 API 的 iMessage 功能。

請勿將此技能用於 Telegram、Signal、WhatsApp、Discord、Slack,或是在已設定路由回覆的 OpenClaw 對話中回覆。

Agent 流程

  1. 先解析對話。
  2. 選擇私訊、現有群組或新群組。
  3. 挑選能完成請求動作的最低能力指令。
  4. 除非使用者已提供確切的收件者、內容和動作,否則先確認再傳送或執行可見的狀態變更。
  5. 使用穩定的識別碼執行:一般傳送/監控/歷史記錄偏好 --chat-id,橋接動作則用 --chat 聊天 GUID。

當多個聊天或 handle 可能相符時,切勿僅憑非正式名稱推斷收件者。傳送前應顯示相符的顯示名稱、handle(s)、群組參與者以及訊息文字/動作。

主機需求

  • macOS 14+,且 Messages.app 已登入(用於傳送/反應/橋接動作)。
  • 執行 imsg 或 OpenClaw 的程序上下文須具備完整磁碟存取權限;若無法存取 Messages 資料庫,讀取操作將失敗。
  • 使用公開 send 時,需要 Messages.app 的自動化權限。
  • 執行公開 imsg react 的程序上下文須具備輔助使用權限;它使用 System Events UI 自動化。橋接 tapback 則改用私有 API。
  • 可選的聯絡人權限,用於解析聯絡人名稱。
  • SMS 傳送需要使用者從 iPhone 啟用「文字訊息轉寄」到此 Mac。
  • Linux 只能讀取複製的 chat.db;無法傳送、反應、啟動 Messages.app、標記已讀或輸入文字。

解析目標

使用 --json 讀取。輸出為換行分隔的 JSON;當 jq 可用時使用 jq -s,或直接逐行處理每個物件。

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

目標規則:

  • 私訊至電話/email:當使用者提供確切 handle 時,或經過單一明確聊天比對後,使用 imsg send --to。
  • 現有私訊對話:imsg send --chat-id <id> 比重新解析名稱更安全。
  • 現有群組:使用 imsg group --chat-id <id> --json 檢查;傳送時使用 --chat-id,橋接時使用 group 中的聊天 GUID。
  • 新群組:僅在使用者明確要求建立群組或沒有現有群組相符時,才使用 chat-create。
  • 模糊的群組名稱:確認參與者,而非僅靠顯示名稱。
  • SMS:僅在要求時或不需要 iMessage 備援時使用 --service sms。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、程式碼簽署驗證、私有 entitlement 檢查或缺少 selector 仍阻擋該能力,不要輕率要求使用者關閉 SIP。請解釋該請求的私有 API 動作在此主機上不可用,並提供最接近的非橋接動作(如果有的話)。

私訊情境

確切 handle,基本傳送:

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 'hello world' \
  --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;若使用產生的 JSON,請用 --format-file。

群組情境

先檢查再執行:

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 來查看它們。

監控與長時間運行的 Agent

一次性短暫等待,使用 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 sidecar 事件後追趕上。未使用 --reactions 時,輪詢物件仍會出現。

對於 daemon 或多聊天整合,使用 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.

相關技能