putfilebot
putfilebot
Bot to automatically save received media files (documents, photos, videos, etc.) to a local directory.
This simple Telegram bot, written in Rust using the library, is designed to automatically download and save files sent by users to the bot's chat.
Features
- Saves various media file types: documents, photos, videos, audio, and voice messages.
- Uses asynchronous operations (
) for efficient download handling.tokio - Sanitizes file names for safe saving on disk.
- Configurable via environment variables.
Usage
These instructions will help you set up and run the file saver bot.
Prerequisites
- Rust and Cargo installed.
- A Telegram bot token obtained from @BotFather.
Setup
-
Clone the repository
-
Create a
file in the project's root directory (where.envis located).Cargo.toml -
Open the
file and add the following lines, replacing the placeholders with your actual values:.env: The token obtained from BotFather.YOUR_BOT_TOKEN: The absolute or relative path to the directory where the bot will save files. Ensure the user running the bot has write permissions for this directory. The bot will attempt to create the directory if it doesn't exist./path/to/your/download/directory
Building
Build the project using Cargo:
- For a debug build:
- For a release build (recommended for production, it's optimized and faster):
Running
Run the bot. The logging level is controlled by the environment variable.
-
Run using
(for debugging):cargo runor for more detailed logs:
-
Run the compiled executable (recommended for production): Navigate to the directory containing the executable (
ortarget/debug/).target/release/- On Linux/macOS:
- On Windows (Command Prompt):
- On Windows (PowerShell):
- On Linux/macOS:
Once started, the bot will begin receiving messages. Send it a document, photo, video, audio, or voice message, and it will attempt to save it to the specified directory.