SmartAgent Bot is an intelligent, AI-driven Telegram bot powered by n8n and Gemini 2.5. It can process both voice and text messages, route tasks to smart agents (like Email, Calendar, Stocks, and more), generate AI-based responses or images, and log everything in Google Sheets.
SmartAgent Bot acts as a unified interface for task automation, using AI orchestration and tool-using agents. Users can interact via Telegram using voice or text, and the bot will understand their intent and respond appropriately — whether it's:
- Answering questions via LLM
- Managing emails
- Scheduling calendar events
- Looking up stock prices
- Generating creative prompts or images
- Saving outputs to Google Sheets / Drive
You can try SmartAgent Bot directly on Telegram:
- User sends either a text or voice message via Telegram.
- If it's a voice message, it's transcribed to text using Gemini.
- The system checks if the user is requesting an image or not.
- Generate a prompt using Gemini 2.5 Flash.
- Generate a filename using Gemini 2.5 Flash.
- Generate the image using Flux.1-Schnell model.
- Download the image.
- Send the image to the user via Telegram.
- Save the image to Google Drive.
- Log the metadata in Google Sheets.
-
Query is passed to the AI Orchestrator (Gemini 2.5 Flash).
-
Orchestrator intelligently chooses the correct agent:
- 📧 Email Agent
- 📅 Calendar Agent
- 📈 Stock Agent
- 📊 Growth Agent
- ✍️ Prompt Agent
- Or falls back to LLM if no agent is relevant.
-
Once the task is processed:
- Extract clear information for the user.
- Append the data to Google Sheets.
- Send a reply via Telegram.
- If sending fails, send an email notification to you.
Each agent is powered by its own Gemini 2.5 Flash model and has specific tools:
Handles tasks related to Gmail.
Get EmailsLabel EmailsMark as UnreadCreate DraftSend EmailGet LabelsReply to Emails
Manages events in Google Calendar.
Create EventCreate Event with AttendeeUpdate EventDelete EventGet Events
Fetches live stock data using SerpAPI.
Web Search Tool(real-time stock prices, market news)
Finds growth strategies and trends using SerpAPI.
Web Search Tool(business ideas, market research)
Creative writing, brainstorming, or prompt generation.
- Just LLM access (Gemini 2.5 Flash)
When the user asks to generate an image:
- Prompt Generation → Gemini 2.5 Flash generates a creative prompt.
- File Name Creation → Another Gemini 2.5 Flash instance generates a Google Drive-safe file name.
- Image Generation → Uses
Flux.1-Schnellmodel to generate the image. - Image Handling:
- Extract image URL
- Download image
- Send it to user in Telegram
- Save it in Google Drive
- Log metadata to Google Sheets
- 🎙️ Voice-to-text via Gemini
- 🧠 AI-powered Orchestration
- 🧩 Modular Agent Design
- 📤 Auto Logging to Google Sheets
- 🖼️ Image Generation Support
- 📧 Email + 📅 Calendar Automation
- 🌐 Live Web Search via SerpAPI
⚠️ Fallback Notifications via Email
- n8n
- Telegram Bot Token
- Gemini API Key
- Google APIs (Sheets, Drive, Gmail, Calendar)
- SerpAPI Key
git clone https://github.com/tanishra/Telegram-Smart-Agent-Bot.git
cd Telegram-Smart-Agent-BotCreate a .env file based on env.example:
- TELEGRAM_BOT_TOKEN= your_bot_token
- GEMINI_API_KEY= your_gemini_key
- GOOGLE_SHEETS_ID= your_sheet_id
- GOOGLE_DRIVE_FOLDER_ID= folder_id
- SERPAPI_KEY= your_serpapi_key
- YOUR_EMAIL= your_email_for_fallbacks
- 🔄 Import Workflow into n8n
- Open your n8n instance
- Go to Workflows → Import
- Upload workflows/Telegram_Smart_Agent_Bot.json
- Start Execution
-
Start the Telegram bot and send a message (text or voice).
-
Try these example prompts:
- 📈 “What is the stock price of Apple?”
- 📅 “Schedule a meeting tomorrow at 5 PM”
- 📧 “Reply to this email with thanks”
- 🖼️ “Generate an image of a robot meditating on a cloud”
-
Observe the outputs:
- ✅ Response in Telegram chat
- 📊 Log entry in Google Sheets
- 📁 Image saved to Google Drive (if applicable)
- ✉️ Email sent to you in case of failure
| Issue | Possible Cause | Solution |
|---|---|---|
| No response in Telegram | Bot not connected or token invalid | Double-check the TELEGRAM_BOT_TOKEN and ensure the bot is started |
| Voice not transcribed | Gemini API limit or voice file not accessible | Check Gemini API usage and file permissions |
| AI Orchestrator returns error | Gemini model failure or bad input | Add validation and fallback handling in the workflow |
| Email actions fail | Google API scopes or token expired | Re-authenticate Gmail node with correct OAuth scopes |
| Calendar events not created | Date format or missing fields | Ensure date/time is parsed and formatted correctly |
| Stock or growth agent returns empty | SerpAPI limit reached or query too vague | Check SerpAPI usage dashboard and refine queries |
| Image not generated | Prompt too generic or file name issues | Improve prompt clarity and ensure valid file name |
| File not saved to Drive | Incorrect folder ID or Google Drive API error | Double-check GOOGLE_DRIVE_FOLDER_ID and folder permissions |
| Sheet row not appended | Google Sheet ID missing or incorrect columns | Ensure the sheet ID is correct and columns match expected format |
| Telegram message fails to send | Chat ID missing or too large file | Check Telegram node config and reduce message/image size |
| Fallback email not sent | Email not authenticated or SMTP error | Verify Gmail connection and check fallback node |
| n8n crashes on load | Too many simultaneous tasks or memory leak | Enable queuing, optimize nodes, increase server memory |
Contributions, ideas, and improvements are welcome!
- 🐛 Report bugs via Issues
- ✨ Suggest new agents, tools, or features
- 🛠️ Submit a pull request to improve code or docs
- 📄 Improve the documentation or add diagrams
