This is the server-side component of the Telegram bot integration for the Flutter File Manager application. It provides remote file access capabilities through Telegram commands.
- File upload, download, and deletion
- Directory listing and file search
- User management (admin-only user addition/removal)
- Device registration and management
- Security controls and access logging
- Create an account on Render
- Create a new Telegram bot using BotFather on Telegram
- Note down the bot token provided by BotFather
-
Log in to your Render account
-
Create a new Web Service
-
Connect your Git repository containing these files
-
Configure the following settings:
- Build Command:
pip install -r requirements.txt
- Start Command:
python main.py
- Python version: 3.11 (specified in runtime.txt)
- Build Command:
-
Configure environment variables in the Render dashboard:
BOT_TOKEN
: Your Telegram bot token from BotFatherADMIN_ID
: Your Telegram user ID (5445671392 by default)STORAGE_PATH
: Path for temporary file storage (default: /tmp/bot_storage)
-
Deploy the service
After deployment, you need to set up the webhook for your bot:
- Get your bot's webhook URL from Render (usually in the format:
https://your-service-name.onrender.com/webhook
) - Set the webhook using the Telegram Bot API:
https://api.telegram.org/bot<BOT_TOKEN>/setWebhook?url=<YOUR_RENDER_WEBHOOK_URL>
The bot requires the following Python packages:
- python-telegram-bot==21.11
- flask==2.3.2
- requests==2.31.0
These are automatically installed by Render based on requirements.txt.
/start
- Initialize bot and show help/list <path>
- List directory contents/download <file_path>
- Download file from device/delete <file_path>
- Delete file from device/search <query>
- Search for files/status
- Show device status/help
- Show help information
/devices
- List registered devices/adduser <user_id>
- Add authorized user/removeuser <user_id>
- Remove authorized user/users
- List authorized users
- Only authorized users can interact with the bot
- Only admin can add/remove users
- File operations are restricted to prevent directory traversal
- All actions are logged for audit purposes
- Rate limiting prevents abuse
{
"device_id": "unique_device_identifier",
"registration_date": "timestamp",
"last_seen": "timestamp",
"device_name": "string",
"online_status": "boolean"
}
{
"user_id": "telegram_user_id",
"role": "admin|user",
"registration_date": "timestamp",
"last_active": "timestamp"
}
- Check Render logs for errors
- Verify webhook URL is correctly configured
- Ensure BOT_TOKEN environment variable is set correctly
- Check network connectivity
- Verify first-launch detection logic in the Flutter app
- Check network connectivity from device
- Ensure bot server is running and accessible
- Validate device ID generation
To run locally for development:
-
Install dependencies:
pip install -r requirements.txt
-
Set environment variables:
export BOT_TOKEN="your_bot_token" export ADMIN_ID="your_telegram_id" export STORAGE_PATH="/tmp/bot_storage"
-
Run the server:
python main.py
-
Use ngrok or similar to expose your local server to the internet for webhook testing