n8n Telegram Bot with Gemini: We Built It, Here’s What Broke
Co-authored by Srushti Jain, developer intern at Selfhost.dev, who built and tested the bot on n8n 2.40.7.
An n8n Telegram bot needs four things: a token from BotFather, an AI key, one workflow, and n8n running on a public HTTPS address. Most guides stop at the bot’s first reply. We kept going until ours remembered the conversation, answered voice notes and behaved in group chats.
We hit five errors the top tutorials don’t mention. The first text reply came 1 hour 24 minutes in, and memory, voice notes and group chats all worked about 3.5 hours in. Replies averaged 3.45 seconds on a free Gemini key.
Every step, error and number below comes from that one build.
Table of Contents
KEY FACTS
- Stack: an 11-node n8n workflow with Telegram Trigger and the Gemini API (free tier), on the Selfhost.dev n8n template, n8n 2.40.7.
- The one hard requirement: Telegram only delivers to a public HTTPS webhook. The template had one 3 minutes 45 seconds after deploy.
- Speed: 3.45 seconds average reply over 10 runs (1.15 to 5.55 seconds, n8n execution time).
- Cost: about $0.20 of server credit on build day; Gemini stayed on the free tier.
- The surprise: on 7 November 2026, n8n’s default Gemini model returned a 404 for our new Google account. HTTP Request nodes fixed it.
- Reuse it: the workflow JSON is on GitHub. Change one line, connect two credentials.
What do you need to build an n8n Telegram bot?
You need a Telegram bot token, an AI key, an n8n workflow, and n8n on a public HTTPS address. HTTPS stops most people: Telegram only posts to an HTTPS webhook. Selfhost.dev runs n8n as a one-click template on a dedicated 4 GB server, with the webhook URL and HTTPS set before n8n starts, so a Telegram Trigger receives messages on the first deploy.
| What | Where you get it | Cost |
|---|---|---|
| Bot access token | @BotFather in Telegram | Free |
| AI key | Google AI Studio (Gemini) | Free tier |
| n8n | Self-hosted, n8n Cloud, or a one-click template | Free software; you pay for the server |
| Public HTTPS address | Your domain plus a TLS certificate, or a generated address | Depends on the host |
Why the n8n Telegram Trigger needs a public HTTPS address
The Telegram Trigger works by webhook, not polling: n8n registers one URL with Telegram, and Telegram sends every new message there. That URL must be public HTTPS. A localhost or plain HTTP address fails activation with this error:
Bad request: bad webhook: An HTTPS URL must be provided for webhook
Self-hosting n8n? The settings Telegram depends on
Behind your own reverse proxy, five things must line up. n8n’s reverse-proxy guide covers the details.
| Setting | What breaks without it |
|---|---|
| A domain or public address | Telegram has nowhere to send messages |
| A valid TLS certificate | Telegram rejects the webhook |
N8N_WEBHOOK_URL set to your public HTTPS address (WEBHOOK_URL before n8n 2.30.0) | n8n registers a localhost URL |
N8N_PROXY_HOPS when a proxy sits in front | n8n builds the wrong URL from proxy headers |
| WebSocket proxying | The trigger looks “stuck waiting” in test mode |
If you’d rather skip that table, our n8n template, where webhooks work on the first deploy, sets all five before n8n starts. Srushti used its generated HTTPS address and never set up a domain.
Choosing a host? Our best n8n hosting providers guide compares who handles webhooks, and n8n cloud vs self hosted lists what self-hosting leaves to you.
How the n8n Telegram AI bot works (11 nodes)
The bot is one n8n workflow with 11 nodes: a Telegram Trigger, a branch that transcribes voice notes, a reply rule, a Gemini call, a memory store and a reply to the same chat.

| Node | Type | Job |
|---|---|---|
| Telegram Trigger | Telegram Trigger | Receives each new message |
| Is voice note? | If | Sends voice notes to the voice branch |
| Download voice file | Telegram (Get file) | Fetches the audio |
| Voice to base64 | Code | Encodes the audio for Gemini |
| Gemini transcribe | HTTP Request | Turns the audio into text |
| Prepare message | Code | Sets chat ID, text, input type and the reply rule |
| Should I reply? | If | Stops group messages not meant for the bot |
| Build request | Code | Adds the system prompt and recent turns |
| Gemini reply | HTTP Request | Gets the answer |
| Save memory and format reply | Code | Stores the exchange, cleans the text |
| Send reply | Telegram (Send message) | Posts the answer in the same chat |
How we tested
| Test parameter | Value |
|---|---|
| n8n | 2.40.7, Selfhost.dev n8n template (SQLite) |
| Server | cx23, 2 vCPU, 4 GB RAM, Nuremberg |
| AI | Google Gemini API, gemini-3.5-flash-lite, free tier |
| Workflow | 11 nodes, published |
| Tester and date | Srushti Jain, 7 November 2026, one day |
| Speed measured as | n8n execution time per run |
Steps 1 to 3: Bot token, free Gemini key and credentials
These three steps took about 20 minutes in Srushti’s log. Both secrets go into n8n credentials, never into the workflow itself.
Create the bot in BotFather and copy the access token
- Open @BotFather in Telegram (the verified account) and send
/newbot. - Give the bot a display name.
- Give it a username that ends in
bot. - Copy the HTTP API access token BotFather sends back, straight into n8n.
Treat the token like a password. If it leaks, replace it with /revoke in BotFather, as Srushti had to.
Get a free Gemini API key
- Open Google AI Studio and sign in.
- Go to API keys and choose Create API key.
- Copy the key into n8n only.
The free tier covered this whole build. On it, Google may use what you send to improve its products, so test with nothing private. Gemini API pricing lists the limits.
Add the Telegram and Gemini credentials in n8n
| Credential | Field | Value |
|---|---|---|
| Telegram API | Access Token | The BotFather token |
| Telegram API | Base URL | https://api.telegram.org (default) |
| Header Auth (for the Gemini HTTP nodes) | Name | x-goog-api-key |
| Header Auth | Value | Your Gemini API key |
The Telegram credential shows “Connection tested successfully” when the token is right.
Step 4: Set up the n8n Telegram Trigger and catch the first message
Add a Telegram Trigger, set Trigger On to Message, click Execute step, and message your bot. Srushti’s first message arrived at 10:28, six minutes after she added the trigger, on a Test URL already using the server’s HTTPS address.
- Create a workflow and add Telegram Trigger as the first node.
- Choose the Telegram credential.
- Set Trigger On to Message.
- Click Execute step, then send
/startto your bot.

What went wrong: Trigger On was first set to Edited Message. New messages never fire that event, so nothing arrived. Fix: choose Message.
How to find your n8n Telegram chat ID
The chat ID is in the trigger output at message.chat.id: positive for a private chat, negative for a group. Read it from each message instead of hard-coding it, so one workflow answers every chat:
{{ $json.message.chat.id }}
Skip the reverse proxy and the certificates. On our template, that Test URL was live on HTTPS 3 minutes 45 seconds after deploy, so you go straight to importing the workflow. Get n8n with Telegram-ready HTTPS on $5 of free credit: no card, about 10 days of the $0.02/hr European server.
Rather look around first? Click through a live console, no signup.
Step 5: Send the message to Gemini and reply
A Code node builds the request: a system instruction, the recent turns of the chat, and the new message. An HTTP Request node posts it to Gemini’s generateContent endpoint, and a Telegram node sends the answer to the same chat ID. The published workflow calls gemini-3.5-flash-lite.
The system instruction Srushti wrote:
You are a friendly, concise assistant inside Telegram. Answer in the same language the user writes in. Keep replies under 120 words unless asked for more. If the message came from a voice note, answer naturally as if spoken to. Do not ask for or store private data.
The Gemini reply node:
POST https://generativelanguage.googleapis.com/v1beta/models/gemini-3.5-flash-lite:generateContent
Authentication: Generic Credential Type → Header Auth (x-goog-api-key)
Body (JSON): {{ JSON.stringify($json.body) }}
Why we replaced the n8n Google Gemini Chat Model node with HTTP Request
Our first version used n8n’s AI Agent node with the Google Gemini Chat Model on gemini-3.8-flash. On 7 November 2026 at 11:00, it failed with fetch failed. Switching to the node’s default model gave a clearer error:
[404] This model models/gemini-2.5-flash is no longer available to new users. Please update your code to use models/gemini-3.8-flash.
Retrying gemini-3.8-flash failed again at 11:19. The key was fine, since Google answered with a clear 404, so we called the API directly with HTTP Request nodes. The first reply came at 11:24.
Google’s model docs now limit 2.5 models to accounts that used them before and recommend newer ones, such as 3.5 Flash-Lite, the model our workflow calls.
Which to use:
- Native Gemini Chat Model node: if it supports your model and account. It plugs into the AI Agent and memory nodes.
- HTTP Request: if the node fails, or you need exact control of the request. Either way, test your key with one HTTP Request first.
Remove the “This message was sent automatically with n8n” footer
The Telegram Send message node adds that line to every reply by default. In the Send reply node, switch Append n8n Attribution off.
Step 6: Give the bot a memory of the last few messages
A Code node stores the last 6 messages (3 exchanges) for each chat ID in n8n’s workflow static data. Build request sends them to Gemini with each new message. When Srushti told the bot her name and later asked “What is my name?”, it answered correctly.
const data = $getWorkflowStaticData('global');
data.history = data.history || {};
data.history[key] = hist.slice(-6);
One trap: static data isn’t available when you test, so memory only works once published. It’s lightweight history: n8n says keep it small, and it may misbehave under high-frequency runs. For a customer-facing bot, use a database or n8n’s data tables.
Step 7: Answer voice notes
A voice message carries a voice object, so the “Is voice note?” node sends it down a side branch. n8n downloads the file, encodes it to base64 and asks Gemini to transcribe it. The transcript then follows the normal text path.

What went wrong: the first clip (3.5 KB, no waveform) got no answer. Our suggestion: when the transcript comes back empty, reply “I couldn’t hear that” instead of staying silent.
Step 8: Make the bot work in Telegram group chats
By default, a Telegram bot in a group only sees commands, @mentions and replies to its own messages. This is privacy mode. Our rule answers only when the bot is @mentioned or replied to, which keeps groups quiet and Gemini calls low.
The reply rule in the Prepare message node:
const isGroup = ['group', 'supergroup'].includes(m.chat.type);
const mentioned = text.toLowerCase().includes('@' + BOT.toLowerCase());
const repliedToBot = !!(m.reply_to_message && m.reply_to_message.from
&& m.reply_to_message.from.is_bot);
const shouldReply = !isGroup || mentioned || repliedToBot;
The longest fight was group chats. Privacy mode was off from 11:49 and getWebhookInfo showed a healthy webhook, yet nothing arrived, even in a brand-new group. Messages started at 1:19 PM, after a token change, a republish and re-adding the bot.
If your bot is silent in a group, try these in order:
- Send
/setprivacyto BotFather, pick the bot, choose Disable. (Admin bots get all messages anyway.) - Remove the bot from the group and add it again. Telegram requires this after a privacy change.
- Check
getWebhookInfo(see below). - Revoke the token, update the n8n credential, republish, and re-add the bot.
Several changes happened together, so we can’t name the single cause. GitHub issue #18895 reports the token revoke fixing a silent trigger too.

Step 9: Test, then publish
Telegram allows one webhook per bot, so a test run and the published workflow can’t listen at the same time. Test while you build, then publish so the bot runs with the editor closed.
| Test (Execute step) | Published | |
|---|---|---|
| URL Telegram calls | Test URL | Production URL |
| Runs | Once, while the editor waits | For every message |
| Results show in | The canvas | The Executions list |
| Use it for | Building | The live bot |
Clicking Execute step while published returns:
Because of limitations in Telegram Trigger, n8n can't listen for test executions at the same time as listening for production ones. Unpublish the workflow to execute.
What went wrong: after revoking the token, publishing failed with
Some triggers failed to activate: "Telegram Trigger": The resource you are requesting could not be found. The credential still held the old token. Fix: paste the new token into the Telegram credential, save, then publish.
n8n Telegram trigger not working? Symptoms, causes and fixes
Most n8n Telegram trigger failures come down to five causes: no HTTPS, test and production fighting over one webhook, the wrong trigger event, a stale token, or group privacy. The table pairs each symptom with its fix.
| Symptom | Exact error or sign | Cause | Fix | We hit it? |
|---|---|---|---|---|
| Workflow won’t activate | Bad request: bad webhook: An HTTPS URL must be provided for webhook | n8n’s webhook URL isn’t public HTTPS | Set N8N_WEBHOOK_URL to your HTTPS address, or use a host that does it | No |
| Test run looks stuck waiting | No error, spinner never stops | Proxy doesn’t pass WebSockets | Enable WebSocket proxying; reopen the workflow | No |
| Trigger fires on nothing | No executions | Trigger On is “Edited Message” | Set Trigger On to Message | Yes |
| Execute step fails | n8n can't listen for test executions at the same time as listening for production ones | Workflow is published | Unpublish to test, or use a second bot | Yes |
| Publish fails after a token change | Some triggers failed to activate ... could not be found | Credential holds the old token | Update the credential, then publish | Yes |
| Silent in groups only | Private chat works | Privacy mode or stale membership | The 4-step group fix above | Yes |
| Message arrives, no reply | [404] This model models/gemini-2.5-flash is no longer available to new users | Model not available to new accounts (as of 7 Nov 2026) | Use a current model such as gemini-3.5-flash-lite; HTTP Request worked for us | Yes |
To see what Telegram thinks, ask its API from a terminal, with the token in an environment variable:
curl "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/getWebhookInfo"
Don’t paste the token into a browser address bar: it ends up in history and screenshots, which is how Srushti’s leaked. A healthy result shows your HTTPS URL, "pending_update_count":0 and no last_error_message.
What older n8n Telegram guides get wrong now
As of November 2026, many tutorials and AI answers still repeat four outdated points. Each correction comes from this build or current docs.
- “Toggle the workflow to Active.” n8n 2.x calls it Publish (“Unpublish the workflow to execute”).
- “Set
WEBHOOK_URL.” From n8n 2.30.0 it’sN8N_WEBHOOK_URL. - “Use gemini-2.5-flash.” It returned a 404 for our new account on 7 November 2026; Google now limits 2.5 models to past users.
- “Disable privacy mode, re-add the bot, and the group works.” Not for us, even in a new group, until a token revoke, republish and another re-add.
How fast is the bot, and what does it cost?
The bot answered in 3.45 seconds on average across 10 runs, on Gemini’s free tier. Left running all month, the 4 GB European server is $15.18 at 730 hours.
| Measurement | Result | How measured |
|---|---|---|
| Deploy click to n8n login | 3 min 45 s | Stopwatch |
| Start to first text reply | 1 h 24 min (10:00 to 11:24 AM) | Timestamps in n8n and Telegram |
| Start to memory, voice and groups working | About 3.5 h (10:00 AM to 1:26 PM) | Timestamps in n8n and Telegram |
| First successful reply | 4.2 s | n8n execution time |
| Average reply, 10 runs | 3.45 s (1.15 to 5.55 s) | n8n execution time, not Telegram delivery |
| Tokens per text request | 138 (110 prompt, 28 reply) | Gemini response metadata |
| Server credit used on build day | About $0.20 | Balance $4.96 at 9:48 AM, $4.76 in a later screenshot |
| Server | cx23 (2 vCPU, 4 GB), Nuremberg | Selfhost.dev console |
Longer chats cost more per reply, because stored history goes back into every prompt. Our n8n system requirements tests show how far one 4 GB server stretches.
If the bot grows into heavy traffic, n8n queue mode is the next step.
What this test doesn’t cover
This was one working build on one day, not a load test.
- 10 reply runs from one tester, with no concurrent users.
- No error workflow or rate limit (only the Gemini reply node retries on failure).
- Gemini free-tier limits over weeks of use.
- Memory under heavy traffic, where static data can misbehave.
Before a busy launch, add an error workflow, a per-chat rate limit and durable memory.
What the n8n template handles, and what stays with you
You can do all of this by hand on any VPS. The template takes the server work, so your time goes into the bot. The full split is on our managed n8n hosting page.
| We run | You run |
|---|---|
| The server, firewall and network rules | Your workflows |
| Reverse proxy, HTTPS and certificate renewals | Your credentials and API keys (BotFather, Gemini) |
| Editor and webhook URL configuration | Your n8n users and roles |
| The encryption key | Data retention inside n8n |
| New n8n releases shown in the console | When to press Update |
| Optional daily backups (+20%), metrics, logs and a health check every 60 seconds | Error handling and API limits in your bot |
Build day used about $0.20 of credit, but keeping the bot online is what sets your monthly bill. See this server’s monthly bill, already filled in: no signup.
Get the n8n Telegram bot workflow JSON from GitHub
The workflow is public on GitHub as telegram-gemini-bot.json. Import it, connect your two credentials, change one line, and publish. No token or key is stored in the file.
- Download
telegram-gemini-bot.jsonfrom the n8n Telegram AI bot repository. - In n8n, create a workflow and choose Import from File.
- Pick your Telegram credential in the 3 Telegram nodes and your Header Auth credential in the 2 Gemini nodes.
- In Prepare message, set the
BOTconstant to your bot’s username without the @, then publish.
Your bot is ready. Where will it run? The workflow and Gemini key are free; the server is the only paid part, and Telegram needs it online on HTTPS. Deploy n8n with HTTPS ready, on $5 of free credit: import the workflow, connect two credentials, no card.
n8n Telegram bot FAQ
Is an n8n Telegram bot free to run?
Mostly. n8n’s Community edition is free, Telegram bots are free, and Gemini’s free tier covered our whole build. The real cost is the always-on server that receives Telegram’s webhooks. Our build day used about $0.20 of server credit. See n8n pricing for what each way of running n8n costs.
Do I need my own domain for an n8n Telegram bot?
No. You need a public HTTPS address, not a domain of your own. Telegram only checks that the webhook URL is reachable over HTTPS with a valid certificate. Our build used the Selfhost.dev template’s generated HTTPS address, and Telegram accepted it on the first try. You can point your own domain at the server later.
Does the n8n Telegram Trigger use webhooks or polling?
Webhooks. When you test or publish, n8n registers one URL with Telegram, and Telegram pushes each message to it. That’s why n8n needs a public HTTPS address. Telegram allows only one webhook per bot, so a test run and a published workflow can’t listen for the same bot at once.
Why does my n8n Telegram bot ignore messages in a group?
Telegram’s privacy mode is on by default, so bots in groups only see commands, @mentions and replies. Disable it with /setprivacy in BotFather, then remove and re-add the bot. If messages still don’t arrive, revoke the token, update the n8n credential, republish, and add the bot again. That order worked for us.
How do I get the Telegram chat ID in n8n?
Send your bot a message while the Telegram Trigger is listening, then read message.chat.id in the trigger output. Private chats have positive IDs and groups have negative ones. In the reply node, use the expression {{ $json.message.chat.id }} instead of a fixed number, so one workflow answers every chat.
Keep reading: How much RAM and CPU n8n needs, measured · What n8n Cloud does that self-hosting doesn’t · n8n hosts compared on webhooks, credentials and backups