RecipeAgents / Recipes / Support
Support recipeTelegram → Telegram: AI agent with memory in n8n
Customers message your Telegram bot with the same questions every day. This n8n workflow answers them with an AI Agent that remembers each chat, reads your FAQ page before it answers, and messages you when a person should step in. It’s a common build: in our study of 13,574 public n8n templates, 56.6% of templates with a Telegram Trigger also use the AI Agent node, and 29.0% of AI Agent templates attach a memory node.
| Input | Text messages sent to your Telegram bot, your public FAQ page |
| Tools | Telegram (bot from @BotFather), n8n, OpenAI API (GPT-6 Luna), your FAQ page |
| Time | Setup about 45 minutes, including creating the bot (our estimate). |
| Cost | GPT-6 Luna costs $0.10 per million input tokens and $0.50 per million output tokens (OpenAI model page, read 2026-10-26). Our arithmetic: if a message uses about 5,000 input tokens (instructions, chat history and up to 8,000 characters of FAQ text, often across two model calls when the tool runs) and 200 output tokens, 1,000 customer messages a month is about $0.50 of input and $0.10 of output. Telegram bots are free. |
n8n nodes in this workflow: Telegram, If, AI Agent, OpenAI Chat Model, Simple Memory, Structured Output Parser. Each links to usage data and known problems in our n8n node library.
Download it
- n8n workflow (.json)Import in n8n: Workflows → Import from file. Then connect your credentials.
- Zapier blueprint (.md)Step-by-step rebuild guide. Zapier has no public import format, so this isn't one-click.
- Open the Zap editorCreate a new Zap and follow the blueprint.
The n8n file has eleven nodes (Telegram Trigger, a text check, the AI Agent with four sub-nodes: OpenAI Chat Model, Simple Memory, an HTTP Request tool and a Structured Output Parser, then three Telegram replies and an IF) plus a read-me note. We check that its JSON structure is valid, but we haven't run every file in a live n8n instance, so test it with sample data before you switch it on. All 25 files, the logins each needs and how to fix common import errors are on our n8n templates page. Not sure which tool to run it on? See what this kind of recipe costs in n8n vs Zapier or n8n vs Make. On n8n Cloud the trigger's poll interval matters more than the node count: n8n pricing works through it.
Steps
- Create the bot: message @BotFather on Telegram, send /newbot and copy the token. In n8n, add a Telegram credential with that token and use it on the trigger and the three Telegram nodes.
- Import our file and add your OpenAI credential on the OpenAI Chat Model sub-node. Our file pins the model ID gpt-6-luna instead of the node's preselected model (see Where it breaks).
- Read FAQ page (an HTTP Request tool): replace https://example.com/faq with your own FAQ URL. It returns only the page text, cut at 8,000 characters, so the model reads less noise.
- Simple Memory: the session key is the Telegram chat ID, so every chat keeps its own history, and Context Window Length is 10, so the agent sees the last 10 exchanges.
- The Structured Output Parser makes the agent return two fields: reply and needs_human. Send reply posts the reply with Parse Mode HTML and the n8n attribution turned off.
- Alert owner: replace YOUR_OWN_CHAT_ID with your own chat ID. To find it, message the bot yourself and read message.chat.id in the Telegram Trigger's output.
- Test, then publish. Telegram allows one webhook per bot, so the test URL and the production URL replace each other. Test with a second bot, or unpublish while you test.
The prompt
You are the Telegram support assistant for YOUR BUSINESS. Answer customer questions using ONLY what the read_faq tool returns: call it before you answer any question about products, prices, delivery, opening hours or policies. Keep replies under 80 words, friendly, plain text with no Markdown. Use the earlier messages in this chat for context. If the FAQ doesn't cover the question, or the customer asks for a refund, is upset, or wants a person, set needs_human to true and tell them a person will reply soon. Never invent prices, dates or policies.
Sample run
Customer (2nd message in the chat): And how long does delivery to Riga take? (1st message was: Do you ship to Latvia?)
{"reply": "Yes, we ship to Latvia, and delivery to Riga usually takes 3-5 working days, as our FAQ says. You'll get a tracking link by email when your order leaves.", "needs_human": false}Where it breaks
- “Bad Request: can’t parse entities”. In the n8n 2.44.6 source we read, the Telegram node sets Parse Mode to Markdown whenever you leave it empty, so a reply with a stray * or _ fails. It’s a common one: this forum thread has 11,717 views. Our file sets Parse Mode to HTML and escapes &, < and > in the reply, and the instructions ask for plain text.
- The bot answers in testing, then goes quiet. Telegram allows one webhook per bot, so the test URL and the production URL overwrite each other (n8n docs). Use a second bot for testing, or unpublish the workflow while you test. On self-hosted n8n, “An HTTPS URL must be provided for webhook” means you need to set WEBHOOK_URL to an HTTPS address.
- It forgets everything after a restart. Simple Memory keeps history in n8n’s memory. Users report it clearing out (forum, Reddit), and the docs say it doesn’t work in queue mode. For a bot customers rely on, swap it for Postgres Chat Memory with the same session key.
- It ignores what the customer said earlier. In this thread, the replies point to two causes: a session key that changes between messages, and instructions pasted into the user prompt, which then fill the memory. Keep the session key on the chat ID and the instructions in the System Message, as our file does.
- “Invalid value for ‘content’: expected a string, got null”. Photos, stickers and voice notes arrive without message.text, so the agent gets an empty prompt (AI Agent docs). Our file’s Has text? node sends those chats a “please type your question” reply instead.
- “Model output doesn’t fit required format”. The Structured Output Parser rejects replies that miss its schema (forum). Generating the schema from a JSON example makes every field required (docs), so we keep it to two fields and name both in the instructions.
- The node preselects an older model. In n8n 2.44.6, the OpenAI Chat Model node preselects gpt-5-mini, which OpenAI’s model page marks as deprecated (read 2026-10-26). Our file pins gpt-6-luna. If your account doesn’t list it, pick another current model by ID.
- Long answers fail to send. Telegram rejects messages that are too long (forum). The instructions ask for under 80 words, which keeps replies well short of that.
- Anything customer-facing or money-related. Keep a human approval step until you've watched a few dozen runs and trust it.
Use Claude or Gemini instead
Only the chat model sub-node changes. The memory, the FAQ tool, the output parser and the Telegram nodes stay as they are. Delete OpenAI Chat Model and attach another chat model to the AI Agent’s Chat Model input.
- Claude: Anthropic Chat Model, model
claude-haiku-5-5, with an Anthropic API key. Haiku 5.5 costs $0.10 per million input tokens and $0.50 per million output tokens for prompts up to 100k tokens (Anthropic pricing, read 2026-10-24). There’s no ongoing free tier. - Gemini: Google Gemini Chat Model, model
models/gemini-3.5-flash-lite, with a Google Gemini(PaLM) API key from Google AI Studio. It costs $0.30/$2.50 per million tokens on the paid tier (Google pricing, last updated 2026-10-22, read 2026-10-24). There’s a free tier, but Google uses free-tier content to improve its products, so link billing before real customer chats go through it. - Since n8n 2.43.5 the Gemini model picker shows product names instead of IDs, so pick Gemini 3.5 Flash-Lite by name. Run a few test chats after any swap, because each model follows the JSON format a little differently.
Tool names and pricing change often, so check each tool's current docs before you build. Times on this page are estimates, not measurements.
More support recipes
- Draft support replies from your help docs
- Flag upset customers before they churn
- Find the questions your FAQ doesn't answer
- Draft replies to Google reviews
All collections · Full inbox-triage walkthrough
New to building agents? Plan this one first with the free agent planner on PlainAgent, our sister site with plain-English guides. Not sure which AI model to use? See the writing and chat assistant ranking on TaskRank.