How to create a universal Telegram bot – parser of any posts from channels with AI-normalization and fallback rules
Next step
Open the bot or continue inside this section.
Article -> plan in AI
Paste this article URL into any AI and get an implementation plan for your project.
Read this article: https://vibecode.morecil.ru/en/telegram-boty/kak-sozdat-yniversalny-parser/
Work in my current project context.
Create an implementation plan for this stack:
1) what to change
2) which files to edit
3) risks and typical mistakes
4) how to verify everything works
If there are options, provide "quick" and "production-ready". How to use
- Copy this prompt and send it to your AI chat.
- Attach your project or open the repository folder in the AI tool.
- Ask for file-level changes, risks, and a quick verification checklist.
In this article, we will discuss how to create a bot that:
- Automatically picks up new posts from any Telegram channels (public and private).
- Through AI, Groq turns chaotic text into a structured card: post type, category, title, summary, links, contacts, etc.
- When AI fails, it instantly switches to reliable rules (fallback).
- Fully autonomously publishes clean tape - without manual moderation.
- It works 24/7 and expands easily to any niche.
What you need (preparation in 10 minutes)
- Installed *Node.js 20+ *
- Telegram account
- Free account Groq (the fastest and cheapest LLM for 2026)
- (Optional) Free Supabase Data Storage Project
Step 1. Create a bot through BotFather
- Open Telegram → find @BotFather
- Write
/newbot - Come up with a name:
МойПарсерБот - Create a username:
my_parser_bot(should end inbot) - BotFather will send a token of the form
123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
Save the token to a safe place. This is your BOT_TOKEN.
Step 2. Get a Groq API key
- Go to https://console.groq.com/keys
- Press Create API key
- Copy the key (starts with
gsk_) - Save as
GROQ_API_KEY
Step 3. (Optional) Create a Supabase Project
- https://supabase.com Sign up (via GitHub)
- Select a region (Europe)
- Remember:
- Project URL (SUPABASE URL)
- anon public key (SUPABASE ANON KEY)
Step 4. Create a project and establish dependencies
Create a folder and execute commands:
mkdir tg-universal-parser-bot
cd tg-universal-parser-bot
npm init -y
npm install telegraf node-cron axios cheerio groq-sdk dotenv
npm install -D nodemon
Create a .env file and paste:
BOT_TOKEN=твой_токен_из_BotFather
GROQ_API_KEY=твой_groq_ключ
SUPABASE_URL=https://...
SUPABASE_ANON_KEY=eyJ...
Step 5. The first prompt is the basic framework of the bot
Copy and send it to Codex or Claude:
Create a full working bot framework on Telegraf v4.
Requirements:
- Use dotenv.
Commands: /start, /addsource, /listsources, /status
Inline buttons and single-navigation (update one message)
Prepare a separate worker.js file for the cronworker (every 10 minutes)
Prepare folders: src/bot, src/worker, src/parsers, src/ai, src/db
Connect Supabase (or SQLite as Fallback)
It should be run by npm start and npm run worker.
- Add comments "// TODO" where you will need to insert parser logic and AI
Output ALL project code as a structure of content files.
Step 6. The second prompt is the architecture and structure of the database
Based on the previous code, add a complete universal parser architecture for any posts from Telegram channels.
Supabase tables (SQL migration):
- sources (id, channel username, type: public|private, cursor, last import)
raw posts (id, source id, message id, raw text, posted at)
- parsed posts (id, raw id, post type, category, title, summary, links: jsonb, contacts: jsonb, confidence, status: published|skipped, published at)
Logic:
Every 10 minutes a worker visits sources.
- for public: parsite https://t.me/s/...
- for private: stub (later add MTProto)
- After receiving raw → AI parse → fallback rules → auto decision (publish if confidence > 75 and there is useful content)
- No manual moderation! Only auto-publish or skip + cause log
Update files: db/migrations.sql, src/ai/parser.js, src/worker/importer. js
Step 7. Third Prompt – Parser of Public Channels
Based on the previous code, implement a full-fledged parser of public channels.
ParsePublicChannel(channel: string, afterTimestamp?: number):
- axios.get (`https://t.me/s/${channel}`)
- cheerio parses all posts
- Retrieves: message id, full text, date, all links, all @username, buttons
- Removes noise: channel footers, advertising, "subscribe", repeated blocks
Returns an array of clean raw posts
Add an anti-duplicate to (channel + message id)
Step 8. Fourth Prompt – AI Contract + Fallback
Create two Prompts for Groq (llama-3.3-70b or mixtral):
1. The main AI prompt (returns only JSON):
Systemic: You are an expert in structuring Telegram posts. Return only valid JSON without markdown.
JSON diagram:
{
“post type: “announcement | sale | question | news | offer | discussion | other”,
Category: String (one word or short phrase)
"title": "string,"
"summary": "stringing up to 300 characters"
"links": ["array of urls"],
“contacts: [”@username”, “phone”, “other”],
"confidence": 0-100,
"Reason": "stringing short"
}
2. Fallback rules (if AI is not available or confidence < 60):
- If you have @username or a link to an external resource → confidence 70
If more than 100 characters of meaningful text → confidence 50
Extract all links and @ via regex
Implement the function normalizePost(rawText) which first tries AI, if the error - fallback.
Step 9. The fifth is a fully automatic decision engine
Add the decision engine without manual moderation:
Rules:
- If confidence >= 78 AND (are contacts OR links.length > 0) → status: "published"
- Otherwise, "skipped" with the preservation of the cause in the database
- For published - save in parsed posts and (optional) send to the channel bot or subscriber's face n
Implement decideAndSave(parsedData)
Step 10. Sixth Prompt – Tests and Launch
Add:
Simple tests (jest or console.log) for parser and AI
- Team in package.json: "dev": "nodemon src/bot/index.js"
- “worker”: “node src/worker/importer.js”
In /start show a beautiful keyboard with buttons
Get the final launch instructions.
Step 11. Launching a bot
npm run dev
In a separate terminal:
npm run worker
Add the first source:
/addsource mychannel (without @)
Done! The bot already parses, normalizes through AI + fallback and publishes only quality posts.
Важно, даже запуск бота или добавление каналы в базу можно сделать через ИИ. В статье написан ручной способ, чтобы было понимание, как это работает. Также не нужно слепо копировать каждый промт, вы его всегда можете откорректировать под себя, задача статьи — объяснить алгоритм, архитектуру, дальше вы можете отправить эту статью в свой ИИ и задавать ему вопросы, чтобы проект был реализован под вашу идею. Идеальных промтов не существует.XX
What's next (expansion in 1 hour)
- Add private channels (MTProto + grammY userbot)
- Subscription of users to categories
- Notifications via Telegram
- Hosting on Railway / Render (free)