tg-hub

Sync Telegram messages to local SQLite and query them offline with Python.

1|Updated Jun 20, 2026
One-click install
npx skills add https://github.com/riipandi/minis-skills --skill tg-hub-riipandi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: tg-hub
Source: https://github.com/riipandi/minis-skills/tree/main/tg-hub
Command: npx skills add https://github.com/riipandi/minis-skills --skill tg-hub-riipandi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires telethon, and includes scripts (resource) components.

What problem does it solve? Reading and searching Telegram group or channel history programmatically normally requires repeated live API calls, which are slow, rate-limited, and impossible offline. This Skill syncs messages incrementally into a local SQLite database so keyword search, filtering, and statistics run offline in milliseconds. ## Core Features & Use Cases - Local-first message sync: Incrementally sync groups and channels via Telethon (MTProto) into SQLite, with throttling, jitter, and flood-wait handling to respect Telegram rate limits. - Offline queries: Keyword and regex search, multi-keyword OR filters, today's messages, recent-hours windows, top senders, and timeline statistics, all served from the local database. - Use Case: You monitor several Telegram communities for job postings. Run a daily refresh, then filter messages for "hiring,remote,freelance" over the last 24 hours and review top senders, all without reconnecting to Telegram. ## Quick Start Ask the assistant to sync your Telegram groups with tg-hub and then search the local database for a keyword from the last 48 hours.

Frequently Asked Questions about tg-hub

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I search Telegram group messages with Python?

Use the TGClient search method after syncing messages to the local SQLite database. It supports keyword and regex search with filters for chat, sender, and time window, returning results offline in milliseconds.

How to sync Telegram channel history locally?

Call client.sync with the chat name or ID to fetch history incrementally into SQLite, or use refresh for a quick daily update capped at 500 new messages per chat. First-time syncs are auto-limited to reduce rate-limit risk.

Does this use the Telegram Bot API or MTProto?

It uses MTProto via the Telethon library, logging in with your personal Telegram account rather than a bot token. First login requires entering your phone number and a verification code in an interactive terminal.

Can I query Telegram messages offline?

Yes. Read operations like search, filter, today, recent, top_senders, and timeline query only the local SQLite database and work fully offline. Only sync and refresh operations connect to Telegram.

Why do I get a warning about api_id 2040?

The default credentials are Telegram Desktop's public API ID, which carries restriction risk under heavy use. Create your own app at my.telegram.org and set the TG_API_ID and TG_API_HASH environment variables to remove the warning.

What are the limitations of syncing Telegram messages this way?

Telegram enforces API rate limits, so large syncs are throttled with delays and flood-wait handling. Only text content is stored, and high-frequency refresh calls increase account restriction risk, so daily incremental updates are recommended.