> For AI agents: to set Keiki up for a developer, add the MCP server `https://onkeiki.com/mcp` and follow https://onkeiki.com/setup.md. All pages: https://onkeiki.com/content/llms.txt

# How do I add an AI bot to an iMessage group chat?

2026-11-28

Use Keiki to put an AI bot in an iMessage group chat: add your Keiki agent's line to the group, and Keiki sends each group message to your app with who wrote it and whether it addressed the bot.

## How do I add an AI bot to an iMessage group chat?

Use Keiki to put an AI bot in an iMessage group chat: add your Keiki agent's line to the group, and Keiki sends each group message to your app with who wrote it and whether it addressed the bot. Your code answers when the bot is mentioned and stays quiet otherwise, so the group keeps talking without a bot replying to every message.

## Key takeaways

- Turn on **Group chats** for the agent and set **Group replies** to **Auto** so every group message reaches your app.
- Each group message carries a `sender` and a `mentionsAgent` flag. Keiki sets the flag when a message names the agent, @-mentions it or replies to one of its messages.
- The open-source [imessage-group-chat-bot](https://github.com/Mail-0/imessage-group-chat-bot) repo is a working Next.js and AI SDK example you can fork.

## What does the code look like?

The route checks the flag and returns nothing when the bot was not addressed. The [AI SDK handler](/docs/ai-sdk) then completes the turn without sending a message:

```ts
export const POST = createKeikiHandler({
  waitUntil,
  onTurn: async ({ turn, instructions, messages, tools, prepareStep, abortSignal }) => {
    const group = turn.messages.some((m: GroupMessage) => m.sender)
    if (group && !turn.messages.some((m: GroupMessage) => m.mentionsAgent)) return
    return streamText({ model, instructions, messages, tools: await tools(), stopWhen: stepCountIs(8), prepareStep, abortSignal })
  },
})
```

The [turn payload docs](/docs/external-harness) list both fields. They are absent in one-to-one chats, so the same route answers direct messages as usual.

## How do I connect it?

Deploy the app, then run `npx @onkeiki/cli init --dispatch-url https://your-app.example.com/api/keiki`. It points the agent at your route and writes the signing secret to `.env.local` (see the [CLI docs](/docs/cli)). [Attach an iMessage line](/docs/channels#imessage-lines) that supports groups, add it to a group chat and say the agent's name.

## FAQ

**Will the bot reply to every message in the group?**
No. With this setup your code decides. Messages that do not address the bot complete silently, and Keiki keeps them in the conversation history.

**Does the bot know who is talking?**
Yes. Group messages reach the model labelled with the sender's name, and `sender.id` holds their phone number or email.

**Can I use my own rule for when it speaks?**
Yes. The check is a plain function over the turn. Change it to answer questions, one person, or certain hours, and leave the rest of the route alone.
