
Mastering Clawed Code Channels: A Step-by-Step Guide to Telegram & Discord Integration
Table of Contents
TL;DR:
- Install Bun and OpenClaw locally and run the gateway.
- Create a Telegram or Discord bot via BotFather / Discord Developer Portal.
- Securely set the bot token and pair your device with a one-time code.
- Enable audio and summarizer plugins to get voice replies and quick summaries.
- Test the bot; persistent memory keeps context across sessions.
Why this matters
Developers and product managers often need an AI assistant that can sit in the chat rooms they already use. A few frustrations show up:
- Setting up the JavaScript runtime (Bun) and all dependencies can feel like a separate project.
- Bot tokens are sensitive; forgetting to store them in a protected environment variable can leak data.
- The pairing step is easy to skip, but then anyone can spam the bot.
- Telegram and Discord both enforce privacy mode; you must adjust the bot’s permissions.
- Audio messages are a huge part of user communication, yet most starter bots only handle text.
- You want the assistant to remember earlier context; otherwise it feels like a stateless chatbot.
- Cloud-based APIs are costly; a $200 plan that gives you $5,000 calls per month can be more economical than per-token billing.
This guide shows you how to build a local OpenClaw instance that talks to Telegram and Discord, keeps a persistent memory, and can understand and reply to audio thanks to Eleven Labs. The steps are hands-on, and each command is explained with context.
Core concepts
The heart of the system is an OpenClaw process, sometimes called the gateway. It receives messages from the messaging platform, forwards them to an LLM, and streams replies back. The gateway is written in TypeScript and runs on Bun, a fast JavaScript runtime that ships with a bundled JavaScript engine OpenClaw — README (2024).
- Channels are logical namespaces. Telegram DM, a Discord guild channel, and even a Slack channel are each a channel. The gateway uses the channel name to keep conversation state isolated.
- DM policy controls who can talk to the bot. The default policy is pairing: the bot sends a short code and only accepts the message if the user approves the code in the CLI. Pairing prevents spam and gives you a quick audit trail.
- Environment variables hold secrets like TELEGRAM_BOT_TOKEN and DISCORD_BOT_TOKEN. The gateway looks for the variables first, then falls back to values in the config.json file.
- Plugins extend the gateway. Official plugins live in the OpenClaw marketplace and are installed with openclaw plugins install
. The marketplace list is in the docs OpenClaw — Plugins (2024). - Persistent memory is powered by the memory-lancedb plugin, which writes conversation history to a local Lancedb database. This keeps context across restarts.
- Audio is handled by the voice-call plugin and the Eleven Labs TTS/STT service Eleven Labs — TTS (2024). A user can send a voice note; the gateway forwards it to Eleven Labs for transcription and then feeds the text to the LLM.
- Summaries are produced by the built-in summarize skill. The skill can take a URL, a file, or an audio clip and return a concise summary OpenClaw — Summarize Skill (2024).
Think of the gateway as a relay: a message comes in from a chat, the relay passes it to the AI, the AI writes a reply, and the relay sends the reply back. The relay is highly configurable; you can add new plugins or change how a channel behaves without touching the AI code.
How to apply it
Below is a step-by-step recipe that starts from a fresh Ubuntu 24.04 server. If you use Windows or macOS, the same commands work with PowerShell or Terminal.
1. Prepare the machine
# Update the package index
sudo apt update && sudo apt upgrade -y
# Install curl and build-essential – required for Bun
sudo apt install -y curl build-essential
# Install Bun – the JavaScript runtime that OpenClaw uses
curl -fsSL https://bun.sh/install | bash
# Add Bun to the current shell
source ~/.bashrc
# Verify Bun
bun --version
Bun is the recommended runtime because it is lightweight and faster than Node for the OpenClaw CLI OpenClaw — README (2024).
2. Clone OpenClaw and start the gateway
# Clone the repo
git clone https://github.com/openclaw/openclaw.git
cd openclaw
# Install dependencies – Bun can install via npm
bun install
# Start the gateway on port 18789
openclaw gateway --port 18789 --verbose
The gateway stays running. In a separate terminal you will use the openclaw command to configure the bot.
3. Create a Telegram bot with BotFather
- Open Telegram and search for @BotFather.
- Type /newbot and follow the prompts – give your bot a name and a username.
- BotFather will return a token that looks like 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11.
Store the token in an environment variable:
export TELEGRAM_BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
The gateway reads TELEGRAM_BOT_TOKEN automatically.
4. Set DM policy and pair the bot
OpenClaw’s default DM policy is pairing, so you must approve the code shown by the bot. First, set the policy:
openclaw config set channels.telegram.dmPolicy pairing
Now send a message to the bot from your Telegram account. The bot replies with a short numeric code, e.g., A1B2C3. Approve the code in the CLI:
openclaw pairing approve A1B2C3
The bot will now accept messages from your account only. This step protects against spam and accidental leaks.
5. Enable the Discord channel (optional)
If you also want to use Discord, create a bot in the Discord Developer Portal and enable the Message Content Intent.
# Create a bot, copy the token
export DISCORD_BOT_TOKEN=YOUR_DISCORD_TOKEN
Set the DM policy for Discord and pair:
openclaw config set channels.discord.dmPolicy pairing
openclaw pairing approve YOUR_CODE
The Discord documentation is in the OpenClaw docs OpenClaw — Discord (2024).
6. Install plugins
OpenClaw ships with a handful of bundled plugins, but you can install more from the marketplace.
# Install the memory-lancedb plugin for persistent memory
openclaw plugins install @openclaw/memory-lancedb
# Install the voice-call plugin for audio
openclaw plugins install @openclaw/voice-call
# Restart the gateway so the new plugins load
openclaw gateway --restart
The marketplace list is in the docs OpenClaw — Plugins (2024).
7. Test text and audio
Send a normal text message to the bot and see a reply. Then send a voice note; the voice-call plugin forwards it to Eleven Labs, which transcribes it and feeds the text to the AI. Finally, ask the bot to summarize a URL:
Hey bot, can you summarize https://openai.com/research/?
You should receive a concise summary powered by the summarize skill OpenClaw — Summarize Skill (2024).
8. Monitor usage and cost
OpenClaw uses an LLM provider. If you use Anthropic, you pay per token; the $200 plan gives you $5,000 calls which can be more economical [UNVERIFIED]. Keep an eye on your usage in the gateway logs or the provider’s dashboard.
Pitfalls & edge cases
| Issue | Why it happens | Mitigation |
|---|---|---|
| Bot token leaks | Storing the token in plain text or committing it to source control | Use an .env file and add it to .gitignore; never expose the token in logs |
| Missing privacy mode permissions | Discord bots default to privacy mode and only see messages from the bot itself | Enable Message Content Intent in the developer portal and set channels.discord.dmPolicy pairing |
| Audio fails after plugin update | Plugin may have changed its API or require a gateway restart | Restart the gateway after any plugin change; check the changelog OpenClaw — Voice Call Plugin (2024) |
| Persistent memory not loading | memory-lancedb needs a running Lancedb database | Ensure the database file is writable and that the plugin is installed OpenClaw — Plugins (2024) |
| Exceeding free tier | The subscription plan has a cap of $5,000 API usage | Set usage alerts in the provider dashboard; limit the number of concurrent sessions |
| Channel flag missing | New OpenClaw releases require the –channel flag to enable channel listening | Run openclaw –channel after updating the gateway |
Quick FAQ
Q: How do I create a Telegram bot token? A: Talk to @BotFather in Telegram, use /newbot, and copy the token. Store it in TELEGRAM_BOT_TOKEN.
Q: What is the pairing token?
A: It’s a short code the bot sends when you first DM it; you approve it with openclaw pairing approve . Only approved users can talk to the bot.
Q: Can I send audio messages? A: Yes – install the voice-call plugin and make sure Eleven Labs TTS/STT is enabled Eleven Labs — TTS (2024).
Q: How do I enable persistent memory? A: Install the memory-lancedb plugin and it will write context to a local database.
Q: How much does the subscription cost? A: The current plan is $200/month for up to $5,000 API calls. Compare this to per-token pricing on Anthropic or other LLMs.
Q: Where can I learn more about plugins? A: The plugin marketplace is documented at OpenClaw — Plugins (2024).
Q: How do I add a Discord server? A: Create a bot in the Discord Developer Portal, enable intents, copy the token to DISCORD_BOT_TOKEN, and run the pairing steps.
Conclusion
You now have a local AI assistant that sits in your Telegram and Discord chats, remembers context, and can understand voice. The steps above are a starting point; you can extend the system with more plugins, custom prompts, or even a UI.
- If you’re building a product, consider hosting the gateway on a dedicated VM or container.
- For developers, the OpenClaw docs and the masterclass videos provide deeper dives into prompt engineering and advanced workflows.
- Keep your tokens safe, monitor usage, and remember to restart the gateway after every plugin change.
Happy building!





