Telegram 羣組管理員瞭解語義反垃圾與關鍵字過濾的分別
Understanding Semantic Anti‑Spam vs. Keyword Filters for Telegram Group Admins
這份教學比較 Telegram 羣組的關鍵字過濾與語義反垃圾,並示範如何在 AIGB 啟用語義過濾及搭配關鍵字清單。AIGB 的語義過濾使用 LLM 判斷訊息的垃圾內容機率,支援 14 種語言。每則訊息的額外 API 呼叫約需 200‑400 ms,管理員可調整垃圾訊息閾值以配合羣組需要。
Introduction
Running a Telegram community means constantly battling unwanted content: promotional links, phishing attempts, repeated nonsense, and language‑specific abuse. The classic defense—keyword filters—relies on a static list of banned words or patterns. While easy to set up, keyword filters become brittle quickly, generate false positives, and are easy for spammers to evade with minor text variations.
Semantic anti‑spam, powered by large language models (LLMs), evaluates the meaning of a message instead of its literal characters. By scoring the intent behind a piece of text, it can block messages that are obviously spammy even when they contain no blacklisted words, while letting legitimate conversations pass.
In this tutorial you’ll learn:
- How keyword filters operate and why they fall short.
- The core concepts behind AI‑driven semantic anti‑spam.
- How to enable and fine‑tune the built‑in semantic filter in AIGB (AI GroupButler, free forever, @groupbutleraibot, gensi.space/upanel) for a multilingual Telegram group.
- Practical tips for combining both approaches for maximum coverage.
1. Keyword Filters – The Basics
| Step | What Happens |
|---|---|
| 1. Define a word list | Admins create an array of banned strings (e.g., "free money", "buy now"). |
| 2. Regex matching | Each incoming message is run through a regular‑expression engine. |
| 3. Action | If a match is found, the bot can delete the message, warn the user, or mute the account. |
1.1 Advantages
- Speed: Simple string matching is virtually instantaneous.
- Predictability: You know exactly which words trigger a block.
1.2 Drawbacks
-
Evasion: Spammers insert spaces, zero‑width characters, or synonyms (
f r e e m o n e y). - False positives: Legitimate discussions about “free software” or “money‑talk” may be blocked.
- Maintenance overhead: The list must be constantly updated as new spam trends appear.
2. Semantic Anti‑Spam – How It Works
Semantic filters use an LLM (e.g., Mistral, Groq‑qwen) to produce a spam probability for each message. The model looks at the whole context, language, and typical spam patterns rather than just matching characters.
2.1 Processing Pipeline
- Message ingestion – The raw text is sent to the model via the bot’s API.
- Embedding & inference – The model converts the text into a high‑dimensional vector and runs a classification head trained on labeled spam/ham data.
-
Score output – A probability
p_spam ∈ [0,1]is returned. -
Threshold decision – If
p_spam > T(whereTis a configurable threshold, e.g.,0.75), the bot executes the configured action (delete, warn, mute).
2.2 Benefits
- Context awareness: Detects spam even when the message contains no banned words.
- Multilingual support: Works across the 14 languages AIGB supports without separate word lists.
- Adaptability: The threshold can be tuned per group size and activity level.
2.3 Limitations
- Latency: An extra API call adds roughly 200‑400 ms per message (still acceptable for most groups).
- Cost: Semantic checks consume tokens from your allocated pool; keep an eye on usage.
3. Enabling the Semantic Filter in AIGB
Below are the step‑by‑step instructions for turning on the semantic filter and pairing it with a lightweight keyword list.
3.1 Prerequisites
- The bot @groupbutleraibot must be added to your group with at least “Delete messages” permission.
- You need a user account on the web panel at gensi.space/upanel.
3.2 Turn on the Feature
- Log in to the panel and select the target group from the dashboard.
- Navigate to Anti‑Spam → Semantic Filter.
- Toggle the switch to ON.
- Set the Spam Threshold. The default
0.80works for most communities; lower it for stricter moderation, raise it to reduce false positives.
3.3 Add a Small Keyword List
Even with semantic detection, a short keyword list catches obvious scams instantly. Paste the following JSON into the Custom Filters field and save:
{
"keyword_filter": {
"enabled": true,
"list": [
"crypto giveaway",
"free usdt",
"click here",
"visit my site",
"join now"
],
"action": "delete_and_warn"
}
}
3.4 Test Your Settings
Send the following messages in the group and observe the bot’s reaction:
| Message | Expected outcome |
|---|---|
🚀 Free USDT for every new member! Click https://spam.link |
Deleted by the keyword filter. |
Hey folks, I just discovered a bot that hands out 0.5 USDT daily. Interested? |
Deleted by the semantic filter (spam intent). |
Anyone knows how to set up a reminder for tomorrow’s meeting? |
Passed (legitimate). |
If a legitimate message is blocked, lower the threshold or add an exception rule in the panel.
4. Fine‑Tuning for Real‑World Use
4.1 Whitelist Trusted Users
Spammers sometimes impersonate admins. Add moderators to the allowlist so their messages bypass the semantic check:
{
"allowlist": [
123456789, // primary admin ID
987654321 // secondary admin ID
]
}
4.2 Dynamic Threshold Adjustment
Busy groups generate more legitimate traffic, which can increase false positives. Consider a schedule that lowers the threshold during peak hours and raises it at night:
import datetime
from groupbutler import set_spam_threshold
now = datetime.datetime.utcnow().hour
if 8 <= now < 20: # 8 AM – 8 PM UTC
set_spam_threshold(0.75)
else:
set_spam_threshold(0.85)
You can run this snippet on a small server or a cloud function that calls the AIGB API daily.
4.3 Use “Exception Rules” for Common Phrases
If your community frequently discusses topics that clash with the keyword list (e.g., “free software”), create an exception rule:
{
"exception_rules": [
{
"pattern": "free software",
"action": "allow"
},
{
"pattern": "money talk",
"action": "allow"
}
]
}
Exception rules are evaluated after the semantic filter, so they won’t override a high spam probability.
5. Combining Keyword and Semantic Approaches
The most robust anti‑spam strategy layers both methods:
- First line of defense – Keyword filter: Executes instantly, catching classic scams with zero latency.
- Second line – Semantic filter: Handles sophisticated messages that slip past the word list.
- Post‑processing – Allowlist & Exception rules: Ensure trusted members and frequent legitimate phrases aren’t penalized.
A flowchart might look like this:
Incoming message
|
v
[Keyword filter] --match?--> Delete & warn --> END
|
v
[Semantic filter] --p_spam > T?--> Delete & warn --> END
|
v
[Allowlist / Exceptions] --> Allow --> END
By arranging the checks in this order you keep latency low (most messages are filtered instantly) while still benefiting from AI‑driven context awareness.
6. Monitoring and Maintenance
- Dashboard analytics: The panel displays spam‑vs‑ham ratios, average latency, and token usage. Review these stats weekly.
- Adjust thresholds: If false positives rise, raise the threshold by 0.05 increments. If spam slips through, lower it.
- Refresh the keyword list: Add new scam phrases as they appear in the wild; remove obsolete ones to keep the list short.
Conclusion
Keyword filters give you speed and predictability but quickly become a maintenance nightmare. Semantic anti‑spam, powered by LLMs, brings context awareness, multilingual support, and adaptability to the table. By enabling the semantic filter in AIGB, adding a concise keyword list, and fine‑tuning thresholds, you can protect your Telegram community with minimal friction.
Disclosure: drafted with AI assistance by the AIGB team and human-reviewed. AIGB is our product - bias disclosed.
來源:DEV Community · dev.to