Telegram anti-spam bot
Read each new group message and decide: keep it, delete it, or delete it and ban.
The new message
Hi everyone 👋 I made $4,800 this week with a simple USDT arbitrage method, no experience needed. DM me for the free guide, only 10 spots left!
Verdict
spam
Category
crypto
Reason
Crypto arbitrage offer, DM request, limited spots
Action
delete_and_ban
Elapsed–
Cost$0.0001
Recorded run, replayed faster than it ran.
$0.0001this recorded run's cost
- 1 message≈ $0.0001
Forking copies the step into your dashboard. You change the input, press Run, and each call is billed to your balance.
Build it yourself
Each step is one request to the Hyperouter API with your key. A later step reads an earlier one's output through {{steps.<id>…}}, and your inputs through {{vars.<name>}}. Models: deepseek/deepseek-v4.1-flash.
The request
Judge the message
POST /v1/chat/completionsdeepseek/deepseek-v4.1-flashText · ≤ 300 tokens{ "model": "deepseek/deepseek-v4.1-flash", "messages": [ { "role": "system", "content": "You moderate a Telegram group. Read the group's rules and one new message, and decide whether the message is spam. Spam is advertising, selling, referral or affiliate links, crypto and investment offers, fake giveaways, adult content, and anyone asking members to DM them for money. A question, a complaint or an off-topic chat is not spam. Answer with one JSON object whose values are all strings: verdict (spam or ok), category (advertising, scam, crypto, adult, recruiting or none), reason (at most 12 words), action (delete_and_ban for clear spam, delete when unsure, keep for ok)." }, { "role": "user", "content": "Group rules:\n{{vars.rules}}\n\nNew message:\n{{vars.message}}" } ], "response_format": { "type": "json_object" }, "reasoning_effort": "none", "max_tokens": 300 }
Run the whole pipeline from code
SYSTEM="You moderate a Telegram group. Read the group's rules and one new message, and decide whether the message is spam. Spam is advertising, selling, referral or affiliate links, crypto and investment offers, fake giveaways, adult content, and anyone asking members to DM them for money. A question, a complaint or an off-topic chat is not spam. Answer with one JSON object whose values are all strings: verdict (spam or ok), category (advertising, scam, crypto, adult, recruiting or none), reason (at most 12 words), action (delete_and_ban for clear spam, delete when unsure, keep for ok)." RULES='A group for developers who use the Hyperouter API. On topic: questions, bugs, code and model results. Not allowed: advertising, selling, referral links, crypto or investment offers.' MESSAGE='Hi everyone 👋 I made $4,800 this week with a simple USDT arbitrage method, no experience needed. DM me for the free guide, only 10 spots left!' jq -n --arg s "$SYSTEM" --arg u "Group rules: $RULES New message: $MESSAGE" \ '{model:"deepseek/deepseek-v4.1-flash", max_tokens:300, reasoning_effort:"none", response_format:{type:"json_object"}, messages:[{role:"system",content:$s},{role:"user",content:$u}]}' | curl -s https://api.hyperouter.app/v1/chat/completions -H "Authorization: Bearer $HYPEROUTER_API_KEY" -H 'Content-Type: application/json' -d @- | jq -r '.choices[0].message.content'
// bot.mjs: a whole bot. Make it an admin of the group (delete messages, ban users) and // turn its privacy mode off in @BotFather, so it sees every message. import OpenAI from 'openai'; const c = new OpenAI({ baseURL: 'https://api.hyperouter.app/v1', apiKey: process.env.HYPEROUTER_API_KEY }); const TG = `https://api.telegram.org/bot${process.env.TELEGRAM_BOT_TOKEN}/`; const SYSTEM = "You moderate a Telegram group. Read the group's rules and one new message, and decide whether the message is spam. Spam is advertising, selling, referral or affiliate links, crypto and investment offers, fake giveaways, adult content, and anyone asking members to DM them for money. A question, a complaint or an off-topic chat is not spam. Answer with one JSON object whose values are all strings: verdict (spam or ok), category (advertising, scam, crypto, adult, recruiting or none), reason (at most 12 words), action (delete_and_ban for clear spam, delete when unsure, keep for ok)."; const RULES = 'A group for developers who use the Hyperouter API. On topic: questions, bugs, code and model results. Not allowed: advertising, selling, referral links, crypto or investment offers.'; const tg = async (method, params) => (await (await fetch(TG + method, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(params) })).json()).result; let offset = 0; for (;;) { for (const u of await tg('getUpdates', { offset, timeout: 50, allowed_updates: ['message'] })) { offset = u.update_id + 1; const m = u.message ?? {}; const text = m.text ?? m.caption; if (!text) continue; const r = await c.chat.completions.create({ model: 'deepseek/deepseek-v4.1-flash', max_tokens: 300, reasoning_effort: 'none', response_format: { type: 'json_object' }, messages: [ { role: 'system', content: SYSTEM }, { role: 'user', content: `Group rules:\n${RULES}\n\nNew message:\n${text}` }] }); let v; try { v = JSON.parse(r.choices[0].message.content); } catch { continue; } // no verdict: keep the message console.log(m.from.username, v); if (v.action === 'delete' || v.action === 'delete_and_ban') await tg('deleteMessage', { chat_id: m.chat.id, message_id: m.message_id }); if (v.action === 'delete_and_ban') await tg('banChatMember', { chat_id: m.chat.id, user_id: m.from.id }); } }
# bot.py: a whole bot. Make it an admin of the group (delete messages, ban users) and # turn its privacy mode off in @BotFather, so it sees every message. import json, os, urllib.request from openai import OpenAI c = OpenAI(base_url='https://api.hyperouter.app/v1', api_key=os.environ['HYPEROUTER_API_KEY']) TG = 'https://api.telegram.org/bot' + os.environ['TELEGRAM_BOT_TOKEN'] + '/' SYSTEM = "You moderate a Telegram group. Read the group's rules and one new message, and decide whether the message is spam. Spam is advertising, selling, referral or affiliate links, crypto and investment offers, fake giveaways, adult content, and anyone asking members to DM them for money. A question, a complaint or an off-topic chat is not spam. Answer with one JSON object whose values are all strings: verdict (spam or ok), category (advertising, scam, crypto, adult, recruiting or none), reason (at most 12 words), action (delete_and_ban for clear spam, delete when unsure, keep for ok)." RULES = 'A group for developers who use the Hyperouter API. On topic: questions, bugs, code and model results. Not allowed: advertising, selling, referral links, crypto or investment offers.' def tg(method, **params): req = urllib.request.Request(TG + method, json.dumps(params).encode(), {'Content-Type': 'application/json'}) return json.load(urllib.request.urlopen(req, timeout=60))['result'] offset = 0 while True: for u in tg('getUpdates', offset=offset, timeout=50, allowed_updates=['message']): offset = u['update_id'] + 1 m = u.get('message') or {} text = m.get('text') or m.get('caption') if not text: continue r = c.chat.completions.create(model='deepseek/deepseek-v4.1-flash', max_tokens=300, reasoning_effort='none', response_format={'type': 'json_object'}, messages=[ {'role': 'system', 'content': SYSTEM}, {'role': 'user', 'content': f'Group rules:\n{RULES}\n\nNew message:\n{text}'}]) try: v = json.loads(r.choices[0].message.content) except ValueError: continue # no verdict: keep the message print(m['from'].get('username'), v) if v.get('action') in ('delete', 'delete_and_ban'): tg('deleteMessage', chat_id=m['chat']['id'], message_id=m['message_id']) if v.get('action') == 'delete_and_ban': tg('banChatMember', chat_id=m['chat']['id'], user_id=m['from']['id'])
Run Telegram anti-spam bot on your account
Read each new group message and decide: keep it, delete it, or delete it and ban. Fork it, change the input, and run it from the dashboard: ≈ $0.0001 per run at the default settings.