Self-hosted web service for parsing public Telegram channels, AI-rewriting posts, and publishing them to your own channels via Bot API.
Stack: FastAPI + SQLAlchemy async, React 18 + Vite + TypeScript, PostgreSQL.
- Python 3.11+
- Node.js 18+
- PostgreSQL 14+
- Telegram API credentials (my.telegram.org)
- Telegram Bot token (@BotFather)
- OpenAI API key (platform.openai.com)
git clone git@github.com:artanov/megaparser.git
cd megaparserCREATE DATABASE telegram_parser;cp .env.example .envEdit .env and fill in all values:
| Variable | Description |
|---|---|
TELEGRAM_API_ID |
App api_id from my.telegram.org |
TELEGRAM_API_HASH |
App api_hash from my.telegram.org |
TELEGRAM_BOT_TOKEN |
Bot token from @BotFather. The bot must be added as admin to all target channels |
OPENAI_API_KEY |
API key from platform.openai.com |
DATABASE_URL |
PostgreSQL connection string, e.g. postgresql+asyncpg://user:password@localhost:5432/telegram_parser |
ALLOWED_USER_ID |
Your numeric Telegram user ID (get it from @userinfobot). Only this user can log in |
cd backend
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
alembic upgrade head
uvicorn main:app --reload --port 8000cd frontend
npm install
npm run dev- Log in with your Telegram phone number (QR code or SMS)
- Add your target channel(s) under "My Channels"
- Add source channels and link them to your channels
- Click a source channel → "Fetch Posts" to parse latest posts
- Click a post → "Rewrite with AI" → edit if needed → "Publish"
Example configs for deployment on a Linux server are in the deploy/ directory:
nginx.conf— Nginx reverse proxy with SSLmegaparser.service— systemd unit for the backenddeploy.sh— pull, build, and restart script
# Build frontend for production
cd frontend
npm run build
# Run backend with uvicorn
cd backend
uvicorn main:app --host 127.0.0.1 --port 8000 --workers 1backend/
main.py # FastAPI app, startup, CORS
config.py # Pydantic settings from .env
models.py # SQLAlchemy models
database.py # Async engine & session
telegram_client.py # Telethon MTProto client (parsing & media download)
bot_publisher.py # Bot API publisher (sendMessage / sendPhoto / sendMediaGroup)
ai_rewriter.py # OpenAI GPT-4o rewriter
routers/
auth.py # Phone login, QR login, session management
channels.py # My channels & source channels CRUD
posts.py # Post list, rewrite, publish, discard
admin.py # Admin panel endpoints
alembic/ # Database migrations
frontend/
src/
pages/ # Login, Dashboard, Admin
components/ # Sidebar, PostCard, PostEditor
api/client.ts # Axios client
deploy/ # Nginx, systemd, deploy script
MIT