telegram
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWe drive personal Telegram over MTProto with Telethon —
this acts as the user's own account (a "userbot"), so unlike the Bot API it can read full
history, list every conversation, and act on anyone the user can reach.
Credentials are injected as env vars by the connector:
- — app id
TELEGRAM_API_ID - — app hash — secret, never echo
TELEGRAM_API_HASH - — Telethon
TELEGRAM_SESSION_STRING= full account access. Never log, echo, or print it. Treat it like the account password.StringSession
我们通过Telethon基于MTProto驱动个人Telegram——它以用户自有账号的身份运行(即“userbot”),因此与Bot API不同,它可以读取完整的消息历史、列出所有对话,并对用户可接触到的任何对象执行操作。
凭证由连接器作为环境变量注入:
- — 应用ID
TELEGRAM_API_ID - — 应用哈希 — 保密,绝不能回显
TELEGRAM_API_HASH - — Telethon的
TELEGRAM_SESSION_STRING= 完整账号访问权限。绝不能记录、回显或打印。 请将其视为账号密码。StringSession
CLI
命令行界面(CLI)
The skill ships — self-contained (the only third-party dep is
, preinstalled in the sandbox). Point a var at the shipped path and call it; no heredoc
to re-create per turn, so a multi-step flow (dry-run → confirm) can't lose the helper between calls:
scripts/tg.pytelethonsh
TG="$SKILL_DIR/scripts/tg.py"
python3 "$TG" whoamiEvery state-changing command (, , , , , ,
, ) is gated: without a trailing it only DRY-RUNS (prints what
it would do, changes nothing). Read commands run directly. is honored only as the
last argument so a message/caption that merely contains "--confirm" can never silently confirm.
sendreplysend-fileforwardeditdeletereactmark-read--confirm--confirm本技能附带了——独立运行(唯一的第三方依赖是,已预先安装在沙箱中)。将变量指向该文件路径并调用它;无需每次重新创建 heredoc,因此多步骤流程(试运行→确认)不会在调用之间丢失辅助工具:
scripts/tg.pytelethonsh
TG="$SKILL_DIR/scripts/tg.py"
python3 "$TG" whoami所有会改变状态的命令(、、、、、、、)都有权限控制:如果没有在末尾添加,则仅执行试运行(打印将要执行的操作,但不做任何修改)。读取类命令直接运行。仅在作为最后一个参数时生效,因此消息/说明文字中即使包含“--confirm”也不会意外触发确认。
sendreplysend-fileforwardeditdeletereactmark-read--confirm--confirmVerify the connection first
先验证连接
sh
python3 "$TG" whoamish
python3 "$TG" whoami→ {"id": 8367450178, "username": "GermeyAce", "name": "Germey", "phone": "..."}
→ {"id": 8367450178, "username": "GermeyAce", "name": "Germey", "phone": "..."}
On an auth/session error the stored session is dead — tell the user to reconnect at
https://auth.acedata.cloud/user/connections.
如果出现认证/会话错误,说明存储的会话已失效——请告知用户前往https://auth.acedata.cloud/user/connections重新连接。Read recipes
读取操作指南
| Goal | Command |
|---|---|
| Recent conversations | |
| Only chats with unread (ranked) | |
| A chat's history (oldest→newest) | |
| Search inside one chat | |
| Search across ALL chats | |
| List contacts | |
| Info about a chat/user | |
| t.me link to a message | |
<target>list-chats@usernameout:truemedia:trueSummarize-unread pattern: → pick the chats that matter → on
each → summarize. Don't dump 20k messages; sample the most-unread / most-relevant.
unreadget-messages <id> N| 目标 | 命令 |
|---|---|
| 最近的对话 | |
| 仅显示有未读消息的聊天(按优先级排序) | |
| 某聊天的消息历史(从旧到新) | |
| 在单个聊天内搜索 | |
| 在所有聊天中全局搜索 | |
| 列出联系人 | |
| 聊天/用户的信息 | |
| 消息的t.me链接 | |
<target>list-chats@用户名out:truemedia:true未读消息总结流程: → 选择重要的聊天 → 对每个聊天执行 → 总结内容。不要直接导出20000条消息;优先选择未读数量最多/最相关的消息样本。
unreadget-messages <id> NMedia
媒体文件操作
sh
undefinedsh
undefinedDownload an attachment from a message → returns the saved path
下载消息中的附件 → 返回保存路径
python3 "$TG" download-media <target> <msg_id> ./tg_downloads
python3 "$TG" download-media <target> <msg_id> ./tg_downloads
Send a local file OR an http(s) URL (optional caption) — GATED
发送本地文件或http(s) URL(可选添加说明文字)——需权限确认
python3 "$TG" send-file <target> /path/or/https-url "caption" --confirm
An `http(s)` URL is downloaded to a real local file first (with the right
extension from the URL / `Content-Type`) and then uploaded, so a remote image
lands as a **photo** — not a document, and not a silent failure. This is the
reliable way to "发图": pass the CDN URL straight to `send-file`.
To hand a downloaded file back to the user as a link, upload it to the CDN (see the
`cos-upload` skill) after `download-media`.python3 "$TG" send-file <target> /path/or/https-url "caption" --confirm
http(s) URL会先被下载为真实的本地文件(根据URL或`Content-Type`获取正确的扩展名),然后再上传,因此远程图片会以**照片**形式发送——而不是文档,也不会静默失败。这是“发图”的可靠方式:直接将CDN URL传给`send-file`即可。
如果要将下载的文件以链接形式返回给用户,请在`download-media`之后使用`cos-upload`技能将其上传到CDN。Write recipes — all GATED (dry-run unless trailing --confirm
)
--confirm写入操作指南 — 所有操作需权限确认(未在末尾添加--confirm则仅试运行)
Sending/editing/deleting acts as the real user. Always run the dry run first, show the user
exactly what will happen, get an explicit "yes", then re-run with as the last
argument. Never bulk-send.
--confirmsh
python3 "$TG" send <target> "text" # → dry_run; add --confirm to send
python3 "$TG" reply <target> <msg_id> "text" --confirm
python3 "$TG" forward <from_target> <msg_id> <to_target> --confirm
python3 "$TG" edit <target> <msg_id> "new text" --confirm # own messages
python3 "$TG" delete <target> <msg_id> --confirm # destructive
python3 "$TG" react <target> <msg_id> "👍" --confirm
python3 "$TG" mark-read <target> --confirm # sends read receiptsThe dry run returns — present that to the
user verbatim as the confirmation prompt.
{"dry_run": true, "command": ..., "args": [...]}发送/编辑/删除操作将以真实用户身份执行。请始终先运行试运行,向用户准确展示将要执行的操作,获取明确的“确认”后,再重新运行并将作为最后一个参数添加。切勿批量发送消息。
--confirmsh
python3 "$TG" send <target> "text" # → 试运行;添加--confirm以发送
python3 "$TG" reply <target> <msg_id> "text" --confirm
python3 "$TG" forward <from_target> <msg_id> <to_target> --confirm
python3 "$TG" edit <target> <msg_id> "new text" --confirm # 仅可编辑自己的消息
python3 "$TG" delete <target> <msg_id> --confirm # 破坏性操作
python3 "$TG" react <target> <msg_id> "👍" --confirm
python3 "$TG" mark-read <target> --confirm # 发送已读回执试运行会返回——请将该内容原封不动地呈现给用户作为确认提示。
{"dry_run": true, "command": ..., "args": [...]}Gotchas — surface before the user is surprised
注意事项 — 在用户遇到问题前提前告知
- This is the user's real account. Confirm before any write; reading exposes private chats.
- : Telegram rate-limits userbots. On a flood-wait of N seconds, tell the user to retry after N — never loop/retry aggressively (escalates toward a ban).
FloodWaitError - Dead session: revoked from Telegram → Settings → Devices, or ~6-month inactivity. On
/unauthorized, reconnect the connector (don't retry).
AuthKeyError - Never print /
TELEGRAM_SESSION_STRING— full-account secrets.TELEGRAM_API_HASH - Targets: prefer the numeric from
id(the helper recovers its access hash by scanning dialogs); names need an exact match, usernames need a leadinglist-chats.@ - only works for public channels/supergroups; private 1:1 / basic groups return an error (no shareable link exists).
message-link - /
editgenerally only apply to the user's own messages (admins can delete others in groups they manage).delete
- 这是用户的真实账号。执行任何写入操作前请确认;读取操作会暴露私人聊天内容。
- :Telegram对userbot有速率限制。如果出现需等待N秒的限流提示,请告知用户N秒后重试——切勿频繁循环/重试(可能导致账号被封禁)。
FloodWaitError - 会话失效:在Telegram设置→设备中撤销了会话,或账号闲置约6个月。如果出现/未授权错误,请重新连接连接器(不要重试)。
AuthKeyError - 绝不能打印/
TELEGRAM_SESSION_STRING——这些是完整账号的保密信息。TELEGRAM_API_HASH - 目标对象:优先使用返回的数字
list-chats(辅助工具会通过扫描对话恢复其访问哈希);名称需要完全匹配,用户名需要以id开头。@ - ****仅适用于公开频道/超级群组;私人一对一聊天/基础群组会返回错误(无可分享的链接)。
message-link - **/
edit**通常仅适用于用户自己的消息(管理员可在其管理的群组中删除他人消息)。delete
Record the output
记录输出结果
After you successfully publish and obtain the live result URL, call the built-in
tool ONCE so the user can track this deliverable in My Outputs:
publish_artifactpublish_artifact(kind="message", channel="telegram", title="<title>", url="<the REAL returned URL>", status="delivered")Use the real returned URL — never fabricate one. Call it once per published item,
only after delivery is confirmed; skip it (or use ) if publishing failed.
See .
status="failed"_shared/artifacts.md成功发布并获取实时结果URL后,请调用内置的工具一次,以便用户在“我的输出”中跟踪该交付物:
publish_artifactpublish_artifact(kind="message", channel="telegram", title="<title>", url="<the REAL returned URL>", status="delivered")请使用真实返回的URL——切勿伪造。每个发布项仅调用一次,且仅在确认交付完成后调用;如果发布失败,请跳过调用(或使用)。详情请查看。
status="failed"_shared/artifacts.md