This guide is specifically structured for AI Coding Agents (Claude Code, Cursor, Codex, Windsurf, Antigravity, etc.) and developers automating the deployment of Telegram Channel Admin.
This project is an asynchronous microservice system running in Docker containers:
db: PostgreSQL 15 (stores posts, moderation logs, deduplication hashes, and settings).redis: Redis 7 (task queue managed via Arq and caching).migrator: One-off Alembic runner (alembic upgrade head) ensuring schema migrations.parser: Telethon Userbot capturing posts from donor channels into DB & Redis queue.worker: Arq background worker performing AI deduplication, ad filtering, and rewrites.bot: aiogram 3 Telegram bot providing the interactive moderation UI.
Before starting execution, verify that the host environment has:
- Docker (
docker --version) & Docker Compose v2 (docker compose version). - Network access to Telegram MTProto, Telegram Bot API, and the chosen AI provider API.
- The following required credentials from the user:
API_ID&API_HASH(from my.telegram.org).TELEGRAM_BOT_TOKEN(from @BotFather).AI_API_KEY(OpenAI, DeepSeek, OpenRouter, etc.).ADMIN_IDS(Telegram numerical User IDs of the administrator).CHANNELS_TO_TRACK(Comma-separated donor channel IDs or usernames).TARGET_CHANNEL_ID(Channel where approved posts are published).
git clone https://github.com/ivanchik-byte/Telegram-Channel-Admin.git
cd Telegram-Channel-AdminCreate .env from .env.example:
cp .env.example .envEnsure the following variables are properly populated in .env:
# PostgreSQL
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=tg_admin
DATABASE_URL=postgresql+asyncpg://postgres:postgres@db:5432/tg_admin
# Redis
REDIS_URL=redis://redis:6379/0
# Telegram MTProto (Userbot)
API_ID=12345678
API_HASH=your_api_hash_here
CHANNELS_TO_TRACK=-1001234567890,@channel_username
# Telegram Bot
TELEGRAM_BOT_TOKEN=123456789:ABCdefGHIjklMNOpqrSTUvwxYZ
TARGET_CHANNEL_ID=-1001234567890
MODERATOR_CHAT_ID=-1001987654321
ADMIN_IDS=123456789
# AI Provider
AI_API_KEY=sk-your-ai-api-key
AI_BASE_URL=https://api.openai.com/v1
AI_MODEL=gpt-4o-mini
AI_EXTRA_BODY={"temperature": 0.6, "top_p": 0.9, "max_tokens": 800}
AD_KEYWORDS=реклама,erid,промокод,подписывайтесь,розыгрыш,подписаться
# Optional interface language (ru / en)
LANGUAGE=ruImportant
Telethon requires an interactive one-time login to create data/anon.session.
Agent Note: If running in an automated non-interactive terminal, prompt the user to input their phone number, confirmation code, and 2FA password.
Execute:
docker compose up -d db redis
docker compose run --rm parser python src/login.pyExpected Prompts:
Please enter your phone (or bot token):-> Enter phone number with country code (e.g.+1234567890).Please enter the code you received:-> Enter code sent by Telegram.Please enter your password:-> Enter 2FA Cloud Password (if enabled on the account).
After successful authorization, the session file will be stored at data/anon.session.
docker compose up -d --build-
Check running containers:
docker compose ps
All services (
db,redis,parser,worker,bot) should be in stateUp/healthy(migratorshould beExited (0)). -
Inspect logs for errors:
docker compose logs -f --tail=50
- Verify
dbandredishealth checks pass. - Verify
migratorranalembic upgrade headwithout errors. - Verify
botloggedBot started successfully/ polling. - Verify
parserconnected to Telegram and began listening toCHANNELS_TO_TRACK. - Verify
workerregistered Arq functions and connected to Redis.
- Verify
| Symptom | Cause | Solution for Agent |
|---|---|---|
parser exits with SessionPasswordNeededError or auth error |
data/anon.session is missing or unauthorized |
Re-run docker compose run --rm parser python src/login.py |
migrator fails with connection refused |
db not ready or wrong DATABASE_URL |
Ensure db container is healthy; verify DATABASE_URL in .env |
worker fails to generate posts |
Invalid AI_API_KEY or unreachable AI_BASE_URL |
Check .env AI_API_KEY and AI_BASE_URL; check docker compose logs -f worker |
bot fails with TelegramUnauthorizedError |
Invalid TELEGRAM_BOT_TOKEN |
Verify bot token with @BotFather |
| Posts not captured | Bot not added / userbot not joined to donor channels | Ensure the userbot account is subscribed to channels listed in CHANNELS_TO_TRACK |
- Stop all services gracefully:
docker compose down - Rebuild after code modification:
docker compose down && docker compose up -d --build - View individual service logs:
- Bot:
docker compose logs -f bot - Worker:
docker compose logs -f worker - Parser:
docker compose logs -f parser - Migrations / DB:
docker compose logs -f db
- Bot: