Night Watch is a powerful Telegram bot inspired by Batman's vigilant guardian role. It acts as a silent protector that monitors specific Telegram groups and channels for keywords, automatically forwarding relevant messages to designated users. This tool is perfect for staying informed about important discussions, mentions, or events across multiple Telegram communities without having to actively monitor each one.
- Bot Membership: The bot must be a member of the groups or channels it's monitoring to be able to read and forward messages. Make sure to add the bot to all target groups/channels before starting the monitoring.
- Privacy: This bot forwards messages, so ensure you have permission to monitor the target channels
- Rate Limits: Be mindful of Telegram's API rate limits
- Session Security: Keep your session string secure and private
- Legal Compliance: Ensure compliance with local laws and Telegram's Terms of Service
- Language: TypeScript
- Runtime: Node.js
- Telegram API:
telegramlibrary - Package Manager: pnpm
- Containerization: Docker & Docker Compose
- Environment Management: dotenv
- Logging: Custom logger with chalk for colored output
Night Watch is particularly useful for:
- Social Media Monitoring: Track brand mentions, product discussions, or competitor activity
- News Aggregation: Monitor news channels for specific topics or keywords
- Community Management: Stay informed about important discussions in multiple groups
- Security Monitoring: Watch for security-related discussions or mentions
- ✅ Multi-Channel Monitoring: Monitor multiple groups and channels simultaneously
- ✅ Keyword-Based Filtering: Forward messages containing specific keywords
- ✅ Flexible Configuration: Easy setup through environment variables
- ✅ Real-time Processing: Instant message forwarding
- ✅ Docker Support: Easy deployment and scaling
- ✅ Colored Logging: Clear and informative console output
- Node.js 20+
- pnpm (recommended) or npm
- Telegram API credentials
- Docker (for containerized deployment)
git clone <repository-url>
cd nightwatchpnpm installCreate a .env file in the root directory:
# Telegram API Credentials
API_ID=your_api_id
API_HASH=your_api_hash
STRING_SESSION=your_string_session
# Forwarding Configuration
FORWARD_TO=username_or_id_to_forward_messages_to
# Monitoring Targets (comma-separated)
TARGET_IDS="123456789,987654321"
TARGET_USERNAMES="channel1,channel2,group1"
# Keywords to Monitor (comma-separated)
KEYWORDS="keyword1,keyword2,important,urgent"- Visit my.telegram.org
- Log in with your phone number
- Go to "API Development Tools"
- Create a new application
- Copy the
API_IDandAPI_HASH
Run the bot for the first time to generate a session:
pnpm run devFollow the prompts to authenticate with your phone number and 2FA if enabled.
pnpm run dev# Build the project
pnpm run build
# Start the application
pnpm start| Variable | Description | Example |
|---|---|---|
API_ID |
Telegram API ID | 12345678 |
API_HASH |
Telegram API Hash | abcdef1234567890abcdef1234567890 |
STRING_SESSION |
Telegram session string | Generated automatically when app is running (you can log and save it to prevent login every time) |
FORWARD_TO |
Username forward messages to | username |
TARGET_IDS |
Channel/Group IDs to monitor | 123456789,987654321 |
TARGET_USERNAMES |
Channel/Group usernames to monitor | channel1,group1 |
KEYWORDS |
Keywords to trigger forwarding | important,urgent,breaking |
You can monitor targets using either:
- IDs: Numeric identifiers (more reliable)
- Usernames: @username format (easier to manage)
- Keywords are matched case-insensitively
- Partial matches are supported
- Multiple keywords can be specified (comma-separated)
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Improve code structure and organization
This project is licensed under the MIT License.
Night Watch - Keeping you informed, one message at a time 🦇
Inspired by Batman's vigilant guardian role
