telespam
v0.9.0
Published
Self-hosted anti-spam bot for Telegram groups — keyword filtering, profile photo check, multi-step verification & auto-approval
Maintainers
Readme
English | 中文
🤖 Telespam
Self-hosted anti-spam bot for Telegram groups — keeps your community clean with keyword filtering, profile photo checks & multi-step verification.
Features
- 🔑 Keyword Blacklist — Block join requests whose name or bio contains blacklisted keywords (case-insensitive)
- 🖼️ Profile Photo Check — Require users to have a profile photo before joining
- ✅ Auto-Approve — Automatically approve requests that pass all rules
- ❓ Verification Questions — Challenge users with single or multi-step quizzes after approval
- 🌐 Multi-Language — Built-in English and Chinese (中文) bot messages
- 🔄 Multi-Instance — Run multiple bots from a single config file
- 🐧 Systemd Service — One-command install for systemd-based Linux servers
Prerequisites
The Bot must be added as a group administrator with at least "Invite Users" permission to receive chat_join_request events and approve / decline join requests. If verification questions are enabled, "Ban Users" permission is also required to kick users who fail.
Installation
sudo npm i -g telespamConfiguration
Create a /etc/telespam/your-telegram-bot.json file with the following structure:
{
"language": "en",
"apiKey": "123456:ABC-DEF",
"requireProfilePhoto": false,
"requireBio": false,
"autoApprove": false,
"keywordBlacklist": ["spam", "广告"],
"verification": null
}| Option | Type | Default | Description |
| --------------------- | -------------------------------- | ------------ | ---------------------------------------------------------------------------------------------------- |
| language | "en" | "zh" | "en" | Language for bot messages |
| apiKey | string | (required) | Bot API key from @BotFather |
| requireProfilePhoto | boolean | false | Require users to have a profile photo |
| requireBio | boolean | false | Require users to have a bio |
| autoApprove | boolean | false | Auto-approve requests that pass all rules |
| keywordBlacklist | string[] | [] | Blacklisted keywords in names & bio (case-insensitive). Wrap with / for regex (e.g. /^spam\d+$/) |
| verification | object | object[] | null | null | Verification question(s) sent after approval |
Verification
A single verification question:
{
"verification": {
"question": "What is 1 + 1?",
"options": ["1", "2", "3"],
"answer": 1,
"timeout": 180
}
}Multiple verification questions (multi-step):
{
"verification": [
{
"question": "What is 2 + 2?",
"options": ["3", "4", "5"],
"answer": 1,
"timeout": 60
},
{
"question": "Which city is the capital of France?",
"options": ["London", "Berlin", "Paris"],
"answer": 2,
"timeout": 60
}
]
}Users must answer all questions correctly in order. A wrong answer at any step results in an immediate kick.
| Field | Type | Default | Description |
| ---------- | ---------- | ------------ | ----------------------------------------- |
| question | string | (required) | The question text |
| options | string[] | (required) | Answer options as inline buttons |
| answer | number | (required) | 0-based index of the correct option |
| columns | number | 2 | Number of options displayed per row |
| timeout | number | 180 | Seconds before kicking unresponsive users |
Multi-instance
To run multiple bots with a single config file, use a JSON array. Each bot username is auto-detected via the Telegram API and included in log output:
[
{
"language": "en",
"apiKey": "123456:ABC-DEF",
"requireProfilePhoto": true,
"autoApprove": true,
"keywordBlacklist": ["spam"],
"verification": null
},
{
"language": "zh",
"apiKey": "654321:GHI-JKL",
"requireProfilePhoto": false,
"autoApprove": false,
"keywordBlacklist": ["广告"],
"verification": [
{
"question": "What is 1 + 1?",
"options": ["1", "2", "3"],
"answer": 1,
"timeout": 180
}
]
}
]Systemd Service
To install and start the service:
telespam installTo stop and uninstall the service:
telespam uninstallTo restart after config changes or package updates:
telespam restartTo view live logs:
telespam logsProgrammatic Usage
import { Telespam } from 'telespam';
const bot = new Telespam({
language: 'zh',
apiKey: '123456:ABC-DEF',
requireProfilePhoto: true,
autoApprove: true,
keywordBlacklist: ['spam', '广告'],
verification: [
{
question: 'What is 1 + 1?',
options: ['1', '2', '3'],
answer: 1,
timeout: 180,
},
],
});
await bot.start();API
new Telespam(options)
| Option | Type | Default | Description |
| --------------------- | ---------------------------------------------- | ------------ | ---------------------------------------------------------------------------------- |
| language | 'en' \ | 'zh' | 'en' | Language for bot messages |
| apiKey | string | (required) | Bot API key from @BotFather |
| requireProfilePhoto | boolean | false | Require users to have a profile photo |
| autoApprove | boolean | false | Auto-approve requests that pass all rules |
| keywordBlacklist | string[] | [] | Blacklisted keywords in first_name / last_name / username / bio (case-insensitive) |
| verification | VerificationConfig | VerificationConfig[] | null | Verification question(s) sent after approval |
VerificationConfig
| Field | Type | Default | Description |
| ---------- | ---------- | ------------ | ----------------------------------------- |
| question | string | (required) | The question text |
| options | string[] | (required) | Answer options as inline buttons |
| answer | number | (required) | 0-based index of the correct option |
| timeout | number | 180 | Seconds before kicking unresponsive users |
bot.start()
Starts long-polling for Telegram updates and reviews incoming join requests.
bot.stop()
Stops the bot and releases resources.
