telegram-bot-api
Skill72 starsChanged 37 days agoMITView on GitHub
Raw Telegram Bot API patterns used by Untether. Covers httpx async HTTP client, inline keyboards, callback queries, long polling, rate limiting, outbox model, forum topics, voice transcription, and media group coalescing. NOT aiogram, python-telegram-bot, or grammY — Untether uses raw HTTP.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- talyuk/telegram-bot-api-skilltheir own version, first seen Nov 8, 2026
- puregram/skillstheir own version, first seen Nov 1, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- puregram/skills★ 3same name
- talyuk/telegram-bot-api-skill★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository11 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .codex/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- llms-full.txtllms.txt
- llms.txtllms.txt
- claude-stream-jsonSkill
- codex-opencode-piSkill
- jsonl-subprocess-runnerSkill
- release-coordinationSkill
- untether-architectureSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 1 is distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 36
All calls go through TelegramClient.
- Very specific: line 49
All responses decoded with msgspec.json.decode into typed structs
- Very specific: line 70
Must call answerCallbackQuery promptly to clear the spinner
- Very specific: line 86
No webhooks — Untether is designed for single-instance long polling
- Very specific: line 90
All writes (send, edit, delete) go through TelegramOutbox:
- Very specific: line 132
After transcription, correct_known_mishears() rewrites the known Claude mishears ("Clawde"/"Clawd" → Claude, "Clawed Code" → Claude Code, …
- Very specific: line 146
After media_group_debounce_s seconds of quiet, buffer flushes
- Very specific: line 152
Wait forward_coalesce_s seconds for additional forwards
- Distinctive: line 159
Default: split across multiple messages with "continued (N/M)" headers (~3500 chars per chunk)
≈ “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.
Files
Telegram Bot API (Raw HTTP)
Untether uses a custom Telegram Bot API client built on httpx (async) and msgspec (JSON). There is no Telegram SDK dependency.
Key files
| File | Purpose |
src/untether/telegram/client.py | TelegramClient — Bot API facade over the outbox, per-chat pacing |
src/untether/telegram/client_api.py | HttpBotClient — the httpx calls: 30 s message-call timeout, one safe retry (#861), benign-rejection classes (#746) |
src/untether/telegram/outbox.py | TelegramOutbox — queued send/edit/delete with rate limiting |
src/untether/telegram/bridge.py | TelegramPresenter — renders progress, inline keyboards, answers |
src/untether/telegram/loop.py | Long polling loop (getUpdates), callback dispatch |
src/untether/telegram/commands/ | Command and callback handlers |
docs/reference/transports/telegram.md | Full transport reference |
Bot API call pattern
All calls go through TelegramClient; the HTTP layer is HttpBotClient (client_api.py), which wraps httpx.AsyncClient:
# Typical Bot API call (simplified; HttpBotClient._post)
resp = await self._http.post(
f"{self._base_url}/bot{self._token}/{method}",
json=params,
)
data = msgspec.json.decode(resp.content, type=TelegramResponse)- Base URL:
https://api.telegram.org - Auth: bot token in the URL path (
/bot<token>/) - All responses decoded with
msgspec.json.decodeinto typed structs - Error handling: check
okfield, raise on HTTP or Telegram errors
Inline keyboards and callback queries
Permission requests and plan mode buttons use Telegram inline keyboards:
# reply_markup structure in RenderedMessage.extra
{
"reply_markup": {
"inline_keyboard": [
[{"text": "Approve", "callback_data": "claude_control:approve:<request_id>"}],
[{"text": "Deny", "callback_data": "claude_control:deny:<request_id>"}],
[{"text": "Pause & Outline Plan", "callback_data": "claude_control:discuss:<request_id>"}],
]
}
}- Callback data format:
<prefix>:<action>:<id>(max 64 bytes) - Must call
answerCallbackQuerypromptly to clear the spinner - Early answering: set
answer_early = Trueon the backend to clear the spinner immediately with a toast approval_originator_only(#388, opt-in): aclaude_control:/aq:tap from anyone but the run's originator getsanswerCallbackQuerywith "Only the person who started this run can answer this." and is dropped — checked before the early answer (telegram/approval_originator.py)
Long polling (getUpdates)
# In telegram/loop.py
updates = await client.get_updates(offset=last_offset + 1) # timeout_s=50 long poll
for update in updates:
last_offset = update.update_id
await handle_update(update)- Bypasses the outbox (direct API call)
- Retries on
RetryAfterby sleeping for the provided delay - No webhooks — Untether is designed for single-instance long polling
Outbox model
All writes (send, edit, delete) go through TelegramOutbox:
- Single worker processes one op at a time
- Keyed deduplication: one pending op per key; new ops overwrite payload but preserve
queued_at - Priority scheduling:
(priority, queued_at)ordering- send=0 (highest), delete=1, edit=2 (lowest)
- Coalescing: rapid edits to the same message naturally coalesce (only latest payload runs)
Key formats (include chat_id to avoid cross-chat collisions):
("edit", chat_id, message_id)for edits("delete", chat_id, message_id)for deletes("send", chat_id, replace_message_id)when replacing a progress message- Unique key for normal sends
Rate limiting
- Per-chat pacing:
private_chat_rps(default 1.0 msg/s),group_chat_rps(default 20/60 msg/s) - Per-chat
_next_at[chat_id]timestamps — worker picks from unblocked chats; globalretry_atblocks all on 429 - On 429:
RetryAfterraised usingparameters.retry_after; op requeued if no newer op superseded it - Non-429 errors: logged and dropped. The HTTP layer retries a message call once on a fresh connection only when the request never left (edits/deletes/callback answers also after a read timeout; a
sendMessagethat may have arrived is never repeated, #861); error logs carrychat_id/message_idandkind— the surface (progress,final,bg_status,approval_surface, …) set by awith message_kind("…")block around the transport call (transport.py); the outbox op captures it at enqueue and re-applies it on the worker (#823)
Replace progress messages
send_message(replace_message_id=...):
- Drops any pending edit for the progress message
- Enqueues the send at highest priority
- On success, queues a delete for the old progress message without awaiting it (
wait=False, #928) — a slow delete must not hold a final past its delivery bound
Voice transcription
[transports.telegram]
voice_transcription = true
voice_transcription_model = "gpt-4o-mini-transcribe"- Download voice payload from Telegram (
getFile+ HTTP fetch) - Transcribe with OpenAI-compatible API (or local Whisper server)
- Route transcript through same command/directive pipeline as typed text
Optional voice_transcription_language (ISO-639-1 hint) and voice_transcription_prompt (vocabulary bias). Unset prompt → DEFAULT_VOICE_TRANSCRIPTION_PROMPT in telegram/voice.py (Claude, Claude Code, CLAUDE.md, AGENTS.md, Codex, OpenCode and product terms — no deprecated or out-of-scope engine names, #703/#789); a value replaces it, "" disables it.
After transcription, correct_known_mishears() rewrites the known Claude mishears ("Clawde"/"Clawd" → Claude, "Clawed Code" → Claude Code, "Claw.md" → CLAUDE.md; whole words only, a bare "clawed" is kept) and logs voice.transcript.corrected with a count, never the text (#789).
Forum topics
Topics bind Telegram forum threads to a project/branch:
- Scope modes:
auto,main,projects,all /topic <project> @branchcreates and binds a topic- Resume tokens persist per topic
- Bot needs Manage Topics permission
Media group coalescing
Multiple documents sent as an album share a media_group_id:
MediaGroupBuffercollects messages with the samemedia_group_id- After
media_group_debounce_sseconds of quiet, buffer flushes - Processed as a single batch via
handle_media_group
Forwarded message coalescing
Comment + forwarded messages arrive as separate updates:
- Wait
forward_coalesce_sseconds for additional forwards - Forwards appended to the prompt; don't start their own runs
- Forwarded messages alone don't start runs
- A second plain prompt in the window is merged into the pending one (texts joined in order), never replacing it (#794); an unmergeable one (different reply target, voice vs text, leading directive, changed context) flushes the pending prompt as its own run first
Message overflow
- Default: split across multiple messages with "continued (N/M)" headers (~3500 chars per chunk)
- Trim mode: truncate to single message (~3500 chars)
- Configure via
message_overflow = "split" | "trim"
Markdown rendering quirks (telegram/render.py)
render_markdown() rewrites markdown-it text tokens before rendering (code spans/blocks untouched):
- Bare
<br>,<br/>,<br />→ line break (a space inside a table row); other tags stay escaped text (#786) - Bare filenames ending
.md,.sh,.py(country-code TLDs) → inline code, so neither linkify nor Telegram clients turnCLAUDE.mdintohttp://claude.md/(#788) - GFM pipe tables keep one row per line with a bold header, repeated across split chunks (#797); single newlines in line-structured text are kept while wrapped prose reflows (#870); an ordered list keeps its own start number (#886)
Approval push notifications
edit_message_text doesn't trigger phone push notifications. Untether sends a separate notify=True message ("Action required -- approval needed") when approval buttons appear. The _approval_notified flag resets when buttons disappear.
Ephemeral message cleanup
Approval-related messages auto-delete:
- "Action required" notification — deleted when user clicks a button
- "Approved/Denied" feedback — deleted when the run finishes
- Tracked via
_approval_notify_ref(inProgressEdits) and_EPHEMERAL_MSGS(inrunner_bridge.py)
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
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.

