This is a simple Telegram bot written in Python using the Pyrogram library. The bot allows you to download files from Telegram and save them to your local machine. It can be useful for quickly saving files sent to you in Telegram chats.
Before running the Telegram File Downloader Bot, you need to set up your environment variables. Make sure you have the following information ready:
API_ID
: Your Telegram API ID. You can obtain it by creating a new application on the Telegram website.API_HASH
: Your Telegram API hash. This is also provided when you create a new application on the Telegram website.SESSION_STRING
: The Pyrogram session string. You can generate it by running thepython3 session_generate.py
.BOT_TOKEN
: The Telegram Bot token. You can create a new bot and obtain the token by talking to the BotFather.allowed_users
: Telegram User ID that allowed to use the bot. All User ID more than one seperate by space, example123 456 789
Once you have the required information, create a .env
file in the project directory and populate it with the environment variables:
API_ID="<your_api_id>"
API_HASH="<your_api_hash>"
SESSION_STRING="<your_session_string>"
BOT_TOKEN="<your_bot_token>"
allowed_users="<user_id_allowed>"
-
Clone the repository:
git clone https://github.com/jusidama18/TG-save-local.git
-
Change to the project directory:
cd TG-save-local
-
Create a virtual environment (optional but recommended):
python3 -m venv env source env/bin/activate # for Linux/Mac env\Scripts\activate # for Windows
-
Install the required dependencies:
pip install -r requirements.txt
-
Make sure you have Docker installed on your system.
-
Build and start the bot using Docker Compose:
docker-compose up -d
This command will build the Docker image and start the bot in detached mode.
If you make any changes to the code, you can rebuild the image with the
--build
flag:docker-compose up -d --build
-
The bot will now be running inside the Docker container.
You can also deploy the bot to a cloud platform like AWS, Google Cloud, or Heroku by adapting the Dockerfile and deployment configuration to the platform's specifications.
Please note that when deploying the bot to a public environment, make sure to secure sensitive information like API credentials and session strings. Consider using environment variables or a secure secret management system.
If you deploy with Docker / Docker-Compose and want to save to local folder you can do by two ways:
(In this example folder for download path is /home/user/downloads
)
- For Dockerfile, do
sudo docker run -v /home/user/downloads:/app/downloads myimage
. - For Docker-Compose, edit this line docker-compose.yml to your download path.
Don't change /app/downloads
part since it's bot download path.
Run the bot using the following command:
python -m src
The bot will start running, and you can now use it to download files. Add the bot to a Telegram group or start a chat with it, and send a file to the bot. The bot will save the file to the local directory.
You can also deploy the bot to a server or cloud platform for continuous operation.
If you want to contribute to this project, you can fork the repository, make your changes, and submit a pull request. Any contributions are welcome!
This project is licensed under the GPL-3.0 license.
This project is intended for educational purposes only. The authors are not responsible for any misuse of the code or any actions taken with the downloaded files. Be aware of the legal implications and respect the rights of others when downloading files.