iMessage(舊版:imsg)
建議: 新的 iMessage 設定請使用 BlueBubbles。
imsg 頻道是舊版的外部 CLI 整合,未來版本可能會移除。
Status: legacy external CLI integration. 狀態:舊版外部 CLI 整合。Gateway 會啟動 imsg rpc(以 stdio 進行 JSON-RPC)。
快速設定(初學者)
- 確認此 Mac 上的「訊息」已登入。
- 安裝
imsg:brew install steipete/tap/imsg
- 使用
channels.imessage.cliPath與channels.imessage.dbPath設定 OpenClaw。 - 啟動 Gateway,並核准任何 macOS 提示(自動化 + 完整磁碟存取)。
它是什麼
- 由 macOS 上的
imsg支援的 iMessage 頻道。 - 確定性路由:回覆一律回到 iMessage。
- 私訊共用代理程式的主要工作階段;群組則是隔離的(
agent:<agentId>:imessage:group:<chat_id>)。 - 若多參與者執行緒以
is_group=false抵達,你仍可透過channels.imessage.groups使用chat_id進行隔離(見下方「類群組執行緒」)。
設定寫入
預設允許 iMessage 寫入由/config set|unset 觸發的設定更新(需要 commands.config: true)。
停用方式:
需求
- 已登入「訊息」的 macOS。
- 為 OpenClaw +
imsg提供完整磁碟存取(存取「訊息」資料庫)。 - 傳送時需要自動化權限。
channels.imessage.cliPath可指向任何可代理 stdin/stdout 的指令(例如:透過 SSH 連線到另一台 Mac 並執行imsg rpc的包裝腳本)。
疑難排解 macOS 隱私權與安全性 TCC
若傳送/接收失敗(例如imsg rpc 非零結束、逾時,或 Gateway 看似卡住),常見原因是未核准的 macOS 權限提示。
macOS 會依應用程式/行程情境授予 TCC 權限。請在執行 imsg 的相同情境中核准提示(例如 Terminal/iTerm、LaunchAgent 工作階段,或由 SSH 啟動的行程)。 Approve prompts in the same context that runs imsg (for example, Terminal/iTerm, a LaunchAgent session, or an SSH-launched process).
檢查清單:
- 完整磁碟存取:允許執行 OpenClaw 的行程(以及任何執行
imsg的 shell/SSH 包裝器)存取。這是讀取「訊息」資料庫(chat.db)所必需。 This is required to read the Messages database (chat.db). - 自動化 → 訊息:允許執行 OpenClaw 的行程(及/或你的終端機)控制 Messages.app 以進行外送。
imsgCLI 健康狀態:確認已安裝imsg並支援 RPC(imsg rpc --help)。
設定(快速路徑)
- 確認此 Mac 上的「訊息」已登入。
- 設定 iMessage 並啟動 Gateway。
專用機器人 macOS 使用者(用於隔離身分)
若你希望機器人以獨立的 iMessage 身分傳送(並保持你的個人「訊息」乾淨),請使用專用的 Apple ID + 專用的 macOS 使用者。- 建立專用 Apple ID(例如:
[email protected])。- Apple 可能需要電話號碼進行驗證/2FA。
- 建立 macOS 使用者(例如:
openclawhome)並登入。 - 在該 macOS 使用者中開啟「訊息」,並使用機器人的 Apple ID 登入 iMessage。
- 啟用「遠端登入」(系統設定 → 一般 → 共享 → 遠端登入)。
- 安裝
imsg:brew install steipete/tap/imsg
- 設定 SSH,讓
ssh <bot-macos-user>@localhost true無需密碼即可運作。 - 將
channels.imessage.accounts.bot.cliPath指向一個 SSH 包裝器,以機器人使用者身分執行imsg。
imsg rpc looks stuck or exits, log into that user (Screen Sharing helps), run a one-time imsg chats --limit 1 / imsg send ..., approve prompts, then retry. See Troubleshooting macOS Privacy and Security TCC.
Example wrapper (chmod +x). 範例包裝器(chmod +x)。請將 <bot-macos-user> 替換為你實際的 macOS 使用者名稱:
channels.imessage.cliPath、channels.imessage.dbPath),而非 accounts 對應表。
遠端/SSH 變體(選用)
若你希望在另一台 Mac 上使用 iMessage,請將channels.imessage.cliPath 設為一個包裝器,透過 SSH 在遠端 macOS 主機上執行 imsg。OpenClaw 只需要 stdio。 OpenClaw only needs stdio.
範例包裝器:
cliPath points to a remote host via SSH, attachment paths in the Messages database reference files on the remote machine. OpenClaw can automatically fetch these over SCP by setting channels.imessage.remoteHost:
remoteHost,OpenClaw 會嘗試解析你的包裝腳本中的 SSH 指令來自動偵測。為了可靠性,建議明確設定。 Explicit configuration is recommended for reliability.
透過 Tailscale 的遠端 Mac(範例)
若 Gateway 在 Linux 主機/VM 上執行,但 iMessage 必須在 Mac 上運作,Tailscale 是最簡單的橋接方式:Gateway 透過 tailnet 與 Mac 通訊,經由 SSH 執行imsg,並將附件以 SCP 傳回。
架構:
具體設定範例(Tailscale 主機名稱):
~/.openclaw/scripts/imsg-ssh):
- 確保 Mac 已登入「訊息」,且已啟用遠端登入。
- 使用 SSH 金鑰,讓
ssh [email protected]無需提示即可運作。 remoteHost應與 SSH 目標相符,以便 SCP 擷取附件。
channels.imessage.accounts 搭配每個帳號的設定,以及選用的 name。共享模式請見[gateway/configuration](/gateway/configuration#telegramaccounts—discordaccounts—slackaccounts—signalaccounts—imessageaccounts)。請勿提交 ~/.openclaw/openclaw.json(通常包含權杖)。 See gateway/configuration for the shared pattern. Don’t commit ~/.openclaw/openclaw.json (it often contains tokens).
存取控制(私訊 + 群組)
私訊(DMs):- 預設:
channels.imessage.dmPolicy = "pairing"。 - 未知寄件者會收到配對碼;在核准前會忽略訊息(配對碼 1 小時後過期)。
- Approve via:
openclaw pairing list imessageopenclaw pairing approve imessage <CODE>
- Pairing is the default token exchange for iMessage DMs. Details: Pairing
channels.imessage.groupPolicy = open | allowlist | disabled。- 當設定
allowlist時,channels.imessage.groupAllowFrom會控制誰可以在群組中觸發。 - 由於 iMessage 沒有原生提及中繼資料,提及閘控使用
agents.list[].groupChat.mentionPatterns(或messages.groupChat.mentionPatterns)。 - 多代理程式覆寫:在
agents.list[].groupChat.mentionPatterns上設定每個代理程式的模式。
運作方式(行為)
imsg會串流訊息事件;Gateway 會將其正規化為共用的頻道封裝。- 回覆一律路由回相同的聊天 ID 或 handle。
類群組執行緒(is_group=false)
某些 iMessage 執行緒可能有多位參與者,但依「訊息」儲存聊天識別碼的方式不同,仍可能以 is_group=false 抵達。
若你在 channels.imessage.groups 下明確設定 chat_id,OpenClaw 會將該執行緒視為「群組」,以便:
- 工作階段隔離(獨立的
agent:<agentId>:imessage:group:<chat_id>工作階段金鑰) - 群組允許清單/提及閘控行為
媒體 + 限制
- 透過
channels.imessage.includeAttachments的選用附件匯入。 - 透過
channels.imessage.mediaMaxMb的媒體上限。
限制
- 外送文字會分段為
channels.imessage.textChunkLimit(預設 4000)。 - 選用的換行分段:設定
channels.imessage.chunkMode="newline",在依長度分段前先依空白行(段落邊界)分割。 - 媒體上傳上限由
channels.imessage.mediaMaxMb控制(預設 16)。
定址/投遞目標
建議使用chat_id 以獲得穩定路由:
chat_id:123(建議)chat_guid:...chat_identifier:...- 直接 handle:
imessage:+1555/sms:+1555/[email protected]
設定參考(iMessage)
完整設定:設定 提供者選項:channels.imessage.enabled:啟用/停用頻道啟動。channels.imessage.cliPath:imsg的路徑。channels.imessage.dbPath:「訊息」資料庫路徑。channels.imessage.remoteHost:當cliPath指向遠端 Mac(例如user@gateway-host)時,用於 SCP 附件傳輸的 SSH 主機。若未設定,將從 SSH 包裝器自動偵測。 Auto-detected from SSH wrapper if not set.channels.imessage.service:imessage | sms | auto。channels.imessage.region:SMS 區域。channels.imessage.dmPolicy:pairing | allowlist | open | disabled(預設:配對)。channels.imessage.allowFrom:私訊允許清單(handle、電子郵件、E.164 號碼,或chat_id:*)。open需要"*"。iMessage 沒有使用者名稱;請使用 handle 或聊天目標。openrequires"*". iMessage has no usernames; use handles or chat targets.channels.imessage.groupPolicy:open | allowlist | disabled(預設:允許清單)。channels.imessage.groupAllowFrom:群組寄件者允許清單。channels.imessage.historyLimit/channels.imessage.accounts.*.historyLimit:納入為上下文的群組訊息最大數量(0 代表停用)。channels.imessage.dmHistoryLimit: DM history limit in user turns.channels.imessage.dmHistoryLimit:以使用者回合計的私訊歷史上限。每位使用者的覆寫:channels.imessage.dms["<handle>"].historyLimit。channels.imessage.groups:每個群組的預設值 + 允許清單(全域預設請使用"*")。channels.imessage.includeAttachments:將附件匯入至上下文。channels.imessage.mediaMaxMb:入站/出站媒體上限(MB)。channels.imessage.textChunkLimit:外送分段大小(字元)。channels.imessage.chunkMode:length(預設)或newline,在依長度分段前先依空白行(段落邊界)分割。
agents.list[].groupChat.mentionPatterns(或messages.groupChat.mentionPatterns)。messages.responsePrefix。