A versatile Telegram bot that downloads videos and images from social media platforms, provides weather updates with AI-powered advice, offers GPT chat integration, and includes various utility features.
- Supported Platforms:
- TikTok
- YouTube Shorts and Clips
- Twitter/X, Vimeo
- Twitch Clips
- Features:
- Automatic video/image download
- Direct chat delivery
- URL shortening for AliExpress links
- Maximum file size: 50MB
- GPT Features:
- Direct responses on mention
/askcommand for chat/analyzefor message summarization- Random responses (2% chance after 50+ messages)
- Context-aware responses
- Image analysis capability
- Model: GPT-4-mini with optimized parameters
- Weather Commands:
/weather- Current conditions with AI recommendations/flares- Solar activity screenshots- Location-specific forecasts
- Country flag emojis
- Geomagnetic Activity:
/gmcommand for current status- Regular updates on significant changes
- Historical data tracking
- Message Processing:
- Content moderation
- Keyboard layout translation
- URL processing and shortening
- Message history tracking
- Other Commands:
/cat- Random cat pictures/errors- Error analytics (admin)/start- Bot information
- The
/analyzecommand now caches results to reduce API usage and speed up repeated requests. - How it works:
- Results are cached per chat, time period, and message content hash.
- Cached results are returned instantly for repeated analysis of the same data (default cache window: 24h).
- Cache is invalidated if new messages are added in the analyzed period or via admin command.
- Admin command:
/analyze flush-cacheclears the cache for the current chat. - Config:
ENABLE_ANALYSIS_CACHE(default: True)ANALYSIS_CACHE_TTL(default: 86400 seconds)
- Python 3.10 or higher
- Telegram Bot Token
- OpenAI API Key
- (Optional) OpenWeather API Key
- Docker and Docker Compose (for containerized setup)
-
Clone the repository:
git clone https://github.com/yourusername/PsychochauffeurBot.git cd PsychochauffeurBot -
Configure your
.envfile (already included with sample values) -
Start with automated setup:
./start.sh source .venv/bin/activate && python main.py
That's it! The database will be automatically created and configured.
# Start PostgreSQL database
docker-compose up -d postgres
# Run bot locally
source .venv/bin/activate && python main.py# Uncomment the bot service in docker-compose.yml, then:
docker-compose up --build# Use the provided startup script
./start.sh- PostgreSQL Database: Automatically configured with proper schema
- Health Checks: Ensures database is ready before bot starts
- Persistent Storage: Data survives container restarts
- Easy Management: Simple commands for backup, restore, and maintenance
See DOCKER_SETUP.md for detailed Docker documentation.
-
Create and activate virtual environment:
python -m venv .venv source .venv/bin/activate # Linux/Mac # or .venv\Scripts\activate # Windows
-
Install dependencies:
pip install -r requirements.txt
-
Set up your database (PostgreSQL recommended)
-
Configure
.envfile with your settings -
Run the bot:
python main.py
# Start database only
docker-compose up -d postgres
# Start everything (uncomment bot service first)
docker-compose up --build
# Stop services
docker-compose down
# Reset everything (deletes data)
docker-compose down -v
# View logs
docker-compose logs -f postgres
# Connect to database
docker-compose exec postgres psql -U postgres -d telegram_bot# Backup database
docker-compose exec postgres pg_dump -U postgres telegram_bot > backup.sql
# Restore database
docker-compose exec -T postgres psql -U postgres -d telegram_bot < backup.sql
# Check database status
docker-compose exec postgres pg_isready -U postgres -d telegram_botdocker-compose.yml- PostgreSQL service with auto-initializationDockerfile- Bot container configurationinit-db.sql- Database schema and setupstart.sh- Automated startup script.dockerignore- Optimized build context
For detailed Docker setup instructions, see DOCKER_SETUP.md.
| Variable | Required | Description |
|---|---|---|
TELEGRAM_BOT_TOKEN |
Yes | Telegram Bot Token |
OPENROUTER_API_KEY |
Yes | OpenRouter API Key |
OPENROUTER_BASE_URL |
Yes | OpenRouter API Base URL |
DB_HOST |
Yes | Database host (localhost or postgres) |
DB_PORT |
Yes | Database port (5432) |
DB_NAME |
Yes | Database name (telegram_bot) |
DB_USER |
Yes | Database user (postgres) |
DB_PASSWORD |
Yes | Database password |
ERROR_CHANNEL_ID |
No | Channel for error logging |
OPENWEATHER_API_KEY |
No | Weather API key |
SHORTENER_MAX_CALLS_PER_MINUTE |
No | URL shortener rate limit |
YTDL_SERVICE_* |
No | YouTube download service config |
SPEECHMATICS_API_KEY |
No | Speech-to-text API key |
global: Default configurationprivate: Per-user settingsgroup: Per-group settings
PsychochauffeurBot/
βββ main.py # Main entry point
βββ api.py # API endpoints
βββ docker-compose.yml # Docker services configuration
βββ Dockerfile # Bot container configuration
βββ init-db.sql # Database initialization
βββ start.sh # Automated startup script
βββ .dockerignore # Docker build optimization
βββ DOCKER_SETUP.md # Docker documentation
βββ config/ # Configuration files
βββ modules/ # Core functionality
β βββ gpt.py # GPT integration
β βββ weather.py # Weather features
β βββ video_downloader.py
β βββ ...
βββ tests/ # Test suite
βββ utils/ # Utility functions
βββ requirements.txt # Dependencies
- Follow PEP 8 guidelines
- Use type hints
- Document functions with docstrings
- Keep functions focused and small
# Run all tests
pytest
# Run without integration tests
pytest --ignore=tests/test_service.py
# Run specific test file
pytest tests/test_weather.py# Generate coverage report
pytest --cov=modules tests/- 50MB maximum video size
- GPT API rate limits
- Platform-specific restrictions
- URL shortener: 30 calls/minute
- Image analysis: specific file types only
- External API dependencies
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests
- Submit a pull request
For issues or suggestions, contact @vo1dee
-
Get your Speechmatics API key from https://www.speechmatics.com/
-
Add the following to your
.envfile:SPEECHMATICS_API_KEY=your_api_key_here
-
The bot will use this key for all speech-to-text requests.
- By default, speech recognition is disabled in all chats.
- To enable, use the
/speech oncommand (admin only by default). - To disable, use
/speech off. - You can allow all users to toggle speech recognition by setting
allow_all_userstotruein the chat's config (seeconfig/global/global_config.jsonor use the config API if available).
-
When enabled, any Telegram voice or video note message sent in the chat will be transcribed using Speechmatics.
-
The transcription will be posted to the chat and logged in the chat history as:
[User Name] (Speech): Transcribed Text
-
Only
voiceandvideo_notemessages are supported (not generic audio or video files).
- Ensure
httpxandpython-dotenvare installed (seerequirements.txt).