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──────┘
Enter fullscreen mode
Exit fullscreen mode
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.…