vibecode.wiki
RU EN
~/wiki / telegram-boty / kak-sozdat-yniversalny-parser

How to create a universal Telegram bot – parser of any posts from channels with AI-normalization and fallback rules

◷ 6 min read 3/1/2026

Main chat

A chat for vibe coders: news, guides, live cases, marketplace, and finding executors.

$ cd section/ $ join vibe dev

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)

  1. Installed *Node.js 20+ *
  2. Telegram account
  3. Free account Groq (the fastest and cheapest LLM for 2026)
  4. (Optional) Free Supabase Data Storage Project

Step 1. Create a bot through BotFather

  1. Open Telegram → find @BotFather
  2. Write /newbot
  3. Come up with a name: МойПарсерБот
  4. Create a username: my_parser_bot (should end in bot)
  5. 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

  1. Go to https://console.groq.com/keys
  2. Press Create API key
  3. Copy the key (starts with gsk_)
  4. Save as GROQ_API_KEY

Step 3. (Optional) Create a Supabase Project

  1. https://supabase.com Sign up (via GitHub)
  2. Select a region (Europe)
  3. 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:

bash
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:

env
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:

code
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

code
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

code
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

code
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

code
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

code
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

bash
npm run dev

In a separate terminal:

bash
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)