Skip to content

luizmz94/TG-FileStreamBot

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

273 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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, you will need to set up the following mandatory variables:

  • API_ID : This is the API ID for your Telegram account, which can be obtained from my.telegram.org.

  • API_HASH : This is the API hash for your Telegram account, which can also be obtained from my.telegram.org.

  • BOT_TOKEN : This is the bot token for the Telegram Media Streamer Bot, which can be obtained from @BotFather.

  • LOG_CHANNEL : This is the channel ID for the log channel where the bot will forward media messages and store these files to make the generated direct links work. To obtain a channel ID, create a new telegram channel (public or private), post something in the channel, forward the message to @missrose_bot and reply the forwarded message with the /id command. Copy the forwarded channel ID and paste it into the this field.

Optional Vars

In addition to the mandatory variables, you can also set the following optional variables:

  • MEDIA_CHANNEL_ID : (New Feature) This is the channel ID where your media files are already stored. When set, you can use the /direct/:message_id route to stream files directly from this channel without needing hash validation or the internal database. To obtain a channel ID, follow the same process as LOG_CHANNEL. Example: MEDIA_CHANNEL_ID=2625729812 (default: null)

  • PORT : This sets the port that your webapp will listen to. The default value is 8080.

  • HOST : A Fully Qualified Domain Name if present or use your server IP. (eg. https://example.com or http://14.1.154.2:8080)

  • HASH_LENGTH : Custom hash length for generated URLs. The hash length must be greater than 5 and less than or equal to 32. The default value is 6.

  • USE_SESSION_FILE : Use session files for worker client(s). This speeds up the worker bot startups. (default: false)

  • USER_SESSION : A pyrogram session string for a user bot. Used for auto adding the bots to LOG_CHANNEL. (default: null)

  • ALLOWED_USERS : A list of user IDs separated by comma (,). If this is set, only the users in this list will be able to use the bot. (default: null)

  • LOG_LEVEL : Set the logging level for console output. Available options: debug, info, warn, error. Set to error to show only errors in the console, which is useful for production environments. (default: info)


Direct Streaming from Media Channel

Note

New Feature: Direct streaming allows you to stream files from a pre-configured media channel using only the message ID, bypassing the hash validation and internal database system.

If you have a channel where your media files are already stored and you know the message IDs, you can use the direct streaming feature:

  1. Set up the media channel: Add the MEDIA_CHANNEL_ID variable to your fsb.env file with your channel ID:

    MEDIA_CHANNEL_ID=2625729812
  2. Stream files directly: Use the /direct/:message_id endpoint to stream files:

    GET http://your-server:8080/direct/12345
    

    Where 12345 is the message ID in your media channel.

  3. Optional download parameter: Add ?d=true to force download instead of inline viewing:

    GET http://your-server:8080/direct/12345?d=true
    

Important Notes:

  • The /direct/:message_id route will only work if MEDIA_CHANNEL_ID is configured.
  • The bot must have access to the media channel.
  • The message must exist and contain media (document, video, photo, etc.).
  • This route does NOT require hash validation, making it simpler for scenarios where you control both the media storage and the streaming service.

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>



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.

About

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

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages

  • Go 54.4%
  • Python 21.6%
  • TypeScript 21.5%
  • Swift 2.3%
  • Other 0.2%