Module 1: Architecture as a System
OpenClaw Channels and Gateway
Learning objectives
- Explain the core mental model behind OpenClaw Channels and Gateway
- Apply OpenClaw Channels and Gateway within Architecture as a System
- Identify important boundaries, trade-offs, and failure modes
- Produce concrete evidence from the practice exercise
Related: OpenClaw Overview and Mental Model | OpenClaw Multi Agent Routing | OpenClaw Deployment and Operations | OpenClaw Safety Sandboxing and Guardrails
The gateway is the system boundary between human communication surfaces and the agent runtime. This note covers what each channel adds, how routing works at the gateway level, and what fails when channels are wired badly.
Gateway Responsibility
If the agent is the brain, the gateway is the nervous system connecting it to the outside world.
The gateway owns:
- Channel connections (WebSocket, polling, webhooks per adapter)
- Channel accounts (specific bot identities on each channel)
- Session key generation
- Routing (binding inbound to agent)
- Dashboard UI
- Media handling (download, re-upload, format conversion)
- Mobile node pairing
- Service lifecycle (boot, reconnect, shutdown)
- Operational commands (CLI, dashboard actions)
- Audit logging at the boundary
┌──────────── EXTERNAL WORLD ────────────┐
│ Slack Telegram Discord WhatsApp Web ... │
└──────────────────┬──────────────────────┘
│ events
▼
┌────────────────────── GATEWAY ────────────────┐
│ │
│ ┌───────────────┐ ┌───────────────┐ │
│ │ Adapters │ │ Routing │ │
│ │ (per channel) │──▶│ (bindings) │ │
│ └───────────────┘ └───────────────┘ │
│ │
│ ┌───────────────┐ ┌───────────────┐ │
│ │ Sessions │ │ Dashboard + │ │
│ │ (key store) │ │ Audit │ │
│ └───────────────┘ └───────────────┘ │
└───────────────────────┬───────────────────────┘
│ dispatch
▼
┌──────────────────┐
│ AGENT RUNTIME │
└──────────────────┘Engineering analogy: the gateway is to agents what nginx is to web apps — handles connections, routing, TLS, observability, and lets the application focus on logic. You don't write a chat app from raw sockets; you don't write an agent system from raw channel APIs.
Channels
OpenClaw official docs describe support for many channels and surfaces:
| Channel | Notes |
|---|---|
| Discord | Bot tokens, slash commands |
| Google Chat | Workspace-bound |
| iMessage | Per-device pairing required |
| Matrix | Federated; self-hosted homeserver friendly |
| Microsoft Teams | App / bot framework |
| Signal | Linked-device approach |
| Slack | OAuth + events API |
| Telegram | Bot tokens; polling or webhook |
| Pairing flow; 24-hour message window | |
| Zalo | Vietnam-specific |
| WebChat | Built-in browser surface |
| Mobile nodes | OpenClaw mobile clients |
Exact channel maturity and setup vary. Start with one channel, verify behavior, then expand. Adding multiple at once mixes failures.
Channel Accounts
Some channels support multiple accounts. OpenClaw routes different account IDs to different agents.
slack:work-bot ──▶ coding agent
slack:helpdesk-bot ──▶ support agent
telegram:personal-bot ──▶ personal agent
telegram:family-bot ──▶ family agentThis is routing plus identity management, not just transport.
Example use cases:
- Personal Telegram bot → personal agent
- Work Slack workspace → work agent
- WhatsApp business number → support agent
- Multiple Slack apps in one workspace, each routing to a different team's agent
See OpenClaw Multi Agent Routing.
Channel-Specific Constraints
Different channels have different rules. Bindings and tools should respect them:
| Channel | Constraint to know |
|---|---|
| 24-hour window for proactive messages; outside that, must be templated | |
| Slack | Mention rules vary by channel privacy; threading rules |
| Telegram | Group bots respect message scope (@mention to activate) |
| iMessage | Per-device pairing; rate-limited delivery |
| Email (when integrated) | Daily quotas; bounce handling |
| Discord | Slash commands vs message events; per-server permissions |
| Matrix | E2E encryption considerations |
A tool that posts to a channel must know the channel's posting rules. The dashboard helps surface these constraints in the channel config view.
Media Handling
Modern chat agents need more than text:
- Images
- Audio (voice messages)
- Documents (PDFs, Office files)
- Videos
- Camera / mobile node inputs
Media expands capability and expands risk. Files can contain:
- Secrets (screenshots of credentials)
- Hostile content (injected instructions in PDFs)
- Huge contexts (large images blow token budgets)
- PII (photos of documents)
The gateway downloads media, may run it through preprocessors (OCR, vision model description, transcription), and surfaces the result to the agent. The agent's tools then operate on the processed text or, for vision-capable models, the original.
Discipline: treat media-derived text as untrusted input the same way you'd treat web content. Apply input guardrails. See OpenClaw Safety Sandboxing and Guardrails.
Gateway Data Flow
Channel adapter
│ receives event
▼
Normalize event
│ message text, media, sender, account, thread
▼
Apply allowlists / mention rules
│
▼
Resolve binding
│ choose agent + session key
▼
Invoke agent runtime
│
▼
Post-process response (channel-specific formatting, length limits)
│
▼
Send response through same channel
│
▼
Audit log (inbound + outbound)Each step is an opportunity for correctness or failure. For example:
- A Slack thread and a Slack channel are not the same session
- A WhatsApp account and a Telegram account should not silently share identity
- A media-bearing event needs a different normalization path
Channel Identity Is Not User Identity
The same human can appear as:
- Telegram peer ID
- Slack user ID
- WhatsApp phone number
- Dashboard user
- Mobile node pairing
OpenClaw should not assume these are the same person unless explicitly configured. Identity merging is powerful, but it can also leak context across boundaries the user expected to be separate.
When merging identity is desired, do it through an explicit user profile mapping, not by inference.
Routing Examples
| Incoming event | Desired route |
|---|---|
| Personal Telegram DM | Personal assistant agent |
Work Slack thread in #dv-regression | Verification / debug agent |
| WhatsApp family group | Restricted family agent |
| Dashboard session in coding workspace | Coding agent |
| Mobile node photo upload | Visual / context agent with media tools |
| Slack DM from new user | Default agent (conservative) |
This is the practical strength of OpenClaw: the same gateway can host different agents with different authority routed by channel + account + peer.
Mention Rules and Activation
Channel-specific rules for when to activate the agent:
| Channel | Default activation |
|---|---|
| Slack DM | Always |
| Slack channel | Only on @mention of bot |
| Slack thread (bot in thread) | Always |
| Telegram DM | Always |
| Telegram group | Only on @mention |
| Discord channel | Per role config; usually mention-only |
| Dashboard | Always (it's a private session) |
Misconfigured activation creates two failure modes:
- Bot is silent when expected → user thinks it's broken
- Bot replies to every message in a busy channel → spam, downvotes, removal
The gateway honors these rules; configure carefully per binding.
WhatsApp / iMessage Pairing
WhatsApp and iMessage use pairing rather than bot tokens. The gateway stores pairing state in the agent directory.
For WhatsApp:
- Initial QR scan from a phone with WhatsApp Web active
- Pairing persists across gateway restarts (if state is preserved)
- Re-pair if state is lost
For iMessage:
- macOS host, signed in to iCloud
- Per-device pairing
- Subject to Apple's rate limits
Pairing is the most painful channel setup. Get it working last; document the recovery procedure.
Gateway Debug Checklist
When traffic isn't reaching the right agent:
- Did the channel adapter receive the event? (gateway logs, dashboard "channel status")
- Was the sender allowed? (allowlist / blocklist)
- Did mention rules block or allow it? (channel + binding config)
- Which binding matched? (specificity ordering)
- Which session key was generated?
- Which agent directory and workspace were used?
- Was media downloaded and passed safely?
- Was the response sent to the correct thread / account?
Walk down this list once per failure. The bug is almost always at the layer you skipped.
Channel Health Monitoring
The dashboard surfaces per-channel health:
- Connected / disconnected / reconnecting
- Last inbound timestamp
- Last outbound timestamp
- Error rate (e.g. 429s, 5xx, auth)
- Pending pairings or auth refreshes
Alerts to wire up:
- Channel disconnected for > 5 minutes
- 5xx rate > threshold
- Pairing expired
- Outbound queue backing up
See OpenClaw Deployment and Operations.
Anti-Patterns
| Pattern | Why it hurts |
|---|---|
| Connecting all channels at once during setup | One fails; you don't know which |
| One channel, one default agent, no bindings | Wrong agent answers everywhere |
| Ignoring mention rules | Bot spams or stays silent |
| Treating media-derived text as trusted | Prompt-injection vector |
| Pairing state in volatile storage | Channel drops on restart |
| Logging full message bodies in plain text | PII leaks via logs |
| Same channel account routed to two agents simultaneously | Race conditions; duplicate replies |
Operational Discipline
For production:
- [ ] Channel-by-channel onboarding documented
- [ ] Pairing recovery runbook
- [ ] Per-channel health monitored
- [ ] Mention rules verified for each channel
- [ ] Media handling tested for each channel that supports it
- [ ] Allowlists configured for high-risk channels
- [ ] Log redaction enabled
- [ ] Outbound retry on transient failures
Related
- OpenClaw Multi Agent Routing — channel-to-agent bindings
- OpenClaw Safety Sandboxing and Guardrails — channel allowlists, media handling
- OpenClaw Configuration Files — channel config in
openclaw.json - OpenClaw Deployment and Operations — running the gateway reliably
- OpenClaw State and Sessions — channel + account + peer = session key
- OpenClaw Index — full topic map
Practice lab
Implement the smallest runnable agent workflow that demonstrates OpenClaw Channels and Gateway. Trace inputs, state, model and tool calls, outputs, and cost; inject one failure and add a regression test that prevents it from returning. Add an operational constraint such as concurrency, recovery, security, latency, or cost, and defend the resulting design trade-off.
Review questions
- What problem does OpenClaw Channels and Gateway solve, and what assumptions does it rely on?
- Which boundary or failure case is easiest to miss, and how would you expose it?
- What alternative design would you consider, and what trade-off would change the decision?
- What artifact, trace, test, or metric proves that your implementation is correct?
Completion evidence
- A working artifact, annotated trace, or reproducible experiment
- At least one normal case and one deliberately failing or boundary case
- A concise explanation of the design choice and its trade-offs
- Saved output showing how correctness was evaluated