agentleFS
leshchenko1979leshchenko1979/fast-mcp-telegram/.cursor/skills/telegram-patterns/SKILL.md

telegram-patterns

Skill50 starsChanged 4 months agoMITView on GitHub

Telegram-specific patterns and Telethon library usage

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Always resolve chat/user entities using the utility functions:

    line 10
  2. Distinctive:

    Use these special identifiers for common chats:

    line 26
  3. Distinctive:

    Check for various types of message content:

    line 44
  4. Distinctive:

    Use proper patterns for iterating through messages:

    line 61

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Telegram-Specific Patterns

Entity Resolution

Always resolve chat/user entities using the utility functions:

from src.utils.entity import get_entity_by_id

# ✅ Correct - handles all entity types (users, chats, channels)
entity = await get_entity_by_id(chat_id)
if not entity:
    raise ValueError(f"Could not find chat with ID '{chat_id}'")

# ❌ Wrong - don't use client.get_entity directly
entity = await client.get_entity(chat_id)  # Missing error handling

Special Chat Identifiers

Use these special identifiers for common chats:

# Saved Messages (your own messages)
chat_id = "me"

# Channel IDs (always start with -100)
channel_id = "-1001234567890"

# User IDs (numeric strings)
user_id = "123456789"

# Usernames (without @)
username = "telegram"

Message Content Detection

Check for various types of message content:

# Check for text content
has_text = message.text and message.text.strip()

# Check for media content (photos, documents, etc.)
has_media = hasattr(message, "media") and message.media is not None

# Check for specific media types
is_photo = hasattr(message, "photo") and message.photo is not None
is_document = hasattr(message, "document") and message.document is not None
is_voice = hasattr(message, "voice") and message.voice is not None

Message Iteration

Use proper patterns for iterating through messages:

# ✅ Correct - limit results and handle empty messages
async for message in client.iter_messages(entity, limit=50):
    if not message:
        continue
    # Process message
    await process_message(message)

# ❌ Wrong - no limit can cause performance issues
async for message in client.iter_messages(entity):  # No limit!
    pass

Forwarded Message Handling

Handle forwarded messages properly:

# Check if message is forwarded
if hasattr(message, "forward") and message.forward:
    forward_info = await _extract_forward_info(message)
    original_sender = forward_info.get("sender")
    original_chat = forward_info.get("chat")
    forward_date = forward_info.get("date")

Peer ID Handling

Work with different peer ID types:

# User peer
user_peer = {"_": "inputPeerUser", "user_id": 123456, "access_hash": 123456789}

# Channel peer
channel_peer = {"_": "inputPeerChannel", "channel_id": 123456, "access_hash": 123456789}

# Chat peer
chat_peer = {"_": "inputPeerChat", "chat_id": 123456}

# Self peer (Saved Messages)
self_peer = {"_": "inputPeerSelf"}

Session Management

Handle Telegram session files properly:

# Session files are managed automatically by the framework
# Don't manually create or delete session files
# Use setup_telegram.py for initial authentication

# Session file location is determined by environment:
# - Local development: project root
# - Production/ephemeral: ~/.config/fast-mcp-telegram/

Rate Limiting Awareness

Be aware of Telegram API limits:

# Respect rate limits
import asyncio
await asyncio.sleep(1)  # Rate limiting between requests

# Use reasonable limits for bulk operations
MAX_MESSAGES = 100  # Don't fetch thousands at once
BATCH_SIZE = 50     # Process in reasonable batches

Error Pattern Recognition

Recognize common Telegram errors:

error_text = str(e).lower()

# Channel access errors
if "channel" in error_text and "access" in error_text:
    return {"error": "Cannot access this channel"}

# Flood wait errors
if "flood" in error_text and "wait" in error_text:
    return {"error": "Rate limited, please wait before retrying"}

# Authentication errors
if "auth" in error_text or "session" in error_text:
    return {"error": "Authentication required, run setup_telegram.py"}

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.