Hey everyone!
I’m working on a Telegram bot project and could really use some guidance. I want to create a bot that can handle file uploads and store them in Cloudflare R2 with proper organization.
What I’m trying to build:
A Telegram bot that takes files from users and uploads them to R2 storage with automatic folder organization and link generation.
File organization structure:
I want files sorted automatically like this:
/files/{year}/{month}/{category}/filename.ext
For example:
- /files/2025/06/photos/image.png
- /files/2025/06/docs/report.pdf
- /files/2025/06/media/song.mp3
Essential features I need:
- Handle all Telegram file types
- Auto-detect file categories (photo, video, doc, audio)
- Create organized folder structure in R2
- Return download links after upload
- Handle large files (up to 4GB)
- Basic commands like
/start
, /help
, /upload
Two versions planned:
Personal version:
- Restricted to my Telegram ID only
- Full control over uploads and deletions
- Commands like
/list
, /remove
, /stats
- File management features
Community version:
- Open for public use with limits
- File size restrictions
- Upload rate limiting
- Basic moderation
Additional features I’m considering:
- Progress indicators during upload
- File renaming options
- Storage quota tracking
- Automatic cleanup after set time
- Usage statistics
- Short URL generation via Cloudflare Workers
Why I’m asking for help:
I’m not experienced with bot development but really want to make this work. Looking for someone who can either build this or help me get started with a basic framework.
If you’re into Telegram bots or Cloudflare R2 development, I’d love to hear your thoughts or get some collaboration going!
Thanks for any help you can provide!
that sounds super cool! i’ve done some bot stuff too, and yeah, r2 is ez once you get the hang of it. check out python-telegram-bot for your bot and boto3 for r2. just watch out for file timeouts, especially with those bigger uploads - errors can happen!
Working with Cloudflare R2 and Telegram bots can be quite rewarding once you get the basics down. From my experience, the trickiest part is handling the authentication flow between Telegram’s API and R2’s S3-compatible interface. You’ll want to set up proper credentials management - I recommend using environment variables for your R2 access keys and bot token. The file categorization logic you’re planning is straightforward with Python’s mimetypes module, though you might need some custom rules for edge cases. One aspect worth considering early is implementing proper logging and monitoring, especially for the community version where you’ll need to track usage patterns and potential abuse. The automatic cleanup feature you mentioned is actually quite important for cost control - R2 charges for storage over time, so having lifecycle policies or scheduled cleanup jobs will save you money in the long run. For the URL generation, Cloudflare Workers integration works seamlessly with R2 and gives you more control over access patterns than basic presigned URLs.
I actually built something similar last year and ran into a few gotchas you should know about. The main challenge with large file uploads is that Telegram’s file download URL expires after a certain time, so you need to handle the download and upload to R2 in one go. For automatic categorization, I ended up using file extensions and MIME types - works well for most cases but you might want to add manual override options. One thing that saved me headaches was implementing proper error handling for network timeouts and partial uploads. Also consider using multipart uploads for files over 100MB to R2; it’s much more reliable. The progress indicators are tricky since Telegram doesn’t give you real-time upload progress, but you can fake it with status updates at key points. For the community version, definitely implement user quotas from day one - learned that the hard way when storage costs got out of hand.