Building a Fully Automated AI Telegram Bot with Google Gemini & GitHub Actions
In the era of automation, managing content across multiple Telegram channels can be a full-time job. To solve this, I developed the Smart Mentor Bot (V48)—a highly intelligent, serverless Telegram publishing bot. By leveraging the power of Google's ecosystem, cutting-edge AI, and GitHub Actions, this bot operates entirely on autopilot, curating, drafting, and publishing highly engaging content around the clock.
Here is a deep dive into how this architecture was built, the Google tools that power it, and how it was successfully deployed using GitHub Actions.
1. The Brain: Google Gemini 2.5 AI
At the core of the bot's content generation capabilities is Google Gemini. Specifically, the bot utilizes the gemini-2.5-flash-preview-09-2025 model.
- Dynamic Formatting: Gemini acts as an expert journalist and teacher. If the category is "EDUCATION," it automatically formats posts as interactive quizzes or Daily Learning Doses using Telegram spoiler tags.
- Content Verification: The bot doesn't just generate text blindly. It cross-references topics against trusted domains (like Reuters, Bloomberg, and official blogs). Gemini then processes these verified sources to create concise, engaging summaries strictly under 900 characters (for image posts) or up to 3000 characters for detailed text.
2. The Database: Google Sheets & Google Forms
Instead of hosting a complex SQL database, I used Google tools to create a zero-cost, highly accessible backend.
- Configuration Management (Google Sheets): A published Google Sheet acts as the control panel. The bot fetches user settings (via CSV export). It reads each channel's active status, target keywords, daily limits, active hours, and specific timezones.
- History Tracking (Google Forms): To track published posts and prevent duplication, the bot submits data to a Google Form via a POST request after every successful publish. This form populates a history sheet that the bot references to ensure it never posts the same link or AI content twice within a 200-post window.
3. Content Sourcing: Google News & Search Integrations
To keep the content fresh, the bot utilizes several scraping logic flows:
- Google News RSS: For categories like NEWS and ENTERTAINMENT, the bot queries the Google News RSS feed dynamically based on the client's keywords to fetch articles published within the last 24 hours.
- DuckDuckGo Integration: For EVERGREEN facts, EVENT launches, or JOB updates, it falls back to DuckDuckGo search and custom RSS feeds provided by the users.
4. Advanced Visual Engine
A post isn't complete without great visuals. The bot features a custom visual processing engine built with the Python Pillow library.
- Anti-Logo Web Scraping: It attempts to scrape the OpenGraph (
og:image) from the news source. It includes smart logic to reject small or square images (preventing it from accidentally downloading website logos instead of article covers). - AI Composite Thumbnails: If a valid image isn't found, the bot searches Pexels or DuckDuckGo images for the primary and secondary keywords. It then programmatically stitches two distinct images together, creating a beautiful split-screen composite thumbnail with a dividing line.
5. Serverless Deployment via GitHub Actions
To avoid server hosting costs and ensure reliable uptime, the entire Python script was containerized and deployed using GitHub Actions.
- CRON Scheduling: A GitHub Actions workflow (
.ymlfile) is configured to trigger the script at regular intervals. - Environment Secrets: Sensitive data like the
TELEGRAM_TOKEN,GEMINI_API_KEY,PEXELS_API_KEY, and the Google Sheet URLs are securely stored in GitHub Secrets and loaded into the script viaos.environ.get(). - Timezone-Aware Execution: The script dynamically calculates user timezones. Even though GitHub Actions runs on UTC, the bot respects each client's specific "sleep hours" (e.g., 10 PM to 8 AM IST), pausing posts for channels that are currently inactive.
Conclusion
By integrating Google Sheets for data storage, Google News for sourcing, Gemini AI for intelligent formatting, and GitHub Actions for execution, the Smart Mentor Bot is a testament to what can be achieved with modern API integrations. It successfully transforms scattered raw data into highly polished, automated journalistic posts.
