OpenClaw Setup Guide: Telegram & Discord Integration
Published July 26, 2026 · Editorial policy

Introduction
Integrating AI agents into existing communication workflows has shifted from an experimental novelty to a standard architectural requirement for modern engineering teams. Whether you are building an automated DevOps sentinel, a code-review copilot, or a custom notification dispatcher, routing agentic loops through your team's chat infrastructure is essential.
OpenClaw is an open-source framework designed to bridge local or cloud-hosted large language models with real-time messaging platforms. Unlike monolithic SaaS wrappers, OpenClaw gives developers raw control over state management, message routing, tool execution, and memory persistence.
This guide walks you through provisioning, configuring, and deploying OpenClaw with bi-directional integration for both Telegram and Discord. By the end of this setup, you will have a localized agent capable of listening to webhook events, processing prompts via your chosen LLM backend, and replying natively within channel threads.
Prerequisites and System Requirements
Before initializing the OpenClaw repository, ensure your environment meets the baseline infrastructure requirements. We assume a Unix-like environment (Linux/macOS) with standard developer tooling.
Minimum Specifications
- OS: Ubuntu 22.04 LTS / Debian 12 / macOS Ventura or later
- Runtime: Node.js
>= 18.17.0or Bun>= 1.0.0 - Python:
>= 3.10(if utilizing local embedding models or custom Python-based tools) - Memory: Minimum 2GB RAM (4GB+ recommended if running local vector databases)
- Network: Outbound HTTPS access to Telegram and Discord API gateways
Required API Keys and Tokens
Gather the following credentials before proceeding to the configuration phase:
- LLM Provider API Key: An active API key from OpenAI, Anthropic, or an endpoint running a local model via Ollama/vLLM.
- Telegram Bot Token: Generated via
@BotFather. - Discord Bot Token: Generated via the Discord Developer Portal with appropriate Gateway Intents enabled.
Step 1: Environment Provisioning and Installation
Start by cloning the OpenClaw repository and installing the necessary workspace dependencies. We will use pnpm for strict dependency resolution, though npm or yarn are fully supported.
# Clone the repository
git clone https://github.com/openclaw/openclaw.git
cd openclaw
# Install dependencies
pnpm install
# Copy the environment template
cp .env.example .env
Open the .env file in your preferred editor and populate your core LLM provider credentials. For this guide, we will use Anthropic's Claude 3.5 Sonnet as our primary inference engine, though you can substitute any supported provider.
# .env
NODE_ENV=production
LOG_LEVEL=info
# Primary LLM Configuration
DEFAULT_LLM_PROVIDER=anthropic
ANTHROPIC_API_KEY=sk-ant-api03-your-actual-key-here
DEFAULT_MODEL=claude-3-5-sonnet-20241022
# Database & Memory
DATABASE_URL=sqlite://./data/openclaw.db
VECTOR_STORE=memory
Build the project binaries to ensure TypeScript compilation succeeds without errors:
pnpm build
Step 2: Configuring the Telegram Channel
To interface OpenClaw with Telegram, you must provision a Telegram bot and configure OpenClaw's polling or webhook transport layer.
1. Create a Telegram Bot
- Open Telegram and search for @BotFather.
- Send the command
/newbotand follow the prompts to name your bot and choose a unique username. - Copy the HTTP API token provided by BotFather.
2. Configure OpenClaw Telegram Integration
Open your main configuration file (typically config/default.yaml or created via initialization) and add the Telegram channel block.
# config/default.yaml
channels:
telegram:
enabled: true
token: "${TELEGRAM_BOT_TOKEN}"
# Optional: restrict bot interaction to specific chat IDs
allowed_chat_ids:
- -1001234567890 # Example group ID
# Polling configuration (use webhooks for high-throughput production setups)
polling:
interval_ms: 1000
handlers:
- type: "default"
system_prompt: "You are OpenClaw, an advanced engineering assistant embedded in Telegram."
Export your bot token to your environment or append it to your .env file:
export TELEGRAM_BOT_TOKEN="your-telegram-bot-token-from-botfather"
Verify that the Telegram connector initializes correctly by running a dry-run test:
pnpm start --verify-channel telegram
Step 3: Configuring the Discord Channel
Discord requires more explicit permission scopes and gateway intents because of its strict event-driven architecture.
1. Create a Discord Application
- Navigate to the Discord Developer Portal.
- Click New Application and give it a descriptive name.
- Navigate to the Bot tab on the left sidebar and click Add Bot.
- Under the Privileged Gateway Intents section, enable:
- Presence Intent
- Server Members Intent
- Message Content Intent (Critical for reading user prompts)
- Reset and copy your Bot Token.
2. Invite the Bot to Your Server
- Go to the OAuth2 > URL Generator tab.
- Select the following scopes:
botapplications.commands
- Select the following bot permissions:
View ChannelsSend MessagesSend Messages in ThreadsRead Message HistoryManage Messages
- Copy the generated URL, open it in your browser, and select the target Discord server to authorize the bot.
3. Configure OpenClaw Discord Integration
Add the Discord configuration block to your config/default.yaml file:
# config/default.yaml
channels:
discord:
enabled: true
token: "${DISCORD_BOT_TOKEN}"
application_id: "${DISCORD_APPLICATION_ID}"
intents:
- "Guilds"
- "GuildMessages"
- "MessageContent"
prefix: "!"
handlers:
- type: "default"
system_prompt: "You are OpenClaw, a technical operations assistant operating in Discord."
Export your Discord environment variables:
export DISCORD_BOT_TOKEN="your-discord-bot-token"
export DISCORD_APPLICATION_ID="your-application-client-id"
Step 4: Multi-Channel Routing and Unified Memory
One of OpenClaw's core architectural advantages is its ability to maintain unified session context across disparate platforms. A developer can start a troubleshooting thread in Discord and reference that conversation state via Telegram.
Configuring the Router
Define your routing rules in config/router.yaml to dictate how incoming payloads are funneled through middleware, security filters, and LLM processing pipelines.
version: "1.0"
router:
default_handler: "llm_agent"
middleware:
- name: "rate_limiter"
config:
window_ms: 60000
max_requests: 30
- name: "content_sanitizer"
config:
strip_secrets: true
max_length: 4000
bindings:
- channel: "telegram"
workspace: "engineering-core"
- channel: "discord"
workspace: "engineering-core"
Shared Memory Store
To ensure conversation history persists across both platforms, configure a persistent backend store. For local setups, SQLite is sufficient; for high-availability clusters, point OpenClaw to a PostgreSQL instance.
# config/database.yaml
database:
driver: "postgres"
url: "${DATABASE_URL}"
pool:
min: 2
max: 10
migrations: "auto"
Step 5: Advanced Tool Execution & Safety Sandbox
OpenClaw allows agents to execute local tools (e.g., executing shell scripts, querying databases, or fetching internal API documentation). Because you are bridging public or semi-private chat apps to system resources, sandboxing is non-negotiable.
Defining Custom Tools
Create a custom tool definition in src/tools/system_diagnostics.ts:
import { Tool } from '@openclaw/core';
export const SystemDiagnosticsTool: Tool = {
name: 'system_diagnostics',
description: 'Returns real-time CPU and memory metrics for the host node.',
parameters: {
type: 'object',
properties: {
detailed: {
type: 'boolean',
description: 'Include process-level breakdown.'
}
}
},
execute: async ({ detailed }) => {
const os = require('os');
return {
uptime: os.uptime(),
freeMemory: os.freemem(),
totalMemory: os.totalmem(),
loadAverage: os.loadavg(),
};
}
};
Register this tool in your agent initialization configuration to allow Telegram and Discord users to trigger diagnostics natively via chat commands like /diagnostics.
Step 6: Production Deployment via Docker Compose
To run OpenClaw reliably in a Tier-1 production environment, containerize the application alongside its persistence layers.
1. Dockerfile
Create a multi-stage Dockerfile in the root of your repository:
# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
COPY package.json pnpm-lock.yaml ./
RUN npm install -g pnpm && pnpm install --frozen-lockfile
COPY . .
RUN pnpm build
# Production stage
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
RUN npm install -g pnpm
COPY package.json pnpm-lock.yaml ./
RUN pnpm install --prod --frozen-lockfile
COPY --from=builder /app/dist ./dist
COPY config ./config
EXPOSE 3000
CMD ["pnpm", "start"]
2. Docker Compose Manifest
Create a docker-compose.yml file to manage the OpenClaw service and its PostgreSQL state backend:
version: '3.8'
services:
postgres:
image: postgres:15-alpine
environment:
POSTGRES_DB: openclaw
POSTGRES_USER: openclaw_user
POSTGRES_PASSWORD: secure_password_here
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U openclaw_user -d openclaw"]
interval: 5s
timeout: 5s
retries: 5
openclaw:
build: .
restart: unless-stopped
depends_on:
postgres:
condition: service_healthy
environment:
- NODE_ENV=production
- DATABASE_URL=postgresql://openclaw_user:secure_password_here@postgres:5432/openclaw
- TELEGRAM_BOT_TOKEN=${TELEGRAM_BOT_TOKEN}
- DISCORD_BOT_TOKEN=${DISCORD_BOT_TOKEN}
- DISCORD_APPLICATION_ID=${DISCORD_APPLICATION_ID}
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
volumes:
- ./config:/app/config
ports:
- "3000:3000"
volumes:
pgdata:
Launch the stack in detached mode:
docker compose up -d --build
Monitor logs to confirm successful handshake with both chat gateways:
docker compose logs -f openclaw
You should see output similar to:
[INFO] [TelegramConnector] Initialized polling for bot @YourEngineeringBot
[INFO] [DiscordConnector] Gateway connection established successfully (Shard 0)
[INFO] [Router] Core agent runtime ready and listening for events.
Troubleshooting Common Integration Issues
-
Discord Bot Ignores Messages:
- Cause: The Message Content Intent is disabled in the Discord Developer Portal.
- Fix: Enable the intent in your application settings, regenerate the token if necessary, and restart your container.
-
Telegram Webhook/Polling Conflicts:
- Cause: Leftover webhook registrations interfering with local polling.
- Fix: Clear existing webhooks by hitting the Telegram API directly:
curl -X POST "https://api.telegram.org/bot<YOUR_TOKEN>/deleteWebhook?drop_pending_updates=true"
-
Database Lock Contension (SQLite):
- Cause: Multiple workers attempting concurrent writes to a local SQLite file.
- Fix: Migrate to PostgreSQL using the Docker Compose setup provided above for high-concurrency production workloads.
Related articles

Cursor IDE: AI-Powered Development Setup Guide

OpenCode CLI Guide: AI-Powered Coding for Developers
