
Telethon Plus
io.github.psyb0t由 GitHub 帳號 psyb0t 發布v0.7.1更新於 Nov 7, 2026
Self-hosted MCP server: Telegram userbot control (Telethon) via HTTP and MCP.
概覽
自架的 Telegram 使用者機器人伺服器,讓助理以你本人帳號的身分透過 MCP 或 HTTP 讀取、傳送與管理 Telegram 對話。
- 可以做什麼
- 讀取帳號資料、解析對話、列出對話清單、讀取與搜尋訊息、下載媒體
- 傳送、編輯、刪除、轉寄、置頂、回應訊息並標記已讀,支援排程傳送與以連結上傳檔案
- 管理對話:建立、加入、邀請、離開、刪除,列出成員,找出關聯討論群組
- 群組管理:封鎖、解除封鎖、踢出、提升與撤銷管理員
- 建立投票:建立、投票、查看結果
- 查看限流狀態、帳號封鎖風險與 Prometheus 指標,並透過 WebSocket 或 webhook 接收新事件
- 適用情境
- 適合讓助理操作你自己的 Telegram 帳號而非機器人帳號:整理對話、彙整或搜尋頻道、起草並傳送訊息、管理群組,或把收到的訊息接進其他流程。定位為自架服務,不適合臨時一次性使用。
- 執行需求
- 以 Docker 容器執行(映像 psyb0t/telethon-plus),對外提供 HTTP 與 streamable HTTP 的 MCP 端點。清單未宣告環境變數,但 README 要求 TELETHON_API_ID 與 TELETHON_API_HASH(來自 my.telegram.org),以及由互動式登入工具產生的 TELETHON_SESSION。可選設定 TELETHON_AUTH_KEY 啟用 Bearer 驗證。需要能連線到 Telegram 的網路。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Telethon Plus,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
docker-telethon-plus
[CI] [version] [license] [Docker Pulls]
Your Telegram account, but it takes HTTP requests. Wraps Telethon — the real MTProto userbot client, not that neutered Bot API garbage — behind a JSON HTTP API and a Model Context Protocol endpoint.
Same tools, two doors. POST some JSON, or point your AI agent at /mcp and let it go nuts. Either way it's talking to Telegram as you, with full account access.
One login. One session string. Never type a code again.
Table of Contents
- How it works
- Quick start
- First-time login
- Configuration
- Tools
- HTTP API
- MCP
- Agent integrations
- Development
- Tests
- License
How it works
One Telethon client. One async lock. Both surfaces share the same tool registry — no duplication, no weird state, no bullshit.
Quick start
Get API_ID / API_HASH from https://my.telegram.org/apps. Get the session string from the login helper below.
First-time login
Telegram makes you prove you're a human once — phone number, SMS code, optionally 2FA. Do it once, never again.
make login builds the image, runs the interactive flow, and shoves TELETHON_SESSION straight into your .env. That's it. Run make run and you're live.
No repo? No problem:
Copy the session string it spits out, set it as TELETHON_SESSION, done.
The session string is full account access. Whoever has it is you. Don't commit it, don't paste it in Slack, don't tattoo it anywhere.
Configuration
All config via environment variables. Copy .env.example to get the full list with comments.
Throttling & cache (anti-flood)
Telegram bans accounts that hammer it. Defaults here are conservative — meant to keep you under the server-side limits without you having to think about it. Tune only if you know what you're doing.
How the layers stack:
- Entity cache short-circuits resolveUsername — first lookup of
@somechannelcalls Telegram; every subsequent lookup is free. Survives container restarts via the/cachevolume. - Per-method token buckets cap the dangerous methods. If you try to resolve 6 new usernames in one minute, the 6th sleeps until the oldest expires.
- Per-chat send interval throttles sends to each chat to ≤1/sec (with margin).
- Global gap + jitter humanizes the overall traffic shape.
- Adaptive backoff: a single FLOOD_WAIT halves your effective rate for an hour. Three in a row → ÷8. Auto-recovers after an idle hour.
For bulk scraping work (the scenario that caused 22-hour bans before): the cache + bucket_resolve_per_min=5 combination is what saves you. Resolving 200 new channels takes ~40 minutes instead of getting you banned in 5.
Tools
JSON in, JSON out. All inputs are pydantic-validated — send garbage, get a 400 back with exactly what's wrong.
Chat references (chat, from_chat, to_chat) accept whatever Telethon accepts:
Numeric IDs only resolve for entities Telethon has already seen — i.e. cached in your session via a prior
@username/t.melookup, dialog list, or incoming message. MTProto needs anaccess_hash, not just an ID, and bare numbers don't carry one. Especially relevant for bots: pass@botusernamefirst (or callGET /api/dialogs/GET /api/entities?chat=@botonce) before referring to it by numeric ID. If you only have the bot's token and no username, hit Telegram's Bot APIgetMeto fetch the username, then use that.
Response shape
Every 2xx returns the resource directly. No {"result": ...} wrapper, no envelope. Lists are JSON arrays, singles are JSON objects.
Errors return {"detail": "..."} (FastAPI standard). Telegram RPC errors arrive as 502 with detail = {"telegram_error": "...", "message": "..."}.
Quick reference
{chat} in path accepts the same formats as elsewhere: @username, numeric ID, me. Phone (+...) and t.me/... links need URL-encoding (%2B etc.) — usernames and IDs work inline.
HTTP API
Standard REST API. JSON in, JSON out. 2xx returns the resource directly; errors return {"detail": ...}.
If TELETHON_AUTH_KEY is set, every request (except /healthz) needs:
GET /api/me
Who am I right now.
GET /api/entities
Resolve any chat reference to a full profile.
GET /api/dialogs
GET /api/messages
Newest first. Returns [] if nothing matches.
POST /api/messages
Send a message. The same endpoint handles text and files — if the body contains file_url, the URL is fetched and sent as media (with text becoming the caption); otherwise text is sent as a plain message.
PATCH /api/messages/{id}
Edit a message. Message ID goes in the URL, everything else in the body.
DELETE /api/messages
Delete messages by ID.
POST /api/messages/forward
POST /api/messages/read
Mark messages as read.
GET /api/participants
List members of a group or channel.
Large public channels may return a limited set or require admin rights.
POST /api/chats
Create a supergroup or broadcast channel.
DELETE /api/chats
Delete a supergroup or channel you own. Irreversible.
POST /api/chats/join
Join a public channel or supergroup.
POST /api/chats/leave
Leave a channel or supergroup.
Errors
Health
authorized: false means the container started but the session is fucked — bad string, revoked, or Telegram unreachable. Always public, no auth required.
Observability
GET /metrics
Prometheus exposition. Scrape it. No auth (publicly readable inside your cluster — if you need it locked down, put it behind your usual scrape-network policy).
Series exported:
telethon_plus_tool_calls_total{tool=...}telethon_plus_tool_errors_total{tool=...}telethon_plus_flood_events_total{bucket=...}telethon_plus_cache_hits_total/_misses_total/_entriestelethon_plus_throttle_multipliertelethon_plus_bucket_used{bucket=...}/_bucket_limit{bucket=...}telethon_plus_uptime_seconds
GET /api/throttle/status
Live state of every bucket, multiplier, recent flood events, cache stats:
GET /api/account/health
risk is ok (multiplier 1×), warning (≥2×), or high (≥8×).
Throttle response headers
Every /api/... response carries:
X-Throttle-MultiplierX-Throttle-Flood-Events-1hX-RateLimit-Remaining-<bucket>for each bucket
Lets clients self-throttle without polling /api/throttle/status.
Updates / webhooks
Two ways to receive incoming Telegram events (new messages, edits, deletes, chat actions):
WebSocket — /ws/updates
If TELETHON_AUTH_KEY is set, pass it as ?token=. Browser WS clients can't set Authorization headers, hence query-string.
Multiple subscribers are supported — each gets its own queue. Slow consumers drop events at TELETHON_UPDATES_BUFFER_SIZE.
Outbound webhook — TELETHON_POST_TO_URL
Set the env var to your endpoint and every event gets POSTed there as JSON. Fire-and-forget — a slow or failing webhook never blocks Telethon's loop. Use for distributed workers, separate processes, anything that can't hold a WS open.
Event payload shape
For MessageEdited, MessageDeleted, ChatAction — same shape, fewer fields.
Safety switches
TELETHON_READ_ONLY=true
Every write endpoint returns 403. Reads, status, metrics still work. Killswitch for panic mode or for keeping a test deployment harmless.
TELETHON_DRY_RUN=true
Write endpoints accept the request, validate it, don't call Telegram, return {"dry_run": true, "would_...": {...}}. Useful for verifying scripts before pointing them at production.
MCP
Mounted at /mcp/ using the streamable HTTP transport. Every tool from the table above shows up automatically as an MCP tool with the same name and schema.
Point your agent at:
Stateless — every request is independent, no session juggling. Drop it into Claude Desktop, a custom agent, anything that speaks MCP over HTTP. Works out of the box.
Agent integrations
The skill works in any agent that reads .agents/skills/ (such as peen), and installs natively in the clients below.
Claude Code
Claude Code prompts for the telethon-plus server URL and, if auth is enabled, the bearer token — the token is stored in your OS keychain.
Codex
Installed via the marketplace, the skill invokes as $telethon-plus:telethon-plus. Codex also picks the skill up automatically with no install in any repo containing .agents/skills/, where it invokes as plain $telethon-plus.
OpenClaw
The skill is published to ClawHub on every release:
For MCP clients that speak local stdio, the @psyb0t/telethon-plus plugin bridges to the service's /mcp/ endpoint:
Then set TELETHON_PLUS_URL (and TELETHON_AUTH_KEY if the server requires auth).
Development
Tests
Real tests. Real Telegram. No mocking bullshit.
tests/ spins up the container and hammers both REST and MCP with your actual account. Messages get sent and deleted. If anything breaks, you'll know.
Setup:
TEST_CHAT is where test messages land. Use me for Saved Messages — private, yours, no one else sees it. All chat reference formats from the Tools section work here.
make test builds both images and runs pytest inside Docker with the socket mounted. No setup beyond .env. If credentials are missing, the suite skips cleanly.
License
WTFPL — do whatever the fuck you want.
來源:README.md,提交 1c2449c
工具
0版本歷史
1- v0.5.7Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分