iMessage & SMS Integration Guide
Complete guide to setting up iMessage integration with OpenClaw, including Full Disk Access permissions, fixing duplicate messages, and troubleshooting common issues.
⚠️ The Problem
🔍 Why This Happens
imsg CLI tool which directly accesses the macOS Messages database (~/Library/Messages/chat.db). This database is protected by System Integrity Protection and requires explicit Full Disk Access permission. Simply adding Terminal.app to FDA is NOT sufficient — you must add the actual binaries that access the database: both imsg AND the OpenClaw gateway binary. Additionally, npm-installed binaries are often wrapper scripts that macOS FDA doesn't accept.
Duplicate Messages: When OpenClaw sends a message via AppleScript, there's a race condition in the iMessage monitor. The chat.db filesystem watch event can fire before the is_from_me flag is properly set in the database. The monitor at src/imessage/monitor.ts:184 filters with if (message.is_from_me) return; but this check fails when the flag isn't populated yet. This affects both the native imsg backend and BlueBubbles.
Outbound as Inbound: Similar race condition — the database sync hasn't completed when the watch event triggers, so the message appears as an incoming message rather than outgoing.✅ The Fix
## Part 1: Setting Up Full Disk Access Correctly
### Step 1: Find the imsg binary location
The location depends on how you installed it:
# Check if imsg is installed and find its pathwhich imsgCommon locations:
- Apple Silicon Macs: /opt/homebrew/bin/imsg
- Intel Macs: /usr/local/bin/imsg
### Step 2: Find the OpenClaw gateway binary
# Find the openclaw/clawdbot binarywhich openclaw# orwhich clawdbotIf installed via npm globally:
``bash
# The path might be something like:
# ~/.npm-global/bin/clawdbot
# Check what the wrapper points to:
file ~/.npm-global/bin/clawdbot
readlink -f ~/.npm-global/bin/clawdbot
If using Homebrew (recommended for FDA):
``bash
brew install openclaw/tap/openclaw
# This puts the binary at /usr/local/bin/openclaw or /opt/homebrew/bin/openclaw
### Step 3: Add both binaries to Full Disk Access
1. Open System Settings → Privacy & Security → Full Disk Access
2. Click the + button
3. Press Cmd+Shift+G to open 'Go to folder'
4. Paste the path to imsg (e.g., /opt/homebrew/bin/imsg)
5. Click Open to add it
6. Repeat for the OpenClaw gateway binary
If the binary disappears when you try to add it: This happens with npm wrapper scripts. Solutions:
- Install via Homebrew instead (creates proper binaries)
- Try adding the parent directory
- Check if it's a symlink with readlink -f and add the actual target
### Step 4: Restart and verify
# Restart the gatewayopenclaw gateway restart# Test iMessage accessimsg list --limit 5---
## Part 2: Fixing Duplicate Messages
### Quick Diagnostic Steps
# Check for multiple gateway processesps aux | grep -i openclaw | grep -v grep# Check logs for duplicate indicatorsopenclaw logs --tail 100 | grep -i "imsg\|duplicate\|is_from_me"# Verify imsg versionimsg --version### Fix 1: Restart Everything Cleanly
# Stop the gatewayopenclaw gateway stop# Kill any orphaned imsg processespkill -f imsg# Quit Messages.app completelyosascript -e 'tell application "Messages" to quit'# Wait a moment, then restartsleep 2openclaw gateway start### Fix 2: Add Sender ID Filtering (Code Patch)
If duplicates persist, add an additional sender check in src/imessage/monitor.ts around line 175:
// Get the current account's sender IDconst accountSenderId = accountInfo.config.senderId ?? accountInfo.accountId;const handleMessage = async (raw: unknown) => { const params = raw as { message?: IMessagePayload | null }; const message = params?.message ?? null; if (!message) return; // Existing check if (message.is_from_me) return; // NEW: Additional check - skip if sender matches our account const normalizedSender = normalizeIMessageHandle(sender); const normalizedAccountSender = normalizeIMessageHandle(accountSenderId); if (normalizedSender === normalizedAccountSender) { logVerbose(`imessage: skipped own message from ${sender}`); return; } // ... rest of handler};This filters by matching the bot's own sender ID, which is more reliable than the is_from_me database flag.
---
## Part 3: Working with Group Chats
### Finding Group Chat IDs
# List recent chats including groupsimsg chats --limit 20# The chat_id for groups looks like: chat123456789# Individual chats use phone/email: +1234567890 or user@icloud.com### Targeting Specific Chats
In your OpenClaw config, you can allowlist specific chat IDs to prevent the bot from responding everywhere.
---
## Part 4: Reading & Summarizing Messages
To have OpenClaw summarize your texts:
# List today's messagesimsg list --since today# Get messages from a specific contactimsg list --from "+1234567890" --limit 50Then ask OpenClaw: "Summarize my recent iMessages" and it can use the imsg tool to fetch and summarize them.
🔥 Your AI should run your business, not just answer questions.
We'll show you how.$97/mo (going to $197 soon)
📋 Quick Commands
| Command | Description |
|---|---|
| which imsg | Find the location of the imsg binary for FDA permissions |
| which openclaw | Find the OpenClaw gateway binary location |
| readlink -f /path/to/binary | Resolve symlinks to find the actual binary path |
| imsg list --limit 5 | Test that iMessage access is working after FDA setup |
| openclaw gateway restart | Restart the gateway after permission changes |
| ps aux | grep -i openclaw | Check for duplicate gateway processes causing duplicates |
| pkill -f imsg | Kill orphaned imsg processes |
| openclaw logs --tail 100 | View recent logs to diagnose message handling issues |
| imsg chats --limit 20 | List recent chats including group chat IDs |
| openclaw doctor | Run diagnostics to check for common issues |
Related Issues
📚 You Might Also Like
iMessage
Native iMessage integration for Mac users. Chat with your AI assistant through Apple's messaging ecosystem.
Private AI Assistant: Keep Your Data Under Your Control
Every message to ChatGPT becomes their data. But there's another way: AI assistants that keep your information completely private. Here's how to set one up.
How to Connect Gmail to Your AI Assistant (Complete Integration Guide)
Turn Gmail into an AI-powered inbox. Summarize threads, draft replies, auto-categorize messages, and search your email with natural language.
Slack
Enterprise-grade AI assistant for Slack. Deploy across workspaces with full Enterprise Grid support, SSO integration, slash commands, and compliance-ready security.
🐙 Your AI should run your business.
Weekly live builds + template vault. We'll show you how to make AI actually work.$97/mo (going to $197 soon)
Join Vibe Combinator →