{"slug": "build-a-free-telegram-ai-bot-on-netlify-with-gemini-groq", "title": "Build a free Telegram AI bot on Netlify with Gemini + Groq", "summary": "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.", "body_md": "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.\n\nWe'll use the open-source template [telegram-ai-bot-lite](https://github.com/nimaai1528/telegram-ai-bot-lite) (MIT).\n\n**How it works**\n\nTelegram can push each message to a URL of your choice (a webhook). Our URL is a Netlify Function:\n\n```\nTelegram ──POST update──▶ Netlify Function (index.mjs)\n                              │ checks secret header\n                              ├─▶ Gemini ──(error/empty)──▶ Groq\n                              ◀── answer\nTelegram ◀──sendMessage──────┘\n```\n\nThe 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.\n\n**Step 1: Create the bot (1 minute)**\n\nOpen [@botfather](https://dev.to/botfather) in Telegram, send `/newbot`, pick a name and copy the token.\n\n**Step 2: Get free AI keys (3 minutes)**\n\nOne key is enough. Two make the bot much more reliable, because free tiers have rate limits and the fallback hides them from your users.\n\n**Step 3: Deploy to Netlify (3 minutes)**\n\n| Variable | Value | \n|---|---|\n| `TELEGRAM_BOT_TOKEN` | token from BotFather | \n| `TELEGRAM_WEBHOOK_SECRET` | a long random string (letters, digits, `_` ,`-` ) | \n| `GEMINI_API_KEY` | your Gemini key | \n| `GROQ_API_KEY` | your Groq key (optional) | \n\n**Step 4: Connect Telegram (1 minute)**\n\nOpen this once in your browser:\n\n```\nhttps://YOUR-SITE.netlify.app/_setup?key=YOUR_TELEGRAM_WEBHOOK_SECRET\n```\n\nYou should see `\"Webhook was set\"`. Now open your bot, press Start and say hi.\n\n**Step 5: Make it yours**\n\nEverything is set with environment variables, so you never edit code to customise it:\n\n`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.\n**Testing without keys**\n\n`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.\n\n**Troubleshooting**\n\n`/_setup` URL again, and make sure you redeployed after adding the variables.`Forbidden` on `key` doesn't match `TELEGRAM_WEBHOOK_SECRET`.\n**Limits to know**\n\nThe 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.\n\n**Where to go next**\n\nFrom 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.\n\n*This article was written with help from AI and edited by me.*", "url": "https://wpnews.pro/news/build-a-free-telegram-ai-bot-on-netlify-with-gemini-groq", "canonical_source": "https://dev.to/nimaai1528/build-a-free-telegram-ai-bot-on-netlify-with-gemini-groq-l23", "published_at": "2026-12-05 18:33:55+00:00", "updated_at": "2026-12-05 18:43:32.904393+00:00", "lang": "en", "topics": ["ai-tools", "ai-products", "developer-tools", "large-language-models"], "entities": ["Netlify", "Google Gemini", "Groq", "Telegram", "BotFather", "telegram-ai-bot-lite"], "also_reported_by": [], "takeaway": "A single stateless Netlify Function can serve a Telegram bot by validating the webhook secret header, calling Gemini, and falling back to Groq on error or empty output, with an offline mocked test covering the fallback and secret rejection.", "recommendation": {"advice": "Add a second LLM provider as a fallback behind your primary so free-tier rate limits and outages stay invisible to users, and test the fallback path offline with mocked services.", "playbook": "production-ops", "playbook_url": "https://wpnews.pro/playbooks/production-ops"}, "alternates": {"html": "https://wpnews.pro/news/build-a-free-telegram-ai-bot-on-netlify-with-gemini-groq", "markdown": "https://wpnews.pro/news/build-a-free-telegram-ai-bot-on-netlify-with-gemini-groq.md", "text": "https://wpnews.pro/news/build-a-free-telegram-ai-bot-on-netlify-with-gemini-groq.txt", "jsonld": "https://wpnews.pro/news/build-a-free-telegram-ai-bot-on-netlify-with-gemini-groq.jsonld"}}