Tutorial

How to Build a Telegram Chatbot with Google AI Studio (Gemini) in n8n: A Step-by-Step Guide

By Shubhranil Layek

Most Telegram bots only answer what they were taught in advance — tap a button, get a fixed reply. An AI chatbot is different: it understands plain questions and writes its own answers. In this guide you will build one without writing any code, using n8n — a visual tool where you connect ready-made blocks instead of typing programs — together with Google's Gemini AI and a free Google AI Studio API key. You will import a ready workflow, add two keys, switch it on, and your bot will start answering real questions on Telegram. No coding experience is needed; every step is explained in simple words. If you'd rather not build it yourself, I can build the bot for you — for your business or a personal project — and there's a note about that at the end of this guide.

The finished workflow from this guide lives in one project, the Telegram Gemini Chatbot on GitHub. You will download the workflow file from there in Step 4, so you can open the repo now and keep it beside you as you go.

Guide header for How to Build a Telegram Chatbot with Google AI Studio and Gemini in n8n, showing the workflow on the n8n canvas and a short sample chat with an AI bot

Start Here: The Basics for Complete Beginners

If words like "API key", "model" and "workflow" are new to you, read this part first. It takes three minutes, and everything after it will make sense.

What is an AI chatbot?

A normal bot follows rules somebody set in advance: if the user types "timings", reply with the opening hours. An AI chatbot sends the user's message to an AI model — a program trained on huge amounts of text that can understand questions and write answers — and replies with whatever the model writes back. You do not write the answers. You only connect the pieces that carry messages between Telegram and the model. In this guide, n8n does that carrying for you.

What are Gemini and Google AI Studio?

Gemini is Google's family of AI models — the same technology behind the Gemini app you may have chatted with. Google AI Studio is a free website from Google where developers get a key that lets their own tools talk to Gemini. That key is called an API key. An API is a fixed set of ways one program can ask another program for things, and the key is the password that proves the request comes from you. Your workflow will use the key to ask Gemini, "here is what the user said — what should I reply?", and Gemini answers with text.

Two things worth knowing before you start. First, the API key from AI Studio is free, with daily limits that are plenty for learning and personal use; you do not add a card. Second, the key is a password for your quota — anyone who has it can spend your limits — so it gets the same treatment as the bot token: it lives inside n8n's credential store, never in a shared file, never in a screenshot.

What is n8n?

n8n is a tool for connecting apps together visually. Instead of writing a program, you place blocks — called nodes — on a canvas and join them with lines. Each node does one small job: receive a Telegram message, call Gemini, send a reply. A set of connected nodes is a workflow, and once you switch a workflow on, n8n runs it for you, day and night, on its own. You can run n8n on your own computer or server (it is free and open source) or use n8n Cloud, where n8n hosts it for you. This guide works exactly the same either way.

The pieces, in one picture

A user types in Telegram. Telegram wakes your workflow in n8n. The workflow sends the message to Gemini with your API key. Gemini writes a reply. The workflow hands it back to Telegram, and the user sees it — usually within a few seconds. Four nodes do the whole job, and Step 4 shows you each one.

What You Need

That is the whole list. No code editor, no installs of programming tools, nothing to buy.

Step 1: Create a Telegram Bot with BotFather

Open Telegram, search for BotFather — the real one has a blue verified tick and the username @BotFather — and send /newbot. BotFather asks two questions: a display name (anything friendly, changeable later) and a username (unique, letters/numbers/underscores only, must end in bot, never changeable). It then replies with your token, a long string that is the bot's password.

Keep the token aside for Step 5 — it goes into an n8n credential, never into the workflow file itself. One safety habit worth learning now: if a token ever leaks, send /revoke to BotFather and it will issue a fresh one.

Step 2: Get Your Free Gemini API Key from Google AI Studio

Now the AI side. This takes about two minutes:

  1. Go to aistudio.google.com and sign in with your Google account. If it asks you to accept the terms of service, read and accept them.
  2. Open aistudio.google.com/apikey directly, or click Get API key in the left-hand menu.
  3. Click Create API key. AI Studio may ask you to create a Google Cloud project or pick an existing one — the default suggestion is fine; it is just the folder the key belongs to.
  4. Your key appears, starting with AIza. Copy it somewhere safe for Step 6. You can come back to this page any time to see, copy or delete keys.

That is the whole signup. The free tier renews daily and is generous enough to build and run a personal chatbot; if you ever hit the limit mid-testing, the workflow will show an error (covered in the mistakes section) and the limit resets the next day.

Step 3: Get n8n Ready

You need n8n open in your browser before the next step. Two ways to get there:

Either way, end this step with n8n open on your screen and an empty canvas or the workflows list in front of you.

Step 4: Download the Workflow and Import It

The workflow is already built for you — this step just brings it into your n8n.

  1. Open the Telegram Gemini Chatbot repo on GitHub and download the file telegram-gemini-chatbot.workflow.json (click the file name, then the download button at the top right of the file view).
  2. In n8n, click the … menu at the top right and choose Import from File — in some versions it sits under Workflows → Import from File.
  3. Pick the JSON file you just downloaded. The workflow opens on the canvas.

You should see four nodes connected in a line. Here is what each one does:

The workflow imports inactive — nothing runs yet. The file also contains placeholders instead of real credentials, on purpose: keys should never travel inside a shared file. The next two steps attach your own keys.

Step 5: Add the Telegram Credential

  1. In n8n, open Credentials → New and search for Telegram API.
  2. Paste the BotFather token from Step 1 into the Access Token field.
  3. Save it, with a name like Telegram account.
  4. Back in the workflow, click the Telegram Trigger node and select this credential. Then click the Telegram Send Message node and select the same credential there too.

Both Telegram nodes must use the same credential — this is the step people most often half-finish, and the mistakes section below starts with it for a reason.

Step 6: Add the Gemini Credential

The Gemini node talks to the API directly, so its key is stored as a header credential:

  1. In n8n, open Credentials → New and search for Header Auth.
  2. Set Name to exactly X-goog-api-key — letter for letter, including the dashes.
  3. Set Value to the Gemini API key from Step 2.
  4. Save it, with a name like Google Gemini API Key.
  5. Back in the workflow, click the Google Gemini (AI Studio) node and, under Credential for Header Auth, select this credential.

Step 7: Activate the Workflow and Test Your Bot

  1. Click the Active toggle at the top right of the workflow so it turns on. n8n now registers your bot with Telegram and starts listening.
  2. Open Telegram, find your bot, press Start, and send it any message — a question, "explain photosynthesis like I'm 12", anything.
  3. The bot should reply with Gemini's answer within a few seconds.
  4. To see what happened under the hood, open the workflow's Executions tab in n8n. Every message shows up there, node by node, so you can see exactly what Gemini returned.
A Telegram chat with the Gemini chatbot built in n8n: the user asks it to explain photosynthesis simply and the bot answers in plain words

To stop the bot later, switch Active off again. Telegram keeps the messages; the bot just stops answering them.

Step 8: Make It Yours

Three small changes cover most of what people want next, and all three live inside the Google Gemini (AI Studio) node:

One Honest Limit: This Bot Has No Memory (Yet)

This version of the workflow is stateless — each message is answered on its own. Ask a question, get a good answer, then ask "and why does that happen?" and the bot will not know what "that" was, because nothing about the earlier messages is sent along. For one-shot questions, explanations, drafts and practice conversations it works well. Remembering the last few messages per chat — for example by saving them in an n8n Data Table and sending them with each request — is the natural next upgrade, and the workflow is a good base for it.

Two smaller limits in this version: it reads text messages only (photos, voice notes and stickers are ignored), and a very long Gemini answer can run into Telegram's 4096-character limit for a single message.

Stuck? Beginner Mistakes and Fixes

Frequently Asked Questions

Is the Gemini API really free?

Yes — the AI Studio free tier gives you a key with daily limits and needs no card. It is meant for building and testing, and it comfortably covers a personal chatbot. Paid tiers exist if a bot ever outgrows it, but nothing in this guide needs one.

Is n8n free?

Running n8n yourself is free — it is open source. n8n Cloud, where n8n hosts it for you, is a paid service with a trial. For a first chatbot, either works; Cloud is simply less setup, and it keeps the bot online when your own computer is off.

Which Gemini model should I use?

The flash models. They are the fast, chat-shaped ones, and gemini-2.5-flash — the one in the workflow — is a good default. Changing it is a ten-second edit in the Gemini node, as Step 8 shows.

Does the bot remember our conversation?

No — this version answers each message on its own, as explained in the limits section above. That keeps the workflow small and easy to understand. Memory is a well-trodden upgrade (store recent messages per chat, send them along with each request) once the basic bot is running.

Can it reply in Hindi or other languages?

Yes. Gemini answers in the language it is spoken to, and you can also add "reply in Hindi" (or any language) to the instruction in the Gemini node, as Step 8 shows, to make it the bot's default.

Can I give the bot a specific job?

That is what the instruction in the Gemini node is for. Describe the job there — "you are the support assistant for my bakery; answer from this price list; be brief and polite" — and the same workflow becomes that bot. Teaching it your own documents is a bigger step (that is called grounding or RAG), but the personality-and-rules version above covers a lot of real uses.

Do I need my computer on for the bot to work?

n8n needs to be running, wherever it lives. On n8n Cloud, that is handled for you. If you run n8n on your own computer, the bot answers only while that computer — and n8n on it — is on; a small always-on server is the usual step up.

You Did It: What You Have Now

If you followed along, here is what you now have:

From here the pattern is yours to bend: change the instruction and it is a different bot; add a node and it can look things up, save notes or send alerts; add memory and it holds a real conversation.

Need a Telegram Bot Built for You?

If you want a Telegram bot built for you, I build bots like this one — AI chatbots powered by Gemini, FAQ and support bots, news and alert bots, and price-tracking bots — for small businesses and personal projects. A bot for your business can answer customer enquiries in plain language, handle routine support questions around the clock and pass the tricky ones to you. You can see my work on GitHub, including the Telegram Gemini Chatbot built in this guide, or reach me at subhralayek7@gmail.com.

I'm Shubhranil Layek, a developer based in Durgapur, West Bengal, and I'm available for freelance projects. If you have a bot in mind, write to me with what it should do — I'll reply with how I would build it.

For more guides and projects, visit Shubhranil Layek's developer website or browse the blog.