sergei-mikhailov-tg-channel-reader
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesetg-channel-reader
tg-channel-reader
Read posts and comments from Telegram channels using MTProto (Pyrogram or Telethon).
Works with any public channel and private channels the user is subscribed to.
Supports fetching discussion replies (comments) for individual posts.
Security notice: This skill requiresandTG_API_IDfrom my.telegram.org. The session file grants full Telegram account access — store it securely and never share it.TG_API_HASH
通过MTProto(Pyrogram或Telethon)读取Telegram频道的帖子和评论。
适用于所有公开频道以及用户已订阅的私有频道。
支持获取单条帖子的讨论回复(评论)。
Exec Approvals
执行权限审批
Just installed via? Complete Setup & Installation (below) first — the skill needsclawhub install, credentials, and a session file before exec approvals matter.pip install
OpenClaw blocks unknown CLI commands by default. The user must approve commands before they can run. If the command hangs or the user says nothing is happening — exec approval is likely pending.
tg-reader刚通过安装完成? 请先完成下方的设置与安装步骤——本技能需要先完成clawhub install、配置凭证和生成会话文件,之后才需要考虑执行权限审批的问题。pip install
OpenClaw默认会拦截未知的CLI命令。用户必须先批准相关命令才能运行。如果命令卡住或用户反馈没有任何反应,很可能是执行权限审批处于待处理状态。
tg-readerQuick setup (recommended)
快速设置(推荐)
Run from the skill directory — checks prerequisites, installs pip packages if needed, and prints the approval commands to run:
bash
cd ~/.openclaw/workspace/skills/sergei-mikhailov-tg-channel-reader
bash setup-tg-reader.sh进入技能目录运行以下命令——会检查前置条件、按需安装pip包,并打印需要运行的权限审批命令:
bash
cd ~/.openclaw/workspace/skills/sergei-mikhailov-tg-channel-reader
bash setup-tg-reader.shManual CLI approval
手动CLI审批
bash
openclaw approvals allowlist add --gateway "$(which tg-reader)"
openclaw approvals allowlist add --gateway "$(which tg-reader-check)"
openclaw approvals allowlist add --gateway "$(which tg-reader-telethon)"bash
openclaw approvals allowlist add --gateway "$(which tg-reader)"
openclaw approvals allowlist add --gateway "$(which tg-reader-check)"
openclaw approvals allowlist add --gateway "$(which tg-reader-telethon)"Alternative: approve on first use
替代方案:首次使用时审批
- Control UI — open , find the pending approval for
http://localhost:18789/, click "Always allow". Docstg-reader - Messenger (Telegram, Slack, Discord) — the bot sends an approval request with an . Reply:
<id>. Other options:/approve <id> allow-always,allow-once.deny
The approval prompt appears in the Control UI or as a bot message — not in the agent's conversation. This is a common source of confusion.
- 控制UI——打开,找到
http://localhost:18789/的待审批请求,点击**“始终允许”**。文档tg-reader - 通讯工具(Telegram、Slack、Discord)——机器人会发送带的审批请求。回复:
<id>。其他选项:/approve <id> allow-always(允许一次)、allow-once(拒绝)。deny
审批提示会出现在控制UI或机器人消息中,而非Agent的对话界面。这是常见的混淆点。
When to Use
使用场景
- User asks to "check", "read", or "monitor" a Telegram channel
- Wants a digest or summary of recent posts
- Asks "what's new in @channel" or "summarize last 24h from @channel"
- Wants to track or compare multiple channels
- Wants channel info (title, description, subscribers) — use
tg-reader info
- 用户要求“查看”“读取”或“监控”某个Telegram频道
- 需要频道近期帖子的摘要或汇总
- 用户询问“@channel频道有什么新内容”或“总结@channel频道过去24小时的内容”
- 需要跟踪或对比多个频道
- 需要获取频道信息(标题、描述、订阅人数)——使用命令
tg-reader info
Quick Start
快速开始
bash
undefinedbash
undefined1. Run pre-flight diagnostic (fast, no Telegram connection)
1. 运行预检诊断(快速,无需连接Telegram)
tg-reader-check
tg-reader-check
2. Get channel info
2. 获取频道信息
tg-reader info @channel_name
tg-reader info @channel_name
3. Fetch recent posts
3. 获取近期帖子
tg-reader fetch @channel_name --since 24h
> **`tg-reader: command not found`?** Run `bash setup-tg-reader.sh` from the skill directory (it will install the package), or manually: `cd ~/.openclaw/workspace/skills/sergei-mikhailov-tg-channel-reader && pip install .`
---tg-reader fetch @channel_name --since 24h
> **提示:如果出现`tg-reader: command not found`?** 进入技能目录运行`bash setup-tg-reader.sh`(会自动安装包),或手动执行:`cd ~/.openclaw/workspace/skills/sergei-mikhailov-tg-channel-reader && pip install .`
---Commands
命令说明
tg-reader-check
— Pre-flight Diagnostic
tg-reader-checktg-reader-check
— 预检诊断
tg-reader-checkAlways run before fetching. Fast offline check — no Telegram connection needed.
bash
tg-reader-check
tg-reader-check --config-file /path/to/config.json
tg-reader-check --session-file /path/to/sessionReturns JSON with or plus a array.
"status": "ok""status": "error"problemsVerifies:
- Credentials available (env vars or )
~/.tg-reader.json - Session file exists on disk (with size, modification date)
- At least one MTProto backend installed (Pyrogram or Telethon)
- Detects stale sessions (config points to older file while a newer one exists)
获取内容前请务必运行此命令。快速离线检查——无需连接Telegram。
bash
tg-reader-check
tg-reader-check --config-file /path/to/config.json
tg-reader-check --session-file /path/to/session返回包含或的JSON,以及数组。
"status": "ok""status": "error"problems验证内容包括:
- 是否有可用凭证(环境变量或)
~/.tg-reader.json - 磁盘上是否存在会话文件(包含文件大小、修改日期)
- 是否至少安装了一个MTProto后端(Pyrogram或Telethon)
- 检测过期会话(配置指向旧文件,但存在更新的文件)
tg-reader info
— Channel Info
tg-reader infotg-reader info
— 频道信息
tg-reader infobash
tg-reader info @channel_nameReturns title, description, subscriber count, and link.
bash
tg-reader info @channel_name返回频道标题、描述、订阅人数和链接。
tg-reader fetch
— Read Posts
tg-reader fetchtg-reader fetch
— 读取帖子
tg-reader fetchbash
undefinedbash
undefinedLast 24 hours (default)
过去24小时的内容(默认)
tg-reader fetch @channel_name --since 24h
tg-reader fetch @channel_name --since 24h
Last 7 days, up to 200 posts
过去7天的内容,最多200条帖子
tg-reader fetch @channel_name --since 7d --limit 200
tg-reader fetch @channel_name --since 7d --limit 200
Multiple channels (fetched sequentially with 10s delay between each)
多个频道(按顺序获取,频道间间隔10秒)
tg-reader fetch @channel1 @channel2 @channel3 --since 24h
tg-reader fetch @channel1 @channel2 @channel3 --since 24h
Custom delay between channels (seconds)
自定义频道间的间隔时间(秒)
tg-reader fetch @channel1 @channel2 @channel3 --since 24h --delay 5
tg-reader fetch @channel1 @channel2 @channel3 --since 24h --delay 5
Fetch posts with comments (single channel only, limit auto-drops to 30)
获取带评论的帖子(仅支持单个频道,自动将限制数降至30)
tg-reader fetch @channel_name --since 7d --comments
tg-reader fetch @channel_name --since 7d --comments
More comments per post, custom delay between posts
每条帖子获取更多评论,自定义帖子间的间隔时间
tg-reader fetch @channel_name --since 24h --comments --comment-limit 20 --comment-delay 5
tg-reader fetch @channel_name --since 24h --comments --comment-limit 20 --comment-delay 5
Skip posts without text (media-only, no caption)
跳过无文本的帖子(仅含媒体、无标题)
tg-reader fetch @channel_name --since 24h --text-only
tg-reader fetch @channel_name --since 24h --text-only
Human-readable output
人类可读格式输出
tg-reader fetch @channel_name --since 24h --format text
tg-reader fetch @channel_name --since 24h --format text
Write output to file instead of stdout (saves tokens)
将输出写入文件而非标准输出(节省令牌)
tg-reader fetch @channel_name --since 24h --output
tg-reader fetch @channel_name --since 24h --comments --output comments.json
tg-reader fetch @channel_name --since 24h --output
tg-reader fetch @channel_name --since 24h --comments --output comments.json
Use Telethon instead of Pyrogram (one-time)
使用Telethon而非Pyrogram(单次生效)
tg-reader fetch @channel_name --since 24h --telethon
tg-reader fetch @channel_name --since 24h --telethon
Read unread mode — only fetch new (unread) posts, no --since needed
未读模式——仅获取新的未读帖子,无需指定--since
Requires "read_unread": true in ~/.tg-reader.json
需要在~/.tg-reader.json中设置"read_unread": true
tg-reader fetch @channel_name
tg-reader fetch @channel_name
Override read_unread mode (fetch everything, don't update state)
覆盖未读模式(获取所有内容,不更新状态)
tg-reader fetch @channel_name --since 7d --all
tg-reader fetch @channel_name --since 7d --all
Custom state file location
自定义状态文件路径
tg-reader fetch @channel_name --since 24h --state-file /path/to/state.json
undefinedtg-reader fetch @channel_name --since 24h --state-file /path/to/state.json
undefinedtg-reader auth
— First-time Authentication
tg-reader authtg-reader auth
— 首次认证
tg-reader authbash
tg-reader authCreates a session file. Only needed once.
bash
tg-reader auth生成会话文件。仅需运行一次。
Read Unread Mode
未读消息读取模式
Only return new (unread) posts — the skill remembers what you've already seen. Useful for daily digests and monitoring workflows.
仅返回新的未读帖子——本技能会记录用户已查看的内容。适用于每日摘要和监控场景。
Setup
设置方法
Option A — config file ():
~/.tg-reader.jsonjson
{
"api_id": 12345,
"api_hash": "...",
"read_unread": true
}Option B — env var (works with ):
~/.openclaw/openclaw.jsonbash
export TG_READ_UNREAD=trueEnv vars take priority over the config file. This lets you enable read_unread via Docker alongside /.
openclaw.jsonenvTG_API_IDTG_API_HASHState is stored in (configurable via in config, env var, or flag).
~/.tg-reader-state.json"state_file"TG_STATE_FILE--state-file选项A — 配置文件():
~/.tg-reader.jsonjson
{
"api_id": 12345,
"api_hash": "...",
"read_unread": true
}选项B — 环境变量(可配合使用):
~/.openclaw/openclaw.jsonbash
export TG_READ_UNREAD=true环境变量优先级高于配置文件。这允许你通过的Docker配置项,与/一起启用未读模式。
openclaw.jsonenvTG_API_IDTG_API_HASH状态存储在中(可通过配置文件中的、环境变量或参数修改路径)。
~/.tg-reader-state.json"state_file"TG_STATE_FILE--state-fileBehavior
行为规则
- is not needed when
--sinceis enabled — the skill automatically returns all unread posts regardless of timeread_unread - First run (no prior state for channel): applies as usual (default 24h); state file created
--since - Subsequent runs: only posts newer than the last read are returned; is ignored
--since - flag: bypasses read_unread mode — fetches everything by
--allwithout updating state (preserves your position)--since - New channel: behaves like a first run (no prior state)
- No new posts: state unchanged, returned
count: 0
- 启用时无需指定
read_unread——技能会自动返回所有未读帖子,不受时间限制--since - 首次运行(频道无历史状态):参数正常生效(默认24小时);同时创建状态文件
--since - 后续运行:仅返回比上次读取时间更新的帖子;参数会被忽略
--since - 参数:绕过未读模式——按
--all指定的范围获取所有内容,且不更新状态(保留上次读取位置)--since - 新频道:行为与首次运行一致(无历史状态)
- 无新帖子:状态不变,返回
count: 0
Examples
使用示例
bash
undefinedbash
undefinedWith read_unread enabled — just fetch, no --since needed
启用未读模式时——直接获取,无需--since
tg-reader fetch @channel_name
tg-reader fetch @channel_name
First run for a new channel — --since determines initial window
新频道首次运行——--since指定初始时间范围
tg-reader fetch @new_channel --since 7d
tg-reader fetch @new_channel --since 7d
Override: fetch everything, don't update tracking state
覆盖未读模式:获取所有内容,不更新跟踪状态
tg-reader fetch @channel_name --since 7d --all
undefinedtg-reader fetch @channel_name --since 7d --all
undefinedOutput
输出格式
When read_unread mode is active, the JSON output includes a field:
read_unreadjson
{
"channel": "@channel_name",
"read_unread": {"enabled": true},
"count": 5,
"messages": [...]
}With :
--all"read_unread": {"enabled": true, "overridden": true}启用未读模式时,JSON输出会包含字段:
read_unreadjson
{
"channel": "@channel_name",
"read_unread": {"enabled": true},
"count": 5,
"messages": [...]
}使用参数时:
--all"read_unread": {"enabled": true, "overridden": true}Limitations
局限性
- Tracking is post-level only — new comments on already-read posts are not caught
- If a channel changes its username, tracking resets (state is keyed by username)
- Concurrent runs for the same channel are safe but last writer wins
- 仅跟踪帖子层级——已读帖子的新评论不会被捕获
- 如果频道更改用户名,跟踪会重置(状态以用户名为键)
- 同一频道的并发运行是安全的,但最后一次写入的状态会生效
Diagnostic
诊断信息
tg-reader-checkjson
{
"tracking": {
"read_unread": true,
"state_file": "~/.tg-reader-state.json",
"state_file_exists": true,
"tracked_channels": 3
}
}tg-reader-checkjson
{
"tracking": {
"read_unread": true,
"state_file": "~/.tg-reader-state.json",
"state_file_exists": true,
"tracked_channels": 3
}
}Output Format
输出格式
info
infoinfo
命令输出
infojson
{
"id": -1001234567890,
"title": "Channel Name",
"username": "channel_name",
"description": "About this channel...",
"members_count": 42000,
"link": "https://t.me/channel_name"
}json
{
"id": -1001234567890,
"title": "Channel Name",
"username": "channel_name",
"description": "About this channel...",
"members_count": 42000,
"link": "https://t.me/channel_name"
}fetch
fetchfetch
命令输出
fetchjson
{
"channel": "@channel_name",
"fetched_at": "2026-02-22T10:00:00Z",
"since": "2026-02-21T10:00:00Z",
"count": 12,
"messages": [
{
"id": 1234,
"date": "2026-02-22T09:30:00Z",
"text": "Post content...",
"views": 5200,
"forwards": 34,
"link": "https://t.me/channel_name/1234",
"has_media": true,
"media_type": "MessageMediaType.PHOTO"
}
]
}json
{
"channel": "@channel_name",
"fetched_at": "2026-02-22T10:00:00Z",
"since": "2026-02-21T10:00:00Z",
"count": 12,
"messages": [
{
"id": 1234,
"date": "2026-02-22T09:30:00Z",
"text": "Post content...",
"views": 5200,
"forwards": 34,
"link": "https://t.me/channel_name/1234",
"has_media": true,
"media_type": "MessageMediaType.PHOTO"
}
]
}fetch
with --comments
fetch--comments带--comments
参数的fetch
输出
--commentsfetchjson
{
"channel": "@channel_name",
"fetched_at": "2026-02-28T10:00:00Z",
"since": "2026-02-27T10:00:00Z",
"count": 5,
"comments_enabled": true,
"comments_available": true,
"messages": [
{
"id": 1234,
"text": "Post content...",
"has_media": false,
"comment_count": 2,
"comments": [
{
"id": 5678,
"date": "2026-02-28T09:35:00Z",
"text": "Great post!",
"from_user": "username123"
}
]
}
]
}Notes:
- — channel has no linked discussion group (no comments possible)
comments_available: false - on a message — rate limit hit for that post's comments
comments_error - may be
from_userfor anonymous commentsnull - Images/videos in comments are not analyzed — only text is captured
- Default post limit drops to 30 when is active (override with
--comments)--limit
json
{
"channel": "@channel_name",
"fetched_at": "2026-02-28T10:00:00Z",
"since": "2026-02-27T10:00:00Z",
"count": 5,
"comments_enabled": true,
"comments_available": true,
"messages": [
{
"id": 1234,
"text": "Post content...",
"has_media": false,
"comment_count": 2,
"comments": [
{
"id": 5678,
"date": "2026-02-28T09:35:00Z",
"text": "Great post!",
"from_user": "username123"
}
]
}
]
}注意事项:
- ——频道未关联讨论组(无法获取评论)
comments_available: false - 帖子出现——获取该帖子评论时触发了速率限制
comments_error - 匿名评论的可能为
from_usernull - 评论中的图片/视频不会被分析——仅捕获文本内容
- 启用时,默认帖子限制数会降至30(可通过
--comments参数覆盖)--limit
After Fetching
获取内容后的处理建议
- Parse the JSON output
- Posts with images/videos have and a
has_media: truefield. Their text is in themedia_typefield (from the caption). Do not skip posts just because they have media — they often contain important text.text - Images and videos are not analyzed (no OCR/vision) — only the text/caption is returned.
- Summarize key themes, top posts by views, notable links
- If , analyze comment sentiment and key themes alongside the main posts
comments_enabled: true - Save summary to if user wants to track over time
memory/YYYY-MM-DD.md
- 解析JSON输出
- 含图片/视频的帖子会标记并带有
has_media: true字段,文本内容在media_type字段(来自媒体标题)。不要仅因为帖子含媒体就跳过——它们通常包含重要文本信息。text - 图片和视频不会被分析(无OCR/视觉识别)——仅返回文本/标题。
- 总结核心主题、高浏览量帖子和重要链接
- 如果,结合主帖子分析评论的情感和核心主题
comments_enabled: true - 如果用户需要长期跟踪,将摘要保存到
memory/YYYY-MM-DD.md
Saving to File (Token Economy)
保存到文件(令牌节省策略)
Use when the result is large (especially with ) and you don't need to analyze it immediately. The full data goes to a file, and stdout returns only a short confirmation — this saves tokens.
--output--commentsPeriodic updates pattern: set up a cron task that runs on schedule. The file gets updated regularly. When the user asks to analyze comments — read the file instead of re-fetching. This avoids consuming tokens on every fetch.
tg-reader fetch @channel --comments --output comments.jsonWhen is used without a filename, the default is . Stdout confirmation:
--outputtg-output.jsonjson
{"status": "ok", "output_file": "/absolute/path/to/tg-output.json", "count": 12}当结果较大时(尤其是启用时),使用参数,无需立即分析。完整数据会写入文件,标准输出仅返回简短确认——这能节省令牌。
--comments--output定期更新模式: 设置定时任务,定期运行。文件会定期更新。当用户要求分析评论时——直接读取文件而非重新获取。这样可以避免每次获取都消耗令牌。
tg-reader fetch @channel --comments --output comments.json使用但不指定文件名时,默认输出文件为。标准输出的确认信息如下:
--outputtg-output.jsonjson
{"status": "ok", "output_file": "/absolute/path/to/tg-output.json", "count": 12}Saving Channel List
保存频道列表
Store tracked channels in :
TOOLS.mdmarkdown
undefined将跟踪的频道存储在中:
TOOLS.mdmarkdown
undefinedTelegram Channels
Telegram Channels
- @channel1 — why tracked
- @channel2 — why tracked
---- @channel1 — 跟踪原因
- @channel2 — 跟踪原因
---Error Handling
错误处理
Errors include an and field to help agents decide what to do automatically.
error_typeaction错误信息包含和字段,帮助Agent自动判断处理方式。
error_typeactionChannel Errors
频道相关错误
| Meaning | |
|---|---|---|
| Channel is private, you were kicked, or access is restricted | |
| You are banned from this channel | |
| Channel doesn't exist or username is wrong | |
| Invite link is expired or invalid | |
| Telegram rate limit | |
| | |
| 含义 | |
|---|---|---|
| 频道为私有、用户被踢出或访问受限 | |
| 用户被该频道封禁 | |
| 频道不存在或用户名错误 | |
| 邀请链接过期或无效 | |
| Telegram速率限制 | |
| 多频道场景下使用了 | |
System Errors
系统相关错误
| Error | Action |
|---|---|
| Run |
| Guide user through Setup (Step 1-2 below) |
| Run |
| Session expired — delete and re-auth (see below) |
| 错误 | 处理方式 |
|---|---|
| 运行 |
| 引导用户完成设置步骤(下方步骤1-2) |
| 进入技能目录运行 |
| 会话过期——删除并重新认证(见下方说明) |
Session Expired
会话过期处理
bash
rm -f ~/.tg-reader-session.session
tg-reader authbash
rm -f ~/.tg-reader-session.session
tg-reader authAuth Code Not Arriving
认证码未收到
Use the verbose debug script for full MTProto-level logs:
bash
python3 debug_auth.pyWarning:deletes existing session files before re-authenticating. It will ask for confirmation first.debug_auth.py
使用 verbose 调试脚本查看完整MTProto层级日志:
bash
python3 debug_auth.py警告:会在重新认证前删除现有会话文件。运行前会要求确认。debug_auth.py
Library Selection
后端库选择
Two MTProto backends are supported:
| Backend | Command | Notes |
|---|---|---|
| Pyrogram (default) | | Modern, actively maintained |
| Telethon | | Alternative if Pyrogram has issues |
Switch persistently:
Switch one-time:
export TG_USE_TELETHON=truetg-reader fetch @channel --since 24h --telethon支持两种MTProto后端:
| 后端 | 命令 | 说明 |
|---|---|---|
| Pyrogram(默认) | | 现代、持续维护 |
| Telethon | | Pyrogram出现问题时的替代方案 |
永久切换:
单次切换:
export TG_USE_TELETHON=truetg-reader fetch @channel --since 24h --telethonSetup & Installation
设置与安装
Full details in README.md.
详细说明见README.md。
Step 1 — Get API Credentials
步骤1 — 获取API凭证
Step 2 — Save Credentials
步骤2 — 保存凭证
Recommended (works in agents and servers):
bash
cat > ~/.tg-reader.json << 'EOF'
{
"api_id": YOUR_ID,
"api_hash": "YOUR_HASH"
}
EOF
chmod 600 ~/.tg-reader.jsonAlternative (interactive shell only):
bash
export TG_API_ID=YOUR_ID
export TG_API_HASH="YOUR_HASH"Set these in your current shell session. Avoid writing to shell profiles () — use instead for persistent storage.
TG_API_HASH~/.bashrc~/.tg-reader.jsonNote: Agents and servers don't load shell profiles. Use(the recommended method above) for non-interactive environments.~/.tg-reader.json
推荐方式(适用于Agent和服务器):
bash
cat > ~/.tg-reader.json << 'EOF'
{
"api_id": YOUR_ID,
"api_hash": "YOUR_HASH"
}
EOF
chmod 600 ~/.tg-reader.json替代方式(仅适用于交互式Shell):
bash
export TG_API_ID=YOUR_ID
export TG_API_HASH="YOUR_HASH"在当前Shell会话中设置。避免将写入Shell配置文件()——推荐使用进行持久化存储。
TG_API_HASH~/.bashrc~/.tg-reader.json注意: Agent和服务器不会加载Shell配置文件。非交互式环境请使用上述推荐的方式。~/.tg-reader.json
Step 3 — Install & Configure
步骤3 — 安装与配置
bash
npx clawhub@latest install sergei-mikhailov-tg-channel-reader
cd ~/.openclaw/workspace/skills/sergei-mikhailov-tg-channel-reader
bash setup-tg-reader.shThe setup script: installs Python packages (), checks credentials and session, runs , and prints the exec approval commands for you to run manually.
pip install .tg-reader-checkOn Linux with managed Python (Ubuntu/Debian), use a venv before running the setup script:
bash
python3 -m venv ~/.venv/tg-reader
echo 'export PATH="$HOME/.venv/tg-reader/bin:$PATH"' >> ~/.bashrc && source ~/.bashrcbash
cd ~/.openclaw/workspace/skills/sergei-mikhailov-tg-channel-reader
pip install pyrogram tgcrypto telethon && pip install .
openclaw approvals allowlist add --gateway "$(which tg-reader)"
openclaw approvals allowlist add --gateway "$(which tg-reader-check)"bash
npx clawhub@latest install sergei-mikhailov-tg-channel-reader
cd ~/.openclaw/workspace/skills/sergei-mikhailov-tg-channel-reader
bash setup-tg-reader.sh设置脚本会:安装Python包()、检查凭证和会话、运行、并打印需要手动运行的权限审批命令。
pip install .tg-reader-check在使用托管Python的Linux系统(Ubuntu/Debian)上,运行设置脚本前请先创建虚拟环境:
bash
python3 -m venv ~/.venv/tg-reader
echo 'export PATH="$HOME/.venv/tg-reader/bin:$PATH"' >> ~/.bashrc && source ~/.bashrcbash
cd ~/.openclaw/workspace/skills/sergei-mikhailov-tg-channel-reader
pip install pyrogram tgcrypto telethon && pip install .
openclaw approvals allowlist add --gateway "$(which tg-reader)"
openclaw approvals allowlist add --gateway "$(which tg-reader-check)"Step 4 — Authenticate
步骤4 — 认证
bash
tg-reader authPyrogram will ask to confirm the phone number — answer . The code arrives in the Telegram app (not SMS).
ybash
tg-reader authPyrogram会要求确认手机号码——回复。验证码会发送到Telegram应用(而非短信)。
yStep 5 — Verify
步骤5 — 验证
bash
tg-reader-checkShould return . If not — fix the reported issues and re-run .
"status": "ok"bash setup-tg-reader.shbash
tg-reader-check应返回。若未返回,请修复报告的问题并重新运行。
"status": "ok"bash setup-tg-reader.shScheduled Tasks & Cron
定时任务与Cron
This skill needs network access (MTProto connection to Telegram servers) and a session file. How you configure OpenClaw cron depends on the session target.
Important: When setting up a scheduled task that uses, tell the user which approach you're using and what it means — so they can make an informed choice.tg-reader
本技能需要网络访问(与Telegram服务器的MTProto连接)和会话文件。OpenClaw定时任务的配置方式取决于会话目标。
重要提示: 设置使用的定时任务时,请告知用户你使用的方式及其含义——以便用户做出知情选择。tg-reader
Option A — sessionTarget: "main"
(recommended)
sessionTarget: "main"选项A — sessionTarget: "main"
(推荐)
sessionTarget: "main"The cron task sends a reminder to the main agent session. The agent then runs in the main environment where the skill, credentials, and session file are already available.
tg-readerPros: No extra configuration — everything works out of the box.
Cons: Not fully autonomous — the task sends a system event, the agent picks it up and executes. Requires (OpenClaw cron API limitation for main target).
payload.kind: "systemEvent"How to set up:
- Create a cron task with and
sessionTarget: "main"payload.kind: "systemEvent" - In the task description, include the exact command to run
tg-reader - The agent receives the reminder and executes the command in its main session
定时任务会向主Agent会话发送提醒。Agent随后会在已安装技能、配置凭证和会话文件的主环境中运行。
tg-reader优点: 无需额外配置——开箱即用。
缺点: 并非完全自主——任务发送系统事件,Agent接收后执行。受限于OpenClaw定时任务API,需要设置(针对main目标的限制)。
payload.kind: "systemEvent"设置方法:
- 创建定时任务,设置和
sessionTarget: "main"payload.kind: "systemEvent" - 在任务描述中包含要运行的命令
tg-reader - Agent接收提醒后,在主会话中执行命令
Option B — sessionTarget: "isolated"
(autonomous, complex setup)
sessionTarget: "isolated"选项B — sessionTarget: "isolated"
(完全自主,配置复杂)
sessionTarget: "isolated"The cron task runs in a Docker container — fully autonomous, no agent interaction needed. However, the container starts empty: no skill, no credentials, no session file.
Pros: Fully autonomous — runs on schedule without agent involvement.
Cons: Requires Docker setup; session file must be mounted into the container (may not work reliably — session files are tied to the machine and Telegram may invalidate them in a new environment).
Required configuration in :
~/.openclaw/openclaw.jsonjson
{
"agents": {
"defaults": {
"sandbox": {
"docker": {
"setupCommand": "clawhub install sergei-mikhailov-tg-channel-reader && cd ~/.openclaw/workspace/skills/sergei-mikhailov-tg-channel-reader && pip install pyrogram tgcrypto telethon && pip install .",
"env": {
"TG_API_ID": "YOUR_ID",
"TG_API_HASH": "YOUR_HASH",
"TG_READ_UNREAD": "true"
}
}
}
}
}
}Session file caveat: The Telegram session file () must also be available inside the container. This may require Docker volume mounting and might not work reliably — Telegram can invalidate sessions when they appear from a different environment. If you encounter errors in isolated mode, switch to Option A.
~/.tg-reader-session.sessionAUTH_KEY_UNREGISTERED定时任务在Docker容器中运行——完全自主,无需Agent交互。但容器启动时为空:无技能、无凭证、无会话文件。
优点: 完全自主——按计划运行,无需Agent参与。
缺点: 需要Docker配置;会话文件必须挂载到容器中(可能无法可靠工作——会话文件与机器绑定,Telegram可能会在新环境中使会话失效)。
~/.openclaw/openclaw.jsonjson
{
"agents": {
"defaults": {
"sandbox": {
"docker": {
"setupCommand": "clawhub install sergei-mikhailov-tg-channel-reader && cd ~/.openclaw/workspace/skills/sergei-mikhailov-tg-channel-reader && pip install pyrogram tgcrypto telethon && pip install .",
"env": {
"TG_API_ID": "YOUR_ID",
"TG_API_HASH": "YOUR_HASH",
"TG_READ_UNREAD": "true"
}
}
}
}
}
}会话文件注意事项: Telegram会话文件()必须在容器内可用。这可能需要Docker卷挂载,但可能无法可靠工作——当会话在不同环境中出现时,Telegram可能会使会话失效。如果在隔离模式下遇到错误,请切换到选项A。
~/.tg-reader-session.sessionAUTH_KEY_UNREGISTEREDExplicit paths (both options)
显式路径(两种选项通用)
When is not available or points to a different location, use explicit paths:
~/bash
tg-reader-check \
--config-file /home/user/.tg-reader.json \
--session-file /home/user/.tg-reader-session
tg-reader fetch @channel --since 6h \
--config-file /home/user/.tg-reader.json \
--session-file /home/user/.tg-reader-sessionBoth flags work with all subcommands and both backends.
当不可用或指向其他位置时,使用显式路径:
~/bash
tg-reader-check \
--config-file /home/user/.tg-reader.json \
--session-file /home/user/.tg-reader-session
tg-reader fetch @channel --since 6h \
--config-file /home/user/.tg-reader.json \
--session-file /home/user/.tg-reader-session这两个参数适用于所有子命令和两种后端。
Security
安全注意事项
- Session file () grants full account access — keep it safe
~/.tg-reader-session.session - Never share or commit or session files
TG_API_HASH - is a secret — store in env vars or config file, never in git
TG_API_HASH
- 会话文件()拥有账户完全访问权限——请妥善保管
~/.tg-reader-session.session - 切勿分享或提交或会话文件
TG_API_HASH - 是机密信息——请存储在环境变量或配置文件中,切勿提交到git
TG_API_HASH