# Chat-bot behaviour on channels

A chat bot is the same `Agent` with the same runtime, tools and memory, behind a room layer (which messages become turns) and a delivery layer (how replies leave), both in `channels/`. OpenClaw and Hermes are built the same way.

## What a room needs

| Need | Why a chat differs |
| --- | --- |
| Know who spoke | A group or a `session_scope: main` agent puts several people in one conversation |
| Stay quiet by default | Most group messages are people talking to each other |
| Still hear the room | A question after "@bot" depends on the messages before it |
| Decide to speak | Useful assistants join when they have something to add |
| Reply like a person | Short paragraphs as they are ready, typing indicator, no tool transcript |
| Limit strangers | Tools that touch the owner's machine stay with the owner |
| Not talk to bots forever | Two bots answer each other until something stops them |
| One person across apps | The same person on WeChat and Telegram is one subject for memory |
| Speak first | Reminders, follow-ups, check-ins |

## Reference systems

| System | Emphasis |
| --- | --- |
| [OpenClaw](https://docs.openclaw.ai/channels) | The most complete room layer: [groups](https://docs.openclaw.ai/channels/groups), [ambient rooms](https://docs.openclaw.ai/channels/ambient-room-events), [sessions](https://docs.openclaw.ai/concepts/session), [streaming](https://docs.openclaw.ai/concepts/streaming), [typing](https://docs.openclaw.ai/concepts/typing-indicators), [bot loop protection](https://docs.openclaw.ai/channels/bot-loop-protection) |
| [Hermes Agent](https://hermes-agent.nousresearch.com/docs/) ([repo](https://github.com/NousResearch/hermes-agent)) | What the bot learns: self-curated `MEMORY.md` and `USER.md`, nudges to save, new skills from solved tasks, full-text recall. One gateway, about twenty platforms, one identity across them; scheduled jobs deliver anywhere. |
| [Poke](https://poke.com) | Lives in iMessage and SMS, fixed voice, texts first when mail or calendar needs attention, treats those accounts as memory. Speaking first and personality make it feel present. |

**OpenClaw's pieces**

- Access: DM pairing, allowlists; `groupPolicy` allowlist, open or disabled per group.
- Mention gating: `requireMention`, `mentionPatterns`, reply-to-bot counts; `/activation mention|always`.
- Pending history: unmentioned messages kept (`historyLimit`, default 50) for the next triggered turn.
- Ambient rooms: `unmentionedInbound: "room_event"` with `visibleReplies: "message_tool"`: every message reaches the agent, final text stays private, the room hears only the `message` tool; typing suppressed.
- Per-group and per-sender tool policy (`tools`, `toolsBySender`); sandbox for non-main sessions.
- Sessions: `dmScope`, `identityLinks`, daily or idle reset, `/new`, `/reset`.
- Delivery: block streaming (`minChars`, `maxChars`, coalescing, newline mode), preview edits, typing keepalive, ack reactions.
- Bot loop protection, one-time group introduction, heartbeats that skip groups, voice-note transcription, media both ways.
- [WeChat](https://docs.openclaw.ai/channels/wechat): plugin by Tencent's Weixin team; direct chats and media, no groups, iLink QR login.

| Capability | OpenClaw | OpenProgram |
| --- | --- | --- |
| Platforms | 34, WeChat by plugin | Telegram, Discord, Slack, WeChat (iLink) |
| DM pairing, allowlist | Yes | Yes |
| Sender identity to the model | Text label plus metadata block | Structured `speaker_*` fields |
| Sender in the web transcript | — | Platform and sender above the bubble |
| Mention gating | All groups, patterns, reply-to-bot | Telegram, Discord, Slack; reply-to-bot; no custom patterns |
| `/activation`, `/new`, `/reset` | Yes | Yes |
| Pending group history | Yes | Yes |
| Ambient rooms | Yes | `/activation ambient`, `chat_send` |
| Tool policy per group or sender | Yes | Per-account `sender_access`; per-user group lists (full or chat), per account or group; `/memory`; asker-only answers |
| Session scope, reset | Yes | `session_scope`, daily or idle |
| Cross-channel identity links | Yes | No |
| Live progress | Preview edits | Placeholder edited with tool steps |
| Paragraph chunking while running | Yes | WeChat; edit-capable platforms keep the placeholder |
| Typing indicator | Yes | Telegram, Discord, WeChat |
| Ack reaction | Yes | Telegram, Discord, Slack (`ack_reaction`) |
| Bot loop protection | Yes | Bot messages dropped, per-room turn limit |
| Group introduction | Yes | No |
| Media in and out | Yes | Yes |
| Voice transcription | Yes | WeChat's own transcript; untranscribed voice kept as SILK |
| Questions back to the user | — | `/answer`, `/decline` |
| Proactive delivery | Heartbeats, cron | Always-on agents deliver to a channel |
| Self-curated memory, skills | Hermes | Shared memory workspace, per-person topics |

## Room modes

| Mode | Starts a turn | Other messages | Reply reaches the room |
| --- | --- | --- | --- |
| **mention** (default) | Mention, or reply to the bot | Pending history | Yes |
| **always** | Every message | — | Yes |
| **ambient** | Every message | — | Addressed: yes. Otherwise only through `chat_send`. |

- A non-addressing ambient message opens with `[room event]`, runs no ack or typing, and its final text stays in the transcript, labelled "overheard" on the web. Room events count against the flood limit.
- The account's `require_mention` gives the default; `/activation` stores a per-group override in `rooms.json`. Adapters only set `ChannelMessage.mentioned` and strip the mention; `channels/inbound/_room.py` decides, the same on every platform. Direct messages are never gated.
- `chat_send(text)` posts into the turn's chat, looked up by session key in `channels/inbound/_active_turns.py` (a `session_scope: main` session holds several chats). Needs only `reply`, is on the safe auto-allow list, is hidden from non-channel sources, at most five per turn. In an addressed turn it serves a short note before long work; the final reply is still posted.

## Pending history

```
[earlier messages in this chat]
> {"speaker": "...", "content": "..."}
> {"speaker": "...", "content": "..."}
```

- Kept in memory per room with speaker fields. The next turn takes the newest 50 ahead of its message. JSON escapes newlines, so a pending message cannot forge another speaker's line.
- Consumed entries are cleared; `/new` clears; a worker restart drops them. It never wakes the agent. The web folds the block at the top of the bubble.

## Delivery

| Element | Behaviour |
| --- | --- |
| Typing | Runs the whole turn. Telegram `sendChatAction` every 4 s, Discord every 8 s, WeChat every 5 s. WeChat needs a ticket from iLink `getconfig` with the user's latest `context_token`; the turn's end sends iLink's cancel. |
| No-edit platforms (WeChat) | A chunk leaves at a blank line once it has 200 characters; the buffer leaves when a tool call starts; open code fences are never split; no chunk exceeds the cap. The final reply, with `send_file` markers, supplies the rest. |
| Edit platforms | Keep the live placeholder |
| Ack reaction | Optional, marks a message picked up |
| Tool steps | Never in ambient mode, never on WeChat |

## Who may do what

| Sender | Group result | Turn runs as | Room commands |
| --- | --- | --- | --- |
| On the allowlist, or `group_full_access` | `full` | `sender_access` tier | Allowed |
| On `group_chat_only` | `chat` | `paired` tier | `/new`, `/reset`, `/activation`, `/memory` refused |
| Anyone else, or no user id | dropped | No reply, code, pending entry or session; worker log records the id | — |

`_access.group_sender_access` decides from the stable user id and never writes. In a direct message, allowlisted senders take the `sender_access` tier.

| `sender_access` | Whole-account ceiling |
| --- | --- |
| `owner` (default) | The owner's principal and tier with interactive approvals; session permission mode and rules apply. Approvals reach the chat as questions, answered with `/answer`. Speaker fields still name the sender. |
| `paired` | Replying, `chat_send` and memory, in groups too; files, shell and network tools refused |

| `/memory` | `TurnRequest.memory_policy_override`, narrowing only |
| --- | --- |
| `on` | The agent's own setting |
| `read` | Hides the writing tools |
| `off` | Stops recall, hides memory tools |

- Lists live in the account's `access.json`. A group may hold its own pair beside its activation in `rooms.json`; once present they replace the account's, only `reset` removes them, and emptying them leaves the group closed.
- A Discord thread has its own chat id and falls back to its parent channel's lists.
- The allowlist applies to every group, so listing a bound contact as `chat` is refused, and binding someone removes them from the chat lists.
- Lists change only from the local CLI and settings page. CLI and worker both write `rooms.json`, under the same cross-process file lock as `access.json`.
- A question from `runtime.ask` belongs to the person who started the turn; in a group `/answer` and `/decline` from anyone else are refused while it runs.

## Loops and floods

Bot messages are dropped. A room starts at most 10 turns in a sliding minute; past that, messages fall into pending history. One message delivered twice (Slack `message` and `app_mention`) starts one turn.

## WeChat

| Direction | Behaviour |
| --- | --- |
| Inbound media | iLink image, voice, file and video items point at AES-128-ECB objects on Tencent's C2C CDN and carry the key. They become attachments with the key; the shared path decrypts while downloading. The CDN says `application/octet-stream`, so image type comes from the decrypted header. |
| Voice | WeChat's transcript becomes the text, with no download. Without one it is SILK, saved as `voice.silk`. |
| Sending a file | `getuploadurl`, encrypt with a fresh key, post to the CDN, send an image, video or file item naming the download parameter and key. A caption follows as its own text. Uses the `channel.wechat.cdn` HTTP consumer, fixed to the CDN origin. |
| Limits | No groups or edits: always paragraph chunking, never the placeholder |

## Implementation status

| State | Items |
| --- | --- |
| Implemented | Pairing, allowlist; structured speaker identity; session scope and reset; room modes; pending history; ambient and `chat_send`; typing; WeChat chunking; ack reactions; `sender_access`; group lists; room memory; asker-only answers; bot dropping; turn limit; duplicate suppression; live placeholder; per-platform markdown and cap splitting; attachments on all four platforms; `/answer`, `/decline`; always-on delivery |
| Designed, not implemented | Custom mention patterns. Identity links: `channel:speaker_id` pairs map to one person id, memory files them under one topic, and a binding may give a linked person one direct session. Channel persona in the agent profile (voice, length, emoji), for channel turns only. Memory-scheduled follow-ups delivered to the person's last active channel, with heartbeats skipping groups. Group introductions. Transcribing voice with no platform transcript (WeChat SILK, Telegram and Discord notes). |
