Skip to content

A telegram bot that will give instant stream links for telegram files without the need of waiting till the download completes.

License

Notifications You must be signed in to change notification settings

EverythingSuckz/TG-FileStreamBot

Repository files navigation

Telegram File Stream Bot

File Stream Bot Logo

A Telegram bot to generate direct link for your Telegram files.


Note

Checkout python branch if you are interested in that.


Table of Contents
  1. How to make your own
  2. Setting up Things
  3. Contributing
  4. Contact me
  5. Credits

How to make your own

Deploy to Koyeb

Important

You'll have to expand the "Environment variables and files" section and update the env variables before hitting the deploy button.

Note

This deploys the latest docker release and NOT the latest commit. Since it uses prebuilt docker container, the deploy speed will be significantly faster.

Deploy to Koyeb

Deploy to Heroku

Note

You'll have to fork this repository to deploy to Heroku.

Press the below button to fast deploy to Heroku

Deploy To Heroku

Click Here to know how to add / edit environment variables in Heroku.


Download from releases

  • Head over to releases tab, from the pre release section, download the one for your platform and architecture.
  • Extract the zip file to a folder.
  • Create an a file named fsb.env and add all the variables there (see fsb.sample.env file for reference).
  • Give the executable file permission to execute using the command chmod +x fsb (Not required for windows).
  • Run the bot using ./fsb run command. ( ./fsb.exe run for windows)

Run using docker-compose

  • Clone the repository
git clone https://github.com/EverythingSuckz/TG-FileStreamBot
cd TG-FileStreamBot
  • Create an a file named fsb.env and add all the variables there (see fsb.sample.env file for reference).
nano fsb.env
  • Build and run the docker-compose file
docker-compose up -d

OR

docker compose up -d

Run using docker

docker run --env-file fsb.env ghcr.io/everythingsuckz/fsb:latest

Where fsb.env is the environment file containing all the variables.


Build from source

Ubuntu

Note

Make sure to install go 1.21 or above. Refer https://stackoverflow.com/a/17566846/15807350

git clone https://github.com/EverythingSuckz/TG-FileStreamBot
cd TG-FileStreamBot
go build ./cmd/fsb/
chmod +x fsb
mv fsb.sample.env fsb.env
nano fsb.env
# (add your environment variables, see the next section for more info)
./fsb run

and to stop the program, do CTRL+C

Windows

Note

Make sure to install go 1.21 or above.

git clone https://github.com/EverythingSuckz/TG-FileStreamBot
cd TG-FileStreamBot
go build ./cmd/fsb/
Rename-Item -LiteralPath ".\fsb.sample.env" -NewName ".\fsb.env"
notepad fsb.env
# (add your environment variables, see the next section for more info)
.\fsb run

and to stop the program, do CTRL+C

Setting up things

If you're locally hosting, create a file named fsb.env in the root directory and add all the variables there. You may check the fsb.sample.env. An example of fsb.env file:

API_ID=452525
API_HASH=esx576f8738x883f3sfzx83
BOT_TOKEN=55838383:yourbottokenhere
LOG_CHANNEL=-10045145224562
PORT=8080
HOST=http://yourserverip
# (if you want to set up multiple bots)
MULTI_TOKEN1=55838373:yourworkerbottokenhere
MULTI_TOKEN2=55838355:yourworkerbottokenhere

Required Vars

Before running the bot, set these mandatory variables:

Optional Vars

In addition to required variables, these optional ones are available:

  • DEV (default: false)

    • Enables development logging behavior.
  • PORT (default: 8080)

    • HTTP port used by the stream server.
  • HOST (default: auto-generated)

    • Base URL used in generated links (for example https://example.com or http://192.168.1.10:8080).
    • If omitted, bot auto-builds it from detected IP + PORT.
  • HASH_LENGTH (default: 6, min 5, max 32)

    • Length of URL hash used in stream links.
  • USE_SESSION_FILE (default: true)

    • Reuse saved worker sessions to speed startup and reduce login overhead.
  • USER_SESSION (default: empty)

    • Optional user session string for userbot features (for example auto-adding bots to LOG_CHANNEL).
  • USE_PUBLIC_IP (default: false)

    • If enabled, bot tries to discover public IP for host generation.
  • ALLOWED_USERS (default: empty)

    • Comma-separated Telegram user IDs that are allowed to use the bot (access allowlist).

Stream Performance Configuration

These optional variables allow you to tune the streaming performance. Most users won't need to change these defaults.

  • STREAM_CONCURRENCY (default: 4)

    • How many block downloads a single stream request runs in parallel.
    • Effective first-batch request fanout per stream request = STREAM_CONCURRENCY.
    • Higher values can improve throughput and startup latency, but increase Telegram API pressure.
  • STREAM_BUFFER_COUNT (default: 8)

    • Capacity of the in-memory block queue between downloader and HTTP writer.
    • It controls how far ahead prefetch can run before the reader catches up.
    • It does not increase parallel download count by itself.
    • Approximate extra memory per request: STREAM_BUFFER_COUNT * blockSize (blockSize is dynamic: 64KB/256KB/512KB/1MB).
  • STREAM_TIMEOUT_SEC (default: 30)

    • Per-block timeout for Telegram UploadGetFile request.
  • STREAM_MAX_RETRIES (default: 3)

    • Retry attempts per block before failing the stream.
Simple explanation (for non-technical users)
  • STREAM_CONCURRENCY = how many Telegram downloads happen at the same time for one stream.

    • Bigger value = video may start faster and download faster.
    • But bigger value also means more chance of Telegram floodwait/rate-limit.
  • STREAM_BUFFER_COUNT = how many downloaded chunks are kept ready in memory.

    • Bigger value = smoother playback on unstable networks.
    • It does not create more Telegram requests by itself.
  • STREAM_TIMEOUT_SEC = how long to wait before saying a chunk request is too slow.

  • STREAM_MAX_RETRIES = how many times to retry a failed chunk.

Quick rule:

  • Telegram request pressure is mainly controlled by STREAM_CONCURRENCY.
  • Approximate in-flight Telegram calls at peak = active_streams × STREAM_CONCURRENCY.

Safe starting presets:

  • Small server / home host:

    • STREAM_CONCURRENCY=4
    • STREAM_BUFFER_COUNT=8
    • STREAM_TIMEOUT_SEC=30
    • STREAM_MAX_RETRIES=3
  • Medium VPS:

    • STREAM_CONCURRENCY=6
    • STREAM_BUFFER_COUNT=12
    • STREAM_TIMEOUT_SEC=45
    • STREAM_MAX_RETRIES=3
  • High bandwidth + multiple worker bots:

    • STREAM_CONCURRENCY=8
    • STREAM_BUFFER_COUNT=16
    • STREAM_TIMEOUT_SEC=60
    • STREAM_MAX_RETRIES=5

Note

Increasing STREAM_CONCURRENCY increases concurrent Telegram requests from one client connection. If you push this too high, floodwait/rate-limit risk increases. Start with 4, test 6 or 8, and only go higher if logs show stable behavior.

Example configuration for high-performance servers:

STREAM_CONCURRENCY=8
STREAM_BUFFER_COUNT=16
STREAM_TIMEOUT_SEC=60
STREAM_MAX_RETRIES=5

This configuration would allow up to 8 blocks to be downloaded in parallel, with a buffer of 16 blocks, and a longer timeout for slow connections.

MULTI_TOKEN variables

You can add worker bots to distribute stream requests across different bot tokens:

  • MULTI_TOKEN1
  • MULTI_TOKEN2
  • MULTI_TOKEN3
  • ...

Each active HTTP stream request uses one worker client in round-robin mode. Using multiple workers reduces floodwait risk versus sending all traffic through a single token.


Use Multiple Bots to speed up

Note

What it multi-client feature and what it does?
This feature shares the Telegram API requests between worker bots to speed up download speed when many users are using the server and to avoid the flood limits that are set by Telegram.

Note

You can add up to 50 bots since 50 is the max amount of bot admins you can set in a Telegram Channel.

To enable multi-client, generate new bot tokens and add it as your fsb.env with the following key names.

MULTI_TOKEN1: Add your first bot token here.

MULTI_TOKEN2: Add your second bot token here.

you may also add as many as bots you want. (max limit is 50) MULTI_TOKEN3, MULTI_TOKEN4, etc.

Warning

Don't forget to add all these worker bots to the LOG_CHANNEL for the proper functioning

Using user session to auto add bots

Warning

This might sometimes result in your account getting resticted or banned. Only newly created accounts are prone to this.

To use this feature, you need to generate a pyrogram session string for the user account and add it to the USER_SESSION variable in the fsb.env file.

What it does?

This feature is used to auto add the worker bots to the LOG_CHANNEL when they are started. This is useful when you have a lot of worker bots and you don't want to add them manually to the LOG_CHANNEL.

How to generate a session string?

The easiest way to generate a session string is by running

./fsb session --api-id <your api id> --api-hash <your api hash>
Image



This will generate a session string for your user account using QR code authentication. Authentication via phone number is not supported yet and will be added in the future.

Contributing

Feel free to contribute to this project if you have any further ideas

Contact me

Telegram Channel Telegram Group

You can contact either via my Telegram Group or you can message me on @EverythingSuckz

Credits

Copyright

Copyright (C) 2023 EverythingSuckz under GNU Affero General Public License.

TG-FileStreamBot is Free Software: 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 Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Also keep in mind that all the forks of this repository MUST BE OPEN-SOURCE and MUST BE UNDER THE SAME LICENSE.

Packages

 
 
 

Contributors 20

Languages