TeleShield — Telegram 廣告封鎖守衛
自動檢測並封鎖 Telegram 個人帳號收到的廣告/垃圾訊息,每日可攔截數十條垃圾訊息。
Overview
TeleShield 是一個執行在 VPS 上的 Telegram 使用者端守衛,使用 Telethon 庫監控非聯絡人私訊,自動檢測廣告、垃圾訊息並進行攔截或舉報。
Problem
Telegram 個人帳號收到大量廣告/垃圾私訊,手動封鎖耗時且煩人。現有方案多為群組機器人,無法保護個人帳號。
Constraints
- 必須使用 MTProto API(非 Bot API)
- 不能誤傷正常私訊
- 需在 VPS 上 24/7 執行
- 需符合 Telegram 使用條款
Approach
使用 Telethon (MTProto) 登入個人帳號,通過關鍵字匹配 + 行為分析雙重檢測機制判斷垃圾訊息。支援自動封鎖、舉報、日誌記錄。
Key Decisions
使用 Telethon 而非 Bot API
Reasoning:
Bot API 無法存取個人私訊,必須使用 MTProto 協議
Alternatives considered:
- Telegram Bot API
- Pyrogram
關鍵字 + 行為雙重檢測
Reasoning:
單純關鍵字匹配誤報率高,結合發送頻率、帳號年齡等行為特徵可大幅降低誤報
Alternatives considered:
- 純關鍵字匹配
- ML 分類器
Tech Stack
- Python 3
- Telethon
- SQLite
- systemd
Result & Impact
- 5GitHub Stars
提供了一個開箱即用的個人 Telegram 防騷擾方案。
Learnings
- MTProto API 的 rate limiting 機制
- 關鍵字匹配的邊界處理(多語言、變體)
TeleShield 是一個執行在 VPS 上的 Telegram 使用者端守衛,使用 Telethon 庫監控非聯絡人私訊,自動檢測廣告、垃圾訊息並進行攔截或舉報。