Comprehensive tutorial series for OpenClaw AI agent gateway
Connect OpenClaw to Telegram — your first channel integration.
Telegram integration uses the Bot API via long polling (default) or webhooks. You’ll need:
openclaw.json/newbotbot (e.g., my_assistant_bot)123456789:ABC-DEF1234ghIkl-zyx57W2v1u123ew11)/setprivacy → Disable (to see all group messages without @mention)
/setjoingroups → Enable (to allow adding to groups)
/setcommands → Set your custom commands
// ~/.openclaw/openclaw.json
{
channels: {
telegram: {
enabled: true,
botToken: "123456789:ABC-DEF...", // Your token here
dmPolicy: "pairing", // Require approval for new users
},
},
}
# Set in your shell profile (~/.bashrc, ~/.zshrc)
export TELEGRAM_BOT_TOKEN="123456789:ABC-DEF..."
// openclaw.json — no token needed, auto-resolved from env
{
channels: {
telegram: {
enabled: true,
dmPolicy: "pairing",
},
},
}
openclaw gateway
Watch for:
[telegram] Bot started: @my_assistant_bot
[telegram] Long polling active
# List pending pairing requests
openclaw pairing list telegram
# Output:
# CODE USER EXPIRES
# ABC123 @yourname in 58 minutes
# Approve it
openclaw pairing approve telegram ABC123
Now your bot will respond!
New users must be approved via pairing code:
{
channels: {
telegram: {
dmPolicy: "pairing",
},
},
}
Pros: Secure, audit trail Cons: Manual approval step
Only specific user IDs can message:
{
channels: {
telegram: {
dmPolicy: "allowlist",
allowFrom: ["123456789", "987654321"], // Numeric Telegram user IDs
},
},
}
Finding your Telegram user ID:
# Method 1: Check gateway logs after messaging
openclaw logs --follow
# Look for: from.id: 123456789
# Method 2: Use Bot API directly
curl "https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates"
Anyone can message:
{
channels: {
telegram: {
dmPolicy: "open",
allowFrom: ["*"], // Required for open mode
},
},
}
Warning: Only use this for public bots with proper session isolation!
{
channels: {
telegram: {
// ... DM settings ...
// Group settings
groupPolicy: "allowlist", // "open" | "allowlist" | "disabled"
groups: {
"*": { // Default for all groups
requireMention: true, // Must @mention the bot
},
},
},
},
}
{
channels: {
telegram: {
groups: {
// Default behavior
"*": { requireMention: true },
// Specific group (use negative chat ID)
"-1001234567890": {
requireMention: false, // No mention needed
groupPolicy: "open", // Anyone in group can trigger
},
// Another group with allowlist
"-1009876543210": {
requireMention: true,
allowFrom: ["123456789"], // Only this user can trigger
},
},
},
},
}
Getting group chat ID:
# Add bot to group, send a message, check logs
openclaw logs --follow
# Look for: chat.id: -1001234567890
For Telegram supergroups with forum topics enabled:
{
channels: {
telegram: {
groups: {
"-1001234567890": {
topics: {
"1": { agentId: "main" }, // General topic → main agent
"3": { agentId: "coder" }, // Topic 3 → coder agent
"5": {
agentId: "support",
requireMention: false,
},
},
},
},
},
},
}
{
channels: {
telegram: {
// "off" | "partial" | "block" | "progress"
streaming: "partial", // Preview message + edits (default)
},
},
}
{
channels: {
telegram: {
textChunkLimit: 4000, // Max chars per message
chunkMode: "newline", // Split on paragraphs
linkPreview: true, // Show link previews
},
},
}
openclaw status
openclaw pairing list telegram
openclaw logs --follow
/setprivacyDisablegroups: {
"-1001234567890": { requireMention: true },
// or use "*" for all groups
}
openclaw logs for authorization failuresFor hosts with unstable connections:
{
channels: {
telegram: {
proxy: "socks5://user:pass@proxy-host:1080", // Optional proxy
network: {
autoSelectFamily: false, // Force IPv4 on WSL2
},
},
},
}
// Full working Telegram setup
{
channels: {
telegram: {
// Core settings
enabled: true,
// botToken from TELEGRAM_BOT_TOKEN env var
// Access control
dmPolicy: "pairing",
// Group behavior
groupPolicy: "allowlist",
groups: {
"*": {
requireMention: true,
},
// Specific trusted group
"-1001234567890": {
requireMention: false,
groupPolicy: "open",
},
},
// Response behavior
streaming: "partial",
textChunkLimit: 4000,
chunkMode: "newline",
linkPreview: true,
// Reliability
retry: {
attempts: 3,
minDelayMs: 1000,
maxDelayMs: 10000,
},
},
},
}
Learn the essential CLI commands for managing your gateway →