EliteXprotectorBot ek Telegram bot hai jo subscribed groups me bot-generated content ko auto-delete karta hai. Project Python + aiogram 3.x + MongoDB (motor) par based hai.
- DM onboarding + payment/subscription flow (unchanged)
- Admin review + owner approval flow (unchanged)
- Protected groups ke liye high-scale auto-delete engine
- Protected group me sab stickers bhi 35 second baad auto-delete
- Polling + Webhook dono run modes
- Heroku one-click deploy via
app.json - Windows local testing friendly setup
Protected groups me bot-generated content ke liye optimized engine use hota hai:
- Primary detect:
message.from_user.is_bot == True - Additional detect:
message.via_botaur forwarded bot-origin cases jahan detect possible ho - Content type neutral: text, photo, video, sticker, gif/animation, document, voice, audio, video note, caption messages, media group items, wagaira (jo Telegram delete API allow kare)
- Sticker special rule: protected group me human ya bot kisi ka bhi sticker ho, ~35s baad auto-delete hoga
- Target delete delay:
35s(env configurable) - Time-bucket/ring-buffer scheduler (
~200mstick) - Per-chat aggregation + chunk delete (
100messages/chunk) - 1000+ bot messages burst handle karne ke liye chunked batch delete
- Duplicate scheduling prevention (
chat_id + message_idunique in-memory) - Floodwait/rate-limit aware retries + exponential backoff
- Mongo per-message read avoid kiya gaya (in-memory protected-group cache)
- Optional crash-safe pending-delete persistence with TTL (env flag)
- Runtime metrics logs:
- scheduled count
- deleted count
- failed count
- average delay drift
Important: Telegram Bot API se dusre bots ke messages har case me reliably nahi milte. Isliye bot_content_scheduled low/zero reh sakta hai jabki stickers delete ho rahe hon.
bot/
config/
db/
handlers/
keyboards/
services/
auto_delete_engine.py
delete_worker.py
group_cache.py
utils/
webhook_app.py
main.py
Ye steps Windows PowerShell ke liye hain.
- Python
3.11+verify karo:python --version - Virtual environment banao:
python -m venv .venv - Venv activate karo:
.\.venv\Scripts\Activate.ps1
- Dependencies install karo:
pip install -r requirements.txt - Env file create karo:
Copy-Item .env.example .env .envme minimum values set karo:BOT_TOKENMONGO_URIMONGO_DB_NAME
- Local test ke liye polling mode ensure karo:
BOT_RUN_MODE=polling WEBHOOK_MODE=false
- Bot run karo:
python main.py
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env
python main.py- Server par code
/opt/elitexprotectorme rakho aur.envconfigure karo. - Dependencies install karo:
cd /opt/elitexprotector python -m venv .venv source .venv/bin/activate pip install -r requirements.txt
systemdunit install karo:sudo cp systemd/elitexprotector.service /etc/systemd/system/elitexprotector.service sudo systemctl daemon-reload sudo systemctl enable --now elitexprotector- Service verify karo:
sudo systemctl status elitexprotector sudo journalctl -u elitexprotector -f
- Polling mode:
BOT_RUN_MODE=pollingWEBHOOK_MODE=false- Local/VPS quick test ke liye best
- Webhook mode:
WEBHOOK_MODE=true(yeBOT_RUN_MODEse upar priority leta hai)WEBHOOK_BASE_URLrequired- Heroku webhook dyno ke liye
WEB_CONCURRENCY=1rakho
Deploy button:
https://www.heroku.com/deploy?template=https://github.com/SkyBotsDeveloper/EliteProtection
app.json me required env prompts milenge. WEBHOOK_BASE_URL ke liye https://<your-app-name>.herokuapp.com value do.
- App create:
heroku login heroku create your-app-name
- Config vars set karo:
heroku config:set BOT_TOKEN="<your_bot_token>" heroku config:set MONGO_URI="<your_mongo_uri>" heroku config:set MONGO_DB_NAME="elitex_protector" heroku config:set LOG_LEVEL="INFO" heroku config:set OWNER_USER_ID="8088623806" heroku config:set OWNER_USERNAME="EliteSid" heroku config:set ADMIN_REVIEW_CHAT_ID="-1003761739308" heroku config:set PAYMENT_QR_IMAGE_URL="https://files.catbox.moe/0svb7x.jpg" heroku config:set BOT_MESSAGE_DELETE_DELAY_SECONDS="35" heroku config:set PROTECTED_GROUP_CACHE_REFRESH_SECONDS="20" heroku config:set AUTO_DELETE_TICK_INTERVAL_MS="200" heroku config:set AUTO_DELETE_CHUNK_SIZE="100" heroku config:set AUTO_DELETE_RETRY_ATTEMPTS="5" heroku config:set AUTO_DELETE_RETRY_BASE_SECONDS="1.5" heroku config:set AUTO_DELETE_RETRY_MAX_SECONDS="35" heroku config:set AUTO_DELETE_WORKER_CONCURRENCY="12" heroku config:set AUTO_DELETE_METRICS_LOG_INTERVAL_SECONDS="60" heroku config:set AUTO_DELETE_PERSISTENCE_ENABLED="false" heroku config:set WEBHOOK_MODE="true" heroku config:set BOT_RUN_MODE="webhook" heroku config:set WEBHOOK_BASE_URL="https://your-app-name.herokuapp.com" heroku config:set WEBHOOK_PATH="/webhook/telegram" heroku config:set WEBHOOK_SECRET_TOKEN="<long_random_secret>" heroku config:set WEB_CONCURRENCY="1"
- Deploy:
git add . git commit -m "deploy: heroku webhook" git push heroku main
- Verify:
heroku ps heroku logs --tail
/start/madad/meri_subscription/cancel
/check/status
/pending/approve <payment_id>/deny <payment_id>/revoke <group_id>/stats
- User
/startkarta hai Subscription Kharidobutton click- QR payment (
₹100) +Done ✅/Cancel ❌ Donepar pending payment request create hota hai- Admin review channel me request aata hai
- Owner approve/deny karta hai
- Approve ke baad user group chat ID bhejta hai
- One approved subscription = one group binding
Group me bot ke liye:
- Admin role dena zaroori hai
Delete messagespermission deni zaroori hai- Observer mode use kar rahe ho to
Invite userspermission deni zaroori hai - Group subscribed/protected hona zaroori hai
- Protected group me sab stickers bhi 35 second baad auto-delete honge
- Privacy mode on ho to bot ko limited visibility mil sakti hai.
- Better detection ke liye privacy mode off recommended hai.
Agar aapko dusre bots ke command replies/media ko bhi aggressively delete karna hai, to optional MTProto observer enable karo:
OBSERVER_ENABLED=trueOBSERVER_API_IDOBSERVER_API_HASHOBSERVER_SESSION_STRINGOBSERVER_SYNC_INTERVAL_SECONDS(default30)
Ye observer Telegram user account session se events read karta hai aur existing auto-delete engine me same 35s scheduling bhejta hai. Bot ke paas Invite users permission ho to observer account auto-invite/auto-join sync bhi chalta hai.
BOT_MESSAGE_DELETE_DELAY_SECONDS(default35)AUTO_DELETE_TICK_INTERVAL_MS(default200)AUTO_DELETE_CHUNK_SIZE(default100, max100)AUTO_DELETE_RETRY_ATTEMPTSAUTO_DELETE_RETRY_BASE_SECONDSAUTO_DELETE_RETRY_MAX_SECONDSAUTO_DELETE_WORKER_CONCURRENCY(default12)PROTECTED_GROUP_CACHE_REFRESH_SECONDS(default20)AUTO_DELETE_PERSISTENCE_ENABLED(falseby default)AUTO_DELETE_PERSISTENCE_TTL_HOURSAUTO_DELETE_RESTORE_LIMITOBSERVER_ENABLED(falseby default)OBSERVER_API_IDOBSERVER_API_HASHOBSERVER_SESSION_STRINGOBSERVER_SYNC_INTERVAL_SECONDS(default30)
- Bot start nahi ho raha:
.envmeBOT_TOKEN,MONGO_URI,MONGO_DB_NAMEcheck karo.- Syntax verify karo:
python -m compileall main.py bot
- Auto-delete nahi chal raha:
- Group subscribed hai ya nahi
/statusse check karo. - Bot admin aur delete permission verify karo.
/checkme observer status dekh lo. AgarDisabledyaIncompletehai to dusre bots ke messages reliably delete nahi honge.- Logs me
Userbot observer disabledyamissing required observer credentialsaa raha ho to observer env vars fill karo. - Logs me permission/floodwait errors check karo.
- Group subscribed hai ya nahi
- Webhook issue:
WEBHOOK_MODE=true+ valid publicWEBHOOK_BASE_URLconfirm karo.
- Approve/deny DM fail:
- User ne bot block kiya ho sakta hai, logs check karo.
- Windows local setup se bot polling mode me run hota hai.
- Protected group cache startup ke baad refresh logs aate hain.
- Subscribed group me bot ka text message ~35s me delete hota hai.
- Photo/video/sticker/document/voice/audio/animation/media-group messages bhi ~35s me delete hote hain (Telegram limits ke andar).
- Human users ke stickers bhi protected group me ~35s baad auto-delete hote hain.
-
via_botcase me message schedule hota hai. - 1000+ bot messages burst me scheduler crash nahi hota.
- Batch delete chunking (100 per call) logs/behavior se verify hoti hai.
- Duplicate schedule attempt par same message double delete queue me nahi aata.
- Floodwait/temporary API errors par retries lagte hain, group me spam nahi hota.
- Non-subscribed group me auto-delete trigger nahi hota.
- Payment/subscription flow pe koi regression nahi aati.
.envkabhi git me commit mat karo.WEBHOOK_SECRET_TOKENstrong random rakho.- Owner-only commands ko public group me use mat karo.