Build a free Telegram AI bot on Netlify with Gemini + Groq A developer published an MIT-licensed open-source template, telegram-ai-bot-lite, that runs a Telegram AI assistant entirely on free tiers: a single Netlify Function JavaScript file handles webhook updates, queries Google Gemini, and falls back to Groq when Gemini errors or returns empty. The function validates Telegram's secret-token header to block unauthorized requests, is configured through environment variables such as SYSTEM_PROMPT and MAX_OUTPUT_TOKENS, and ships with an offline npm test that mocks all three services. Most "build an AI chatbot" tutorials end with a server you pay for every month. This one doesn't. We'll put an AI assistant in Telegram using three free tiers: Netlify Functions to host it, Google Gemini to answer, and Groq as a backup when Gemini is busy. There's no server, no database and no npm packages. The whole bot is one JavaScript file. We'll use the open-source template telegram-ai-bot-lite https://github.com/nimaai1528/telegram-ai-bot-lite MIT . How it works Telegram can push each message to a URL of your choice a webhook . Our URL is a Netlify Function: Telegram ──POST update──▶ Netlify Function index.mjs │ checks secret header ├─▶ Gemini ── error/empty ──▶ Groq ◀── answer Telegram ◀──sendMessage──────┘ The function does four things: it checks Telegram's secret-token header, sends the text to Gemini, tries Groq if Gemini fails or returns nothing, and replies with sendMessage . A request without the right secret is rejected. That matters, because otherwise anyone who finds the URL could run up your API usage. Step 1: Create the bot 1 minute Open @botfather https://dev.to/botfather in Telegram, send /newbot , pick a name and copy the token. Step 2: Get free AI keys 3 minutes One key is enough. Two make the bot much more reliable, because free tiers have rate limits and the fallback hides them from your users. Step 3: Deploy to Netlify 3 minutes | Variable | Value | |---|---| | TELEGRAM BOT TOKEN | token from BotFather | | TELEGRAM WEBHOOK SECRET | a long random string letters, digits, , - | | GEMINI API KEY | your Gemini key | | GROQ API KEY | your Groq key optional | Step 4: Connect Telegram 1 minute Open this once in your browser: https://YOUR-SITE.netlify.app/ setup?key=YOUR TELEGRAM WEBHOOK SECRET You should see "Webhook was set" . Now open your bot, press Start and say hi. Step 5: Make it yours Everything is set with environment variables, so you never edit code to customise it: SYSTEM PROMPT sets the personality and rules "You are a concise cooking assistant…" . GEMINI MODEL / GROQ MODEL choose any model your key can use. MAX OUTPUT TOKENS caps the answer length default 1024 . PRIVATE CHATS ONLY default true makes the bot ignore groups. Testing without keys npm test runs offline. It mocks Telegram, Gemini and Groq, sends fake webhook updates, and checks three things: a text message gets an answer, Groq takes over when Gemini fails, and a wrong secret is rejected. Run it after every change. Troubleshooting / setup URL again, and make sure you redeployed after adding the variables. Forbidden on key doesn't match TELEGRAM WEBHOOK SECRET . Limits to know The Lite bot is stateless: every message is answered on its own, with no memory of the conversation. Free-tier quotas belong to Netlify, Google and Groq, and they can change. Check them before you give the bot to many users. Where to go next From here you can add conversation memory a Redis store such as Upstash works well on serverless , photo input Gemini accepts images , or voice notes transcribe them, then answer . The repo README lists ideas for extending it. The template stays free and MIT-licensed. This article was written with help from AI and edited by me.