Monitor selected Telegram groups and automatically forward messages from chosen users (admins or manually selected members) to a destination chat — preserving media, captions, and formatting.
Uses your personal Telegram account via Telethon (not the Bot API), so you can monitor any group you are a member of.
- User ID matching — Users are stored and matched by immutable Telegram user IDs, not usernames
- Flexible watch modes — Watch admins only, selected users, or both
- Media preservation — Forwards photos, videos, voice notes, documents, and captions
- Duplicate prevention — Tracks forwarded messages in SQLite to avoid re-sending
- Auto-reconnect — Recovers automatically after network interruptions
- Rate limit handling — Graceful backoff on Telegram flood waits
- Interactive CLI — Rich terminal UI for managing groups and users
- Extensible architecture — Notification backend port ready for Discord, Slack, Email, ntfy, webhooks
- Python 3.12 or newer
- A Telegram API application (
api_id+api_hash) - A personal Telegram account
git clone https://github.com/Fraeiy/sentri.git
cd sentri
python -m venv .venv
# Windows
.venv\Scripts\activate
# Linux / macOS / Termux
source .venv/bin/activate
pip install -e ".[dev]"cp .env.example .envEdit .env and set your Telegram API credentials:
TELEGRAM_API_ID=12345678
TELEGRAM_API_HASH=your_api_hash_heresentri authEnter your phone number, verification code, and 2FA password if enabled. A session file is saved to ./data/session.session.
# Interactive menu (recommended for first-time setup)
sentri interactive
# Or use individual commands:
sentri config set-destination # Where to forward messages
sentri groups add # Add a group to monitor
sentri users add # Add users to watch (by user ID)
sentri users sync-admins # Auto-discover group adminssentri watchPress Ctrl+C to stop.
Sentri includes a browser-based UI that mirrors the CLI — manage groups, users, destination, authentication, and start/stop the watcher without the terminal.
pip install -e ".[web]"sentri webOpen http://127.0.0.1:8080 in your browser.
- Dashboard with live status
- Telegram login (phone → code → 2FA)
- Add groups and users from Telegram dialogs
- Set destination chat
- Start/stop background watcher
- Sync group admins
| Variable | Default | Description |
|---|---|---|
SENTRI_WEB_HOST |
127.0.0.1 |
Bind address |
SENTRI_WEB_PORT |
8080 |
Bind port |
SENTRI_WEB_TOKEN |
(none) | Optional access token |
When WEB_TOKEN is set, append ?token=your_token to the URL or send Authorization: Bearer your_token.
Security: Bind to
127.0.0.1by default. Only expose to your network with aWEB_TOKENset.
# Install Python 3.12+ from https://www.python.org/downloads/
# Ensure "Add Python to PATH" is checked during installation
git clone https://github.com/Fraeiy/sentri.git
cd sentri
python -m venv .venv
.venv\Scripts\activate
pip install -e ".[dev]"
copy .env.example .env
# Edit .env with your API credentials
sentri auth
sentri interactivesudo apt update
sudo apt install python3.12 python3.12-venv git
git clone https://github.com/Fraeiy/sentri.git
cd sentri
python3.12 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
cp .env.example .env
nano .env # Set API credentials
sentri auth
sentri interactive# Install Python via Homebrew
brew install python@3.12 git
git clone https://github.com/Fraeiy/sentri.git
cd sentri
python3.12 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
cp .env.example .env
# Edit .env with your API credentials
sentri auth
sentri interactivepkg update && pkg upgrade
pkg install python git
git clone https://github.com/Fraeiy/sentri.git
cd sentri
python -m venv .venv
source .venv/bin/activate
pip install -e .
cp .env.example .env
nano .env # Set API credentials
sentri auth
sentri interactive
# Run in background with tmux:
pkg install tmux
tmux new -s tgwatch
sentri watch
# Detach: Ctrl+B then DTermux note: Keep Termux alive in the background (disable battery optimization for Termux) so the watcher stays connected.
| Command | Description |
|---|---|
sentri auth |
Authenticate with Telegram |
sentri watch |
Start monitoring and forwarding |
sentri web |
Launch the web dashboard |
sentri status |
Show configuration summary |
sentri interactive |
Launch interactive menu |
sentri groups list |
List monitored groups |
sentri groups add |
Add a group interactively |
sentri groups enable <id> |
Enable a group |
sentri groups disable <id> |
Disable a group |
sentri groups edit <id> |
Edit group settings |
sentri groups remove <id> |
Remove a group |
sentri users list <group_id> |
List watched users |
sentri users add <group_id> |
Add a user (matched by ID) |
sentri users sync-admins <group_id> |
Sync admin users from Telegram |
sentri users remove <id> |
Remove a watched user |
sentri config set-destination |
Set global forward destination |
sentri config show |
Show all configuration |
| Mode | Behavior |
|---|---|
selected_users |
Forward only manually added users |
admins_only |
Forward all group admins |
admins_and_selected |
Forward admins plus manually added users |
Usernames on Telegram can change at any time. Sentri stores and matches users by their immutable numeric user ID internally. The CLI displays usernames and display names for convenience, but all matching logic uses user_id.
CLI display: Alice Smith · @alice · id:123456789
Internal key: user_id = 123456789
# Build
docker compose build
# Authenticate (interactive, one-time)
docker compose run --rm sentri auth
# Configure (interactive)
docker compose run --rm sentri interactive
# Start watching
docker compose up -d
# View logs
docker compose logs -fData (session, database, logs) is persisted in the tg-data Docker volume.
src/sentri/
├── cli/ # Typer CLI + Rich UI
├── config/ # Pydantic settings
├── core/
│ ├── models.py # Domain models
│ ├── ports.py # Interfaces (repositories, notification backends)
│ └── services/ # Business logic (MonitorService)
├── infrastructure/
│ ├── database/ # SQLite repository
│ ├── telegram/ # Telethon client, events, formatter
│ └── notifications/ # Notification backends (Telegram, future: Discord, etc.)
└── utils/ # Logging, rate limiting
The codebase follows clean architecture principles:
- Core contains business logic and abstract ports — no Telethon or SQLite imports
- Infrastructure implements ports with concrete adapters
- Notification backends implement
BaseNotificationBackendand register viaNotificationRegistry
from sentri.infrastructure.notifications.base import (
BaseNotificationBackend,
notification_registry,
)
class DiscordBackend(BaseNotificationBackend):
@property
def name(self) -> str:
return "discord"
async def send_text(self, text: str, *, destination: int | str) -> int | str:
# Send to Discord webhook/channel
...
async def send_media(self, media, *, caption, destination) -> int | str:
...
notification_registry.register("discord", DiscordBackend)All configuration is stored in SQLite (./data/sentri.db by default). Environment variables control runtime settings:
| Variable | Default | Description |
|---|---|---|
TELEGRAM_API_ID |
(required) | Telegram API ID |
TELEGRAM_API_HASH |
(required) | Telegram API hash |
SENTRI_DATA_DIR |
./data |
Data directory |
SENTRI_LOG_LEVEL |
INFO |
Log level |
SENTRI_RECONNECT_MAX_DELAY |
300 |
Max reconnect delay (seconds) |
SENTRI_RATE_LIMIT_MAX_RETRIES |
5 |
Max rate limit retries |
# Install dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Lint
ruff check src tests
ruff format src tests
# Type check
mypy src/sentri --ignore-missing-importsContributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Write tests for new functionality
- Ensure
ruff checkandpytestpass - Submit a pull request
MIT License — see LICENSE for details.
This tool uses the Telegram Client API with your personal account. Use responsibly and in compliance with Telegram's Terms of Service. The authors are not responsible for any account restrictions resulting from misuse.