Telegram Keyword Alert Bot Setup Guide
Recently, I developed a Telegram keyword alert bot
uploaded to GithubThis article describes the setup process.
First, you can take a look at the readme of the Github project, which is a step-by-step illustrated tutorial in operating order from start to finish.
If you find that tutorial a bit confusing, then below, I'll describe it from a different angle.
System Architecture
Information Source -> Collector -> This Program -> Publisher -> Consumer
Components of the System
Information Source is the various tg groups and channels you want to monitor
Collector is a tg account
* It is recommended that you register a new tg account to play with.
This Program is the main.py of this project
* This program requires api_id and api_hash. You need to apply for them at https://my.telegram.org/apps. You need to log in to a tg account here, which can be the same account as the collector, or a different account.
Publisher is a tg bot
* This program requires bot_token, which needs to be applied for from https://t.me/BotFather. The tg account that initiates the bot application to @BotFather can be the same account as before, or a different account.
Consumer is the user or group or channel that receives keyword notification messages
Runtime Environment for This Project
Install python
Generally, the relatively new versions of operating systems Debian / Ubuntu you use already come with it.
Omitted
Install pip
apt install -y python3-pip
Pull the project
apt install -y git
git clone https://github.com/crazypeace/tg-keyword-monitor-bot
cd tg-keyword-monitor-bot
Install python dependencies
pip3 install -r requirements.txt --break-system-packages
Copy config.yaml.default to config.yaml
Relationships Between Components in the System
Relationship between Information Source and Collector
You log in as the collector account and join the information source.
Group entry verification, non-public groups need someone to invite you, require admin approval, ... and so on. These issues need to be resolved by yourself.
Relationship between Collector and This Program
Edit config.yaml
Starting this program requires api_id and api_hash
Edit config.yaml
Settings for this program's keyword filtering
Edit config.yaml
Relationship between This Program and Publisher
Edit config.yaml
Relationship between Publisher and Consumer
Edit config.yaml
Running This Project
python3 ./main.py
The command line prompts you to enter the verification code, and at the same time, the telegram account receives a verification code
Enter this verification code into the command line
* A verification code is only required the first time you run it. No verification code is needed for subsequent runs.
========
The above is the basic setup of this project.
========
Postscript
If you need to run the bot for a long time.
You can enable the service
cp tg-keyword-monitor-bot.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable tg-keyword-monitor-bot.service
systemctl start tg-keyword-monitor-bot.service
* If your directory is not /root/tg-keyword-monitor-bot, please edit the contents of the tg-keyword-monitor-bot.service file yourself
If you want to use an administrator tg account to send commands to the bot to modify the keyword list.
Edit config.yaml
========
Why did I design Consumer and Administrator this way?
This is related to my envisioned commercialization plan. Coming soon. Welcome to follow my blog. :)
========









