Skip to content

muhammedadnank/Google-Drive-Access-Manager-Bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

270 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“‚ Google Drive Access Manager Bot

Version Python Framework Database Docker License Status

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


πŸ“– Overview

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.

Why Use This Bot?

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

✨ Features

🎯 Access Management

Three Grant Modes

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.

Duration Options

1 hour Β· 6 hours Β· 1 day Β· 7 days Β· 30 days Β· ♾️ Permanent Β· ✏️ Custom (e.g. 59d, 91d, 12h, 2d12h)

Folder Management

  • 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

πŸ“Œ Pinned Folders (/favorites)

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

πŸ” Folder Search

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

⏰ Expiry System

Expiry Dashboard

  • View all timed grants with live countdown timers
  • Unlimited pagination
  • Extend access inline: +1h Β· +6h Β· +1d Β· +7d Β· +30d
  • Quick revoke with confirmation prompt

Auto-Expire Scheduler

  • 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 & Revoke

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

πŸ“Š Analytics & Reporting

  • 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

πŸ“₯ Bulk Operations

  • 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

πŸ“ Activity Logs

  • Structured log types: Grant, Remove, Role Change, Auto-Revoke, Bulk Import
  • Paginated view
  • CSV export
  • Soft delete β€” no data loss

πŸ“’ Channel Integration

  • Broadcast grant/revoke events to a Telegram channel
  • Auto-detect channel ID via message forward
  • Daily status summaries and error alerts

πŸ—‚οΈ Quick Commands

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

πŸ”‘ Authentication System

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

πŸ” Security

  • 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)

βš™οΈ Settings (/settings)

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

πŸ–₯️ System Monitor (/info)

  • Bot uptime and version
  • Python and Kurigram versions
  • Service health: Drive API, MongoDB, Telegram
  • Auto-expire scheduler status
  • RAM, CPU, Disk usage

πŸš€ Quick Start

Prerequisites

  • Python 3.11+
  • MongoDB database (Atlas free tier works)
  • Google Cloud Project with Drive API enabled
  • Telegram Bot Token from @BotFather

Option A β€” Docker 🐳 (Recommended)

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 -d

Check logs:

docker compose logs -f bot

Option B β€” Python Direct

Step 1 β€” Clone & Install

git clone https://github.com/muhammedadnank/Google-Drive-Access-Manager-Bot.git
cd Google-Drive-Access-Manager-Bot
pip install -r requirements.txt

Step 2 β€” Google Drive API Setup

  1. Go to Google Cloud Console
  2. Create or select a project β†’ Enable Google Drive API
  3. Create an OAuth 2.0 Client ID β†’ Web application
  4. Add authorized redirect URI: http://localhost:8080/oauth/callback
  5. Copy Client ID and Client Secret into .env

Step 3 β€” Configure Environment

# 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

Step 4 β€” Run

# Development
python bot.py

# Production (with health check server)
python server.py

Step 5 β€” Connect Google Drive

Send /auth to your bot and follow the link.


πŸ“ Project Structure

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

πŸ“¦ Packages

All dependencies are in requirements.txt.

Core

Package Version Purpose
kurigram latest Telegram MTProto bot framework β€” Pyrofork fork with ButtonStyle support
TgCrypto latest Fast C-extension encryption required by Kurigram

Database

Package Version Purpose
motor 3.7.1 Async MongoDB driver built on PyMongo β€” used for all DB operations

Google Drive

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

Web Server

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

Utilities

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

requirements.txt

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

πŸš€ Deployment

Render (Recommended)

Deploy to Render

  1. Fork this repo β†’ Create a new Web Service on Render
  2. Connect your GitHub repo
  3. Configure:
    • Build Command: pip install -r requirements.txt
    • Start Command: python server.py
    • Health Check Path: /health
  4. Add environment variables
  5. Deploy β†’ send /auth to connect Google Drive

Docker (VPS / Self-Hosted)

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 bot

Supported: DigitalOcean, Hetzner, Fly.io, Railway, Coolify, any VPS.


Railway

Fork repo β†’ New Project β†’ Deploy from GitHub β†’ Add env vars.
Railway auto-detects Dockerfile β€” deploy starts automatically.


Heroku

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 main

VPS (systemd)

sudo 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.target
sudo systemctl daemon-reload
sudo systemctl enable gdrive-bot
sudo systemctl start gdrive-bot

πŸ“Š Project Stats

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

πŸ—ΊοΈ Roadmap

v2.3.0 βœ… Released

  • πŸ“Œ 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

v2.4.0

  • Auto-extend rules (renew before expiry)
  • Scheduled grants (future start date)
  • REST API for external integrations

v3.0.0

  • Shared Drive support
  • Multi-Drive management
  • Multi-tenant architecture

πŸ“š Documentation

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

❓ FAQ

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.


🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/your-feature
  3. Commit: git commit -m 'feat: add your feature'
  4. Push and open a Pull Request

πŸ“ž Support


πŸ“„ License

MIT License β€” free for commercial use, modification, and distribution.


πŸ™ Built With

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

⬆ Back to Top

About

πŸ“‚ Telegram bot to manage Google Drive folder access β€” grant, revoke, auto-expire permissions with admin controls

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages