iMessage(legacy: imsg)でOpenClawを使うイメージ

【最新版】iMessage(legacy)でOpenClawを使う方法(imsg CLI連携)

iMessage

iMessage(legacy: imsg)

注意: 新規の iMessage 導入は BlueBubbles を使ってください。
imsg 連携はレガシーで、将来のリリースで削除される可能性があります。

ステータス:レガシー外部CLI連携。Gateway は imsg rpc を spawn し、 stdio 上の JSON-RPC で通信します(別daemon/別ポートは不要)。

クイックセットアップ

ローカルMac(最短ルート)

Step 1:imsg をインストールして確認

brew install steipete/tap/imsg
imsg rpc --help

Step 2:OpenClaw を設定

{
  channels: {
    imessage: {
      enabled: true,
      cliPath: "/usr/local/bin/imsg",
      dbPath: "/Users/<you>/Library/Messages/chat.db",
    },
  },
}

Step 3:Gateway を起動

openclaw gateway

Step 4:最初のDMペアリングを承認(デフォルト dmPolicy)

openclaw pairing list imessage
openclaw pairing approve imessage <CODE>

ペアリング要求は 1 時間で期限切れになります。

リモートMac(SSH 経由)

OpenClaw が必要なのは stdio 互換の cliPath だけなので、cliPath を「リモートMacにSSHして imsg を実行するラッパー」にできます。

#!/usr/bin/env bash
exec ssh -T gateway-host imsg "$@"

添付ファイルを有効にする場合の推奨設定:

{
  channels: {
    imessage: {
      enabled: true,
      cliPath: "~/.openclaw/scripts/imsg-ssh",
      remoteHost: "user@gateway-host", // SCP で添付を取得する際に使用
      includeAttachments: true,
      // 任意:許可する添付ファイルのrootを上書き
      // デフォルトには /Users/*/Library/Messages/Attachments が含まれます
      attachmentRoots: ["/Users/*/Library/Messages/Attachments"],
      remoteAttachmentRoots: ["/Users/*/Library/Messages/Attachments"],
    },
  },
}
  • remoteHost を設定していない場合、OpenClaw は SSH ラッパースクリプトをパースして自動検出を試みます。
  • remoteHosthost もしくは user@host(スペースやSSHオプションなし)である必要があります。
  • OpenClaw は SCP で strict host-key checking を使います。そのため、リレーホストの鍵がすでに ~/.ssh/known_hosts に存在している必要があります。
  • 添付ファイルのパスは許可root(attachmentRoots / remoteAttachmentRoots)に対してバリデーションされます。

要件と権限(macOS)

  • Messages は imsg を動かすMacでサインインしている必要があります。
  • OpenClaw / imsg を動かすプロセスコンテキストに フルディスクアクセス が必要です(Messages DBアクセス)。
  • Messages.app 経由で送信するために 自動化(Automation)権限 が必要です。

Tip: 権限はプロセスコンテキスト単位で付与されます。Gateway を headless(LaunchAgent/SSH)で動かす場合、 同じコンテキストで一度だけ対話的コマンドを実行して権限プロンプトを出してください:

imsg chats --limit 1
# or
imsg send <handle> "test"

アクセス制御とルーティング

DM policy

channels.imessage.dmPolicy はDM(ダイレクトメッセージ)を制御します:

  • pairing(デフォルト)
  • allowlist
  • openallowFrom"*" を含める必要があります)
  • disabled

Allowlist フィールド:channels.imessage.allowFrom

Allowlist エントリは、handle でも chat target でも指定できます(chat_id:*, chat_guid:*, chat_identifier:*)。

Group policy + mentions

channels.imessage.groupPolicy はグループの扱いを制御します:

  • allowlist(設定されている場合のデフォルト)
  • open
  • disabled

グループ送信者 allowlist:channels.imessage.groupAllowFrom

  • Runtime fallback:groupAllowFrom が未設定の場合、iMessage グループ送信者チェックは、可能であれば allowFrom にフォールバックします。
  • Runtime note:channels.imessage が完全に欠けている場合、runtime は groupPolicy="allowlist" にフォールバックし警告ログを出します(channels.defaults.groupPolicy を設定していても同様)。

グループのメンションゲート:

  • iMessage にはネイティブの mention メタデータがありません。
  • メンション検出は regex パターン(agents.list[].groupChat.mentionPatterns、フォールバック:messages.groupChat.mentionPatterns)を使います。
  • パターンが設定されていない場合、メンションゲートを強制できません。

認可された送信者からの control commands は、グループのメンションゲートをバイパスできます。

セッションと決定的な返信(deterministic replies)

  • DM は direct routing、グループは group routing を使います。
  • デフォルト session.dmScope=main の場合、iMessage DM はエージェントの main セッションに集約されます。
  • グループセッションは分離されます(agent:<agentId>:imessage:group:<chat_id>)。
  • 返信は、元の channel/target メタデータを使って iMessage に戻るようにルーティングされます。

グループっぽいスレッド挙動:

一部の複数参加者 iMessage スレッドは is_group=false で届くことがあります。 その chat_idchannels.imessage.groups に明示的に設定されている場合、 OpenClaw はそれをグループトラフィックとして扱います(グループゲート + グループセッション分離)。

デプロイパターン

専用の bot macOS ユーザー(separate iMessage identity)

ボットのトラフィックを個人の Messages プロファイルから分離するために、専用の Apple ID と macOS ユーザーを使います。

典型的な流れ:

  1. 専用の macOS ユーザーを作成/サインインします。
  2. そのユーザーで、Messages にボット用 Apple ID をサインインします。
  3. そのユーザーで imsg をインストールします。
  4. OpenClaw がそのユーザーコンテキストで imsg を実行できるよう、SSH ラッパーを作成します。
  5. そのユーザープロファイルのパスに channels.imessage.accounts.<id>.cliPath.dbPath を向けます。

初回実行では、その bot ユーザーのGUIセッションでの承認(Automation + Full Disk Access)が必要になる場合があります。

Tailscale 経由のリモートMac(例)

よくあるトポロジ:

  • gateway は Linux/VM 上で動く
  • iMessage + imsg は tailnet 内の Mac 上で動く
  • cliPath ラッパーは SSH で imsg を実行
  • remoteHost により SCP で添付ファイルを取得

設定例:

{
  channels: {
    imessage: {
      enabled: true,
      cliPath: "~/.openclaw/scripts/imsg-ssh",
      remoteHost: "bot@mac-mini.tailnet-1234.ts.net",
      includeAttachments: true,
      dbPath: "/Users/bot/Library/Messages/chat.db",
    },
  },
}
#!/usr/bin/env bash
exec ssh -T bot@mac-mini.tailnet-1234.ts.net imsg "$@"
  • SSH と SCP が non-interactive になるよう、SSH keys を使ってください。
  • 事前にホスト鍵を信頼済みにしてください(例:ssh bot@mac-mini.tailnet-1234.ts.net)。これで known_hosts が作られます。

マルチアカウントパターン

iMessage は channels.imessage.accounts によるアカウント別設定をサポートします。

各アカウントは cliPath / dbPath / allowFrom / groupPolicy / mediaMaxMb / history 設定 / 添付root allowlist などを上書きできます。

メディア、分割(chunking)、配信ターゲット

添付ファイルとメディア

  • inbound 添付の取り込みは任意です:channels.imessage.includeAttachments
  • remoteHost が設定されている場合、リモート添付パスは SCP で取得できます。
  • 添付パスは、許可rootに一致する必要があります:
    • ローカル:channels.imessage.attachmentRoots
    • リモート(SCP):channels.imessage.remoteAttachmentRoots
    • デフォルト root パターン:/Users/*/Library/Messages/Attachments
  • SCP は strict host-key checking(StrictHostKeyChecking=yes)を使います。
  • outbound メディアサイズ上限:channels.imessage.mediaMaxMb(デフォルト 16MB)

アウトバウンドの分割(chunking)

  • テキスト分割の上限:channels.imessage.textChunkLimit(デフォルト 4000)
  • chunk mode:channels.imessage.chunkMode
    • length(デフォルト)
    • newline(段落優先の分割)

アドレス指定形式

推奨される明示ターゲット:

  • chat_id:123(安定ルーティングに推奨)
  • chat_guid:...
  • chat_identifier:...

handle 指定もサポートされます:

  • imessage:+1555...
  • sms:+1555...
  • user@example.com
imsg chats --limit 20

Config writes

iMessage はデフォルトでチャネル主導の config 書き込み(commands.config: true のときの /config set|unset)を許可します。

無効化:

{
  channels: {
    imessage: {
      configWrites: false,
    },
  },
}

トラブルシューティング

imsg が見つからない / RPC が未対応

バイナリと RPC サポートを検証します:

imsg rpc --help
openclaw channels status --probe

probe が RPC 未対応を報告する場合は、imsg を更新してください。

DM が無視される

次を確認します:

  • channels.imessage.dmPolicy
  • channels.imessage.allowFrom
  • ペアリング承認:openclaw pairing list imessage

グループメッセージが無視される

次を確認します:

  • channels.imessage.groupPolicy
  • channels.imessage.groupAllowFrom
  • channels.imessage.groups の allowlist 挙動
  • メンションパターン設定:agents.list[].groupChat.mentionPatterns

リモート添付ファイルが失敗する

次を確認します:

  • channels.imessage.remoteHost
  • channels.imessage.remoteAttachmentRoots
  • gateway ホストからの SSH/SCP の鍵認証
  • gateway ホストの ~/.ssh/known_hosts にホスト鍵が存在すること
  • Messages を動かす Mac 上でのリモートパス可読性

macOS の権限プロンプトを取り逃した

同じユーザー/セッションコンテキストのGUIターミナルで、対話的に再実行して承認してください:

imsg chats --limit 1
imsg send <handle> "test"

OpenClaw / imsg を実行するプロセスコンテキストに対し、Full Disk Access + Automation が付与されていることを確認します。

設定参照(ポインタ)

参考

BizClaw 導入支援

OpenClaw の構築を
まるごと代行します

Mac mini のセットアップから Slack・iMessage 連携まで、届いた日から使える状態でお届けします。

サービスを見る

関連記事

Read article
AIエージェントのメモリスタックとは?2026年に重要度が上がる理由をやさしく解説

AIエージェントのメモリスタックとは?2026年に重要度が上がる理由をやさしく解説

Read article
OpenClaw vs Hermes vs Claude、創業者はどれを選ぶべき?2026年版の実務比較

OpenClaw vs Hermes vs Claude、創業者はどれを選ぶべき?2026年版の実務比較

Read article
X公式MCPサーバーとは?AIエージェント運用で何が変わるのかを実務目線で解説

X公式MCPサーバーとは?AIエージェント運用で何が変わるのかを実務目線で解説