A high-performance, event-driven social media monitoring system that tracks specific keywords across social media platforms and sends real-time alerts to Telegram.
- Twitter Scraping: Uses twscrape to fetch real Twitter data without official API access
- Modular Data Ingestion: Abstract provider pattern for easy integration with different data sources
- Smart Filtering: Filter posts by follower count and keyword matching
- Deduplication: Prevents duplicate alerts using efficient in-memory cache
- Telegram Integration: Real-time alerts sent to your Telegram channel
- Production Ready: Dockerized with resource limits optimized for VPS environments
- Async Architecture: Built with asyncio for high performance and low resource usage
βββββββββββββββββββ
β Data Provider β (twscrape Twitter Scraper or Mock)
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Filter Pipeline β (Followers, Keywords, Dedup)
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β Alert Manager β (Telegram Bot)
βββββββββββββββββββ
telegram-tracking-app/
βββ main.py # Main orchestration script
βββ data_provider.py # Abstract provider + Twitter scraper + Mock
βββ alert_manager.py # Telegram alert dispatcher
βββ config.py # Configuration management (Pydantic)
βββ requirements.txt # Python dependencies
βββ Dockerfile # Multi-stage Docker build
βββ docker-compose.yml # Docker Compose configuration
βββ .env.example # Environment variable template
βββ accounts.txt.example # Twitter accounts template
βββ README.md # This file
- Python 3.11+ (for local development)
- Docker & Docker Compose (for containerized deployment)
- Telegram Bot Token (from @BotFather)
- Telegram Channel (where alerts will be posted)
- Twitter Account(s) (for real data scraping - 2-5 dedicated accounts recommended)
- Message @BotFather on Telegram
- Send
/newbotand follow the prompts - Save your bot token (looks like
123456789:ABCdefGHIjklMNOpqrsTUVwxyz)
- Create a new Telegram channel
- Add your bot as an administrator to the channel
- Get your channel ID:
- For public channels:
@channelname - For private channels: Use @userinfobot
- For public channels:
# Copy the example environment file
cp .env.example .env
# Edit .env with your credentials
nano .envUpdate these required fields:
TELEGRAM_BOT_TOKEN=your_bot_token_here
TELEGRAM_CHANNEL_ID=@your_channel_name# Build and start the container
docker-compose up -d
# View logs
docker-compose logs -f
# Stop the container
docker-compose down# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Run the application
python main.pyAll configuration is managed through environment variables in .env:
| Variable | Description | Default |
|---|---|---|
TELEGRAM_BOT_TOKEN |
Your Telegram bot token | Required |
TELEGRAM_CHANNEL_ID |
Target channel ID | Required |
KEYWORDS |
Comma-separated keywords to monitor | $hylo,hylo,hyusd,... |
MIN_FOLLOWER_COUNT |
Minimum followers to process | 100 |
DEDUP_CACHE_SIZE |
Max post IDs to track | 10000 |
POLL_INTERVAL_SECONDS |
Seconds between polls | 60 |
USE_MOCK_PROVIDER |
Use mock (true) or Twitter scraper (false) | true |
MOCK_POSTS_PER_POLL |
Mock posts per cycle | 5 |
TWITTER_ACCOUNTS_FILE |
Twitter credentials file path | accounts.txt |
TWITTER_MAX_TWEETS |
Max tweets per poll | 50 |
TWITTER_SEARCH_TYPE |
Search type: latest or top |
latest |
TWITTER_LANGUAGE |
Language filter | en |
Default keywords (case-insensitive):
$hylohylohyusdshyusdxsolxbtcxeth
Customize by editing KEYWORDS in .env.
Alerts are sent to Telegram in this format:
π’ 2026-01-23 14:30:45 HYLO ALERT
π https://twitter.com/username/status/123456789
π€ @username (5,432 followers)
π¬ Just bought some $hylo! π
The system uses twscrape to fetch real Twitter data without requiring official API access. This approach is more accessible but requires Twitter account credentials.
-
Create accounts file:
cp accounts.txt.example accounts.txt nano accounts.txt
-
Add Twitter account credentials (format:
username:password:email:email_password):myuser1:mypass1:email1@example.com:emailpass1 myuser2:mypass2:email2@example.com:emailpass2Important notes:
- Use dedicated accounts, not your personal Twitter account
- Multiple accounts improve reliability and rate limits (recommended: 2-5 accounts)
- Aged accounts work better than brand new accounts
- Accounts should have email verification enabled
- Keep
accounts.txtsecure (already in.gitignore)
-
Enable Twitter scraper in
.env:USE_MOCK_PROVIDER=false TWITTER_ACCOUNTS_FILE=accounts.txt TWITTER_MAX_TWEETS=50 TWITTER_SEARCH_TYPE=latest TWITTER_LANGUAGE=en
-
Run the system:
# With Docker docker-compose up -d # Or locally python main.py
- No official API required: Scrapes Twitter directly using account sessions
- Keyword search: Automatically searches for all configured keywords
- Automatic filtering: Only returns tweets matching your criteria
- Rate limit handling: Rotates between multiple accounts to avoid limits
- Deduplication: Tracks seen tweets to avoid duplicate alerts
| Variable | Description | Default |
|---|---|---|
TWITTER_ACCOUNTS_FILE |
Path to account credentials file | accounts.txt |
TWITTER_MAX_TWEETS |
Max tweets per poll | 50 |
TWITTER_SEARCH_TYPE |
latest or top tweets |
latest |
TWITTER_LANGUAGE |
Language filter (e.g., en) |
en |
Accounts getting locked:
- Use aged accounts (1+ months old)
- Don't scrape too aggressively (increase
POLL_INTERVAL_SECONDS) - Add more accounts to distribute load
- Use residential IP addresses when possible
No tweets found:
- Check that keywords match actual Twitter content
- Try
TWITTER_SEARCH_TYPE=topfor popular tweets - Increase
TWITTER_MAX_TWEETS - Verify accounts are logged in (check logs)
Rate limits:
- Add more accounts to the pool
- Increase
POLL_INTERVAL_SECONDS - Reduce
TWITTER_MAX_TWEETS
Optimized for low-resource VPS environments:
- CPU: ~0.25-0.5 cores
- Memory: 128-256 MB
- Disk: ~50 MB (container)
- Network: Minimal (polling-based)
# Build image
docker-compose build
# Start in background
docker-compose up -d
# View logs
docker-compose logs -f telegram-monitor
# Restart container
docker-compose restart
# Stop and remove
docker-compose down
# View resource usage
docker stats social-media-monitordocker-compose psdocker-compose logs -fdocker-compose exec telegram-monitor shThe application prints statistics periodically in logs:
[Monitor] Statistics: {
'total_posts_processed': 150,
'posts_filtered_followers': 45,
'posts_filtered_keywords': 89,
'posts_filtered_duplicates': 3,
'alerts_sent': 13
}
-
Connect to your VPS:
ssh user@your-vps-ip
-
Clone repository:
git clone <your-repo-url> cd telegram-tracking-app
-
Configure environment:
cp .env.example .env nano .env # Add your credentials -
Deploy with Docker:
docker-compose up -d
-
Set up auto-restart (optional):
# Docker Compose will auto-restart on failure # To start on boot, enable Docker service: sudo systemctl enable docker
- Never commit
.envfile to version control - Use environment-specific
.envfiles - Rotate bot tokens periodically
- Monitor logs for suspicious activity
- Keep Docker images updated
- Verify bot token is correct
- Ensure bot is admin in the channel
- Check channel ID format (
@channelnameor-100...)
- Verify
USE_MOCK_PROVIDER=truefor testing - For Twitter: Check accounts are valid and logged in
- Review keyword configuration
- Check
POLL_INTERVAL_SECONDSis appropriate
- Reduce
DEDUP_CACHE_SIZE - Decrease
MOCK_POSTS_PER_POLL - Increase
POLL_INTERVAL_SECONDS
# Check logs for errors
docker-compose logs --tail=100 telegram-monitor
# Verify environment variables
docker-compose config# With mock provider (default)
USE_MOCK_PROVIDER=true python main.py
# With Twitter scraper
USE_MOCK_PROVIDER=false python main.py
# Test with specific keywords
KEYWORDS="test,debug" python main.py- Type hints on all functions
- Async/await for I/O operations
- Docstrings for classes and methods
- PEP 8 formatting
This project is provided as-is for monitoring social media content.
For issues or questions:
- Check logs:
docker-compose logs -f - Review configuration in
.env - Verify bot permissions in Telegram
- Twitter data scraping with twscrape
- Database persistence for historical data
- Web dashboard for statistics
- Multiple channel support
- Sentiment analysis
- Custom alert templates
- Advanced filtering rules (regex, user lists)
- Twitter Spaces monitoring
- Support for other platforms (Reddit, Discord)
Built with β€οΈ using Python, asyncio, twscrape, and Telegram Bot API