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.


