Back to Blog
AI AgentsTelegramTutorialAutomation

How To Build An AI Agent On Telegram (2026 Guide)

A practical guide to building an AI agent on Telegram in 2026: BotFather setup, the four main paths (Python, n8n, hosted SaaS, agent runtime), and how to pick.

By Hermify Team||10 min read
Dark background with the Telegram paper-plane icon and the bold text 'Build an AI Agent on Telegram' alongside a small green accent line

You want an AI agent that lives in Telegram. Not a browser tab, not yet another mobile app, but a contact in your sidebar that answers when you message it, remembers what you said last week, and can actually do things instead of only chatting.

The good news is that Telegram is the friendliest messaging surface for building this. The Bot API is free, opens in two minutes via BotFather, and has no per-message fees - unlike WhatsApp Business, which charges per conversation and requires Meta verification. The harder news is that "how to build an AI agent on Telegram" splits into at least four different paths in 2026, and the right one depends on whether you are a developer who likes wiring stacks or a non-developer who wants the agent running by tonight.

This guide walks through what you actually need, the four real paths, and an honest decision tree at the end.

What "An AI Agent On Telegram" Really Means

Before picking a stack, it helps to be specific about what you are building. The phrase covers a wide spectrum:

  • A simple chat wrapper. The bot forwards your messages to an LLM and forwards the answer back. Useful, but it forgets everything when the chat scrolls.
  • A chatbot with memory. Same flow, but with a session memory or a vector store so it can recall earlier messages.
  • An agent. A long-running process that has a personality, tools it can call (web search, calendar, email, your own APIs), persistent memory across sessions, and the ability to do multi-step work on its own.

Most "build a Telegram bot" tutorials online stop at chat-wrapper. That is fine if you only want chat. If you want the agent to remember a project you described last Wednesday or to run a daily morning briefing on a schedule, you need persistent memory and a scheduler, which are the features that turn a bot into an agent.

The dimensions that pinch when you pick a stack:

  • Memory across sessions - does the agent remember you next week, or does every new chat start from zero?
  • Tools and skills - can it actually do things (send emails, search the web, summarize a PDF, hit your own API), or is it just chat?
  • BYOK - can you point it at your own OpenAI, Anthropic, or OpenRouter key, or are you locked into the vendor's bundled credits?
  • Hosting - hosted SaaS, no-code cloud, self-hosted server, or fully managed runtime?
  • Allowlist - can you restrict the bot to your own Telegram user ID, or is anyone who finds it free to burn through your API credits?

Memory is the differentiator that matters most. A chatbot answers questions; a personal agent remembers them.

Diagram contrasting a single one-shot Telegram message with a long persistent memory thread spanning multiple weeks

Step Zero: Create The Bot In BotFather

Every path below starts with the same five-minute step, so do it first.

Open Telegram, search for @BotFather, and send /newbot. BotFather will ask for two things in order:

  1. A display name (can contain spaces, can be changed later).
  2. A username, which must end in bot and is permanent.

Once both are accepted, BotFather replies with an API token that looks like 123456789:ABCdef.... Treat it like a password - anyone with this token can post messages as your bot. Save it in a password manager or a .env file you do not commit.

A few useful BotFather commands worth knowing on day one:

  • /setdescription - the short intro users see when they first open the chat.
  • /setcommands - the autocomplete menu of slash commands.
  • /setprivacy - in group chats, switch to "Disable" if you want the bot to see all messages, not just ones mentioning it.

Two final notes that surprise beginners. First, the Telegram Bot API is genuinely free with no per-message charges, even at scale. Second, by default a bot in Telegram only initiates conversation after the user sends the first message - so during development, message your bot once yourself before you expect it to reply.

Path 1: Python From Scratch (BotFather + python-telegram-bot + OpenAI)

The classic developer path. You write a small Python service that connects the Telegram Bot API to an LLM API and decides what happens in between.

The stack everyone converges on:

# requirements.txt
python-telegram-bot==22.1
openai==1.40.0
python-dotenv==1.0.1

The minimal loop is:

from telegram.ext import Application, MessageHandler, filters
from openai import OpenAI
import os

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

async def reply(update, context):
    msg = update.message.text
    answer = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": msg}],
    ).choices[0].message.content
    await update.message.reply_text(answer)

app = Application.builder().token(os.environ["TELEGRAM_BOT_TOKEN"]).build()
app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, reply))
app.run_polling()

That code is a chatbot, not an agent yet. To turn it into an agent you add four things on top:

  • Memory. A SQLite or Postgres table keyed by chat_id for short-term history. For longer recall, a vector store like ChromaDB, Qdrant, or pgvector.
  • Tools. Function-calling on the LLM so it can hit your APIs, the web, or the file system.
  • Allowlist. Check update.effective_user.id against an ALLOWED_USERS env var so a random Telegram user cannot drain your key.
  • A host. Something that keeps the process alive when your laptop sleeps. A $5/mo VPS like Hetzner CX22 or a Raspberry Pi is plenty - the model runs on OpenAI's servers, not yours.

Time to "agent that remembers and uses tools": a weekend if you are comfortable with Python, longer if not. Cost: provider tokens (a few dollars a month at personal use) plus the host.

Best fit: developers who want full control, no vendor lock-in, and are willing to maintain a Python service.

Path 2: No-Code With n8n (Or Make)

If you do not want to write code but you do want full control over the workflow, n8n is the strongest open-source option in 2026. It is a visual workflow builder you can self-host on a $5 VPS or use on n8n.cloud.

The build is roughly four nodes:

  1. Telegram Trigger - listens for new messages on your bot.
  2. AI Agent node - n8n's built-in agent node, configured with an LLM (OpenAI, Anthropic, Groq, etc.) and a memory buffer.
  3. Tool nodes (optional) - HTTP Request, Google Sheets, Postgres, your own APIs.
  4. Telegram Send Message - replies in the same chat.

The AI Agent node has a built-in Memory option. Pick Window Buffer Memory for the last N turns, or wire in a Postgres or Redis memory node for persistence across n8n restarts.

The trade-off worth being honest about: n8n is a workflow tool first and an agent platform second. It is excellent when the bot is mostly a triage layer over a workflow you already have - lead intake, expense logging, CRM updates, customer support pre-triage. It starts to strain when the agent needs to think rather than route. The moment you find yourself adding a fifth IF node to handle edge cases in human-language input, you are simulating reasoning with branches and the agent will lose. We covered the deeper trade-off in Hermes Agent vs n8n.

Best fit: non-developers, or developers who already use n8n for other workflows and want a Telegram surface for them.

Path 3: Hosted SaaS Builders

These are platforms that wrap the whole stack behind a web UI. You sign up, paste the BotFather token, drag a few blocks, click publish, and the bot is live. Voiceflow, Botpress, Mosaia, Lobster Father, and a long tail of niche builders all live here.

The trade-offs are the predictable ones:

  • Setup is the easiest in the field - often under an hour, sometimes under five minutes.
  • BYOK is rare. You usually consume the vendor's bundled credits at a markup, or you tap out of the free tier within a day.
  • The "memory" advertised on the marketing page is often session-scoped, not cross-session. Test this on day eight before you commit.
  • Your messages and your users' messages flow through the vendor's infrastructure. Read the privacy policy.

This path is fine when the bot is a customer-facing FAQ or lead-capture surface and you do not need persistent personal memory.

Best fit: small businesses that want a customer-facing Telegram bot with minimum operational overhead and do not need cross-session personal memory.

Path 4: A Self-Hosted Agent Runtime

This is the newest category and the one that fits the "personal agent on Telegram" use case best. A self-hosted agent runtime is a long-running process built specifically to be an agent - it ships with structured memory, a skills layer, a scheduler, and first-class delivery on Telegram (plus other messaging platforms) out of the box.

The two real open-source options:

  • OpenClaw stores everything as plain Markdown and YAML files under your workspace. Local-first, transparent, skills are portable across machines because they are just files.
  • Hermes Agent is the one we know best, since Hermify is the managed version of it. It maintains a persistent profile and memory across sessions, automatically creates and improves skills as it works, runs on a $5 VPS or a Raspberry Pi, and has first-class Telegram support including allowlist enforcement, voice mode, and natural-language scheduling. For a step-by-step Hermes walkthrough, see How To Deploy Hermes Agent On Telegram.

The cost shape here is similar to Path 1 (you host it) with the upside that the runtime does the heavy lifting on memory, skills, and reliability. You point it at your own OpenAI or Anthropic key, drop your BotFather token in the config, and you have an agent that remembers and acts - no Python service to maintain.

Best fit: users who want a real personal agent (remembers, learns, does things), care about owning the stack, and are happy on a $5 VPS or comfortable on a Pi.

Photorealistic dark home office desk with a phone showing a Telegram notification in green, a small server LED glowing faintly behind it

How To Pick

A short decision tree, ordered by what most people actually need:

| Your situation | Path | |---|---| | You want a chatbot, do not care about memory or tools | Hosted SaaS (Path 3). Free or near-free, instant. | | You already use n8n / Make for other workflows | n8n (Path 2). Use the Telegram trigger + AI Agent nodes. | | You are a Python developer who wants full control | Python from scratch (Path 1). Plan a weekend. | | You want a real personal agent that remembers and learns | Self-hosted agent runtime (Path 4). | | You want Path 4 without running a server | Managed runtime - that is what Hermify is. |

A sanity check before committing: build the bot, message it for a week, then on day eight see what it remembers when you come back. If it can recall the project you described last Wednesday, you have an agent. If it cannot, you have a chatbot. There is nothing wrong with a chatbot, but you should know which you ended up with.

Why Telegram And Not WhatsApp Or Discord

This is the second-most asked question and worth a paragraph. Telegram won for personal agents because three things line up: the Bot API is free and instant (no per-message fees, no business verification, no template approvals), the platform allows third-party bots with no friction, and the chat UX (replies, file attachments, voice messages, inline keyboards) is rich enough to support agent-style interactions. WhatsApp Business charges per conversation and requires Meta verification with pre-approved templates - workable for transactional customer service, painful for a $19/mo personal agent. Discord is a fine alternative when your community lives there; we cover it in a separate deploy guide.

We also wrote a longer comparison at Best AI Assistant For Telegram if you want a side-by-side look at the leading options instead of building one yourself.

Closing

The smallest path - hosted SaaS - is genuinely fine for a chatbot. Python from scratch is the right answer if you enjoy wiring stacks and want every line of code to be yours. n8n is the right answer if your bot is mostly workflow plumbing. A self-hosted agent runtime is the right answer if you want the assistant to be a long-term tool that gets better the longer you use it.

If you want the personal-agent version without running a server, Get started with Hermify. It is the managed version of Hermes Agent - persistent memory, BYOK, Telegram delivery, allowlist enforcement, no Docker to babysit.

Whichever path you pick, the prize is the same: an assistant that lives in the app you already check fifty times a day.

Sources

Run Your Own Hermes Agent

Bring your API key, connect Telegram, and get a self-improving AI agent live in 60 seconds.

Get Started