iMessage Integration
iMessage Integration
Section titled “iMessage Integration”OpenClaw integrates with iMessage on macOS using the imsg CLI tool. This allows you to send and receive iMessages, handle group chats, and manage rich content through your OpenClaw gateway.
Quick Setup
Section titled “Quick Setup”Prerequisites
Section titled “Prerequisites”- macOS with Messages app signed in
- Homebrew installed
- Full Disk Access permissions
Basic Configuration
Section titled “Basic Configuration”- Install imsg CLI:
brew install steipete/tap/imsg- Configure OpenClaw (
~/.openclaw/openclaw.json):
{ channels: { imessage: { enabled: true, cliPath: "/usr/local/bin/imsg", dbPath: "/Users/YOUR_USERNAME/Library/Messages/chat.db" } }}-
Set macOS permissions:
- Open System Settings → Privacy & Security → Full Disk Access
- Add OpenClaw and imsg to the allowed applications
- Grant Automation permissions when prompted
-
Start the gateway:
openclaw gatewayConfiguration Options
Section titled “Configuration Options”Basic Settings
Section titled “Basic Settings”{ channels: { imessage: { // Enable/disable iMessage enabled: true,
// CLI configuration cliPath: "/usr/local/bin/imsg", dbPath: "/Users/YOUR_USERNAME/Library/Messages/chat.db",
// Contact filtering allowFrom: [ "contact@example.com", "+15551234567", "John Appleseed" ], blockFrom: [ "spam@example.com", "+15551112233" ],
// Message handling messages: { maxMessageLength: 1000, mediaEnabled: true, readReceipts: true, typingIndicator: false } } }}Advanced Settings
Section titled “Advanced Settings”{ channels: { imessage: { // Group chat settings groups: { enabled: true, requireMention: false, mentionPatterns: ["@openclaw", "@ai"], // Group-specific settings "chat1234567890": { // chat_id requireMention: true, autoRespond: false } },
// Media handling media: { downloadPath: "~/.openclaw/media/imessage", maxSize: "100MB", autoDownload: false, supportedTypes: ["image", "video", "audio", "document"] },
// Command permissions commands: { enabled: true, prefix: "/", allowConfigWrites: true, allowedCommands: [ "help", "status", "ping", "config" ] },
// Process management process: { timeout: 30000, restartDelay: 5000, maxRestarts: 3 },
// Database settings database: { readOnly: false, backup: true, backupPath: "~/.openclaw/backups/imessage" } } }}Features
Section titled “Features”Direct Messages
Section titled “Direct Messages”- Contact filtering: Control who can message your OpenClaw
- Rich content: Send and receive images, videos, audio, documents
- Read receipts: Optional read receipt functionality
- Message history: Access to iMessage history
Group Chats
Section titled “Group Chats”- Group detection: Automatic identification of group chats
- Chat-specific settings: Different behavior per group
- Mention-based activation: Respond only when mentioned
- Group isolation: Separate sessions for different groups
Media Support
Section titled “Media Support”- Image handling: Send and receive photos
- Video support: Handle video messages
- Audio messages: Voice note support
- Document sharing: File attachments
Command System
Section titled “Command System”- Built-in commands:
/help,/status,/ping - Config commands:
/config set,/config get - Custom commands: Define your own command handlers
- Permission control: Restrict command usage
Usage Examples
Section titled “Usage Examples”Basic Commands
Section titled “Basic Commands”# Test iMessage connectionopenclaw channels test imessage
# Check iMessage statusopenclaw channels status imessage
# Send a messageopenclaw message send --channel imessage --target "contact@example.com" --message "Hello from OpenClaw!"
# Send to phone numberopenclaw message send --channel imessage --target "+15551234567" --message "Hi there!"
# Send mediaopenclaw message send --channel imessage --target "contact@example.com" --file ./photo.jpg
# View recent messagesopenclaw channels logs imessage --limit 10Interactive Usage
Section titled “Interactive Usage”Once configured, you can interact with OpenClaw directly through iMessage:
You: @openclaw helpOpenClaw: Available commands:- /help - Show this help message- /status - Check gateway status- /ping - Test connectivity- /config set key=value - Update configuration
You: @openclaw Write a Python script to calculate fibonacciOpenClaw: Here's a Python script that calculates Fibonacci numbers:
```pythondef fibonacci(n): if n <= 1: return n return fibonacci(n-1) + fibonacci(n-2)
# Test the functionfor i in range(10): print(f"F({i}) = {fibonacci(i)}")You: @openclaw /status OpenClaw: Gateway Status:
- Status: Running
- Uptime: 1h 45m
- iMessage: Connected
- Messages processed: 23
- Active chats: 2
## macOS Permissions Setup
### Full Disk Access
1. **Open System Settings**: - Go to **System Settings → Privacy & Security → Full Disk Access**
2. **Add applications**: - Click the `+` button - Add OpenClaw (usually in `/usr/local/bin/openclaw`) - Add imsg (usually in `/usr/local/bin/imsg`)
3. **Restart the gateway**:```bashopenclaw gateway restartAutomation Permissions
Section titled “Automation Permissions”When starting the gateway, you may see prompts for:
- Messages automation: Allow OpenClaw to control Messages
- Database access: Allow access to Messages database
Click OK on these prompts to grant necessary permissions.
Troubleshooting Permissions
Section titled “Troubleshooting Permissions”# Check if imsg is accessibleimsg version
# Test database accessimsg list-chats
# Check OpenClaw permissionsopenclaw channels test imessage --verboseAdvanced Features
Section titled “Advanced Features”Custom Contact Management
Section titled “Custom Contact Management”{ channels: { imessage: { contacts: { // Contact aliases aliases: { "mom": "+15551234567", "work": "colleague@company.com" },
// Contact groups groups: { "family": ["mom", "dad", "sister"], "work": ["boss@company.com", "colleague@company.com"] },
// VIP contacts (always allow) vip: ["emergency@contact.com"] } } }}Message Templates
Section titled “Message Templates”Create message templates for common responses:
{ channels: { imessage: { templates: { "busy": "I'm currently busy, but I'll get back to you soon!", "away": "I'm away from my computer. I'll respond when I return.", "meeting": "I'm in a meeting. Please text me instead." } } }}Scheduled Messages
Section titled “Scheduled Messages”Schedule messages to be sent later:
# Schedule a messageopenclaw message schedule --channel imessage --target "contact@example.com" --message "Don't forget our meeting!" --time "2024-01-15 09:00"
# List scheduled messagesopenclaw message schedule list
# Cancel scheduled messageopenclaw message schedule cancel --id 12345Message Filtering
Section titled “Message Filtering”Filter incoming messages based on content:
{ channels: { imessage: { filtering: { enabled: true, rules: [ { name: "spam_filter", pattern: "\\b(buy now|free money|click here)\\b", action: "block", caseSensitive: false }, { name: "urgent_filter", pattern: "\\burgent\\b|\\bemergency\\b", action: "priority", notify: true } ] } } }}Security Considerations
Section titled “Security Considerations”Privacy Protection
Section titled “Privacy Protection”- Contact filtering: Strict allowlist for contacts
- Content filtering: Filter sensitive content
- Message encryption: Messages stored encrypted
- Access logs: Log all message access
Data Protection
Section titled “Data Protection”- Database backup: Regular backups of Messages database
- Secure storage: Secure storage of sensitive data
- Access control: Proper file permissions
- Audit logging: Log all configuration changes
Network Security
Section titled “Network Security”- Local only: iMessage integration is local-only
- No external exposure: No network exposure of Messages data
- Secure communication: Secure communication with imsg CLI
Troubleshooting
Section titled “Troubleshooting”Common Issues
Section titled “Common Issues”Permission Denied Errors
# Check Full Disk Access permissionsls -la ~/Library/Messages/chat.db
# Test imsg CLI directlyimsg list-chats
# Grant permissions manuallysudo tccutil reset All com.apple.MessagesMessages Not Sending
# Check iMessage account statusimsg account-status
# Test message sendingimsg send --to "contact@example.com" --message "Test"
# Check gateway logsopenclaw gateway logs --filter imessageDatabase Access Issues
# Check database permissionssqlite3 ~/Library/Messages/chat.db ".tables"
# Repair database (if needed)imsg repair-database
# Rebuild database indeximsg rebuild-indeximsg CLI Not Found
# Check if imsg is installedwhich imsg
# Reinstall imsgbrew reinstall steipete/tap/imsg
# Update imsgbrew upgrade steipete/tap/imsgDebug Mode
Section titled “Debug Mode”Enable detailed logging for iMessage:
# Enable debug loggingopenclaw config set logging.components.imessage debug
# Restart with debugopenclaw gateway restart --debug
# View iMessage logsopenclaw gateway logs --follow --filter imessage
# Test with verbose outputopenclaw channels test imessage --verboseBest Practices
Section titled “Best Practices”-
Permission Management
- Grant minimal necessary permissions
- Regular permission audits
- Document permission requirements
- Use secure permission practices
-
Contact Management
- Use contact aliases for easier management
- Regular contact list updates
- Implement proper contact filtering
- Maintain VIP contact lists
-
Message Handling
- Set appropriate message length limits
- Use message templates for consistency
- Implement proper content filtering
- Monitor message queue sizes
-
Performance
- Monitor database performance
- Regular database maintenance
- Optimize message processing
- Implement proper caching
API Reference
Section titled “API Reference”Channel Commands
Section titled “Channel Commands”# iMessage channel managementopenclaw channels test imessageopenclaw channels status imessage [--detailed]openclaw channels repair imessage
# Message operationsopenclaw message send --channel imessage --target "contact@example.com" --message "Hello"openclaw message send --channel imessage --target "+15551234567" --file ./image.jpgopenclaw message history --channel imessage --target "contact@example.com" --limit 50
# Contact managementopenclaw contacts list --channel imessageopenclaw contacts add --channel imessage --alias "mom" --target "+15551234567"openclaw contacts remove --channel imessage --alias "mom"
# Configurationopenclaw config set channels.imessage.allowFrom '["contact@example.com"]'openclaw config get channels.imessageopenclaw config unset channels.imessage.blockFromConfiguration Schema
Section titled “Configuration Schema”interface iMessageConfig { enabled: boolean; cliPath: string; dbPath: string; allowFrom?: string[]; blockFrom?: string[]; groups?: { enabled?: boolean; requireMention?: boolean; mentionPatterns?: string[]; [chatId: string]: { requireMention?: boolean; autoRespond?: boolean; }; }; messages?: { maxMessageLength?: number; mediaEnabled?: boolean; readReceipts?: boolean; typingIndicator?: boolean; }; media?: { downloadPath?: string; maxSize?: string; autoDownload?: boolean; supportedTypes?: string[]; }; commands?: { enabled?: boolean; prefix?: string; allowConfigWrites?: boolean; allowedCommands?: string[]; }; contacts?: { aliases?: { [alias: string]: string }; groups?: { [groupName: string]: string[] }; vip?: string[]; }; templates?: { [templateName: string]: string }; filtering?: { enabled?: boolean; rules?: Array<{ name: string; pattern: string; action: "block" | "priority" | "forward"; caseSensitive?: boolean; notify?: boolean; }>; };}Your iMessage integration is now ready! You can start sending and receiving messages through OpenClaw on macOS. 📱