cd /news/ai-tools/build-a-free-telegram-ai-bot-on-netl… · home › topics › ai-tools › article
[ARTICLE · art-182540] src=dev.to ↗ pub= topic=ai-tools verified=true sentiment=↑ positive

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.

recommendation

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.

more in playbook: Running AI in production
by read3 min views18 publishedDec 5, 2026

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 (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 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.

── more in #ai-tools 4 stories · sorted by recency
── more on @netlify 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/build-a-free-telegra…] indexed:0 read:3min 2026-12-05 · —