A lightweight Content Delivery Network (CDN) that leverages the Telegram Bot API for file storage and retrieval.
telerealm provides a cost-effective solution for hosting files and serving them via a CDN-like infrastructure using Telegram's robust backend. This project is perfect for those looking for an affordable way to store and retrieve files without managing complex infrastructure.
Author: Lai Chi Thinh (ThinhPhoenix) - FPT University
- File Upload: Upload files to Telegram Bot API and receive a unique file URL for accessing the content
- File Metadata Retrieval: Retrieve file URLs and metadata (such as file size) using dedicated API endpoints
- CORS Support: Seamless integration with web applications through Cross-Origin Resource Sharing configuration
- Secure File Download: Generate secure, unique URLs for file downloads with automatic expiration
- Bot and Chat Verification: Verify bot and chat information to ensure proper configuration
- Unlimited Storage: Utilizes Telegram's cloud storage for files, offering virtually unlimited capacity
- Easy to Use: Integration with Telegram Bot API simplifies file upload and retrieval operations
- Free: No additional cost for storage or bandwidth usage beyond what Telegram charges for bot API usage
- Automatic Removal: Files may be removed if Telegram considers them inactive for a prolonged period due to privacy policies and storage management
- Go programming language (version 1.16 or later)
- Telegram Bot API token (obtain one by creating a new bot using BotFather)
-
Create a bot in Telegram:
- Follow the instructions on the Telegram Bot Features page to create a new bot and obtain your API token
-
Clone the repository:
git clone https://github.com/ThinhPhoenix/telerealm.git cd telerealm
-
Installed dependencies:
go get github.com/gin-contrib/cors go get github.com/gin-gonic/gin go get github.com/google/uuid go get github.com/joho/godotenv
-
Run the project:
go run main.go
The server will start running on http://localhost:7777 by default.
To upload a file, send a POST request to the /send
endpoint with the following form data:
chat_id
: The chat ID where you want to upload the file (you can use your own chat ID or a group/channel ID)document
: The file you want to upload
Example:
curl -X POST -H "Authorization: Bearer <your_bot_token>" -F "chat_id=<your_chat_id>" -F "document=@/path/to/your/file" http://localhost:7777/send
To retrieve the file URL, send a GET request to the /url
endpoint with the following query parameters:
file_id
: The file ID obtained from the upload response
Example:
curl -X GET -H "Authorization: Bearer <your_bot_token>" "http://localhost:7777/url?file_id=<your_file_id>"
You can download the file by accessing the secure URL generated after uploading:
/drive/:id
: Endpoint to download the file associated with:id
(secure ID)
Example:
curl -OJL http://localhost:7777/drive/<secure_id>
To get information about a file (including its size and URL), send a GET request to the /info
endpoint with the following query parameters:
file_id
: The file ID obtained from the upload response
Example:
curl -X GET -H "Authorization: Bearer <your_bot_token>" "http://localhost:7777/info?file_id=<your_file_id>"
To verify bot and chat information, send a GET request to the /verify
endpoint with the following query parameters:
chat_id
: The chat ID where you want to verify the bot
Example:
curl -X GET -H "Authorization: Bearer <your_bot_token>" "http://localhost:7777/verify?chat_id=<your_chat_id>"
- Replace
<your_bot_token>
,<your_chat_id>
,<your_file_id>
, and<secure_id>
with actual values as per your application's requirements - Ensure that the Telegram Bot API token is kept secure and not exposed in client-side code
- Files may be subject to Telegram's inactive file removal policies
- Keep your bot token private and secure
- Consider implementing rate limiting for your API endpoints
- Monitor your usage to ensure compliance with Telegram's terms of service
Contributions are welcome! Please feel free to submit a Pull Request.