Π ΡΡΡΠΊΠ°Ρ Π²Π΅ΡΡΠΈΡ | English
A Telegram bot for receiving and managing videos on Android TV-box (X96Q, slimBOXtv, and similar devices) using Termux.
- π₯ Video Reception: Send videos to the bot β they're saved to your TV-box
- π File Management: Browse, download, and delete files via Telegram
- π Whitelist Access: Only authorized users can access
- βΎοΈ No Size Limits: Uses local Bot API server for unlimited file sizes
- β‘ Atomic Writes: Safe file saving with transaction-like behavior
- π Auto-start: Works with Termux:Boot for automatic startup
βββββββββββββββ ββββββββββββββββββββ ββββββββββββββ
β Telegram β HTTPS β Telegram API β HTTP β Bot API β
β Servers ββββββββββΊβ (Cloud) ββββββββββΊβ Server β
βββββββββββββββ ββββββββββββββββββββ β (Local) β
ββββββββ¬ββββββ
β HTTP
ββββββββΌββββββ
β Python β
β Bot β
β (PTB) β
ββββββββ¬ββββββ
β
ββββββββΌββββββ
β SHARED_ β
β DIR β
ββββββββββββββ
The entire stack runs locally on your TV-box in Termux.
Framework: python-telegram-bot (PTB) - standard Telegram Bot API library for Python, no pydantic-core dependency.
- Android TV-box (X96Q, slimBOXtv, or similar)
- Android 7.0+
- Access to shared storage
- Internet connection
- Termux (from F-Droid - required!)
- Termux:Boot (from F-Droid)
- Python 3.8+
- Git
- ffmpeg (for correct video metadata handling)
Before installation, you'll need to gather the following information:
-
Create a Telegram Bot
- Open @BotFather in Telegram
- Send
/newbotand follow instructions - Save the bot token (looks like
123456789:ABCdefGHIjklMNOpqrsTUVwxyz)
-
Get Telegram API Credentials
- Visit https://my.telegram.org
- Log in with your phone number
- Go to API development tools
- Create a new application:
- App title:
TV-box Video Inbox - Short name:
tvbox - Platform:
Other
- App title:
- Save the api_id (number) and api_hash (string)
-
Get Your Telegram User ID
- Open @userinfobot in Telegram
- Send any message
- Save your user ID (number)
-
Know Your Hardware (optional, for troubleshooting)
- Device model (e.g., X96Q, slimBOXtv)
- Android version
Important
Install Termux from F-Droid ONLY!
The Google Play version is outdated and incompatible.
- F-Droid: https://f-droid.org/
- Termux: https://f-droid.org/packages/com.termux/
- Termux:Boot: https://f-droid.org/packages/com.termux.boot/
One-Command Installation:
# 1. Install Termux from F-Droid, then open it
# 2. Grant storage access
termux-setup-storage
# Allow when prompted
# 3. Clone the repository
cd ~
git clone https://github.com/Spiceman161/Telegram-video-inbox.git
cd Telegram-video-inbox
# 4. Run automated installation
chmod +x scripts/install_dependencies.sh
./scripts/install_dependencies.shThe script will:
- Install all system dependencies (Python, Git, ffmpeg, build tools)
- Build Telegram Bot API Server (~45 minutes on TV-box)
- Install Python packages
- Guide you through configuration
- Set up all necessary directories
During installation, you'll be asked to enter:
- Bot token (from step 1)
- API ID and API Hash (from step 2)
- Your user ID (from step 3)
- Video storage path (default:
/storage/emulated/0/Movies/TelegramInbox)
After installation completes:
# If scripts are not executable (automated install handles this)
# Run this only if you get "Permission denied" error:
chmod +x scripts/*.sh
# Start Bot API Server (in first terminal window)
./scripts/start_bot_api.sh &
# Wait 5 seconds for it to initialize
sleep 5
# Start the bot (in second terminal window or use tmux/screen)
./scripts/start_bot.sh &Test the bot:
- Open Telegram on your phone
- Find your bot
- Send
/start- you should see a welcome message - Send a video - it should be saved to your TV-box
/start- Start the bot and show main menu
- π₯ Inbox - Browse saved files
- β¬οΈ Status - System statistics
- β Help - Help information
Simply send or forward any video to the bot. It will be automatically saved to SHARED_DIR.
- Press π₯ Inbox
- Select a file from the list
- β¬οΈ Download - Get the file back in Telegram
- π Delete - Delete from disk (with confirmation)
To make the bot start automatically when your TV-box boots:
# 1. Install Termux:Boot from F-Droid
# 2. Disable battery optimization
# Settings β Apps β Termux β Battery β Unrestricted
# Settings β Apps β Termux:Boot β Battery β Unrestricted
# 3. Copy boot script
mkdir -p ~/.termux/boot
cp scripts/termux_boot_template.sh ~/.termux/boot/01-telegram-video-inbox.sh
chmod +x ~/.termux/boot/01-telegram-video-inbox.sh
# 4. Open Termux:Boot app at least once
# 5. Reboot your deviceAfter reboot, the bot will be ready in ~60 seconds.
All settings are in the .env file:
# Bot token from @BotFather
BOT_TOKEN=your_bot_token_here
# API credentials from my.telegram.org
TELEGRAM_API_ID=your_api_id
TELEGRAM_API_HASH=your_api_hash
# Whitelist (comma-separated Telegram user IDs from @userinfobot)
# You can add multiple users: ALLOWED_USER_IDS=123456789,987654321
ALLOWED_USER_IDS=123456789
# Path to video folder (shared storage)
SHARED_DIR=/storage/emulated/0/Movies/TelegramInbox
# Temporary folder
TMP_DIR=/data/data/com.termux/files/home/Telegram-video-inbox/tmpPAGE_SIZE=10 # Files per page
MAX_CONCURRENT_DOWNLOADS=2 # Parallel downloads
SEND_AS=video # or 'document'
LOG_LEVEL=INFODiagnostics:
# 1. Check if Bot API server is running
ps aux | grep telegram-bot-api
# 2. Check if bot is running
ps aux | grep "python.*bot.main"
# 3. Check recent logs
tail -50 ~/Telegram-video-inbox/logs/bot.log
tail -50 ~/Telegram-video-inbox/logs/bot-api.logIf bot is not running:
cd ~/Telegram-video-inbox
./scripts/start_bot_api.sh &
sleep 5
./scripts/start_bot.sh &Cause: Bot API server is not running or unreachable on port 8081.
Solution:
# Check Bot API server logs
tail -50 ~/Telegram-video-inbox/logs/bot-api.log
# Check if port is in use
netstat -tulpn | grep 8081
# Restart Bot API server
pkill telegram-bot-api
./scripts/start_bot_api.sh &Diagnostics:
# 1. Check storage permissions
ls -ld /storage/emulated/0/Movies/TelegramInbox
# 2. Check free space
df -h /storage/emulated/0
# 3. Check download errors in logs
grep -i "error\|failed" ~/Telegram-video-inbox/logs/bot.log | tail -20
# 4. Check specific download failures
grep "download_failed" ~/Telegram-video-inbox/logs/bot.logDiagnostics:
# 1. Check boot script logs
cat ~/boot_debug.log
# 2. Check if boot script exists and is executable
ls -la ~/.termux/boot/01-Telegram-video-inbox.sh
# 3. Check bot logs from boot
tail -50 ~/Telegram-video-inbox/logs/bot-boot.logCommon issues:
-
Battery optimization not disabled
- Settings β Apps β Termux β Battery β Unrestricted
- Settings β Apps β Termux:Boot β Battery β Unrestricted
-
Termux:Boot not activated
- Open Termux:Boot app at least once
-
Script errors
# Test boot script manually bash ~/.termux/boot/01-Telegram-video-inbox.sh # Check for errors
-
PATH issues
# Check if telegram-bot-api is in PATH which telegram-bot-api # Should output: /data/data/com.termux/files/home/.local/bin/telegram-bot-api
# Quick status check
echo "=== Bot Process ===" && ps aux | grep "python.*bot.main" && \
echo "=== API Server ===" && ps aux | grep telegram-bot-api && \
echo "=== Recent Bot Log ===" && tail -10 ~/Telegram-video-inbox/logs/bot.log && \
echo "=== Recent API Log ===" && tail -10 ~/Telegram-video-inbox/logs/bot-api.log# Stop everything
pkill -f "python.*bot.main"
pkill telegram-bot-api
# Start fresh
cd ~/Telegram-video-inbox
./scripts/start_bot_api.sh &
sleep 5
./scripts/start_bot.sh &
# Monitor logs
tail -f logs/bot.logOnly users listed in ALLOWED_USER_IDS can:
- Upload files
- Browse file list
- Download and delete files
Others will receive "π« Access denied" without information leakage.
All paths are validated to prevent directory traversal attacks.
All actions are logged with user_id:
upload_received- video receiveddownload_ok- download completedfile_sent- file sent to userfile_deleted- file deletedunauthorized_access- access attempt denied
Logs: logs/bot.log
See detailed instructions in docs/INSTALLATION.md
For easier session management:
pkg install tmux
# Create session
tmux new -s telegram
# Inside tmux:
# Ctrl+B then C - new window
# Ctrl+B then N - next window
# Ctrl+B then D - detach
# Reattach
tmux attach -t telegramContributions are welcome! Please see docs/PRD.md for project requirements.
MIT License - see LICENSE file for details.
Created for X96Q/slimBOXtv TV-box deployment.
- Issues: Report bugs and feature requests on GitHub Issues
- Documentation: See docs/ folder for detailed guides
- Changelog: See CHANGELOG.md for version history