OpenClaw Telegram
Connect OpenClaw to Telegram in an E2B sandbox, approve pairing, and chat through your bot.
OpenClaw supports Telegram as a chat channel. In E2B you can run OpenClaw in a sandbox, attach your bot token, and approve user pairing from the terminal.
This guide covers the working flow we used:
- Start OpenClaw in a sandbox.
- Enable the Telegram plugin.
- Add Telegram channel credentials.
- Start the channel runtime in background.
- Approve Telegram pairing.
Prerequisites
- A Telegram bot token from @BotFather. There’s instructions to follow there, it runs /newbot for you and walks you through naming and creating your bot.
- An OpenAI API key for the OpenClaw model.
- E2B API key configured locally.
Quick start
import { Sandbox } from 'e2b'
const GATEWAY_PORT = 18789
const GATEWAY_TOKEN = process.env.OPENCLAW_APP_TOKEN || 'my-openclaw-token'
const sandbox = await Sandbox.create('openclaw', {
envs: {
OPENAI_API_KEY: process.env.OPENAI_API_KEY,
TELEGRAM_BOT_TOKEN: process.env.TELEGRAM_BOT_TOKEN,
},
timeoutMs: 3600_000,
})
await sandbox.commands.run('openclaw config set agents.defaults.model.primary openai/gpt-5.2')
// Enable the Telegram plugin (required before adding the channel)
await sandbox.commands.run('openclaw config set plugins.entries.telegram.enabled true')
await sandbox.commands.run('openclaw channels add --channel telegram --token "$TELEGRAM_BOT_TOKEN"')
await sandbox.commands.run(
`bash -lc 'openclaw config set gateway.controlUi.allowInsecureAuth true && ` +
`openclaw config set gateway.controlUi.dangerouslyDisableDeviceAuth true && ` +
`openclaw gateway --allow-unconfigured --bind lan --auth token --token ${GATEWAY_TOKEN} --port ${GATEWAY_PORT}'`,
{ background: true }
)
for (let i = 0; i < 45; i++) {
const probe = await sandbox.commands.run(
`bash -lc 'ss -ltn | grep -q ":${GATEWAY_PORT} " && echo ready || echo waiting'`
)
if (probe.stdout.trim() === 'ready') break
await new Promise((r) => setTimeout(r, 1000))
}For Telegram setup, you do not need to open the gateway URL in a browser. The gateway process is used here as a long-running channel runtime.
Pair your Telegram user
- Open your bot in Telegram and send a message (for example:
hi). - Telegram will return a pairing prompt similar to:
OpenClaw: access not configured.
Your Telegram user id: ...
Pairing code: XXXXXXXX
Ask the bot owner to approve with:
openclaw pairing approve telegram XXXXXXXX- Approve that pairing code via
sandbox.commands.run(...):
const PAIRING_CODE = 'XXXXXXXX' // from Telegram
await sandbox.commands.run(
`openclaw pairing approve --channel telegram ${PAIRING_CODE}`
)openclaw pairing approve telegram <PAIRING_CODE> also works if you prefer that form.
Verify channel status
const channels = await sandbox.commands.run('openclaw channels list --json')
const status = await sandbox.commands.run('openclaw channels status --json --probe')
const pairing = await sandbox.commands.run('openclaw pairing list --json --channel telegram')
console.log(JSON.parse(channels.stdout))
console.log(JSON.parse(status.stdout))
console.log(JSON.parse(pairing.stdout))If you need logs from channel handlers:
const logs = await sandbox.commands.run(
'openclaw channels logs --channel telegram --lines 200'
)
console.log(logs.stdout)Troubleshooting
Unknown channel: telegram- The Telegram plugin is not enabled. Run
openclaw config set plugins.entries.telegram.enabled truebefore adding the channel.
- The Telegram plugin is not enabled. Run
OpenClaw: access not configured- Pairing has not been approved yet. Run
openclaw pairing approve ....
- Pairing has not been approved yet. Run
No API key found for provider ...- This guide uses
openai/gpt-5.2. SetOPENAI_API_KEYin sandbox envs.
- This guide uses
- No pending pairing requests from
pairing list- Send a fresh message to the bot first, then retry
pairing list --channel telegram.
- Send a fresh message to the bot first, then retry
Related
Was this page helpful?Suggest editsRaise issue