Skip to content

Latest commit

Β 

History

26 Commits

Folders and files

Repository files navigation

⚑ GitHub Trending Telegram Bot with Gemini AI

An enterprise-grade, serverless Telegram bot that monitors daily GitHub Trending repositories, crafts senior-level architectural insights via Google Gemini Flash, enables RAG-powered interactive repository Q&A, and grounds external questions with live Google Search.

Live Demo Deploy with Vercel

Node.js Gemini AI Supabase Vercel License Stars Forks

πŸ‡»πŸ‡³ Ghi chΓΊ dΓ nh cho LαΊ­p trΓ¬nh viΓͺn Việt Nam: MαΊ·c Δ‘α»‹nh bot biΓͺn soαΊ‘n bαΊ£n tin, phΓ’n tΓ­ch kα»Ή thuαΊ­t vΓ  giαΊ£i Δ‘Γ‘p hỏi Δ‘Γ‘p bαΊ±ng TiαΊΏng Việt, vα»›i phong cΓ‘ch tΓ³m tαΊ―t sαΊ―c bΓ©n cα»§a mα»™t Senior Tech Lead (khΓ΄ng vΓ²ng vo, tαΊ­p trung vΓ o bαΊ£n chαΊ₯t cΓ΄ng nghệ vΓ  bΓ i toΓ‘n giαΊ£i quyαΊΏt).


πŸ“‘ Table of Contents


🌟 Overview & Highlights

GitHub Trending Telegram Bot is a modern, serverless automation tool built for developers, tech leads, and open-source enthusiasts. It tracks top trending repositories on GitHub each day, extracts their comprehensive README.md documentation, analyzes their core architecture using Google Gemini 2.5 / 3.8 Flash, and automatically broadcasts curated technical digests to Telegram subscribers.

Beyond automated broadcasts, the bot acts as an interactive AI documentation assistant: developers can bind any GitHub repository and perform conversational Q&A grounded directly on the actual codebase documentation (RAG), with automated fallback to live Google Search whenever technical questions extend beyond the README scope.


⚑ Key Features

Feature Description
πŸ•·οΈ High-Speed Scraper Parallel Cheerio scraper extracting top trending repositories, programming languages, stars, and full markdown body content from GitHub.
🧠 Dual Gemini AI Engine Instant in-chat switching between gemini-2.5-flash (ultra-fast, free Google Search grounding) and gemini-3.8-flash (deep technical reasoning).
πŸ“š RAG Repository Q&A Chat interactively with any repository’s real documentation using /ask <owner/repo> or by simply dropping a GitHub repository link into the chat.
🌐 Live Google Search Grounding Auto-detects out-of-scope queries ([OUT_OF_SCOPE]) and seamlessly falls back to real-time Google Search targeted to GitHub and official docs.
⏰ Serverless Morning Digest Automated Vercel Cron triggered daily at 07:00 AM (00:00 UTC), delivering concise, developer-focused tech summaries.
πŸ›‘οΈ Production-Ready Multi-User Scale Built-in rate limiting (15 msgs/min per user), 40ms broadcast throttling (Telegram API compliance), and automatic cleanup for blocked bots (403 Forbidden).
πŸŽ›οΈ Modern Telegram UX Interactive Telegram Inline Keyboard buttons, real-time typing indicators, and automatic Markdown error recovery with plain-text fallback.

πŸ—οΈ System Architecture

A high-level architectural overview illustrating how the Telegram Client, Vercel Serverless Platform, Google Gemini AI, Supabase PostgreSQL, and GitHub Trending Scraper integrate cleanly:

High-Level System Architecture

πŸ” View Mermaid Source Code
flowchart LR
    subgraph Clients["πŸ“± Clients & Triggers"]
        TG["Telegram Client<br/>(Bot API)"]
        Cron["Vercel Cron<br/>(00:00 UTC)"]
    end

    subgraph Serverless["⚑ Vercel Serverless (Node.js)"]
        Webhook["/api/webhook.js<br/>(Interactive Q&A & Commands)"]
        CronAPI["/api/cron.js<br/>(Daily Broadcast Handler)"]
    end

    subgraph DataAI["🌐 Data, AI & Persistence"]
        GitHub["GitHub Trending<br/>(Cheerio Scraper)"]
        Gemini["Google Gemini AI<br/>(2.5 & 3.8 Flash + Search)"]
        Supabase[("Supabase PostgreSQL<br/>(Cache, Sessions, History)")]
    end

    TG <-->|Commands & Replies| Webhook
    Cron -->|Daily Trigger| CronAPI
    CronAPI -->|Broadcast Digest| TG

    Webhook & CronAPI -->|Fetch & Scrape| GitHub
    Webhook & CronAPI <-->|Summarize & RAG| Gemini
    Webhook & CronAPI <-->|Read & Write Cache| Supabase
Loading

πŸ“ Project Structure

github-trending-telegram-bot/
β”œβ”€β”€ api/
β”‚   β”œβ”€β”€ cron.js             # Vercel Cron handler: scrapes daily trending & broadcasts to subscribers
β”‚   └── webhook.js          # Telegram Webhook handler: processes commands, callbacks & RAG Q&A
β”œβ”€β”€ ai.js                   # Google Gemini integration (2.5 Flash, 3.8 Flash, Search Grounding)
β”œβ”€β”€ db.js                   # Supabase PostgreSQL client initialization
β”œβ”€β”€ main.js                 # Local execution CLI to scrape and broadcast immediately
β”œβ”€β”€ scraper.js              # Cheerio-based scraper for trending repositories & raw READMEs
β”œβ”€β”€ setup.sql               # PostgreSQL database schema and performance index definitions
β”œβ”€β”€ vercel.json             # Vercel deployment configuration & daily cron schedule
β”œβ”€β”€ package.json            # Project dependencies and metadata
└── .env.example            # Environment variables template

πŸ€– Bot Commands & Interactive UI

The bot supports both text commands and one-tap Inline Keyboard Buttons:

Command Action Inline Button
/start, /help Displays the interactive main menu and registers the user for morning digests. βœ…
/trending5, /trending10 Retrieves the top 5 or 10 cached trending repositories and summarizes them. βœ…
/model Opens an interactive model switcher (gemini-2.5-flash vs gemini-3.8-flash). βœ…
/setmodel <name> Sets the active AI model for the current user session. -
/status Shows the current active repository session and selected AI model. βœ…
/ask <owner/repo> Connects to a specific repository in the database for RAG Q&A (e.g., /ask commaai/openpilot). -
Send GitHub URL Paste any GitHub link (e.g., https://github.com/vllm-project/vllm) to scrape, save, and start chatting. -
/subscribe Activates daily automated morning broadcasts (07:00 AM ICT). βœ…
/unsubscribe Pauses daily automated broadcasts while keeping full interactive access. βœ…
/exit, /clear Exits the active repository session and returns to free-form AI chat. βœ…

πŸ—„οΈ Database Schema (Supabase PostgreSQL)

The project leverages Supabase PostgreSQL for persistence, session isolation, and fast retrieval:

-- 1. Repositories cache (scraped metadata and full README text)
CREATE TABLE IF NOT EXISTS repositories (
    id SERIAL PRIMARY KEY,
    repo_name VARCHAR(255) UNIQUE NOT NULL,
    link TEXT NOT NULL,
    description TEXT,
    readme TEXT,
    language VARCHAR(100),
    scraped_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);

-- 2. User sessions (active repository context and per-user model choice)
CREATE TABLE IF NOT EXISTS user_sessions (
    chat_id BIGINT PRIMARY KEY,
    active_repo VARCHAR(255),
    selected_model VARCHAR(100) DEFAULT 'gemini-2.5-flash',
    last_active TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);

-- 3. Subscribers (automated daily broadcast distribution list)
CREATE TABLE IF NOT EXISTS subscribers (
    chat_id BIGINT PRIMARY KEY,
    username VARCHAR(255),
    first_name VARCHAR(255),
    is_active BOOLEAN DEFAULT TRUE,
    subscribed_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);

-- 4. Chat history (multi-turn conversational context)
CREATE TABLE IF NOT EXISTS chat_history (
    id SERIAL PRIMARY KEY,
    chat_id BIGINT NOT NULL,
    role VARCHAR(50) NOT NULL, -- 'user' or 'model'
    content TEXT NOT NULL,
    created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);

Performance Indexes: Pre-indexed on chat_history(chat_id, created_at DESC), repositories(scraped_at DESC), and subscribers(is_active).


πŸš€ Getting Started

Prerequisites

  • Node.js: v20.6.0+ (supports native .env loading).
  • Telegram Bot Token: Created via @BotFather.
  • Google Gemini API Key: Acquired via Google AI Studio.
  • Supabase Account: A free cloud project on Supabase.

Installation

  1. Clone the repository:

    git clone https://github.com/hm4uc/github-trending-telegram-bot.git
    cd github-trending-telegram-bot
  2. Install dependencies:

    npm install

Database Setup

  1. Open your Supabase Dashboard -> SQL Editor.
  2. Paste the contents of setup.sql and execute the query to provision all tables and indexes.

Environment Configuration

Create a .env file in the root directory:

# Telegram Bot Configuration
BOT_TOKEN=your_telegram_bot_token
CHAT_ID=your_personal_or_channel_chat_id # Required for local test script

# Google Gemini AI Configuration
GEMINI_API_KEY=your_google_gemini_api_key
GEMINI_MODEL=gemini-2.5-flash # Optional default (gemini-2.5-flash or gemini-3.8-flash)

# Supabase PostgreSQL Configuration
SUPABASE_URL=https://your-project-id.supabase.co
SUPABASE_KEY=your_supabase_service_role_key

Running Locally

To manually trigger a live scraping run, generate AI summaries, and dispatch a test message to your configured CHAT_ID:

node main.js

☁️ Production Deployment (Vercel)

Deploying as a serverless application on Vercel is free, zero-maintenance, and fully automated.

1. Deploy to Vercel

Click the button below or import your GitHub repository into the Vercel Dashboard:

Deploy with Vercel

In your Vercel Project Settings -> Environment Variables, define:

  • BOT_TOKEN
  • GEMINI_API_KEY
  • SUPABASE_URL
  • SUPABASE_KEY
  • CHAT_ID (optional fallback)

2. Set Up Telegram Webhook

Once your Vercel deployment URL is ready (e.g., https://your-project.vercel.app), register the webhook endpoint with Telegram:

https://api.telegram.org/bot<YOUR_BOT_TOKEN>/setWebhook?url=https://<YOUR_VERCEL_URL>/api/webhook

Open this URL in your web browser. You should receive a confirmation response:

{ "ok": true, "result": true, "description": "Webhook was set" }

3. Automated Daily Cron

The vercel.json file configures an automatic cron trigger:

{
  "crons": [
    {
      "path": "/api/cron",
      "schedule": "0 0 * * *"
    }
  ]
}

Every day at 00:00 UTC (07:00 AM ICT), Vercel automatically invokes /api/cron, scraping the latest trends, generating the AI digest, and broadcasting it to all active subscribers.


πŸ› οΈ Tech Stack

Technology Role & Justification
Node.js (ESM) Fast, non-blocking asynchronous execution and modern ECMAScript Module support.
Cheerio Lightweight and fast server-side HTML parsing for GitHub Trending & README DOM extraction.
Google Gemini API Advanced reasoning via gemini-2.5-flash & gemini-3.8-flash with native Google Search Grounding.
Supabase (PostgreSQL) Reliable relational persistence, ACID guarantees, and instant serverless connection pooling.
Telegram Bot API Global messaging infrastructure with rich markdown rendering, inline keyboards, and typing feedback.
Vercel Serverless Zero-cold-start edge endpoints and built-in global cron scheduling without dedicated server costs.

πŸ“ˆ Star History

Star History Chart


🀝 Contributing & License

Contributions, feedback, and pull requests are warmly welcomed! Please feel free to open an issue or submit a PR:

  1. Fork the Project (https://github.com/hm4uc/github-trending-telegram-bot/fork)
  2. Create your Feature Branch (git checkout -b feat/amazing-feature)
  3. Commit your Changes (git commit -m 'feat: add amazing feature')
  4. Push to the Branch (git push origin feat/amazing-feature)
  5. Open a Pull Request

This project is licensed under the ISC License. See the LICENSE file for more details.

Built with ❀️ for the open-source and developer community.

Releases

Packages

Contributors

Languages