A production-grade private Telegram bot that manages your Google Drive: upload files, browse folders, rename, delete, share, and generate links — all from Telegram. Built in Go with MongoDB persistence, rclone for optimised multi-threaded uploads, and an optional Redis cache.
| Feature | Detail |
|---|---|
| Login | Full Google OAuth2 loopback flow — one login, never again |
| File explorer | Real folder tree with breadcrumbs, pagination, search, refresh |
| Upload | Telegram files + direct HTTP/HTTPS links, progress bars, ETA |
| Worker queue | Configurable pool with retries, survives restarts |
| File actions | Rename, delete (with confirm), share toggle, view + direct link |
| Owner commands | Auth/unauth users, tune workers/queue/limits, stats, broadcast |
| Auto-cleaner | Periodically frees disk space from the downloads directory |
| Cache | Redis-backed (or in-memory fallback) for fast explorer navigation |
| Tool | Purpose |
|---|---|
| Go 1.22+ | Build the bot |
| MongoDB 6+ | All persistent state |
| rclone | Optimised Drive upload engine |
| Redis (optional) | Faster cache across restarts |
- Open Google Cloud Console → APIs & Services → Credentials.
- Create an OAuth 2.0 Client ID → Application type: Desktop app.
- Note the Client ID and Client Secret.
- Enable the Google Drive API for the project.
- Message @BotFather →
/newbot. - Note the bot token.
- Message @userinfobot to get your Telegram user ID (this becomes
OWNER_ID).
git clone <repo> && cd gdrive-bot
make setup # copies config/.env.example → config/.env
nano config/.env # fill in all valuesMinimum required variables:
BOT_TOKEN=123456789:AAExampleToken
API_ID=123456
API_HASH=yourhash
OWNER_ID=111111111
GOOGLE_CLIENT_ID=your-client-id.apps.googleusercontent.com
GOOGLE_CLIENT_SECRET=your-secret
MONGO_URI=mongodb://localhost:27017curl https://rclone.org/install.sh | bashmake tidy # go mod tidy
make build # produces build/gdrive-bot
./build/gdrive-botOr with Docker Compose (includes MongoDB + Redis):
docker compose up -d --buildSend /login to the bot and follow the two-step OAuth flow. After that:
/myfiles— browse your Drive- Send any file or
https://…link — it's uploaded automatically
| Command | Description |
|---|---|
/auth <id> |
Authorize a user |
/unauth <id> |
Revoke access |
/setworkers <n> |
Resize worker pool (live) |
/setqueue <n> |
Set queue capacity (restart to apply) |
/setdownloadlimit <MB|0> |
Download size limit (0 = unlimited) |
/setuploadlimit <MB|0> |
Upload size limit |
/stats |
CPU, RAM, disk, queue, uptime |
/disk |
Disk usage only |
/users |
List authorized users |
/broadcast <msg> |
Send to all authorized users |
/clean |
Clear the downloads directory |
/settings |
Show all current settings |
/restart |
Exit (supervisor restarts the process) |
/shutdown |
Stop the bot permanently |
# Create a dedicated user
useradd -r -s /sbin/nologin gdrive-bot
# Deploy
mkdir -p /opt/gdrive-bot
cp build/gdrive-bot /opt/gdrive-bot/
cp -r config /opt/gdrive-bot/
mkdir -p /opt/gdrive-bot/{downloads,logs}
chown -R gdrive-bot:gdrive-bot /opt/gdrive-bot
# Install and start
cp gdrive-bot.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable --now gdrive-bot
# View logs
journalctl -fu gdrive-botcmd/bot/main.go — entrypoint, config load, signal handling
internal/
bot/ — composition root, queue.Processor, auto-cleaner
handlers/ — all /command handlers (Deps bundle)
callbacks/ — inline button routing
explorer/ — file browser: breadcrumb, pagination, search
drive/ — Google Drive API v3 (list, rename, delete, share)
auth/ — Google OAuth2 flow
rclone/ — rclone binary wrapper (optimised uploads)
queue/ — worker pool, retry, DB persistence
download/ — Telegram file + direct-link downloaders
upload/ — rclone upload orchestration
progress/ — rate-limited Telegram message editor
database/ — MongoDB repositories
cache/ — Redis / in-memory cache
middleware/ — auth guard (cached)
models/ — shared data types
utils/ — formatting, retry, disk, safe filenames
config/ — static config from .env
MIT