A relay bridge that keeps Discord and Telegram bots online while letting the AI backend sleep to save costs.
If you’re running OpenClaw on a Sprite or any cloud sandbox, you’ve probably hit the cost problem: keeping a machine running 24/7 just to respond to occasional Discord or Telegram messages is wasteful. But if you stop the machine, your bots go offline.
ClawRelay solves this with a wake-on-message pattern. A tiny, always-on relay stays connected to Discord and Telegram, queues incoming messages, wakes the sleeping sandbox when a message arrives, and forwards everything to your OpenClaw gateway.
The architectureh2
The system has two parts:
-
The relay (
packages/relay) — An always-on Node.js service that maintains Discord WebSocket and Telegram long-polling connections. It’s lightweight enough to run on a Fly.io machine with minimal resources. -
The channel plugin (
packages/relay-channel) — An OpenClaw plugin that registers arelay.inboundgateway method and a/relay/healthHTTP endpoint. This is what the relay talks to.
When a message arrives:
- The platform adapter normalizes the message into a common format
- The message hits an in-memory FIFO queue (5-minute TTL)
- The wake manager checks
/relay/health— if the gateway is down, it wakes the Sprite via the Machines API - The relay connects to the OpenClaw gateway via WebSocket and authenticates
- The message is sent as a
relay.inboundmethod call with streaming enabled - As tokens arrive, the relay progressively edits the Discord/Telegram message with accumulated text
- On completion, the final response is delivered, split across messages if needed
The result: your bots appear permanently online, but the expensive AI backend only runs when there’s actually a conversation happening.
Streaming responsesh2
One detail I’m proud of is the streaming implementation. When OpenClaw generates a response, tokens stream back via relay.stream.delta events. The relay accumulates these and progressively edits the platform message — so users see the response being typed out in real time, just like native OpenClaw channels.
Discord messages are edited every second (throttled to avoid rate limits), and long responses are automatically split at platform limits (2000 chars for Discord, 4096 for Telegram).
Deploymenth2
The relay runs on Fly.io, connected to an OpenClaw gateway on a Sprite:
cd packages/relayfly deployfly secrets set DISCORD_TOKEN="..." TELEGRAM_BOT_TOKEN="..." \ GATEWAY_AUTH_TOKEN="..." SPRITE_TOKEN="..."The Sprite can be set to auto-stop when idle. When the next message comes in, ClawRelay wakes it up, waits for the health check to pass, and forwards the queued messages. Cold start is typically under 10 seconds.
Check it out on GitHub.