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:

ChannelNotes
DiscordBot tokens, slash commands
Google ChatWorkspace-bound
iMessagePer-device pairing required
MatrixFederated; self-hosted homeserver friendly
Microsoft TeamsApp / bot framework
SignalLinked-device approach
SlackOAuth + events API
TelegramBot tokens; polling or webhook
WhatsAppPairing flow; 24-hour message window
ZaloVietnam-specific
WebChatBuilt-in browser surface
Mobile nodesOpenClaw 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 agent

This 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:

ChannelConstraint to know
WhatsApp24-hour window for proactive messages; outside that, must be templated
SlackMention rules vary by channel privacy; threading rules
TelegramGroup bots respect message scope (@mention to activate)
iMessagePer-device pairing; rate-limited delivery
Email (when integrated)Daily quotas; bounce handling
DiscordSlash commands vs message events; per-server permissions
MatrixE2E 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 eventDesired route
Personal Telegram DMPersonal assistant agent
Work Slack thread in #dv-regressionVerification / debug agent
WhatsApp family groupRestricted family agent
Dashboard session in coding workspaceCoding agent
Mobile node photo uploadVisual / context agent with media tools
Slack DM from new userDefault 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:

ChannelDefault activation
Slack DMAlways
Slack channelOnly on @mention of bot
Slack thread (bot in thread)Always
Telegram DMAlways
Telegram groupOnly on @mention
Discord channelPer role config; usually mention-only
DashboardAlways (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

PatternWhy it hurts
Connecting all channels at once during setupOne fails; you don't know which
One channel, one default agent, no bindingsWrong agent answers everywhere
Ignoring mention rulesBot spams or stays silent
Treating media-derived text as trustedPrompt-injection vector
Pairing state in volatile storageChannel drops on restart
Logging full message bodies in plain textPII leaks via logs
Same channel account routed to two agents simultaneouslyRace 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

  1. What problem does OpenClaw Channels and Gateway solve, and what assumptions does it rely on?
  2. Which boundary or failure case is easiest to miss, and how would you expose it?
  3. What alternative design would you consider, and what trade-off would change the decision?
  4. 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