Ever wondered what's happening in your Telegram channels and chats but got tired of manual tracking? Meet TG Stats Dashboard Bot - your friendly neighborhood statistics collector that turns Telegram data into neat Google Sheets dashboards.
100% Free, hosting included. Made for content creators who use private telegram chats and channels and want to show what's behind the paywall.
Example (ru) for the https://boosty.to/rzv_de data engineering community. Click the link and try yourself:
---> Datalens BI dashboard <---
This bot is your Swiss Army knife for Telegram analytics, designed for community managers, content creators, and data enthusiasts who want to:
- Show how much content do you have behind the paywall (for Boosty, Patreon etc)
- Track channel growth
- Monitor chat activity patterns
- Analyze content performance
- Build custom dashboards without coding
Unlike official Telegram analytics, this tool gives you raw data in Google Sheets, letting you slice and dice it however you want. Plus, it works with private channels and tracks way more metrics!
-
π Channel Analytics
- Member count tracking
- Message volume monitoring
- Hashtag usage analysis
- Word frequency tracking
-
π¬ Chat Insights
- Topic activity monitoring
- Message distribution by hour
- User engagement patterns
-
π Automated Collection
- GitHub Actions integration for scheduled runs
- Configurable collection intervals
- Cache system for reliable data gathering
- Progress tracking with detailed logging
-
π Data Processing
- Word normalization (supports English and Russian)
- Smart deduplication
- Rate limit-aware collection
-
π‘οΈ Privacy & Security
- Uses your own Telegram account (no bot token needed)
- Private channel support
- Masked channel IDs in logs
- Onlly processed content storage (normalized or aggregated)
- Python 3.10 or higher
- Google account with access to Google Cloud Console
- Telegram account (no bot token needed!)
- Basic familiarity with command line
- ~50MB of disk space
# Clone the repository
git clone https://github.com/yourusername/tg-stats-dashboard-bot.git
cd tg-stats-dashboard-bot
# Create and activate virtual environment
python -m venv venv
source venv/bin/activate # Linux/MacOS
venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
- Visit https://my.telegram.org/apps
- Log in with your phone number
- Create new application if you don't have one
- Save your
api_id
andapi_hash
- you'll need these later
This is a bit tricky but super important - we need to create a special session string that lets the bot access Telegram using your account:
# Run this in Python console
from telethon.sessions import StringSession
from telethon.sync import TelegramClient
api_id = 123456 # Your api_id here
api_hash = "your_api_hash_here"
with TelegramClient(StringSession(), api_id, api_hash) as client:
print(client.session.save())
You'll be asked to:
- Enter your phone number
- Input the verification code sent to your Telegram
- Provide 2FA password if enabled
Save the long string that's printed - this is your session string!
- Go to Google Cloud Console
- Create a new project (or select existing)
- Enable Google Sheets API:
- Navigate to "APIs & Services" > "Library"
- Search for "Google Sheets API"
- Click "Enable"
- Go to "IAM & Admin" > "Service Accounts"
- Click "Create Service Account"
- Fill in the details:
- Name: e.g., "tg-stats-bot"
- Role: No role needed
- Click "Create and Continue"
- Click "Done"
- Find your new service account in the list
- Create key:
- Click on the service account
- Go to "Keys" tab
- "Add Key" > "Create new key"
- Choose JSON
- Download the file (keep it safe!)
- Create a new Google Sheet
- Share it with the service account email (found in your JSON file)
- Copy the sheet URL - you'll need it for configuration
Create .env
file in the project root:
TELEGRAM_API_ID=your_api_id
TELEGRAM_API_HASH=your_api_hash
TG_SESSION="your_session_string"
# Channels to track - format is important!
TELEGRAM_CHANNELS={"channels":["https://t.me/channel1","https://t.me/+invite_link2"],"chats":["https://t.me/chat1"]}
# Google configuration
GOOGLE_SHEET_URL=your_sheet_url
GOOGLE_CREDENTIALS_PATH=path_to_your_downloaded.json
# Other settings
TIMEZONE=Europe/Moscow
MODE=regular # or 'backfill' for historical data
Pro Tips:
- For private channels, use invite links in the TELEGRAM_CHANNELS config
- Make sure you're a member of all channels/chats you want to track
- Keep your credentials file secure - never commit it to git!
The bot creates several sheets in your Google Spreadsheet, each serving a specific purpose:
Key columns: channel_id, date
Data: channel_name, member_count, messages_count
Updated: Daily rewrite
Is used to store current total number of members and messages. Does not store history (yet).
Key columns: channel_id, message_id, word
Data: message date, normalized words
Updated: Every run
Great for content analysis:
- Most used words
- Topic trends
- Content patterns
- Language analysis
Key columns: chat_id, topic_id, hour
Data: topic_name, message_count, first/last message IDs
Updated: Hourly aggregation
Perfect for forum-style chats:
- Topic popularity
- Discussion peaks
- Activity heatmaps
Key columns: channel_id, message_id, hashtag
Data: usage date, hashtag text
Updated: Every run
Track hashtag performance:
- Popular tags
- Usage patterns
- Campaign tracking
- Content categorization
Quick start for testing or one-off collection:
python -m src.main
For automated collection, use the included GitHub Actions workflow:
- Fork this repository
- Add these repository secrets:
TELEGRAM_API_ID TELEGRAM_API_HASH TELEGRAM_CHANNELS GOOGLE_SHEET_URL GOOGLE_CREDENTIALS (entire JSON content) TG_SESSION
- Enable Actions in your repository
- The bot will run automatically twice daily (can be customized in
.github/workflows/stats.yml
)
- β±οΈ Rate limits may slow down collection
- π± Phone number verification required initially
- π No historical data beyond available messages
- π Message edits might be missed
- ποΈ Deleted messages not tracked
- π Requires user account (not bot)
- π Google Sheets row limit (5M per sheet)
- β‘ RAM usage scales with channel count
- Check existing issues first
- Use the bug report template
- Include:
- Your Python version
- Complete error traceback
- Steps to reproduce
- Expected vs actual behavior
- Open an issue with 'enhancement' label
- Describe the feature and its value
- Provide use cases if possible
We love PRs! Here's how to make them awesome:
- Fork the repo
- Create a feature branch
git checkout -b feature/amazing-feature
- Make your changes
- Add tests if applicable
- Update documentation
- Submit PR with detailed description
Code Style:
- Follow PEP 8
- Use meaningful variable names
- Add comments for complex logic
- Keep functions focused and small
# Fork and clone your fork
git clone https://github.com/yourusername/tg-stats-dashboard-bot.git
cd tg-stats-dashboard-bot
# Create development environment
python -m venv venv
source venv/bin/activate # Linux/MacOS
venv\Scripts\activate # Windows
# Install dev dependencies
pip install -r requirements.txt
pip install black flake8 pytest # Development tools
# Create branch for your feature
git checkout -b feature/your-amazing-feature
# Happy coding! π
This project is licensed under the MIT License.
Made with β€οΈ by Razvodov Aleksei. Star β if you find it useful!
Need help? Open an issue or join our discussions!