App Hosting

n8n Telegram Bot with Gemini: We Built It, Here’s What Broke

Dr. Somya Hallan · Nov 16, 2026 · 19 min read
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.

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.

WhatWhere you get itCost
Bot access token@BotFather in TelegramFree
AI keyGoogle AI Studio (Gemini)Free tier
n8nSelf-hosted, n8n Cloud, or a one-click templateFree software; you pay for the server
Public HTTPS addressYour domain plus a TLS certificate, or a generated addressDepends 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.

SettingWhat breaks without it
A domain or public addressTelegram has nowhere to send messages
A valid TLS certificateTelegram 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 frontn8n builds the wrong URL from proxy headers
WebSocket proxyingThe 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.

n8n Telegram bot workflow in the n8n editor: 11 nodes from Telegram Trigger to Send reply, with a voice-note branch through Gemini transcribe, published
The finished n8n Telegram bot workflow: the voice-note branch runs on top, the text path below.
NodeTypeJob
Telegram TriggerTelegram TriggerReceives each new message
Is voice note?IfSends voice notes to the voice branch
Download voice fileTelegram (Get file)Fetches the audio
Voice to base64CodeEncodes the audio for Gemini
Gemini transcribeHTTP RequestTurns the audio into text
Prepare messageCodeSets chat ID, text, input type and the reply rule
Should I reply?IfStops group messages not meant for the bot
Build requestCodeAdds the system prompt and recent turns
Gemini replyHTTP RequestGets the answer
Save memory and format replyCodeStores the exchange, cleans the text
Send replyTelegram (Send message)Posts the answer in the same chat

How we tested

Test parameterValue
n8n2.40.7, Selfhost.dev n8n template (SQLite)
Servercx23, 2 vCPU, 4 GB RAM, Nuremberg
AIGoogle Gemini API, gemini-3.5-flash-lite, free tier
Workflow11 nodes, published
Tester and dateSrushti Jain, 7 November 2026, one day
Speed measured asn8n 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

  1. Open @BotFather in Telegram (the verified account) and send /newbot.
  2. Give the bot a display name.
  3. Give it a username that ends in bot.
  4. 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

  1. Open Google AI Studio and sign in.
  2. Go to API keys and choose Create API key.
  3. 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

CredentialFieldValue
Telegram APIAccess TokenThe BotFather token
Telegram APIBase URLhttps://api.telegram.org (default)
Header Auth (for the Gemini HTTP nodes)Namex-goog-api-key
Header AuthValueYour 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.

  1. Create a workflow and add Telegram Trigger as the first node.
  2. Choose the Telegram credential.
  3. Set Trigger On to Message.
  4. Click Execute step, then send /start to your bot.
n8n Telegram bot setup: the Telegram Trigger node with an HTTPS Test URL, the Telegram account credential and Trigger On set to Message, waiting for the first event
The n8n Telegram bot’s Test URL on the template’s HTTPS address (hostname blurred). Note n8n’s own warning: one Telegram trigger per 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.

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.

n8n Telegram bot answering voice notes in a private Telegram chat: it replies that New Delhi is the capital of India, then confirms it in context after the next voice note
Our n8n Telegram bot answering voice notes at 1:26 PM. The second answer builds on the first, so transcription and memory work together.

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:

  1. Send /setprivacy to BotFather, pick the bot, choose Disable. (Admin bots get all messages anyway.)
  2. Remove the bot from the group and add it again. Telegram requires this after a privacy change.
  3. Check getWebhookInfo (see below).
  4. 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.

n8n Telegram bot answering an @mention in a Telegram group chat at 1:19 PM, right after the bot was re-added to the group
Our n8n Telegram bot’s first group reply at 1:19 PM, right after it was re-added (bot username blurred).

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 callsTest URLProduction URL
RunsOnce, while the editor waitsFor every message
Results show inThe canvasThe Executions list
Use it forBuildingThe 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.

SymptomExact error or signCauseFixWe hit it?
Workflow won’t activateBad request: bad webhook: An HTTPS URL must be provided for webhookn8n’s webhook URL isn’t public HTTPSSet N8N_WEBHOOK_URL to your HTTPS address, or use a host that does itNo
Test run looks stuck waitingNo error, spinner never stopsProxy doesn’t pass WebSocketsEnable WebSocket proxying; reopen the workflowNo
Trigger fires on nothingNo executionsTrigger On is “Edited Message”Set Trigger On to MessageYes
Execute step failsn8n can't listen for test executions at the same time as listening for production onesWorkflow is publishedUnpublish to test, or use a second botYes
Publish fails after a token changeSome triggers failed to activate ... could not be foundCredential holds the old tokenUpdate the credential, then publishYes
Silent in groups onlyPrivate chat worksPrivacy mode or stale membershipThe 4-step group fix aboveYes
Message arrives, no reply[404] This model models/gemini-2.5-flash is no longer available to new usersModel 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 usYes

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’s N8N_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.

MeasurementResultHow measured
Deploy click to n8n login3 min 45 sStopwatch
Start to first text reply1 h 24 min (10:00 to 11:24 AM)Timestamps in n8n and Telegram
Start to memory, voice and groups workingAbout 3.5 h (10:00 AM to 1:26 PM)Timestamps in n8n and Telegram
First successful reply4.2 sn8n execution time
Average reply, 10 runs3.45 s (1.15 to 5.55 s)n8n execution time, not Telegram delivery
Tokens per text request138 (110 prompt, 28 reply)Gemini response metadata
Server credit used on build dayAbout $0.20Balance $4.96 at 9:48 AM, $4.76 in a later screenshot
Servercx23 (2 vCPU, 4 GB), NurembergSelfhost.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 runYou run
The server, firewall and network rulesYour workflows
Reverse proxy, HTTPS and certificate renewalsYour credentials and API keys (BotFather, Gemini)
Editor and webhook URL configurationYour n8n users and roles
The encryption keyData retention inside n8n
New n8n releases shown in the consoleWhen to press Update
Optional daily backups (+20%), metrics, logs and a health check every 60 secondsError 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.

  1. Download telegram-gemini-bot.json from the n8n Telegram AI bot repository.
  2. In n8n, create a workflow and choose Import from File.
  3. Pick your Telegram credential in the 3 Telegram nodes and your Header Auth credential in the 2 Gemini nodes.
  4. In Prepare message, set the BOT constant 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