> For the complete documentation index, see [llms.txt](https://www.openclawbook.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.openclawbook.xyz/en/ch03-channel-setup/3.1-telegram-bot-complete-setup.md). Agents can also search and read this documentation through its [MCP server](https://www.openclawbook.xyz/~gitbook/mcp).

# 3.1 Telegram Bot: Complete Setup

> **Generated by**: Claude Opus 5 (claude-opus-5\[1m]) **Token usage**: Input \~216,000 tokens, Output \~9,000 tokens (this section) **Source baseline**: `v2026.3.9` (`v2026.3.8-170-g665f67726`)

***

Telegram is the easiest channel to get working, and the one with the best experience — it supports native slash commands, forum topics, and draft streaming (that "watch it type" effect, §18.4). Start here.

## 3.1.1 Creating a Bot with BotFather

Telegram bots are created through an official bot.

1. Search for **@BotFather** in Telegram and start a chat;
2. Send `/newbot`;
3. Enter a display name (shown in the contact list, changeable later);
4. Enter a username — **must end in `bot`**, e.g. `my_openclaw_bot`, and this one is permanent;
5. BotFather returns a token that looks like:

```
1234567890:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw
```

**That token is a credential.** Anyone holding it fully controls the bot. Don't paste it into a chat, a screenshot, or a git commit.

### Two settings worth doing now

Still in BotFather:

| Command                     | Why                                                                                                                                                                                                                                                                                           |
| --------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `/setprivacy` → **Disable** | By default a bot in a group only sees messages that mention it or are commands. Disabling privacy mode lets it see all group messages — **required if you want the agent to have group context** (§14.5.2's history buffer). Leave it enabled if you'd rather it only respond when addressed. |
| `/setcommands`              | Optional. OpenClaw registers commands automatically at startup (§33.4.2), so you usually don't need this.                                                                                                                                                                                     |

## 3.1.2 Configuration and Connection

### The recommended path: the wizard

```bash
openclaw onboard
```

Pick Telegram when it asks about channels and paste the token. The wizard writes the config and validates the connection.

### The manual path

Edit `~/.openclaw/openclaw.json`:

```json5
{
  channels: {
    telegram: {
      enabled: true,
      // Better: use a secret reference rather than plaintext (§32.6.3)
      token: "${TELEGRAM_BOT_TOKEN}",
      allowFrom: ["123456789"],   // your Telegram numeric user ID
    },
  },
}
```

Then:

```bash
export TELEGRAM_BOT_TOKEN='1234567890:AAHdqTc...'
openclaw gateway
```

> **Why `${TELEGRAM_BOT_TOKEN}` instead of pasting the token?** Because config write-back preserves the reference rather than expanding it (§31.6.4), so a later `openclaw config set` won't bake your token into the file as plaintext — and from there into git.

### Finding your user ID

You need your numeric ID for `allowFrom`. The simplest way: message the bot once. OpenClaw's default `dmPolicy` is `pairing` (§32.6.2), so a stranger — including you, before you're on the allowlist — receives a pairing code rather than a reply.

Then approve it:

```bash
openclaw pairing list telegram          # see pending requests
openclaw pairing approve telegram <CODE>
```

Approval writes you into the allowlist store automatically. **That's the recommended path** — no hunting for your ID, and it exercises the same admission flow real users will take.

### Webhook vs. long polling

OpenClaw uses **long polling** by default (§20.6.1), which needs no public address and works behind NAT. That's what you want for a personal machine.

Webhook mode requires a publicly reachable HTTPS endpoint and is only worth it at high message volume.

> A conflict worth knowing: **only one process may poll a given bot token at a time.** Running a second instance produces a 409 error. OpenClaw self-heals from this (§20.6.1), but if you see persistent 409s, check whether an old process is still running.

## 3.1.3 Groups, Permissions, and Testing

### Adding the bot to a group

1. Add the bot as you would any member;
2. If you disabled privacy mode, it can now see all messages;
3. **By default it only replies when mentioned** (`requireMention`, §14.5.2).

Mention detection accepts several forms: an `@username` mention, a reply to one of the bot's messages, or the agent's configured name appearing in the text.

### Group access control

```json5
{
  channels: {
    telegram: {
      groupPolicy: "allowlist",     // default
      groupAllowFrom: ["-1001234567890"],   // group IDs
      requireMention: true,          // default
    },
  },
}
```

**Group command authorization does not inherit DM pairing** (§32.6.2). Someone you approved in DMs cannot issue `/config set` in a group unless they're in the configured `allowFrom` list. That separation is deliberate: pairing is session admission, not permission granting.

### Verifying it works

```bash
openclaw channels status      # is telegram connected?
openclaw logs tail            # watch messages arrive
```

Then send the bot a DM. If nothing happens, work through:

| Symptom                           | Likely cause                                                  |
| --------------------------------- | ------------------------------------------------------------- |
| No response at all                | Not on the allowlist — check `openclaw pairing list telegram` |
| Responds in DMs, silent in groups | Not mentioned, or the group isn't in `groupAllowFrom`         |
| Persistent 409 in logs            | Another process is polling the same token                     |
| "Unauthorized" at startup         | Bad token, or extra whitespace when pasting                   |

***

## Section Summary

1. **Create the bot through @BotFather**; the username is permanent and must end in `bot`. **The token is a credential** — keep it out of chats, screenshots, and commits.
2. **`/setprivacy` → Disable is required if you want group context** — otherwise the bot only sees messages addressed to it.
3. **Use `${TELEGRAM_BOT_TOKEN}` rather than pasting the token**, so config write-back preserves the reference and never bakes plaintext into the file.
4. **Get onto the allowlist by pairing rather than hunting for your ID** — message the bot, then `openclaw pairing approve telegram <CODE>`. It's easier and exercises the real admission flow.
5. **Long polling is the default** — no public address needed; **only one process may poll a token at a time**, so persistent 409s mean a leftover process.
6. **Group command authorization does not inherit DM pairing** — pairing is session admission, not permission granting.
