A powerful Telegram bot for managing Google Drive folder permissions at scale
Built with Kurigram Β· Motor Β· Google Drive API Β· MongoDB
Features β’ Quick Start β’ Deployment β’ Packages β’ Documentation
Google Drive Access Manager Bot is a full-featured Telegram bot that lets admins manage Google Drive folder permissions entirely from chat β no manual Drive UI needed. It supports multi-mode grants, timed expiry with auto-revoke, bulk import from Drive scans, analytics dashboards, CSV exports, and more.
| Problem | Solution |
|---|---|
| Managing 100s of folder permissions manually | Bulk grant/revoke with smart selection |
| Forgetting to remove access after projects end | Auto-expiry with background scheduler |
| No visibility into who has access to what | Analytics dashboard + CSV exports |
| Duplicate access grants causing confusion | Database-level unique index enforcement |
| Cloud deployment credential headaches | In-bot OAuth via /auth command |
| Searching through 1000+ folders manually | Folder search + pinned favorites for instant access |
| Mode | Description | Best For |
|---|---|---|
| π€ Single Grant | One email β One folder | Quick individual access |
| π Multi-Folder | One email β Multiple folders | Power user onboarding |
| π₯ Batch Grant | Multiple emails β One folder | Team setup |
All grant flows include email validation, role selection (Viewer/Editor), duration picker, and duplicate detection.
1 hour Β· 6 hours Β· 1 day Β· 7 days Β· 30 days Β· βΎοΈ Permanent Β· βοΈ Custom (e.g. 59d, 91d, 12h, 2d12h)
- Browse folders with A-Z group picker β jump directly to any letter/number group
- Smart natural sort (numeric-aware)
- View all users with access and their expiry times
- Change role (Viewer β Editor) with one tap
- Remove individual or all access per folder
- Configurable folder cache with adjustable TTL
Pin frequently used root folders for instant access β no more scrolling through hundreds of folders.
- β Pin any folder from Manage β folder view
- π Browse sub-folders of a pinned root folder directly
- π Grant access to root or any sub-folder in one flow
- π Unpin anytime from the same folder view
- Up to 20 pinned folders per admin
Flow:
Manage β Open Folder β β Pin Folder
/favorites β Leo AD 2500 β Hero / Villain / Scripts β Grant
Search folders by name instead of scrolling through the full list.
- Type any keyword (e.g.
AD 2500,Hero) β results appear instantly - Available from Grant Access flow β π Search Folders button
- Searches across all Drive folders using Google Drive API
- Shows top 25 matches, ordered by name
- View all timed grants with live countdown timers
- Unlimited pagination
- Extend access inline:
+1h Β· +6h Β· +1d Β· +7d Β· +30d - Quick revoke with confirmation prompt
- Runs every 5 minutes in background
- Automatically revokes expired viewer access from Drive
- Full audit trail logged for every auto-revocation
- Zero manual intervention needed
Search grants by email or folder name, then selectively revoke:
- β Select All β bulk select everything instantly
- β Unselect All β clear all at once
- π’ Live Counter β "X selected | Y total"
- π― Individual Toggle β click any item to toggle
- Expiry Timeline β Urgent (<24h), This Week, This Month, Later
- Top 15 Most Accessed Folders
- Top 15 Users by Grant Count
- CSV Export β full data in Excel-compatible format with IST timestamps
- Statistics Dashboard (
/stats) β daily/weekly/monthly activity metrics
- Full Drive scan with live progress indicators
- Before/after import report
- 40-day expiry auto-assigned for imported viewers
- Skips owners, editors, and duplicates automatically
- Structured log types: Grant, Remove, Role Change, Auto-Revoke, Bulk Import
- Paginated view
- CSV export
- Soft delete β no data loss
- Broadcast grant/revoke events to a Telegram channel
- Auto-detect channel ID via message forward
- Daily status summaries and error alerts
| Command | Description |
|---|---|
/start |
Open main menu |
/grant |
Grant Drive access (3 modes) |
/manage |
Manage folder permissions |
/search |
Search grants by email or folder |
/expiry |
View & manage timed access |
/favorites |
Pinned folders for instant access |
/analytics |
Analytics dashboard |
/stats |
Activity statistics |
/info |
System health monitor |
/settings |
Bot configuration |
/logs |
Activity log viewer |
/auth |
Connect Google Drive (OAuth) |
/revoke |
Disconnect Google account |
/authstatus |
Check auth status |
In-bot OAuth β no file uploads or manual token management needed.
| Command | Description |
|---|---|
/auth |
Start Google Drive authorization |
/revoke |
Disconnect your Google account |
/authstatus |
Check current authorization status |
- Unique MongoDB indexes prevent duplicate grants
- Email normalization (auto-lowercase) prevents injection
- 90+ admin-protected handler endpoints
- Super admin role for system commands (
/info) - Input sanitization and type validation on all inputs
- Complete activity log with soft delete (data retention)
| Setting | Options |
|---|---|
| Default access role | Viewer / Editor |
| Folder page size | 3β10 per page |
| Notification preferences | Toggle on/off |
| Channel configuration | Set/clear broadcast channel |
- Bot uptime and version
- Python and Kurigram versions
- Service health: Drive API, MongoDB, Telegram
- Auto-expire scheduler status
- RAM, CPU, Disk usage
- Python 3.11+
- MongoDB database (Atlas free tier works)
- Google Cloud Project with Drive API enabled
- Telegram Bot Token from @BotFather
git clone https://github.com/muhammedadnank/Google-Drive-Access-Manager-Bot.git
cd Google-Drive-Access-Manager-Bot
cp .env.example .env
nano .env # fill in your credentials
docker compose up --build -dCheck logs:
docker compose logs -f botgit clone https://github.com/muhammedadnank/Google-Drive-Access-Manager-Bot.git
cd Google-Drive-Access-Manager-Bot
pip install -r requirements.txt- Go to Google Cloud Console
- Create or select a project β Enable Google Drive API
- Create an OAuth 2.0 Client ID β Web application
- Add authorized redirect URI:
http://localhost:8080/oauth/callback - Copy Client ID and Client Secret into
.env
# Telegram
API_ID=your_api_id
API_HASH=your_api_hash
BOT_TOKEN=your_bot_token
# Database
MONGO_URI=mongodb+srv://user:pass@cluster.mongodb.net/dbname
# Admins (comma-separated Telegram user IDs)
ADMIN_IDS=123456789,987654321
# Google Drive OAuth
G_DRIVE_CLIENT_ID=your_client_id.apps.googleusercontent.com
G_DRIVE_CLIENT_SECRET=your_client_secret
# Optional
CHANNEL_ID=-1001234567890# Development
python bot.py
# Production (with health check server)
python server.pySend /auth to your bot and follow the link.
Google-Drive-Access-Manager-Bot/
βββ bot.py # Main bot + background schedulers
βββ server.py # Flask wrapper + process manager
βββ config.py # Environment config loader
βββ requirements.txt
βββ .env.example
βββ Dockerfile # Docker support (v2.2.3)
βββ docker-compose.yml
βββ .dockerignore
βββ Procfile # Heroku
βββ render.yaml # Render
β
βββ plugins/ # Feature handlers
β βββ start.py # /start, /help, main menu
β βββ auth.py # /auth, /revoke, /authstatus
β βββ grant.py # 3-mode grant system
β βββ manage.py # Folder management
β βββ expiry.py # Expiry dashboard & bulk import
β βββ analytics.py # Analytics dashboard
β βββ search.py # Search + smart selection revoke
β βββ stats.py # /stats dashboard
β βββ info.py # /info system monitor
β βββ settings.py # Bot settings
β βββ channel.py # Channel integration
β βββ logs.py # Activity logs
β βββ csv_export.py # CSV export utilities
β
βββ services/
β βββ database.py # MongoDB operations (Motor)
β βββ drive.py # Google Drive API + cache
β βββ broadcast.py # Telegram channel broadcasts
β
βββ utils/
β βββ filters.py # Admin + state filters
β βββ states.py # Conversation state management
β βββ validators.py # Email validation
β βββ time.py # IST timezone + safe_edit helper
β βββ pagination.py # Pagination + sorting + ButtonStyles
β
βββ docs/
βββ Changelog.md
βββ UI_GUIDE.md
βββ DEPLOYMENT.md
βββ DATABASE_MAINTENANCE.md
βββ DUPLICATE_PREVENTION.md
All dependencies are in requirements.txt.
| Package | Version | Purpose |
|---|---|---|
| kurigram | latest | Telegram MTProto bot framework β Pyrofork fork with ButtonStyle support |
| TgCrypto | latest | Fast C-extension encryption required by Kurigram |
| Package | Version | Purpose |
|---|---|---|
| motor | 3.7.1 | Async MongoDB driver built on PyMongo β used for all DB operations |
| Package | Version | Purpose |
|---|---|---|
| google-api-python-client | 2.115.0 | Official Google Drive API client |
| google-auth | 2.27.0 | Google OAuth 2.0 token management |
| oauth2client | 4.1.3 | Legacy OAuth credential flow helper |
| httplib2 | 0.22.0 | HTTP client used internally by Google API client |
| Package | Version | Purpose |
|---|---|---|
| Flask | 3.0.0 | Web server for /health, /status, /metrics, /oauth/callback |
| gunicorn | 21.2.0 | Production WSGI server used in Procfile and Render |
| Package | Version | Purpose |
|---|---|---|
| python-dotenv | 1.0.1 | Loads environment variables from .env file |
| psutil | 5.9.8 | System metrics β CPU, RAM, Disk for /info command |
kurigram
tgcrypto
google-api-python-client==2.115.0
google-auth==2.27.0
motor==3.7.1
python-dotenv==1.0.1
Flask==3.0.0
gunicorn==21.2.0
psutil==5.9.8
oauth2client==4.1.3
httplib2==0.22.0
- Fork this repo β Create a new Web Service on Render
- Connect your GitHub repo
- Configure:
- Build Command:
pip install -r requirements.txt - Start Command:
python server.py - Health Check Path:
/health
- Build Command:
- Add environment variables
- Deploy β send
/authto connect Google Drive
git clone https://github.com/muhammedadnank/Google-Drive-Access-Manager-Bot.git
cd Google-Drive-Access-Manager-Bot
cp .env.example .env && nano .env
docker compose up --build -d
docker compose logs -f botSupported: DigitalOcean, Hetzner, Fly.io, Railway, Coolify, any VPS.
Fork repo β New Project β Deploy from GitHub β Add env vars.
Railway auto-detects Dockerfile β deploy starts automatically.
heroku login
heroku create your-app-name
heroku config:set API_ID=... API_HASH=... BOT_TOKEN=... MONGO_URI=... \
ADMIN_IDS=... G_DRIVE_CLIENT_ID=... G_DRIVE_CLIENT_SECRET=...
git push heroku mainsudo apt update && sudo apt install python3.11 python3-pip git -y
git clone https://github.com/muhammedadnank/Google-Drive-Access-Manager-Bot.git
cd Google-Drive-Access-Manager-Bot
pip3 install -r requirements.txt
cp .env.example .env && nano .env# /etc/systemd/system/gdrive-bot.service
[Unit]
Description=Google Drive Access Manager Bot
After=network.target
[Service]
Type=simple
User=ubuntu
WorkingDirectory=/home/ubuntu/Google-Drive-Access-Manager-Bot
ExecStart=/usr/bin/python3 server.py
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl enable gdrive-bot
sudo systemctl start gdrive-bot| Metric | Value |
|---|---|
| Python files | 30+ |
| Lines of code | 5,400+ |
| Protected endpoints | 90+ |
| MongoDB collections | 6 |
| Grant modes | 3 |
| Expiry durations | 7 |
| Architecture | 100% async/await |
- π Pinned Folders β pin root folders for instant access
- π Folder Search β filter folders by keyword
- Sub-folder browsing from pinned root folders
- βοΈ Custom duration input (59d, 91d, 12h, 2d12h) for all 3 grant modes
- π€ Alphabetical A-Z/0-9 Group Browsing β jump directly to character groups in massive folder structures
- π Multi-Level Back & Cancel Navigation β preserve state (parsed emails, selected folders) on backward steps
- Invert selection in bulk revoke
- Select by role (viewers/editors only)
- Batch extend multiple grants
- Email notifications to users on grant/revoke
- Auto-extend rules (renew before expiry)
- Scheduled grants (future start date)
- REST API for external integrations
- Shared Drive support
- Multi-Drive management
- Multi-tenant architecture
| Document | Description |
|---|---|
| Changelog | Full version history |
| UI Guide | Interface walkthrough |
| Deployment Guide | Platform-specific setup |
| Database Maintenance | DB management guide |
| Duplicate Prevention | Prevention system details |
Q: How do I authenticate Google Drive on Render/Heroku?
A: Send /auth to your bot after deploying. Set G_DRIVE_CLIENT_ID and G_DRIVE_CLIENT_SECRET as env vars and follow the OAuth link.
Q: Do I need credentials.json or token.json?
A: No. The /auth command handles everything through the bot.
Q: How many admins can use the bot?
A: Unlimited. Add all Telegram user IDs to ADMIN_IDS (comma-separated).
Q: How many folders can it manage?
A: No hard limit. Tested with 500+ folders.
Q: Is this free to run?
A: Yes β MIT licensed. Render and MongoDB Atlas both have free tiers sufficient for most deployments.
- Fork the repository
- Create a feature branch:
git checkout -b feature/your-feature - Commit:
git commit -m 'feat: add your feature' - Push and open a Pull Request
- π Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
- π Bot Help: Send
/helpinside the bot
MIT License β free for commercial use, modification, and distribution.
| Library | Role |
|---|---|
| Kurigram | Telegram bot framework |
| Motor | Async MongoDB driver |
| Google Drive API | Drive integration |
| Flask | Health check web server |
| MongoDB | Database |
v2.3.0 Β· Updated April 2026 Β· β Production Ready
Built with β€οΈ using Kurigram, MongoDB & Google Drive API