Back to Blog
AI AgentsTelegramSetupHermes

How to Connect an AI Assistant to Telegram

A practical guide to putting an AI assistant on Telegram, from BotFather token to live replies, plus the operational trap most guides skip.

By Hermify Team||7 min read
Telegram paper plane icon next to a glowing chat bubble representing an AI assistant reply

You want the same assistant you already use in a browser tab to live inside Telegram, so you can text it from the phone in your pocket instead of opening a laptop. The good news is that the plumbing is simple: a bot token, a message loop, and an LLM. The less obvious part is what it takes to keep that pipeline online after the first "hello world" reply.

Why put an AI assistant on Telegram at all

Most AI tools live behind a URL. You navigate to them, type, read the reply, and close the tab. The context vanishes the moment you do.

Telegram flips this by treating your assistant like any other conversation in your contact list. You can send it a voice note from the car, forward it a link from a group chat, or paste in an error message while you are logged in on desktop. On the back end, the same assistant keeps the memory of every one of those exchanges, because a persistent process is doing the answering rather than a page that reloads.

That is the framing to hold onto while you evaluate setup options. The interesting question is not "can I get a reply out of a Telegram bot", almost every guide answers that in five minutes. It is "who is on the hook when the bot goes silent at 11 pm on a Tuesday?"

Step 1: Create the bot in BotFather

Open Telegram and search for @BotFather. It is the official account with the blue verified check. Hit Start and send:

/newbot

BotFather asks two questions:

  • Display name, what shows up as the bot's contact card name. Editable later.
  • Username, the @handle used in links and mentions. It must be 5-32 characters, Latin only, and end in bot (for example myai_assistant_bot).

Once you accept a valid username, BotFather sends back a token. It looks like this:

7123456789:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw

Treat that string like a password. Do not paste it into screenshots, group chats, or public repos. If it leaks, message BotFather with /revoke, pick the bot, and it will hand you a fresh one, the old token stops working immediately.

Step 2: Decide who does the thinking

The bot token only lets you send and receive messages. It does not decide what to say. That is the LLM's job. You have three broad options:

  • A single LLM API: point directly at OpenAI, Anthropic, or Google. Simple, but each provider has its own SDK, its own auth model, and its own rate limits.
  • A router like OpenRouter: one API key that fronts dozens of models. You get to swap models per task (fast and cheap for chat, big model for reasoning) without juggling accounts.
  • A local model: Ollama or llama.cpp on your own hardware. No per-token cost, but you own the uptime.

For a personal assistant that has to feel responsive, most people land on a hosted API. Latency to a local model over consumer hardware is usually worse than a well-connected commercial one, and quality still trails on general reasoning.

Whichever provider you pick, generate the key in that provider's dashboard now and store it alongside your bot token. You will need both in the next step.

Diagram of a phone messaging a Telegram bot backed by an LLM provider

Step 3: Build (or borrow) the message loop

Between Telegram and the LLM there needs to be a small piece of software that:

  1. Long-polls (or webhooks) the Telegram Bot API for new messages.
  2. Passes the message text (and optionally the chat history) to the LLM.
  3. Sends the LLM's reply back to Telegram in the same chat.
  4. Handles errors so a single failed request does not silently kill the loop.

If you are comfortable in Python, the python-telegram-bot library plus your provider's SDK gets you a working prototype in about 40 lines. Node has similar packages. For a strictly no-code path, tools like Make.com or n8n let you drop a Telegram trigger and an OpenAI action onto a canvas and connect them with a line.

Two details you will almost certainly want to add before you consider it usable:

  • An allowed-users list, so random strangers who guess the bot's handle cannot burn through your API budget. Bots on Telegram are discoverable by search; without an allowlist, your bot answers everyone.
  • Conversation memory, so the assistant remembers earlier turns in the same chat instead of treating every message like the first. Either persist the message history in a database keyed by chat ID, or use an agent framework that ships memory built in.

Step 4: Keep the process alive

Here is where most weekend projects quietly die.

Your Telegram bot is only responsive while the message loop is running. If it is running in a terminal on your laptop, it stops the moment the laptop sleeps. If it is a python bot.py on a cheap VPS, it stops the next time the process crashes, the VPS reboots for kernel updates, or you hit an unhandled exception at 3 am.

The industry answer is unglamorous:

  • Wrap the process in systemd (or Docker with restart: unless-stopped) so the OS brings it back after a crash or reboot.
  • Send logs somewhere you will actually see them (a file rotated by logrotate, or a hosted log service).
  • Add a health check that pings you if the bot has not seen a Telegram update in N minutes.
  • Store your bot token and API keys in a secret store, not in a config.yaml on the same disk as the code.

None of that is hard in isolation. It is just an ongoing responsibility, and it is the part that decides whether "AI assistant on Telegram" is a delightful daily tool or a project you have to redeploy every few weeks.

The shortcut: use a managed Hermes Agent

If you like the sound of an AI assistant on Telegram but not the sound of running a Linux server, the shortcut is to hand off the middle two steps and keep the parts you actually care about.

Hermify runs a managed Hermes Agent as a Telegram contact for you. You bring:

  • Your bot token (from step 1)
  • A model provider key (from step 2), or use a plan that bundles the model access

Hermify handles the message loop, the process supervisor, the memory files that persist across conversations, and the credential storage. The bot is live in your Telegram in about a minute, and when the process needs to restart it restarts itself, so you find out from a dashboard rather than from a silent chat. Get started with Hermify to try the managed path.

The Hermes Agent underneath is open source, so you are not locked into hosted hosting; you can move the same setup to your own VPS later if you decide the operational overhead is worth taking on. Most people find they never do.

A dark cinematic scene of a phone glowing with a Telegram chat, hinting at an always-on AI assistant

Choosing between DIY and managed

Both paths work. The decision is really about where you want to spend attention:

  • DIY if you already run this class of infrastructure, want full control of the model, memory files, and prompts, and see the operational work as part of the fun.
  • Managed if you want the assistant to just be a Telegram contact you can text from anywhere, without weekend maintenance.

Either way, the core UX gain is the same: your assistant stops being a URL and starts being a person you can message. Once it lives in Telegram, you actually use it.

If you want to compare setup steps to a specific rollout, the deploy on Telegram guide walks through a complete configuration end to end. If you want the shortcut, get started with Hermify and your assistant is live on Telegram in about a minute.

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