iMessage AI Bot with BlueBubbles Setup Guide
Build an AI assistant for iMessage using BlueBubbles on macOS. Full feature support including reactions and effects.
Molted Team
molted.cloud
Build an AI assistant for iMessage using BlueBubbles on macOS. Full feature support including reactions and effects.
Molted Team
molted.cloud
iMessage is the messaging platform Apple users actually use. Unlike WhatsApp or Telegram, there is no official bot API. But with BlueBubbles running on a Mac, you can build an AI assistant that responds to your iMessages. This guide shows how.
Apple does not provide a public iMessage API. The only way to automate iMessage is:
BlueBubbles is the most reliable option. It runs on a Mac (can be a Mac Mini) and provides a full API for sending/receiving messages.
In BlueBubbles settings:
mkdir imessage-ai
cd imessage-ai
npm init -y
npm install axios @anthropic-ai/sdk dotenv expressCreate .env:
BLUEBUBBLES_URL=http://localhost:1234
BLUEBUBBLES_PASSWORD=your-server-password
ANTHROPIC_API_KEY=your-anthropic-keyrequire('dotenv').config();
const axios = require('axios');
const Anthropic = require('@anthropic-ai/sdk');
const express = require('express');
const BB_URL = process.env.BLUEBUBBLES_URL;
const BB_PASSWORD = process.env.BLUEBUBBLES_PASSWORD;
const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
const conversations = new Map();
// BlueBubbles API helper
const bb = axios.create({
baseURL: BB_URL,
params: { password: BB_PASSWORD },
});
// Send message via BlueBubbles
async function sendMessage(chatGuid, text) {
await bb.post('/api/v1/message/text', {
chatGuid,
message: text,
method: 'private-api', // Uses private API for delivery receipts
});
}
// Get recent messages from a chat
async function getChatMessages(chatGuid, limit = 10) {
const response = await bb.get(`/api/v1/chat/${chatGuid}/message`, {
params: { limit, sort: 'DESC' },
});
return response.data.data;
}
// Process incoming message with AI
async function handleMessage(chatGuid, text, senderName) {
// Get or create conversation
if (!conversations.has(chatGuid)) {
conversations.set(chatGuid, []);
}
const history = conversations.get(chatGuid);
// Add user message
history.push({ role: 'user', content: text });
// Trim history
if (history.length > 20) {
history.splice(0, history.length - 20);
}
try {
const response = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
system: `You are a helpful iMessage assistant. Keep responses concise for mobile.
The user's name is ${senderName}.`,
messages: history,
});
const reply = response.content[0].text;
history.push({ role: 'assistant', content: reply });
await sendMessage(chatGuid, reply);
} catch (error) {
console.error('Error:', error);
await sendMessage(chatGuid, 'Sorry, I encountered an error.');
}
}
// Webhook server for BlueBubbles events
const app = express();
app.use(express.json());
app.post('/webhook', async (req, res) => {
const { type, data } = req.body;
if (type === 'new-message') {
const message = data;
// Ignore our own messages
if (message.isFromMe) {
return res.sendStatus(200);
}
const chatGuid = message.chats?.[0]?.guid;
const text = message.text;
const senderName = message.handle?.firstName || 'User';
if (chatGuid && text) {
await handleMessage(chatGuid, text, senderName);
}
}
res.sendStatus(200);
});
app.listen(3000, () => {
console.log('Webhook server running on port 3000');
console.log('Configure BlueBubbles to send webhooks to http://localhost:3000/webhook');
});iMessage AI made easy
OpenClaw includes BlueBubbles integration. Configure once, works forever.
Coming soonIn BlueBubbles settings → Webhooks:
http://localhost:3000/webhookNow every incoming iMessage triggers your AI handler.
app.post('/webhook', async (req, res) => {
const { type, data } = req.body;
if (type === 'new-message') {
const message = data;
if (message.isFromMe) return res.sendStatus(200);
const chatGuid = message.chats?.[0]?.guid;
// Check for attachments
if (message.attachments?.length > 0) {
const attachment = message.attachments[0];
if (attachment.mimeType?.startsWith('image/')) {
// Download attachment
const imageResponse = await bb.get(
`/api/v1/attachment/${attachment.guid}/download`,
{ responseType: 'arraybuffer' }
);
const base64 = Buffer.from(imageResponse.data).toString('base64');
const aiResponse = await anthropic.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
messages: [{
role: 'user',
content: [
{
type: 'image',
source: {
type: 'base64',
media_type: attachment.mimeType,
data: base64,
},
},
{
type: 'text',
text: message.text || 'What is in this image?',
},
],
}],
});
await sendMessage(chatGuid, aiResponse.content[0].text);
return res.sendStatus(200);
}
}
// Handle text messages
if (message.text) {
await handleMessage(chatGuid, message.text, message.handle?.firstName);
}
}
res.sendStatus(200);
});app.post('/webhook', async (req, res) => {
const { type, data } = req.body;
if (type === 'new-message') {
const message = data;
const chat = message.chats?.[0];
const isGroupChat = chat?.participants?.length > 1;
// In group chats, only respond if mentioned
if (isGroupChat) {
const botName = 'AI'; // Your trigger word
if (!message.text?.toLowerCase().includes(botName.toLowerCase())) {
return res.sendStatus(200);
}
}
// ... rest of handler
}
});BlueBubbles Private API supports iMessage features:
// Send a reaction
await bb.post('/api/v1/message/react', {
chatGuid,
messageGuid: originalMessageGuid,
reaction: 'love', // love, like, dislike, laugh, emphasize, question
});
// Send with effect
await bb.post('/api/v1/message/text', {
chatGuid,
message: 'Congrats!',
method: 'private-api',
effectId: 'com.apple.messages.effect.CKConfettiEffect',
});Full iMessage AI experience
OpenClaw on Molted supports reactions, effects, and group chats. No code needed.
For 24/7 operation:
# Install PM2
npm install -g pm2
# Start with PM2
pm2 start index.js --name imessage-ai
# Auto-start on boot
pm2 startup
pm2 saveAlso configure your Mac:
OpenClaw supports BlueBubbles as a channel. If you have BlueBubbles running, you can:
OpenClaw handles webhooks, conversation state, and multi-model support automatically.
OpenClaw with BlueBubbles. Full iMessage support on your Mac Mini.
24-hour free trial · no credit card · cancel anytime
Run ChatGPT or Claude on WhatsApp with Baileys. Complete self-hosted setup guide with code examples and deployment options.
Build an AI-powered Telegram bot using grammY framework. Step-by-step tutorial with Claude and GPT integration.
Run an AI assistant on Signal for encrypted conversations. Complete signal-cli setup with Claude integration.
ENCORE DEBOUT ?