Building an AI Telegram bot with n8n: a step-by-step guide
Published 25 July 2026 · 5 min read
Putting an AI agent in an entire team's pocket requires neither a mobile app to build nor a business verification process: a Telegram bot wired to n8n is enough. In an hour, you get an assistant that replies inside a regular Telegram conversation, remembers context, and can query an internal document base. This guide walks through the build step by step — creating the bot, the Telegram Trigger, an AI agent with memory, replying, and then the guardrails you need before inviting anyone to talk to it.
Why Telegram is the simplest channel for an AI agent
Compared with other messaging channels, Telegram combines rare advantages:
- Bot creation is free and instant: one exchange with @BotFather, a name, and you have an API token. No business account, no validation file.
- The bot API is open and well documented, with a native Telegram node in n8n that covers the essentials (sending messages, photos, documents, buttons).
- No business verification, unlike WhatsApp Business which requires a verified Meta Business account — we covered that journey in our guide to a RAG chatbot on WhatsApp; the comparison speaks for itself: what takes days on the WhatsApp side takes five minutes on Telegram.
- The app is already installed for many users, and works on mobile and desktop alike.
Wiring an AI onto this channel isn't a gimmick: a study by Brandtzaeg and Følstad presented at the INSCI 2017 conference ("Why People Use Chatbots" — Google Scholar) surveyed chatbot users and showed that productivity — getting help or information quickly and efficiently — is the primary motivation for using chatbots, well ahead of entertainment. In other words: a bot that answers concrete questions fast and accurately is exactly what users expect from the format.
Step 1: create the bot with @BotFather
In Telegram, open a conversation with @BotFather (the official bot-creation bot):
- Send
/newbot, choose a display name and then a handle ending inbot. - BotFather returns an API token of the form
123456789:AAE.... That token grants full control of the bot: treat it like a password, store it only in n8n credentials, never in plain text inside a node. - Optional but useful:
/setdescriptionand/setcommandsto give users a description and visible commands.
Step 2: the Telegram Trigger in n8n
Create a workflow with a Telegram Trigger node, configure the credentials with the token, and select the "Message" event. One essential technical point: this trigger works via webhook — Telegram pushes every message to a URL on your n8n instance. That requires the instance to be publicly reachable over HTTPS with a valid certificate; an instance on localhost will never receive anything. If that's not in place yet, set up a reverse proxy with a certificate first, and while you're at it apply the habits from our article on securing n8n webhooks.
Once the workflow is activated (not just tested), every message sent to the bot arrives in the workflow with, among other fields, the message text and the conversation's chat_id — two fields the rest of the workflow will rely on.
Step 3: wire in the AI agent with memory
This is the heart of the bot. Add an AI Agent node (or a plain chat model node for basic cases), connected to your provider — credential setup is covered in our guide to connecting Claude or GPT to n8n:
- The user prompt receives the Telegram message text.
- The system prompt frames the bot's role: scope, tone, language, what it must refuse.
- Conversation memory is the detail that changes everything: use the Telegram
chat_idas the memory's session key (Session ID). Each conversation then keeps its own history — the bot remembers what a given user told it, without ever mixing two people together. The different memory types (sliding window, external storage) and their trade-offs are detailed in our article on conversation memory for an AI agent in n8n.
For an assistant that answers from your documents rather than its general knowledge, give the agent a vector search tool: that's exactly the architecture of the RAG chatbot with citations workflow, which cites its sources in every answer.
Step 4: reply with the Telegram node
Add a Telegram node with the "Send Message" operation (sendMessage):
- Chat ID: reuse the
chat_idfrom the incoming message, so the reply lands in the right conversation. - Text: the agent's answer.
- Long messages: Telegram caps the size of a text message (around 4,000 characters). A verbose AI agent can exceed that limit and make the send fail. The robust habit: split the answer into chunks (a Code node is enough) and send several consecutive messages, or constrain the length in the system prompt.
At this point, the bot works: incoming message → agent with memory → reply in the conversation.
Concrete use cases
- Internal assistant over a document base: the team asks the bot questions (procedures, products, contracts), and it queries a RAG base and answers with sources — the core of the RAG Assistant Pack, whose output channel swaps from WhatsApp to Telegram without changing the architecture.
- Interactive notifications: instead of an ignored email, the bot notifies (new lead, workflow error, file awaiting approval) and the user can reply directly to act.
- Customer FAQ: a public bot that answers recurring questions, with escalation to a human when the question falls outside its scope.
- Guided information collection: a structured dialogue that asks questions one by one and records the answers — the pattern behind the guided questionnaire bot workflow.
The guardrails before opening the bot up
Three non-negotiable precautions before sharing the bot's handle:
- A chat_id allowlist. A Telegram bot is public: anyone can message it once they find its handle. Add an IF node at the top of the workflow that checks the incoming
chat_idagainst a list of authorized IDs, and cut things short (silence or a polite refusal) for unknown senders. Without this, third parties can burn through your LLM calls without you knowing. - Cost control. Every message triggers an LLM call, and a lively conversation triggers dozens. Log tokens consumed per conversation and set alerts — the full method is in our article on tracking the cost of AI calls in n8n.
- Prompt injection. Everything the user types goes into the agent's prompt; if the agent has tools (document search, database writes), a malicious message can try to hijack its instructions. Limit tools to the strict minimum and frame the system prompt — our guardrails against prompt injection detail the protections that apply to n8n.
In short
An AI Telegram bot with n8n comes down to four building blocks: a token obtained in five minutes via @BotFather, a Telegram Trigger on an HTTPS instance, an agent with memory keyed by chat_id, and a Telegram node to reply — plus the three guardrails (allowlist, cost tracking, prompt protection) that separate a prototype from a bot you can leave running. If you'd rather start from a proven base than a blank page, the RAG Assistant Pack (€119) ships the document ingestion, the RAG chatbot with citations and the guided collection bot, ready to plug into Telegram.
FAQ
Frequently asked questions
Do I need business verification to create a Telegram bot, like on WhatsApp?
No, and that's Telegram's big advantage: creating a bot via @BotFather is free, instant and open to everyone — a short message exchange is enough to get an API token. WhatsApp Business, by contrast, requires a verified Meta Business account and a validation process. To prototype an AI agent or equip an internal team, Telegram is the shortest path.
Why isn't my Telegram Trigger receiving any messages?
The Telegram Trigger works via webhook: Telegram must be able to reach your n8n instance through a public HTTPS URL with a valid certificate. An instance on localhost or plain HTTP will receive nothing. Also check that the workflow is activated (not just tested) and that the bot token in the credentials is correct.
How do I give my Telegram bot conversation memory in n8n?
Use the chat_id Telegram includes in every message as the session key (Session ID) of the agent's memory. Each Telegram conversation then gets its own history: the bot remembers previous exchanges with a given user without mixing conversations together.
How do I stop just anyone from talking to my Telegram bot?
A Telegram bot is public by nature: anyone who finds its handle can message it. Add an IF node at the top of the workflow that compares the incoming chat_id against an allowlist of authorized IDs, and stop the workflow (or reply with a polite refusal) for any unknown sender. Without this guardrail, strangers can burn through your LLM calls without you knowing.
Bundle FlowKit Complet
€269