File size: 7,431 Bytes
a230509
956d39d
957d007
 
9376a74
956d39d
 
957d007
a230509
 
 
 
 
 
 
 
972b6f2
cc6f785
0ea7be6
cc6f785
0ea7be6
cc6f785
0ea7be6
cc6f785
972b6f2
 
5c153bd
cc6f785
fee842c
972b6f2
5eb88a0
972b6f2
 
 
5c153bd
972b6f2
5c153bd
972b6f2
5c153bd
972b6f2
5c153bd
5eb88a0
5c153bd
 
972b6f2
5c153bd
972b6f2
 
 
5c153bd
5eb88a0
5c153bd
972b6f2
5c153bd
972b6f2
5c153bd
972b6f2
 
 
5c153bd
972b6f2
5c153bd
 
 
 
 
 
972b6f2
 
 
 
 
5c153bd
5eb88a0
972b6f2
5c153bd
972b6f2
5c153bd
972b6f2
 
5c153bd
972b6f2
 
 
5c153bd
 
956d39d
 
cc6f785
5c153bd
cc6f785
 
 
 
 
5c153bd
fa6f6d3
cc6f785
 
 
5c153bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99f0a25
 
 
5c153bd
da5659b
 
e4cf54e
 
 
fa6f6d3
972b6f2
 
5eb88a0
972b6f2
5c153bd
972b6f2
 
 
5c153bd
 
 
972b6f2
 
 
fa6f6d3
 
 
 
 
972b6f2
fa6f6d3
 
972b6f2
cc6f785
5c153bd
cc6f785
972b6f2
 
 
cc6f785
5eb88a0
cc6f785
5eb88a0
 
5c153bd
 
 
 
5eb88a0
fa6f6d3
 
 
 
da5659b
fa6f6d3
 
5eb88a0
fa6f6d3
5eb88a0
 
cc6f785
 
 
972b6f2
 
5c153bd
972b6f2
5eb88a0
 
 
972b6f2
5c153bd
972b6f2
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
---
title: antispam.bot
emoji: πŸ›‘οΈ
colorFrom: blue
colorTo: indigo
sdk: docker
app_port: 8080
pinned: false
license: mit
tags:
  - telegram
  - anti-spam
  - ilang
  - chatbot
---

<div align="center">

# πŸ›‘οΈ antispam.bot

**The AI guardian that keeps your Telegram groups clean β€” and actually answers your questions.**

Open source (MIT), zero config, self-hostable β€” the **TelegramGuard** project.

[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
[![Powered by I-Lang](https://img.shields.io/badge/powered%20by-I--Lang%20Spec-blueviolet)](https://ilang.ai)
[![AI: OpenAI-compatible](https://img.shields.io/badge/AI-OpenAI--compatible-06D6A0)](#self-host)

🌐 [English](README.md) Β· [δΈ­ζ–‡](README_CN.md) Β· [Русский](README_RU.md) Β· [EspaΓ±ol](README_ES.md) Β· [Ψ§Ω„ΨΉΨ±Ψ¨ΩŠΨ©](README_AR.md) Β· [فارسی](README_FA.md)

</div>

---

## Add it to your group (zero setup)

Add the official bot β€” no install, no config, no cost.

### β†’ [@iLangGuardBot](https://t.me/iLangGuardBot)

1. Search `@iLangGuardBot` on Telegram
2. Add it to your group
3. Give it admin β€” **delete messages** + **ban users**
4. Done. Spam is cleaned automatically; @ it anytime with a question.

You can also DM it directly for AI chat.

---

## What it does

**🚫 Anti-Spam** β€” Catches ads, scams, crypto & gambling spam. Sees through Unicode lookalikes, full-width and zero-width tricks, emoji stuffing and slang. A zero-cost pre-filter kills the obvious stuff before it ever reaches the AI, and repeat-flooding is caught with no AI call at all.

**πŸ‘οΈ Vision** β€” Reads images and video thumbnails to catch image-based ads and QR-code scams. In chat, it reads the story behind a photo, not just the pixels.

**πŸ’¬ Chat** β€” @ it in any group or DM it privately. Multilingual, auto-detects your language. Ask it anything and get a clear, useful answer β€” factual on sensitive topics, with sensible boundaries on genuinely harmful ones.

---

## Self-Host

Bring any **OpenAI-compatible** AI provider β€” [SiliconFlow](https://cloud.siliconflow.cn) (default), OpenAI, DeepSeek, or a local model. You need two things:

- **Bot Token** β€” [@BotFather](https://t.me/BotFather) β†’ `/newbot`
- **AI API Key** β€” from your provider (default targets SiliconFlow)

### Option 1 β€” VPS (one command)

```bash
curl -sL https://raw.githubusercontent.com/ilang-ai/TelegramGuard/main/install.sh | sudo bash
```

Clones, installs dependencies, prompts for your two keys, and runs as a systemd service. Manage it with:

```bash
systemctl status telegramguard     # status
systemctl restart telegramguard    # restart
journalctl -u telegramguard -f     # live logs
```

### Option 2 β€” HuggingFace Space (free, no server)

1. Fork this repo
2. Create a [HuggingFace Space](https://huggingface.co/new-space) β†’ Docker SDK β†’ Blank
3. GitHub repo β†’ Settings β†’ Secrets β†’ add `HF_TOKEN` (your HF write token)
4. HF Space β†’ Settings β†’ Secrets β†’ add `BOT_TOKEN` + `AI_API_KEY`
5. HF Space β†’ Settings β†’ enable **persistent storage** so `/data` (the SQLite DB) is writable β€” or add a `DB_PATH` secret pointing somewhere writable
6. Push to GitHub β€” it auto-deploys to the Space

### Option 3 β€” Manual

```bash
git clone https://github.com/ilang-ai/TelegramGuard.git
cd TelegramGuard
pip install -r requirements.txt
cp .env.example .env         # fill in BOT_TOKEN + AI_API_KEY
set -a; source .env; set +a  # load .env into the environment
python bot.py
```

After creating your bot, send to [@BotFather](https://t.me/BotFather): `/setjoingroups β†’ Enable` and `/setprivacy β†’ Disable` (so it can see group messages).

### Configuration

Everything is set via environment variables β€” see [`.env.example`](.env.example):

| Variable | Default | Purpose |
|----------|---------|---------|
| `BOT_TOKEN` | *(required)* | Telegram bot token |
| `AI_API_KEY` | *(required)* | OpenAI-compatible API key |
| `AI_BASE_URL` | `https://api.siliconflow.cn/v1` | Provider endpoint |
| `AI_MODEL` | `deepseek-ai/DeepSeek-V4-Flash` | Text model |
| `AI_VISION_MODELS` | `Qwen/Qwen3-VL-30B…` | Vision fallback chain (comma-separated) |
| `AI_AUDIO_MODEL` | `Qwen/Qwen3-Omni-30B-A3B-Instruct` | Voice-message model |
| `AI_IMAGE_MAX_WIDTH` | `600` | Downscale width before vision calls |
| `AI_FALLBACK_API_KEY` | *(empty)* | Optional second provider; set to enable a cross-vendor fallback |
| `AI_FALLBACK_BASE_URL` | *(empty)* | Endpoint of that backup provider |
| `AI_FALLBACK_MODEL` | *(empty)* | Text/judge model there |
| `LEXICON_HARD_THRESHOLD` | `6` | Slang pre-filter strictness (higher = stricter) |
| `PROBE_FLAG_DELETE` | `2` | Check-in filler flags before it starts deleting (never bans) |
| `PROBE_WINDOW_HOURS` | `24` | Rolling window for those flags |
| `JUDGE_TEXT_LIMIT` | `1800` | Chars of a long message the judge sees (head + tail) |
| `JUDGE_CAPTION_LIMIT` | `900` | Same, for image captions |
| `GROUP_CMD_COOLDOWN` | `60` | Cooldown (s) on public group commands for non-admins |

---

## Customize the AI

The bot's brain lives in plain `.ilang` files β€” [I-Lang Prompt Spec](https://ilang.ai), where each `::GENE` defines a behavior.

```
prompts_demo/
β”œβ”€β”€ persona.ilang     how it thinks + how it talks
β”œβ”€β”€ antispam.ilang    what counts as spam
└── vision.ilang      how it reads images
```

```
::GENE_IMMUTABLE{S002, T:RUTHLESS_RED_TEAM, A:FLATTERβ‡’FAIL, G:ALL, Θ:ALWAYS}
# Show it a plan and it hunts the fatal flaw instead of praising.

::GENE_MUTABLE{P002, T:CONCISE, G:ALL, Θ:ALWAYS}
# 2-3 sentences. Answer first, detail after, zero filler.

::IMMUNE{SPAM, DETECT_THEN_NUKE}
# Ads / scams / flooding β†’ delete + strike, see through evasion.
```

Change the genes, change the bot. To customize: copy `prompts_demo/` to `prompts/` (loaded first) and edit.

**[Learn I-Lang Prompt Spec β†’](https://ilang.ai)**

---

## Architecture

```
TelegramGuard/
β”œβ”€β”€ bot.py                 Entry β€” handlers (group Β· private Β· events)
β”œβ”€β”€ config.py              Env config
β”œβ”€β”€ install.sh             One-command VPS installer
β”œβ”€β”€ Dockerfile             Container build
β”œβ”€β”€ modules/
β”‚   β”œβ”€β”€ ai_provider.py     OpenAI-compatible AI layer (text Β· vision Β· audio)
β”‚   β”œβ”€β”€ chat.py            Prompt orchestration (loads .ilang)
β”‚   β”œβ”€β”€ prefilter.py       Zero-cost spam pre-filter + triage
β”‚   β”œβ”€β”€ lexicon.py         Slang / evasion normalization + scoring
β”‚   β”œβ”€β”€ probe.py           Check-in filler detection (mark-only, never bans)
β”‚   β”œβ”€β”€ ilang_judge.py     I-Lang decision function
β”‚   β”œβ”€β”€ admin.py           Group admin
β”‚   β”œβ”€β”€ db.py              Shared SQLite + async lock
β”‚   └── database.py        Schema
└── prompts_demo/          AI personality (.ilang files)
```

---

<div align="center">

Built with **[I-Lang Prompt Spec](https://ilang.ai)** β€” structured AI instructions as genetic code.

[![Spec](https://img.shields.io/badge/spec-ilang--ai/ilang--spec-black?logo=github)](https://github.com/ilang-ai/ilang-spec)
[![Web](https://img.shields.io/badge/web-ilang.ai-blue)](https://ilang.ai)
[![HF](https://img.shields.io/badge/HF-i--Lang-yellow?logo=huggingface)](https://huggingface.co/i-Lang)

MIT Β· Β© [iLang Inc.](https://eastsoft.com) Β· [antispam.bot](https://antispam.bot) Β· [ilang.ai](https://ilang.ai)

</div>