A powerful, modular anti-spam bot for Telegram with customizable filtering strategies per chat.
Built for communities, powered by AI and flexible rules.
- βοΈ Setup Steps
- π§ͺ Setup Filters
- π₯ Upload Filter Configuration
- π Filters
- π§Ύ
filters.yaml
- Filters logic file - βοΈ Self-Hosted Deployment
Follow these steps to get your Telegram anti-spam bot up and running:
- Create a Telegram group that will serve as the log/admin chat.
- Add
@spam_eater_bot
to the group. - Grant the bot admin permissions:
- Set Admin Permissions
This group will receive logs and alerts about spam detection and actions taken.
Send the following command in the log group:
/get_chat_id
- The bot will reply with the groupβs ID.
- Copy this value β you'll need it in the next steps.
-
Invite
@spam_eater_bot
to the Telegram group you want to protect. -
Grant it admin permissions:
- Can delete messages
- Can restrict members
- Can read all messages
- Add Admin Permission
In your main chat, activate the bot:
/enable
Back in your main chat, link the log group:
/set_admin_chat_id <your_log_chat_id>
Example:
/set_admin_chat_id -1001234567890
β The bot is now actively protecting your group and logging actions to the admin group.
You can configure the bot using custom filters defined in a YAML file.
- Open the log/admin chat.
- Upload your
filters.yaml
file as a document (not text/photo).
The bot will:
- β Confirm successful loading.
- β Warn if the file is invalid.
Each filter includes common parameters:
enabled
: Enables/disables the filter.quarantineWeight
: Contributes to the userβs quarantine score.banWeight
: Contributes to the userβs ban score.inputTransformer
: Preprocesses the message (e.g.,lowercase
,remove_unicode
).
- The message is transformed.
- Filters are applied sequentially.
- Scores accumulate.
- If a ban score is reached, the message is blocked.
- If only a quarantine threshold is met, the user is quarantined.
type: language_injection
name: 'Injection in English words'
strictLanguagePattern: '[A-Za-z]'
quarantineWeight: 2
banWeight: 3
inputTransformer:
type: remove_unicode
type: weight
name: 'Emoji Limit'
restrictionPatterns:
- '[^\\p{L}\\p{M}\\p{N}\\p{P}\\p{Z}\\p{Cf}\\p{Cs}\\s[!-/][:-@][\\[-`][{-~]]'
quarantineWeight: 5
banWeight: 10
inputTransformer:
type: pass
type: remote_filter
name: 'AI Spam Model'
endpoint: https://your.api.endpoint/check
minMessageLengthForCheck: 40
enabled: true
quarantineWeight: 0.3
banWeight: 0.98
inputTransformer:
type: pass
It will call API endpoint https://your.api.endpoint/check?text=Message from the chat
and expect the response with the following format:
{ "spam": 0.99 }
Where 0.0 -> 1.0 is spam confidence
type: weight
name: 'Strong restricted words'
restrictionPatterns:
- '\\d+\\s*[$]'
- '[$]\\s*\\d+'
- '18\\s*[+]'
- '\\s\\d{3}k'
- 'usd'
- 'eur'
- 'income'
- 'bitcoin'
quarantineWeight: 1
banWeight: 2
inputTransformer:
type: combine
transformers:
- type: remove_unicode
- type: lowercase
filters:
- type: language_injection
strictLanguagePattern: '[A-Za-z]'
name: Injection in English words
quarantineWeight: 2
banWeight: 3
inputTransformer:
type: remove_unicode
- type: weight
name: Emoji Limit
restrictionPatterns:
- '[^\p{L}\p{M}\p{N}\p{P}\p{Z}\p{Cf}\p{Cs}\s[!-/][:-@][\[-`][{-~]]'
quarantineWeight: 5
banWeight: 10
inputTransformer:
type: pass
- type: remote_filter
endpoint: 'https://your.api.endpoint/check'
minMessageLengthForCheck: 40
name: AI Spam Model
enabled: true
quarantineWeight: 0.3
banWeight: 0.98
inputTransformer:
type: pass
- type: weight
name: Restricted words
restrictionPatterns:
- '\\d+\\s*[$]'
- '[$]\\s*\\d+'
- '18\\s*[+]'
- '\\s\\d{3}k'
- 'usd'
- 'eur'
quarantineWeight: 1
banWeight: 2
inputTransformer:
type: combine
transformers:
- type: remove_unicode
- type: lowercase
You can self-host your own instance of the SpamFighters bot.
Thanks! Iβve added your requested steps to the Setup Section in the final README.md
. Here's the updated section including how to create a bot with BotFather and disable group privacy:
If you're self-hosting or using your own bot instead of @spam_eater_bot
, follow these steps:
- Open @BotFather on Telegram.
- Send
/newbot
and follow the prompts to name your bot. - Copy the bot token provided at the end β you'll need it in your
config.yaml
or startup config. - Disable group privacy by sending this to BotFather:
Then select your bot and choose Disable
β this allows the bot to read group messages, which is essential for spam detection.
Hereβs how to pull the vacxe/telegram-anti-spam-bot
Docker image and run it while mounting local folders to the containerβs chats/
and config/
directories.
docker pull vacxe/telegram-anti-spam-bot
Make two directories on your local system to store config and chat data:
mkdir -p ./config ./chats
./config
β where you place your config file../chats
β used for local chat logs or persistent storage (if used by the bot).
Example: config/config.yaml
token: "<your_bot_token>"
pollingTimeout: 10
debug: false
goodBehaviourMessageCount: 2
# Optional: Metrics logging via InfluxDB
influxDb:
url: "https://my.influx.db"
token: "<your_influxdb_token>"
org: "default"
bucket: "telegram_bot"
Key | Description |
---|---|
token |
Your Telegram Bot API token from @BotFather. |
pollingTimeout |
Timeout (in seconds) for long polling. Recommended: 10β30 . |
debug |
Set to true to enable verbose debug logging. |
goodBehaviourMessageCount |
Number of good messages to offset spam score. Helps reduce false positives. |
π§© Metrics Logging If you donβt use InfluxDB, simply omit the entire influxDb: block. The bot will run normally without sending metrics.
Key | Description |
---|---|
influxDb.url |
URL to your InfluxDB instance for metrics. |
influxDb.token |
Auth token for accessing InfluxDB. |
influxDb.org |
InfluxDB organization name. |
influxDb.bucket |
Target bucket where bot metrics are stored. |
Ensure this file is available inside the container at /config/config.yaml
, typically by mounting the folder:
docker run -d \
--name telegram-antispam-bot \
-v $(pwd)/config:/app/config \
-v $(pwd)/chats:/app/chats \
vacxe/telegram-anti-spam-bot
Replace
$(pwd)
with full paths if you're not on Linux/macOS.