This project provides a Telegram bot that monitors specific groups or channels for messages containing predefined keywords. Upon detection, the bot forwards these messages to a designated Telegram channel. Additionally, it supports excluding messages from particular users.
- Keyword Monitoring: Monitors messages in specified Telegram groups or channels based on user-defined keywords.
- Message Forwarding: Automatically forwards detected messages to a specified Telegram channel.
- User Exclusion: Enables the bot to ignore messages from specific users by their Telegram user ID.
- Logging: Includes detailed logging for better debugging and monitoring.
- Python 3.12.1
- Telegram account
- Telegram bot token
To install and configure the bot, run the following command in your terminal:
bash <(curl https://raw.githubusercontent.com/ItsOrv/Telegram-Message-Monitor/main/install.sh)
This script will install Docker and Docker Compose, clone the project repository, prompt you for required environment variables, create a .env
file, and set up a Docker container. After installation, the tmm
command will be available for managing the Docker container.
During the installation process, you will be prompted to provide the following environment variables:
API_ID=your_api_id
API_HASH=your_api_hash
BOT_TOKEN=your_bot_token
CHANNEL_ID=your_channel_id
API_ID
andAPI_HASH
: Obtain these from my.telegram.org.BOT_TOKEN
: Generated through the BotFather on Telegram.CHANNEL_ID
: ID of the channel where messages will be forwarded.
After installation, you can manage the Docker container using the tmm
command. Available options are:
- Start container: Starts the container if it is not already running.
- Stop container: Stops the container if it is running.
- Restart container: Restarts the container and checks for correct installation.
- Update project from GitHub: Pulls the latest changes from the GitHub repository and rebuilds the container.
- Uninstall project: Stops and removes the Docker container, deletes the project directory, and removes the
tmm
command. - Exit: Exits the script.
To install the bot manually, follow these steps:
-
Clone the repository:
git clone https://github.com/ItsOrv/Telegram-Message-Monitor.git cd Telegram-Message-Monitor
-
Set up a virtual environment (optional but recommended):
python3 -m venv venv source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Configure the environment: Create a
.env
file in the project’s root directory with the following contents:API_ID=your_api_id API_HASH=your_api_hash BOT_TOKEN=your_bot_token CHANNEL_ID=your_channel_id
API_ID
andAPI_HASH
: Obtain these from my.telegram.org.BOT_TOKEN
: Generated through the BotFather on Telegram.CHANNEL_ID
: ID of the channel where messages will be forwarded.
To run the bot, use the following command:
python3 src/main.py
The bot will begin monitoring the specified Telegram groups or channels, forwarding any detected messages containing the specified keywords to your designated channel. Messages from ignored users will be excluded.
The bot is equipped with error handling mechanisms for common scenarios, including:
- Two-Factor Authentication (2FA): If 2FA is enabled, the bot will prompt for the necessary second factor.
- General Errors: Logs any unexpected issues that occur during message processing or while starting the client.
Contributions are welcome! Feel free to submit a pull request or open an issue to discuss proposed changes.
- 1.1:
Fix handling of private group links (prepend a 1 to the link). - 1.2:
Support for links from Glass Telegram groups. - 2.1:
Refactor Docker setup to support running both Python scripts simultaneously. - 2.2:
Add CLI control for restarting/updating the bot, or possibly implement these controls via the Telegram bot interface. - 3.1:
Createinstall.sh
script - 4.1:
Combinemanagement.py
andbot.py
into a single Python script. - 5.1: Fix
await event.respond
. - 5.2: Fix docker setup.
- 5.3 Fix
install.sh
file.
Feel free to adjust any details as needed!