Telegram howto

From tonydzi/second-brain-starter-kit · View interactive version

Telegram howto is an AI agent skill from the GitHub repository tonydzi/second-brain-starter-kit. Operating manual for Telegram over its MCP connector and roughly 115 tools: how to find a chat by title, the tool inventory grouped by job, resolving chat ids, auto-transcribing voice notes, and the connector gotchas (pinned-first ordering, big-page crashes, reload after reconnect, untrusted fields,

How to use this skill

Skill file

Telegram howto — operating manual (the operator's account @work_acct_a)

Born 2026-06-08: finding ONE private chat by title cost a dozen calls. The operator taught the fix, then we removed the gap for good by adding a search_dialogs tool to the connector. The connector is chigwell/telegram-mcp (a git checkout at <TELEGRAM_MCP_DIR>, Telethon + FastMCP, tools mcp__telegram__*). After it reconnects, reload schemas via ToolSearch before calling.

0) Find a chat by title — LOCAL INDEX FIRST, live MCP only as fallback

⚡ STEP 0 (default, ALWAYS try first): the local index. PYTHONUTF8=1 python "$IMPORTS_ROOT/dialogs/find_chat.py" <words> — queries chats.db (125,885 entities / 21,146 groups+channels + 104,739 user DMs; backbone = the CRM tg_entities export + live refresh). ~0.16s, 0 API calls, 0 tokens, zero FloodWait/ban risk. Translit + wrong-keyboard-layout aware (a Latin-typed query still finds a chat named in another script). Prints [TYPE] telegram_id name t.me-link (+members). Flags: --all (include user DMs), --users (only DMs), --limit N. The /chat skill wraps this. This is why chat-finding is INSTANT — never go to the live API for a chat you can find here. (Born 2026-06-19: the operator flagged "you take AGES to find chats" — the cause was skipping this local step and paginating the live API. Rebuilt 2026-06-19 from the CRM dump; chats.db supersedes the old 10k-capped dialogs.db.)

STEP 1 fallback (live, slower, costs API + FloodWait budget): search_dialogs(query) matches the title / name / @username of EVERY dialog you're in — including private groups/channels with no @username. It's the MCP twin of the app's search box. Example: search_dialogs("voice archive") → the content hub.

0a) Keep the local index fresh — refresh routine

chats.db = a CRM-export backbone (build_chats_db.py from crm_export\contacts.csv, idempotent DROP+rebuild) kept fresh per-account by refresh_chats.py (Telethon iter_dialogs(), UNCAPPED — fixes the old 10k cap). It can go stale on new/renamed chats. Refresh it:

Why the built-in searches don't cover private chats:

Fallbacks if search_dialogs is unavailable:

  1. Bump-to-top: have the operator send anything (even .) into the chat → it jumps to just below the pinned block → list_chats(limit≈15) and match the title.
  2. Page the dialog list: get_chats(page=N, page_size≤100) and match locally.

1) Resolved chat ids (this account; verify before destructive use)

2) The content hub already transcribes voice for you

In <YOUR_CHAT_ID>, each the operator voice message gets two auto-replies from bot "Personal Audio Summary" (both reply_to the voice id):

  1. raw transcript — ends Transcribed by whisper AI
  2. cleaned summary — ends Summary: GPT-5.5 + whisper

So you do NOT download + Whisper this chat — just get_history and read the bot's text. Only chats WITHOUT this bot (e.g. Saved Messages) need the manual download→faster-whisper path (_imports/tg_voice/transcribe_pokupki_voice.py, CUDA RTX A3000).

3) Full tool inventory (~115), grouped by job

Self / account: get_me, list_accounts, get_full_user, get_user_status, get_user_photos, get_last_interaction, update_profile, set_profile_photo, delete_profile_photo, get_privacy_settings, set_privacy_settings

Find / resolve chats & people: search_dialogs (our add — find a chat by title), list_chats, get_chats, get_chat, get_full_chat, resolve_username, search_contacts, search_public_chats, search_global, search_messages, get_common_chats, get_contact_chats, get_direct_chat_by_contact, list_contacts, get_contact_ids, list_topics

Read / search messages: get_history, get_messages, list_messages (one chat; supports from_date/to_date), search_messages_global (our add — search ALL chats by text), find_media (our add — voice/photo/docs by type, optionally since a date), get_new_messages_since (our add — incremental cursor: only msgs newer than an id), resolve_message_link (our add — read a t.me link + context), get_unread_mentions (our add — where you were tagged & unread), get_message_context, get_pinned_messages, get_scheduled_messages, get_drafts, get_message_reactions, get_message_read_by, get_media_info, get_message_link, list_inline_buttons

Send / edit: send_message, reply_to_message, edit_message, delete_message, delete_messages_bulk, forward_message, forward_messages, send_file, upload_file, send_album, send_voice, send_gif, get_gif_search, send_sticker, get_sticker_sets, send_contact, create_poll, send_reaction, remove_reaction, send_scheduled_message, delete_scheduled_message, save_draft, clear_draft, press_inline_button, set_bot_commands, get_bot_info

Media: download_media

Chat management: create_group, create_channel, edit_chat_title, edit_chat_about, edit_chat_photo, delete_chat_photo, invite_to_group, export_chat_invite, get_invite_link, import_chat_invite, join_chat_by_link, leave_chat, subscribe_public_channel, delete_chat_history, set_default_chat_permissions, toggle_slow_mode, pin_message, unpin_message, unpin_all_messages, mark_as_read, mute_chat, unmute_chat, archive_chat, unarchive_chat

Members / admin: get_participants, get_admins, promote_admin, demote_admin, edit_admin_rights, ban_user, unban_user, get_banned_users, block_user, unblock_user, get_blocked_users, get_recent_actions

Contacts: add_contact, delete_contact, import_contacts, export_contacts

Folders: list_folders, get_folder, create_folder, delete_folder, add_chat_to_folder, remove_chat_from_folder, reorder_folders

Realtime watch: wait_for_new_message, wait_for_settled_message

Upstream had no search_chats/search_groups/search_channels; we added search_dialogs (§6) to fill exactly that gap.

4) Connector gotchas (learned the hard way)

5) Common recipes

6) Local modifications to the connector (keep these alive)

The connector at <TELEGRAM_MCP_DIR> is a git checkout of upstream github.com/chigwell/telegram-mcp. We have LOCAL changes that a naive reinstall/git pull could lose:

7) Safety — user-account ban / FloodWait avoidance

This is the operator's PERSONAL warmed account (not a bot). Operate gently:

<!--kit-footer-->


Like this skill? It is part of second-brain-starter-kit: the second brain we built for ourselves and run every day at Palo Alto AI Research Lab. Install the whole set with npx skills add tonydzi/second-brain-starter-kit. Everything is open source and free, so take what you need.

Flagships worth a look on their own: secondop-panel (a second opinion from a panel of external models), claude-memory-tidy (stop your agent's memory from rotting), telegram-mcp-kit (your own Telegram over MCP in about 15 minutes).

Author: Anton Dziatkovskii, Palo Alto AI Research Lab. Telegram @tonydzi - WhatsApp +1 341 222 9178 - X @Tony_Stef_

Engineers: want to test-drive this setup? Message me. I hand out free starter seeds to engineers who test and report back, and custom skill requests are welcome.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.