Skip to content
BrainRoad BrainRoad

How to Connect Telegram to Your AI Agent — Complete Setup Guide

BrainRoad ·
Beacon the lighthouse character shining light on a Telegram logo, illustrating a telegram setup guide.
Share
On this page

When this works, you’re texting your AI agent from your phone like you’d text a colleague. It reads your messages, takes action, and replies in seconds. No open browser tab. No copied prompts. No app to install. Just Telegram — which you probably already have.

When it doesn’t work, you get a bot that connects but never responds. Or a pairing error you can’t decode. Or messages that vanish into silence. We’ve seen all three. The good news: every one of those failures traces back to the same handful of config fields. Miss one, and the whole integration goes quiet.

Telegram now has over 1 billion monthly active users. More than 10 million bots are running on the platform, handling over 15 billion messages every month. The infrastructure is solid. The problem is never Telegram — it’s always the setup. This guide covers the exact sequence that works, including the step most tutorials skip. I’ll flag it clearly when we get there.

If you’re exploring AI automation for your workflows, Telegram is one of the fastest channels to get an agent running on your phone — no custom app, no complex server setup.

What You’ll Have When This Is Done

Before the prerequisites, here’s the end state so you know what you’re building toward.

A Telegram bot that talks back

Your AI agent responds to natural language messages — not preset commands like /start. Ask it anything. It understands context.

Mobile control of your agent

Instead of running commands from a terminal, you interact with your AI agent directly from Telegram messages on any device.

Workflow automation from chat

Trigger AI workflows, get AI-generated summaries and alerts, pull data into your agent's context — all from Telegram messages.

Access control you define

You choose who can interact with the bot: just you, a specific list of users, or anyone. This matters more than most guides admit.

Prerequisites: What You Need Before You Start

This guide assumes OpenClaw is already installed and running. If it’s not, get that sorted first — there’s nothing to connect Telegram to until your agent is up.

  • OpenClaw installed and running (core installation complete)
  • A Telegram account (personal account is fine — you’ll create a separate bot identity)
  • Access to your OpenClaw config file
  • 5-10 minutes for the BotFather setup, 5 minutes for config

Step-by-Step: The Complete Configuration

This sequence matters. Missing even one step produces symptoms that look unrelated to where the actual problem is. Follow it in order.

1

Create your bot via BotFather

Open Telegram and search for @BotFather. Send /newbot. Choose a display name (e.g., 'My AI Agent'), then a username ending in 'bot' (e.g., 'myagent_bot'). BotFather will return a bot token — a long string that looks like 7123456789:AAF... Copy it. You'll need it in the next step. Time: 3–5 minutes.

2

Add the bot token to your OpenClaw config

Open your OpenClaw config file. Find or create the channels.telegram section. Add your token to the channels.telegram.botToken field. This is the only field most tutorials cover — and it's not enough on its own.

3

Set your dmPolicy

This is the field most setups miss. Under channels.telegram, set dmPolicy to one of three values: 'pairing' (users must pair with a code before interacting), 'allowlist' (only specific user IDs you specify), or 'open' (anyone can message the bot). If you skip this field entirely, your bot will connect but reject all incoming messages — it'll look broken when it's just locked. For personal use, start with 'pairing'.

4

Choose polling or webhook mode

Polling mode has your agent check Telegram for new messages at regular intervals. It's simpler to set up and fine for personal use. Webhook mode has Telegram push messages to your server instantly — more efficient for production deployments with higher message volume. For most personal setups, polling is the right call. Add polling: true (or equivalent) to your channels.telegram config.

5

Restart OpenClaw

Save your config file and restart OpenClaw. The Telegram channel won't activate until the service reinitializes with the new config. Time: under 1 minute.

6

Pair your Telegram account

If you set dmPolicy to 'pairing', go to your OpenClaw dashboard to retrieve your pairing code. Open Telegram, start a conversation with your bot, and send the pairing code. Once paired, send a test message. Your agent should respond within a few seconds.

The Field That Breaks 90% of First Setups

Here’s what most tutorials — including responses from many AI tools — get wrong: they stop after the bot token. That’s step one of six. A configured token with no dmPolicy produces a bot that handshakes with Telegram perfectly, passes all connection checks, and then silently drops every message it receives.

The symptom looks like a broken integration. The actual cause is that OpenClaw is correctly enforcing an access policy you never defined — so it defaults to blocking everything.

The fix is three characters in a config field. But you have to know to look for it.

The other thing worth knowing: the two message-delivery modes (polling vs. webhook) behave differently under load. Polling works reliably for personal agents — one user, moderate message volume, no real-time requirements. If you’re running a bot for a team or community, webhook mode handles the load better and reduces latency. Switching later is straightforward; you don’t need to get it perfect on day one.

Where This Integration Actually Breaks

We’ve watched this integration fail in consistent patterns. Here are the ones worth knowing before you hit them.

  • Bot token miscopy: BotFather tokens are long and easy to truncate when copying. If your token ends in ’…’ or has a line break in the middle, paste it into a plain text editor first to verify it’s complete.
  • Config file not saved before restart: OpenClaw reads the config at startup. If you restart before saving, you’re running on the old config. The channel stays silent. Save first, then restart — every time.
  • Pairing code entry errors: The pairing code is case-sensitive and time-limited. If the pairing fails, generate a fresh code from the dashboard rather than retrying the same one.
  • Webhook mode with no public URL: If you choose webhook mode on a local machine with no public endpoint, Telegram has nowhere to send messages. Either use polling, or expose your endpoint with a tool like ngrok before enabling webhook.
  • dmPolicy set to ‘allowlist’ with no user IDs configured: The field is set, but the list is empty. Result: same as no dmPolicy — everything gets blocked. Add at least one Telegram user ID to the allowlist before testing.

None of these are complicated to fix. They’re all easy to miss the first time.

One more thing worth knowing: unlike traditional Telegram bots that respond only to preset commands like /start or /help, an AI-powered bot supports contextual, open-ended conversations. That means the scope of what can go wrong in responses is wider — and your agent’s behavior config (the SOUL.md file in OpenClaw) matters more than most setup guides acknowledge. A professional-context agent should be tuned differently than a personal assistant or a community bot. The personality should match the channel’s context.

For a comparison of Telegram vs. WhatsApp as agent channels, the WhatsApp setup guide covers the key differences — both in setup complexity and in which use cases each channel handles better.

How to Know It’s Working

Don’t trust a green status indicator alone. Run through these checks after setup.

  • Send a plain natural-language message (not a command) to your bot and verify you get a contextual reply — not just an echo or an error
  • If using pairing mode, verify the pairing persists across an OpenClaw restart — re-pairing every restart means something in the session storage config needs attention
  • Check your OpenClaw logs for the Telegram channel showing as ‘active’ or ‘connected’ — a missing log line here means the channel didn’t initialize
  • Send a multi-turn message (a follow-up that depends on your first message) and verify the agent maintains context between messages
  • If you have workflow triggers configured, send a trigger phrase and verify the downstream action fires

If the multi-turn test fails — the agent responds to message one but treats message two as a new conversation — the issue is usually in context/session configuration, not the Telegram channel itself. The channel is working; the memory layer needs attention.

Your Telegram Agent Setup Checklist

Beacon the lighthouse illuminating a Telegram logo, glowing amber light connecting AI chat interface on dark navy background. Beacon says: your AI agent has a lot to say — let’s make sure Telegram is ready to listen.

Work through this in order. Each step has a verification point so you’re not debugging blindly at the end.

  1. Create your bot in BotFather — takes 3–5 minutes. Verify you have a complete token before moving on (no truncation, no line breaks).
  2. Add the token to channels.telegram.botToken in your OpenClaw config. Save the file immediately after — don’t continue until it’s saved.
  3. Set dmPolicy explicitly — choose pairing, allowlist, or open. If you’re unsure, use pairing. This field cannot be skipped.
  4. Choose polling mode unless you have a public endpoint ready. Add polling: true to your channels.telegram config. Switch to webhook later when you need it.
  5. Restart OpenClaw and check the startup logs. The Telegram channel should appear as initialized within 10–15 seconds.
  6. If using pairing mode: retrieve your pairing code from the OpenClaw dashboard within 5 minutes of generating it (codes are time-limited). Send it to your bot in Telegram.
  7. Send a test message — a plain sentence, not a slash command. If you get a contextual reply, the integration is live.
  8. If no response: check dmPolicy first, then verify the token is complete, then check that OpenClaw was restarted after saving. Those three issues account for the majority of first-setup failures.

What This Unlocks for Your AI Agent

Once Telegram is connected, your agent isn’t just a chat interface — it’s a mobile control layer. You can trigger AI workflows from a message, receive AI-generated summaries and alerts directly in Telegram, pull external data into your agent’s context on demand, and get automated responses to questions or events without opening a laptop.

That last one is the shift that matters. Your agent monitors Telegram and acts — not when you prompt it, but when something needs attention. That’s the difference between a tool you use and an assistant that works.

If you want to go further — giving your agent a phone number to call and receive calls, not just chat — the AI voice agent setup guide covers that path. Telegram gets you to mobile control. Voice gets you to hands-free.

BrainRoad runs OpenClaw-based agents with the Telegram channel pre-configured — the token, dmPolicy, and polling setup are handled through a wizard rather than manually editing config files. If the steps above felt like a lot, that’s the managed version. But the underlying setup is exactly what’s described here, and knowing it matters regardless of how you deploy.

The interesting work starts after setup. Tune the SOUL.md for your communication context, configure the workflows you want triggered by Telegram events, and decide how much autonomy the agent gets. Most people who deploy this spend more time calibrating behavior than they did on the technical setup. That’s the right problem to have.

What This Setup Gives You

  • Telegram is a built-in OpenClaw channel — no plugin required, just config
  • The setup requires 6 sequential steps; missing any one produces symptoms that look unrelated to the actual cause
  • The dmPolicy field is the most commonly skipped — set it explicitly to pairing, allowlist, or open, or your bot will connect but drop all messages
  • Use polling mode for personal setups; webhook mode is more efficient for production deployments with higher volume
  • Telegram’s platform handles over 15 billion bot messages per month — the infrastructure is reliable; the setup is where things go wrong
  • After setup, the real work is behavior configuration: tune your agent’s personality to match the communication context of the channel

Frequently Asked Questions

Do I need a separate Telegram account to create a bot?

No. You create bots through your existing Telegram account via BotFather. The bot gets its own identity (a separate username and profile) — it’s not tied to your personal account in any visible way. Users who message the bot interact with the bot identity, not your personal account.

What's the difference between polling and webhook mode?

Polling has your OpenClaw agent check Telegram for new messages at regular intervals. It’s simpler — no public URL required — and works well for personal use. Webhook mode has Telegram push messages to your server the moment they arrive, which is more efficient and lower latency. Use polling to start. Switch to webhook when you need real-time responsiveness at scale or are running the bot for a group.

Why does my bot connect but not respond to messages?

The most common cause is a missing or misconfigured dmPolicy field. If dmPolicy isn’t explicitly set, OpenClaw defaults to blocking all incoming messages — which produces exactly this symptom. Add dmPolicy: pairing (or allowlist or open) to your channels.telegram config, save the file, and restart OpenClaw. If that doesn’t fix it, check that your bot token is complete and that OpenClaw was actually restarted after you saved the config.

Can I use the same Telegram bot for multiple users?

Yes. Set dmPolicy to ‘open’ for unrestricted access, or ‘allowlist’ to specify exactly which Telegram user IDs can interact with the bot. The ‘pairing’ mode works for personal or small-team setups where each user pairs individually. For larger deployments, allowlist gives you the most control.

How is an AI-powered Telegram bot different from a regular bot?

Traditional Telegram bots respond to preset commands like /start or /help. An AI-powered bot supports contextual, open-ended conversations — it understands what you mean, not just what you typed. It can answer follow-up questions, maintain context across a conversation, generate content, and trigger complex workflows based on natural language.

Sources

Topics

Personal AI Assistant

Stay updated

Get AI strategy insights delivered weekly. No fluff, no spam.

Related Articles