- 可转发内容到私聊/频道/群组(有且只能有一个)
- 关键字匹配可使用黑名单和白名模式,正则表达式匹配为白名单模式(/subscribe指令添加 -w 参数代表白名单模式)
- 完整转发消息,但(文字+媒体)类型消息选择链接预览
- 添加/info指令,用于获取群组或频道ID
本质上修改成了针对某些频道,过滤不需要的消息
用户可以自行向Telegram的BotFather添加以下指令:
botfather -> 选择bot -> Edit Bot -> Edit Commands 发送以下内容
start - 开始
info - 显示群组/频道ID
subscribe - 关键字1,关键字2/正则表达式 频道1,群组2 [转发目标ID] (-w)白名单参数
unsubscribe_id - id1,id2
unsubscribe_all - 删除所有规则
list - 显示所有订阅列表
help - 帮助
先配置config.yml
git clone https://github.com/Heavrnl/keyword_alert_bot.git
cd ./keyword_alert_bot
docker build -t heavrnl/keyword_alert_bot .
docker run -it --name keyword_alert_bot -v $(pwd)/config.yml:/app/config.yml heavrnl/keyword_alert_bot
展开查看原始内容
# 🤖Telegram keyword alert bot⏰Telegram关键字提醒机器人,用于实时监测频道/群组中的关键字消息。
确保普通Telegram账户能够在不需要验证的情况下加入指定群组。
Warning: Demo bot使用过载,建议使用 Docker 镜像自行搭建。
👉 Features:
-
关键字消息订阅:根据设定的关键字和频道实时推送消息提醒
-
支持正则表达式匹配语法
-
支持多频道订阅 & 多关键字订阅
-
支持订阅群组消息
-
支持私有频道ID/邀请链接的消息订阅
👉 Todo:
- 私有群组订阅和提醒
- 私有频道消息提醒完整内容预览
- 多账号支持
- 扫描退出无用频道/群组
将 config.yml.default 复制到本地并重命名为 config.yml,然后根据下面申请的 api 进行配置
建议使用新Telegram账户开通api 来使用
https://t.me/BotFather 创建机器人
配置好config.yml文件后,使用docker命令一键启动
$ docker run -it --name keyword_alert_bot -v $(pwd)/config.yml:/app/config.yml yha8897/keyword_alert_bot
Please enter the code you received: 12345
Please enter your password:
Signed in successfully as DEMO; remember to not break the ToS or you will risk an account ban!
#################################################################
## ##
## ● success ##
## 🤖️Telegram keyword alert bot (Version: 20240627.f6672cf) ##
## ##
#################################################################
首次运行需要Telegram账户接收数字验证码,并输入密码(Telegram API触发),之后提示success即成功启动
之后可以直接根据容器名重启或者停止:
$ docker restart keyword_alert_bot
$ docker stop keyword_alert_bot
运行环境 python3.7+
$ pipenv install
$ pipenv shell
$ python3 ./main.py
- update telethon
依赖库telethon可能存在旧版本不可用的情况或其他BUG,建议通过定时任务执行依赖更新。
e.g.
0 0 * * * cd /PATH/keyword_alert_bot && pipenv telethon > /dev/null 2>&1
/subscribe 免费 https://t.me/tianfutong
/subscribe 优惠券 https://t.me/tianfutong
使用类似JavaScript正则语法规则,用/包裹正则语句,目前可以使用的匹配模式:i,g
# 订阅手机型号关键字:iphone x,排除XR,XS等型号,且忽略大小写
/subscribe /(iphone\s*x)(?:[^sr]|$)/ig com9ji,xiaobaiup
/subscribe /(iphone\s*x)(?:[^sr]|$)/ig https://t.me/com9ji,https://t.me/xiaobaiup
# xx券
/subscribe /([\S]{2}券)/g https://t.me/tianfutong
Bug Feedback: https://github.com/Hootrix/keyword_alert_bot/issues
BOT中所有订阅频道的总数超过 500。原因是BOT使用的Telegram演示账户限制导致。建议你自行部署
🤔尝试更新telethon到最新版本或者稳定的1.24.0版本
$ pipenv install
/(?=.*cc)(?=.*bb)(?=.*aa).*/
[USDT-TRC20]:TDELNhqYjMJvrChjcTBiBBieWYiDGiGm2r