Telegram-to-Bale File Transfer Bot is a JavaScript script designed to run on Cloudflare Workers. It forwards files sent to a Telegram bot over to a corresponding bot on Bale, an Iranian messaging platform. The project, hosted at ixabolfazl/telegram-to-bale-file-transfer-bot, has garnered 85 stars on GitHub. Access is limited to predefined user mappings, which pair specific Telegram user IDs with Bale user IDs. This setup prevents unauthorized forwarding and keeps the process secure without needing a traditional server.

The need arises from Telegram's bot API limits and the separation between Telegram and Bale ecosystems. Bots on Telegram can't directly send files to Bale users, so users must bridge the gap manually or through insecure means. This worker handles that by receiving updates via webhook from Telegram, checking sender authorization, downloading the file (up to Telegram's 20 MB bot limit), and uploading it to the mapped Bale recipient. Everything runs serverlessly on Cloudflare's edge network.

Core features

The script supports a focused set of capabilities:

  • File forwarding for documents, photos, videos, and audio from Telegram to Bale.
  • User authorization via a mapping object in index.js, where each Telegram sender ID links to a specific Bale recipient ID.
  • 20 MB file size limit, matching Telegram's bot API constraint.
  • Webhook-based operation with a configurable endpoint like /endpoint.
  • Serverless deployment on Cloudflare Workers, avoiding VPS maintenance.

These features keep the bot lightweight and abuse-resistant.

Getting it running

Start with prerequisites: a free Cloudflare account from dash.cloudflare.com/sign-up, a Telegram bot token from @BotFather, a Bale bot token from @BotFather, and user IDs—Telegram IDs via @userinfobot, Bale IDs via @userinfo_idbot.

Edit the top of index.js with your details:

const BOT_TOKEN = "YOUR_TELEGRAM_BOT_TOKEN"; // Replace with your Telegram bot token
const BALE_BOT_TOKEN = "YOUR_BALE_BOT_TOKEN"; // Replace with your Bale bot token
const BOT_WEBHOOK = "/endpoint"; // You can change this or leave it as is

// User Mapping: Telegram Sender → Bale Recipient
const USER_MAPPING = {
  "tg_user_id": "bale_user_id", // e.g., "123456789": "987654321"
};

Deploy using Wrangler CLI (recommended, requires Node.js) or the Cloudflare dashboard.

For Wrangler:

  1. In the project directory, run:

    npm install
    
  2. Authenticate:

    npx wrangler login
    
  3. Deploy:

    npm run deploy
    

Wrangler outputs the live URL, such as https://telegram-file-transfer.<your-subdomain>.workers.dev.

For manual dashboard deployment:

  1. Log in to dash.cloudflare.com.
  2. Go to Workers & Pages > Create Worker.
  3. Name it (e.g., telegram-file-transfer), deploy, then Edit Code.
  4. Paste the full index.js contents (with config updated).
  5. Save and Deploy, note the URL.

Set the Telegram webhook next. Visit https://YOUR_WORKER_DOMAIN.workers.dev/registerWebhook in a browser. Expect a JSON response like {"ok":true,"result":true,"description":"Webhook was set"}.

Test usage: Message your Telegram bot with /start for confirmation, then send a file, photo, video, or audio. If authorized, it forwards to the mapped Bale user.

Who this is for

This bot suits users active on both Telegram and Bale who need to share files across platforms without manual downloads and re-uploads. Iranian users or those in regions where Bale is common might find it practical for bridging chats. Developers familiar with Cloudflare Workers or bot APIs can extend it, though it's ready out-of-the-box for non-coders who follow the config steps.

Common scenarios include transferring work documents from Telegram groups to Bale colleagues, sharing media from Telegram channels to personal Bale bots, or backing up files across apps securely. The user mapping enforces one-to-one transfers, so it's ideal for private, controlled sharing rather than group broadcasts. If you handle files under 20 MB and value zero-server costs, it fits.

How it compares

Compared to self-hosted bots on a VPS (like those using Node.js with Telegraf or grammY libraries), this avoids ongoing hosting fees and scaling worries—Cloudflare Workers have a generous free tier for low-traffic use. It's lighter than full Telegram-Bale proxies, which might require Docker or persistent storage.

Direct alternatives are scarce due to the niche Telegram-to-Bale focus. Broader file-forwarding bots exist on GitHub, such as generic multi-messenger bridges, but they often lack built-in auth or serverless support. For larger files, Telegram Premium users get 4 GB limits, but bots cap at 50 MB for uploads (still above this script's 20 MB download limit). VPS-based options like a simple Express server with Telegram and Bale APIs offer more flexibility but demand maintenance.

This project stands out for its minimalism: single-file deployment, no database, pure edge execution.

Users needing group forwards, custom file processing, or files over 20 MB will need custom solutions. The script's JavaScript base keeps it editable, but it's not for high-volume traffic without Cloudflare's paid plans.

Check the source at github.com/ixabolfazl/telegram-to-bale-file-transfer-bot for the latest code and issues.