Telegram bot that instantly hashes uploaded files (MD5 / SHA1 / SHA256 / SHA512) and keeps a 5-day temporary share vault using only Telegram file_id + SQLite — no permanent file storage on disk.
Optimized for Railway.app free tier (worker process, SQLite file, no external DB).
- Instant streaming hashes on upload (8 MB chunks, no full-file RAM load)
- Unique 6-character share codes (
A7K9P2style; noO/0/I/1) - Temporary vault: metadata +
file_idonly invault.db - Retrieve via
/get CODE, plain code message, or deep linkt.me/<bot>?start=CODE - Inline actions: copy SHA256, share link, delete (uploader-only delete)
- Flood control: max 5 files / minute / user
- Persian UX messages
- Hourly expired-row cleanup job
FileHashVaultBot/
├── bot.py # Main async bot (python-telegram-bot v21)
├── database.py # SQLite vault helpers
├── hash_utils.py # Streaming hash + share-code helpers
├── requirements.txt
├── Procfile # Railway worker process
├── railway.json
├── .env.example
├── .gitignore
└── README.md
- Python 3.10+
- A Telegram bot token from @BotFather
cd FileHashVaultBot
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env
# edit .env and set BOT_TOKEN=...
python bot.py| Variable | Required | Description |
|---|---|---|
BOT_TOKEN |
Yes | Telegram bot token |
ADMIN_ID |
No | Your numeric Telegram user id (enables /stats) |
DATABASE_PATH |
No | SQLite path (default: ./vault.db) |
LOG_LEVEL |
No | INFO (default), DEBUG, ... |
| Command | Description |
|---|---|
/start |
Welcome text; also handles deep-link retrieval |
/help |
Help |
/get CODE |
Fetch file by share code |
/hash |
Reply to a file message → hashes only (no vault) |
/myfiles |
Last 10 of your vault entries |
/clearme |
Delete all of your vault rows |
/stats |
Admin health check (if ADMIN_ID set) |
Sending any document / video / photo / audio / voice / animation / sticker stores it in the vault automatically.
- User uploads a file to the bot.
- Bot streams the file from Telegram only to compute hashes (never keeps a permanent copy).
- Bot stores in SQLite:
file_id, name, size, hashes, uploader id, timestamps, share code. - Anyone with the code can ask the bot to re-send the file via
file_id. - After 5 days the DB row is purged (hourly job + on-access cleanup).
Important Telegram Bot API limit: bots can download files for hashing up to ~20 MB. Re-sending by
file_idstill works up to Telegram’s 2 GB upload limit. Files larger than 20 MB are still vaulted and shareable; hashes may be unavailable unless you run a local Bot API server.
- Open Telegram → @BotFather
/newbot→ choose name & username- Copy the token
cd FileHashVaultBot
git init
git add .
git commit -m "Initial FileHashVaultBot"
# create an empty GitHub repo, then:
git remote add origin https://github.com/<you>/FileHashVaultBot.git
git branch -M main
git push -u origin main- Go to https://railway.app and sign in
- New Project → Deploy from GitHub repo
- Select
FileHashVaultBot - Railway will detect Python via Nixpacks
- Open the service → Variables
- Add:
BOT_TOKEN=123456:ABC-your-token
ADMIN_ID=your_numeric_telegram_id
- Optional:
LOG_LEVEL=INFO
DATABASE_PATH=/data/vault.db
- Settings → Deploy
- Start command (if not using
railway.json/Procfile):python bot.py - This must be a worker (long-running polling process), not a one-shot web build
- Start command (if not using
Railway free/ephemeral disks lose files on redeploy. For better durability:
- Service → Settings → Volumes
- Mount a volume at
/data - Set
DATABASE_PATH=/data/vault.db
Without a volume the bot still works; vault.db is recreated after redeploys and old share codes are lost.
- Click Deploy
- Open Logs — you should see:
Bot started as @YourBot - In Telegram, send
/startto your bot, then upload a small file - Confirm you receive hashes + a 6-char code
- Send the code back → file should return
- Use polling (this project). No public HTTP port / webhook domain required.
Procfilecontains:worker: python bot.pyrailway.jsonsetsstartCommandtopython bot.py- Free tier sleeps / limits apply; if the dyno sleeps, the bot is offline until woken (Railway policy dependent)
- Never commit real
.envorvault.db
- Download: anyone with the share code can retrieve the file while it is valid
- Delete: only the original
uploader_idcan delete that code - Codes use a non-ambiguous alphabet and 6 chars (
32^6space) - Do not share codes for sensitive files in public channels
-
/startshows Persian welcome - Upload document → hashes + code + buttons
- Upload photo / video / audio
-
/get CODEreturns file - Plain text code returns file
- Deep link
t.me/<bot>?start=CODEworks for a new user chat -
📋 کپی SHA256sends monospace hash -
🔗 لینک اشتراکsends deep link -
🗑️ حذفworks for uploader, denied for others -
/myfileslists entries -
/clearmeclears user rows - Flood: 6th file within a minute is rejected
MIT — use and modify freely.