A powerful, beginner-friendly Telegram AI Chatbot built with Node.js, the Telegraf framework, and dual AI engine support: Groq API (Llama 3.3) and Google Gemini API (gemini-2.0-flash-lite).
The bot acts as a warm, friendly conversational assistant. It can chat, answer questions, explain code, write stories, and translate languages, and it understands almost every global language.
- Dual AI Engine Support:
- Groq Llama 3.3 (Primary): Extremely fast, intelligent, and comes with a massive free tier of 14,400 messages per day!
- Google Gemini (Secondary Fallback): Auto-falls back to Gemini if Groq encounters issues or rate limits.
- Multilingual Support: Converses fluently in Hindi, Urdu, English, Spanish, Arabic, and dozens of other languages.
- Warm & Friendly Persona: Customized system prompts instruct the AI to behave as a friendly companion.
- Robust Redundancy: If both AI keys are missing, the bot falls back gracefully to a friendly static echo bot instead of crashing.
- Production Webhook Mode: Automatically switches to Webhook mode when hosted on Render (using
RENDER_EXTERNAL_URL) to wake the server up when a message is received, solving the free-tier sleep issue. - Graceful Shutdown: Cleans up and stops polling gracefully on process termination signals (
SIGINT,SIGTERM).
- Node.js (v18 or higher recommended)
- NPM (Node Package Manager)
Ensure you have the following files in your workspace directory:
package.jsonindex.js.env.gitignore
Run the following command to install the required packages:
npm install- Open Telegram and search for @BotFather (the official bot with the blue verified badge).
- Start a conversation and send the
/newbotcommand. - Follow the instructions to choose a name (e.g.,
shayan_your_friendly_bot) and a unique username ending inbot. - Copy the HTTP API token provided by BotFather.
- Go to console.groq.com.
- Sign up with your Google account or email (completely free).
- Click on API Keys in the left menu, then click Create API Key.
- Copy the key starting with
gsk_.
- Go to Google AI Studio.
- Click on the Create API key button.
- Copy the generated API key starting with
AIzaSy.
Open the .env file in the root of the project and populate your keys:
BOT_TOKEN=your_telegram_bot_token_here
GEMINI_API_KEY=your_gemini_api_key_here
GROQ_API_KEY=your_groq_api_key_hereTo run the bot in development mode where it auto-restarts on any file change:
npm run devTo run the bot in production mode:
npm start- Push your code to your GitHub repository.
- Log in to Render using your GitHub account.
- Click New + -> Web Service.
- Connect your repository.
- Configure the service:
- Name:
shayan-friendly-bot - Runtime:
Node - Build Command:
npm install - Start Command:
npm start - Instance Type: Free
- Name:
- Click Environment Variables and add the following keys:
BOT_TOKENGROQ_API_KEYGEMINI_API_KEY
- Click Deploy Web Service.