DirectlinkRobot: Generate Direct Download Links from Telegram
π Directlink Robot
Directlink Robot is a Telegram bot designed to generate direct download links for files, videos, and audios sent to it. The bot uses Cloudflare Workers for serverless deployment, ensuring fast and reliable performance.
π Demo in Telegram: @directlink_robot
β¨ Features
- π¬ Responds to the
/startcommand with a welcome message. - π₯ Supported chat types: private, groups, supergroups.
- π Handles file, video, and audio messages to generate direct download links.
- π Auto rename unnamed videos with a timestamp.
- π Limits file sizes to a maximum of 20 MiB due to Telegram Bot API constraints.
- π Utilizes encryption for secure message handling.
- π Supports CORS for cross-origin requests.
βοΈ Setup
-
π§© Clone the Repository
1 2
git clone https://gitlab.com/fr0stb1rd/directlink-robot.git cd directlink-robot -
π Configure Bot Tokens
Add your bot tokens in the
BOT_TOKENSarray in the script. You can add multiple tokens separated by a comma.1
const BOT_TOKENS = ["your_bot_token"];
-
π Set the Channel ID
Set the
CHANNEL_IDto the ID of your Telegram channel where the bot will forward messages.1
const CHANNEL_ID = -1000000000;
-
βοΈ Deploy to Cloudflare Workers
-
π οΈ Install the Wrangler CLI.
1
npm install -g @cloudflare/wrangler
-
π Login to your Cloudflare account.
1
wrangler login
-
π Publish your worker.
1
wrangler publish
-
-
π Set Webhook URL
Set the webhook URL for your bot using the following format:
1
const webhook_url = `https://api.telegram.org/bot<your_bot_token>/setWebhook?url=https://<your_worker_url>/webhook`;
π Replace
<your_bot_token>with your bot token and<your_worker_url>with your Cloudflare Worker URL.
β‘οΈ How It Works
-
βΆοΈ Start Command
When a user sends the
/startcommand, the bot responds with a welcome message and instructions. -
π¦ File Handling
When a user sends a file, video, or audio, the bot:
- Forwards the message to the specified channel.
- Generates a direct download link.
- Sends the download link to the user.
-
π Download Links
The download links are generated using a cipher function to ensure security. π
π οΈ Functions
- π cipher(textV)
- Encrypts the given text using a predefined salt.
- π decipher(textV)
- Decrypts the given text using the same salt.
- π¨ handleOptions(request)
- Handles CORS preflight requests.
- π€ getBotToken()
- Retrieves a random bot token from the list of tokens.
- π² generateRandomString(length)
- Generates a random string of the specified length.
- π fetchJson(url)
- Fetches JSON data from the specified URL.
- π₯ downloadFile(message_id)
- Downloads the file from Telegram using the message ID.
- π handleUpdate(update)
- Handles incoming updates from Telegram.
π CORS Headers
The bot includes CORS headers to support cross-origin requests:
1
2
3
4
5
const corsHeaders = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, HEAD, POST, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type",
};
πΈ Screenshots
π» Source Code
Soonβ¦
π License
You can use, study, share and improve it at your will. Specifically you can redistribute and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.


