Automated summary
Skill that drives `tg`, a read-only CLI speaking Telegram's MTProto protocol, to list chats, fetch messages and download media.
Strengths
- Read-only by design: no command sends messages or mutates Telegram data, and the only writes are local (session files and downloaded media).
- Bypasses Bot API restrictions by talking to MTProto directly, so user-account history is accessible.
- JSON output plays well with jq, making filtering and scripted extraction straightforward.
- api_id/api_hash are kept in the system keychain rather than environment variables, with explicit guardrails around session files.
Limitations
- Initial authentication (`tg auth`) is interactive (phone number plus OTP) and cannot be automated.
- Requires api_id/api_hash credentials created manually at my.telegram.org/apps.
- No support for sending messages or modifying groups/channels, so write-side automation is out of scope.
- Session files under ~/.tg-mtproto-cli/sessions/ hold sensitive auth keys and must not be exposed.
Use it when you need to read, export or archive Telegram conversations and media from a user account, for instance to feed an analysis pipeline.
Avoid it when the goal is sending messages, managing groups or automating any write action on Telegram, or when no authenticated session can be created on the machine.
Security analysis
CautionThe skill is read-only by design and does not instruct destructive actions, but it handles highly sensitive personal data (Telegram messages, media) and requires storing API credentials in the keychain. Network and filesystem writes are limited to downloading media and session files, which is legitimate for the stated purpose but still involves risk if misused. Rating as caution due to the sensitive nature of the data and reliance on an external tool.
- •Accesses sensitive personal data (Telegram chats, media)
- •Stores API credentials in system keychain
- •Network access to Telegram servers
- •Downloads media files locally, which could be large or contain sensitive content
- •Uses a third-party CLI tool not widely audited
Examples
List my Telegram groups and supergroups, then show me the last 50 messages from the one called 'Data Engineering'.Fetch the last 200 messages from @somechannel using tg and output them as JSON so I can grep for mentions of 'pricing'.Download all media from chat -1001234567890 into ./telegram-media using the tg CLI.name: tg-cli description: > Read-only Telegram CLI via MTProto. Lists chats, fetches messages, downloads media, manages local accounts/sessions. Does not send messages or modify Telegram data. Use when the user asks to read Telegram chats, fetch messages, download media, or automate Telegram data extraction. required_binaries:
- name: tg package: tg-mtproto-cli install: npm install -g tg-mtproto-cli registry: https://www.npmjs.com/package/tg-mtproto-cli source: https://github.com/cyberash-dev/tg-mtproto-cli
- name: jq optional: true install: brew install jq credentials:
- name: Telegram API credentials
fields: [api_id, api_hash]
obtain: https://my.telegram.org/apps
storage: system keychain (macOS Keychain / Windows Credential Vault / Linux Secret Service)
input: interactive prompt via
tg auth - name: Phone number + OTP
storage: not persisted
input: interactive prompt via
tg auth(one-time, creates session) runtime_permissions: network: outbound TCP to Telegram DC servers (MTProto protocol) filesystem:- read/write: ~/.tg-mtproto-cli/sessions/*.session (SQLite auth sessions)
- write: media files to --out dir or cwd (tg download only) keychain: read/write account metadata and API credentials shell: false browser: false
tg — Telegram CLI via MTProto
CLI tool for reading Telegram data directly via MTProto protocol. No Bot API, no limits.
Required binaries
| Binary | Install | Purpose |
|---|---|---|
| tg | npm install -g tg-mtproto-cli | Core CLI |
| jq (optional) | brew install jq or apt install jq | JSON filtering in workflow examples |
Source and provenance:
Verify after install:
tg --version
npm ls -g tg-mtproto-cli
Required credentials
| Credential | How to obtain | Storage |
|---|---|---|
| Telegram api_id + api_hash | my.telegram.org/apps | System keychain (macOS Keychain / Windows Credential Vault / Linux Secret Service) |
| Phone number + OTP code | Interactive prompt during tg auth | Not persisted; used once for session creation |
Credentials are entered interactively via tg auth. No environment variables required.
Runtime surface
| Resource | Access | Details |
|---|---|---|
| Network | Outbound TCP to Telegram DC servers | MTProto protocol, required for all commands |
| Session files | Read/write ~/.tg-mtproto-cli/sessions/*.session | SQLite databases with auth keys; created by tg auth |
| System keychain | Read/write | Stores api_id, api_hash, account metadata, default account |
| Filesystem | Write (only tg download) | Saves media to --out dir or current directory |
Guardrails
- The CLI is read-only by design — it has no commands to send messages, create chats, modify groups, or perform any write operations on Telegram. The only write targets are local: session files and downloaded media.
tg downloadwrites files only to the explicitly specified--outdirectory or cwd.- Session files contain sensitive auth material — do not read, copy, or expose
~/.tg-mtproto-cli/sessions/contents. - Do not log or display
api_id/api_hashvalues. - If
tg authis needed, inform the user — it requires interactive input (phone, OTP) and cannot be automated.
Chat identification
Chats can be referenced by:
- Username:
@usernameorusername - Numeric ID:
-1001234567890(groups/supergroups use negative IDs) - Phone:
+1234567890(for private chats)
To find a chat's numeric ID, use tg chats --json | jq '.[] | {id, title}'.
Commands reference
List chats
tg chats [--type private|group|supergroup|channel] [--limit 50] [--offset 0]
Read messages
tg messages <chat> [-n 100] [--all] [--topic <id>] [--after <datetime>]
| Flag | Description |
|---|---|
| -n <count> | Number of messages (default: 100) |
| --all | Entire history (shows progress) |
| --topic <id> | Forum topic (get IDs via tg topics <chat>) |
| --after <datetime> | Only messages after this time |
--after formats: 2026-02-22, 2026-02-22T10:00, 10:00 (today).
When --after + -n are combined: filter by date first, then take last N.
List forum topics
tg topics <chat>
Returns topic IDs needed for --topic flag.
Download media
tg download <chat> <messageId> [--out <dir>]
Downloads the media attachment from a specific message. Get message IDs from tg messages output (shown as #<id>).
Account management
tg auth # authenticate (interactive)
tg logout [alias] # remove session
tg accounts # list accounts
tg accounts rename <old> <new> # rename alias
tg default <alias> # set default
Global flags
| Flag | Effect |
|---|---|
| --account <alias> | Use specific account instead of default |
| --json | JSON output (for scripting/piping) |
JSON output
All commands support --json for structured output. Dates are ISO 8601.
tg chats --json
tg messages @chat -n 10 --json
tg download @chat 42 --json
Message JSON schema
{
"id": 42,
"chatId": -1001234567890,
"senderName": "John",
"text": "Hello",
"date": "2026-02-22T10:15:00.000Z",
"media": { "type": "photo", "fileName": null, "mimeType": "image/jpeg", "size": 262525 },
"replyToId": null,
"isOutgoing": false
}
media is null when no attachment. media.type: photo, video, document, audio, voice, sticker.
Common workflows
Extract text from a chat since a date
tg messages @channel --after 2026-02-01 --json | jq -r '.[].text // empty'
Find messages with photos
tg messages @chat -n 500 --json | jq '[.[] | select(.media.type == "photo")]'
Download all photos from recent messages
for id in $(tg messages @chat -n 50 --json | jq -r '.[] | select(.media.type == "photo") | .id'); do
tg download @chat "$id" --out ./photos
done
Read a forum topic
tg topics -1001234567890 # find topic ID
tg messages -1001234567890 --topic 42 -n 20
Multi-account usage
tg chats --account work
tg messages @chat -n 10 --account personal
Exit codes
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Runtime error (invalid args, chat not found) |
| 2 | Auth required (no account, expired session) — run tg auth |
Troubleshooting
- "No default account" → run
tg author use--account <alias> - "Session expired" → run
tg authto re-authenticate - Chat not found → use numeric ID from
tg chats --json - Empty messages → check chat ID sign (groups are negative)
From the file to a first result
The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.
View the source and supporting filesThis download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.
1. Download the file
Download SKILL.mdFrom the root of a test project, save the file as .skill-downloads/telegram-cli-via-mtproto-mrwakfam/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.
Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.
mkdir -p '.skill-downloads/telegram-cli-via-mtproto-mrwakfam' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/telegram-cli-via-mtproto-mrwakfam/download' --output '.skill-downloads/telegram-cli-via-mtproto-mrwakfam/SKILL.md.part' && mv '.skill-downloads/telegram-cli-via-mtproto-mrwakfam/SKILL.md.part' '.skill-downloads/telegram-cli-via-mtproto-mrwakfam/SKILL.md'2. Check prerequisites
Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.
No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.
The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.
3. Load the skill
After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.
Claude Code
test -f '.skill-downloads/telegram-cli-via-mtproto-mrwakfam/SKILL.md' && test -s '.skill-downloads/telegram-cli-via-mtproto-mrwakfam/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/tg-cli' && cp -R '.skill-downloads/telegram-cli-via-mtproto-mrwakfam' '.claude/skills/tg-cli'Codex
test -f '.skill-downloads/telegram-cli-via-mtproto-mrwakfam/SKILL.md' && test -s '.skill-downloads/telegram-cli-via-mtproto-mrwakfam/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/tg-cli' && cp -R '.skill-downloads/telegram-cli-via-mtproto-mrwakfam' '.agents/skills/tg-cli'OpenSkills
OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.
Official OpenSkills installationopenskills install './.skill-downloads/telegram-cli-via-mtproto-mrwakfam'openskills read 'telegram-cli-via-mtproto-mrwakfam'Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.
For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.
openskills syncManual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.
4. Try a first task
Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:
Read .skill-downloads/telegram-cli-via-mtproto-mrwakfam/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.
PDF Reader
Productivity
Read and extract text from PDF files, including documents, reports, contracts, and spreadsheets. Works with local files, URLs, and WhatsApp attachments. Use whenever PDF content is needed, even if not explicitly requested.
Discord Messaging Workflows
Productivity
Use the message tool to send, edit, and moderate Discord messages with interactive components.
Interactive Verdict Preview
Productivity
Generate an interactive HTML preview of keep/drop verdicts for maintainer review, then process the pasted feedback JSON.