Imported from terrylica/cc-skills (
plugins/tlg/skills/send-message/SKILL.md). Install upstream withnpx skills add terrylica/cc-skills --skill send-message. Copyright stays with the author.
Send Telegram Message
Send a message from your personal Telegram account (not a bot) via MTProto.
Self-Evolving Skill: This skill improves through use. If instructions are wrong, parameters drifted, or a workaround was needed — fix this file immediately, don't defer. Only update for real, reproducible issues.
Preflight
Before sending, verify the session is authorized (not just that the file exists):
bun "$SCRIPT" check-auth
If EXPIRED, run /tlg:setup first (uses 3-step non-interactive auth pattern).
Supergroup-First Methodology
The Bruntwork group (-1003958083153) is a supergroup with Topics. All messages to this group MUST target a specific topic — never post to the bare supergroup without a topic target.
Why supergroup over basic chat:
- Server-global message IDs. Every member sees the same
id=Nfor each message. Both sides' Claude Code resolves citations identically — no viewer-qualifier needed, no cross-boundary ambiguity. - Topic namespaces. Policies don't get buried between daily check-ins. Each subject has its own searchable thread with independent pins.
- AI-agent addressability. Claude Code can target reads/writes to specific topics via
reply_to_msg_id, enabling precise routing: "post this bug report to Bug Reports" or "search Policies for the carve-out decision." - Emoji reactions as acknowledgment signals. Reactions are programmatically readable via
message.reactions.results— enables lightweight ACK checking without requiring a text reply.
Topic selection discipline: When composing a message, select the most specific topic from the Topic Registry below. Use General only as a fallback. Never cross-post the same message to multiple topics.
Citation convention: Bare id=N citations resolve identically for every member. When referencing a prior message, cite its ID. Claude Code on both sides can look it up autonomously via client.get_messages(supergroup_id, ids=N).
Sending to a topic via tg-cli.ts: use the --reply-to flag with the topic's root_msg_id. See the Topic Registry section below for root_msg_id values.
bun "$SCRIPT" send --html --reply-to 5 -1003958083153 "<b>Policy update</b> ..."
Replying to a specific message
Telegram keeps a reply's link to the message it answers (replyTo.replyToMsgId) and, when the sender selected part of that message, the quoted part (replyTo.quoteText). Both show in read, search and thread as ↩N and ❝…❞ (list-dialogs skill, "What a listed line shows").
- Before answering, find what they answered. When a message carries
↩Nor a quote you do not recognise, runthread <chat> <id>: it climbs the chain to where the conversation began, so an answer addresses the right earlier point. Useread <chat> --around Nfor the messages around the parent. - Reply to the message you answer:
send <to> "…" --reply-to <id>. Do this in groups always, and in a private chat whenever the answer is not to the newest message, so the recipient sees which question it answers. Every part of a split message carries the same--reply-to. - In a forum topic, reply to the message itself;
--reply-to <topic root>only posts into the topic. - One question, one answer. When an earlier unanswered message of ours is superseded, delete it (
delete <chat> <id>) before sending the replacement, rather than leaving the recipient two versions. --reply-tomust be a whole number (sendrefuses anything else).
Auto-split for long messages
Telegram's hard limit is 4096 post-parsing chars per message. tg-cli.ts send and draft both auto-split messages exceeding ~3900 plain chars into multiple sequential posts, preserving HTML formatting and section structure.
Split algorithm: splits at the finest-grained safe boundary that fits all chunks:
\n\n━━━━━━━━━━━━━━\n\n(major section separator, preferred)\n━━━━━━━━━━━━━━\n(section separator)\n\n(paragraph break)\n(line break)- Hard character split (last resort — prints warning; may break tags)
Each continuation chunk gets a <i>(Part N/M)</i> header prepended so recipients see the sequence clearly. All parts share the same --reply-to target so a multi-part post stays in one topic thread.
You do NOT need to manually split messages anymore. Compose the full HTML as one string, pass to send, and the splitter handles it.
Size-aware authoring guidance: prefer messages that fit in one post (≤ 3900 plain chars) — splits add visual overhead with part headers. If a message is naturally larger (e.g., a pinned reference), let the splitter do its job. Structure with ━━━━━━━━━━━━━━ separators so split boundaries land cleanly between logical sections.
Session-reference footer (automatic — project policy)
Every send (and every send-file caption and draft) automatically ends with ONE short footer line, so the Telegram history doubles as a provenance trail. You do not add it by hand. It applies to all recipients, and rides the last chunk of a split message. It is the smallest Telegram allows natively (no font size exists): a single italic line, one newline after the text, no ------ rule and no blank line before it.
<i>via Claude Code · cc:<8 hex></i>
-
cc:is the first 8 hex ofCLAUDE_CODE_SESSION_ID(left out if unset). The line is<i>…</i>in an--htmlsend and__…__in the default markdown mode. There is no context label and no time: Telegram shows when a message was sent.--contextis still accepted and ignored. -
An Orca bot's send names the responsible bot, always (never a separate
— <name> · bot:<id>line):<i>via <bot name> · bot:<8 hex> · cc:<8 hex></i>A bot session is told apart by
ORCA_BOT_NAME/ORCA_BOT_IDin its environment, or--bot-name/--bot-id. Any one of them makes the send a bot's; then the name, the id (hex, at least 8 characters; only the first 8 show) andCLAUDE_CODE_SESSION_IDare all required, or the send exits 2 and nothing is sent.--no-footeris refused for a bot. A text carrying a hand-written— <name> · bot:line, a footer line of its own or the old two-line form (------/via Claude Code | …) is refused for a bot; a hand-written bot line is refused for a person too. -
--no-footeropts out — use it for an external or sensitive chat, or a message whose provenance must not travel (e.g. relaying a one-time code). -
A person's content already ending with a Claude Code footer (e.g. piped straight from
draft-park get, whose marker readsParked by Claude Code …) is not re-stamped, so its own marker survives. -
Do not write a footer, or a bot line, by hand. A bot's name and id are only ever added by the sender, in the one line.
-
Captions: Telegram allows 1,024 characters in a media caption (4,096 with Premium), footer included.
send-filerefuses a longer caption before uploading; send the text as its own message, replying to the file (send <to> "…" --reply-to <file_id>).
SSoT for the logic: scripts/session-footer.ts (unit tests in scripts/session-footer.test.ts).
Exact links (automatic) — no link may swallow Chinese text
Telegram's server linkifies a bare URL greedily, up to the next whitespace. Measured on 2026-11-22 (sent to Saved Messages, entities read back): 打开 github.com/login/device,用你自己的账号 was stored with a MessageEntityUrl over github.com/login/device,用你自己的账号, so the full-width comma and the Chinese after it became part of the link (the https:// form did the same). A space before the comma gave the exact link; an explicit <a href="https://github.com/login/device">github.com/login/device</a> gave a TextUrl over exactly the URL and no other link; <code>…</code> gave a code span, not a link.
So send, draft, send-file captions and edit give every bare link an explicit, exact link before sending (scripts/safe-links.ts): a link ends at the first whitespace or non-ASCII character (every full-width and CJK punctuation mark, every ideograph, emoji) and loses trailing ASCII punctuation (.,;:!?'" and an unbalanced )/]); it also ends before an opening (, [ or { it never closes, so …/windows(不用登入) links …/windows alone while Wikipedia-style …/Foo_(bar) keeps its pair. With --html each one becomes <a href="https://…">visible</a>; plain text keeps its own parse and gains an exact link entity. Text inside <a>, <code> and <pre> is left alone. Each sent message is then read back, and the command exits 1 naming the link if Telegram stored one that covers more than its URL. Fix already-sent messages with relink <chat> <ids>, which re-edits only their link entities (the text is unchanged, and mentions survive: read-back MessageEntityMentionName entities are sent as InputMessageEntityMentionName, without which the edit drops them).
E-mail addresses are linkified greedily too: on 2026-11-23 an e-mail entity in a group message ran from the Chinese 是 before the address to its .com. The read-back check covers MessageEntityEmail as well, and relink replaces such an entity with one over the address alone.
Labelled links pass the same check. Measured on 2026-11-28 (a group message sent through a relay that imports safe-links.ts, read back, then deleted): three labelled GitHub links, one with a Chinese label followed directly by Chinese text, were stored with only their labels visible, with no link preview, and badLinks passed. So linked text (next section) is both the readable form and the safe one.
You need not add spaces around links. A URL that really contains ideographs is not supported: send it percent-encoded. Other code imports the same functions from "$(cc-plugin-root tlg)/scripts/safe-links.ts": exactLinks(text, { html }) before sending and badLinks(message) on the read-back message.
The same greedy cut is a known bug class: openai/codex#55722, NousResearch/hermes-agent#144736, earendil-works/pi#10933, egoist/mygo#980, eight04/linkify-plus-plus#78.
Linked text, not bare links — tlg refuses bare GitHub links
A link is shown as its title, and the URL lives in the href: "Title, then the reference."
<a href="https://github.com/example/repo/issues/36"
>Lineage in the ledger's shape (#36)</a
>
<a href="https://github.com/example/repo/pull/37"
>账本血缘按台账结构呈现 (repo#37)</a
>已合并。
Put the repository in the reference, as (repo#36) or (owner/repo#36), when the context does not make it obvious. A #N inside an <a> label is fine: that is the reference.
send, draft, edit and send-file captions refuse (exit 2, nothing sent) a text whose visible part, outside <a>, <code> and <pre>, shows either of these:
- a
github.comURL (orwww./gist.github.com), with or withouthttps://, asexactLinkswould linkify it. An<a>whose label shows the URL (<a href="u">u</a>) counts as visible; - a bare GitHub reference:
#N,repo#Norowner/repo#N.
The error names each one and its offset. --show-url sends it anyway, when showing the address is the point (a link to copy, a URL being discussed). A bare link to any other host is not refused: the command prints Advice: bare link(s) shown as raw text on stderr and sends. Plain-text sends are checked too, after GramJS's parse (inline code passes), but plain text has no link syntax, so write linked text with --html.
Other code uses the same check from "$(cc-plugin-root tlg)/scripts/safe-links.ts": bareLinks(text, { html }) (or bareLinksInMessage({ message, entities }) for text plus entities) gives every bare link with refused set for GitHub, bareGithubLinks only the refused ones, and linkedTextVerdict(bare, { showUrl }) the send decision.
Usage: tg-cli.ts (when session is valid)
When in doubt, USE
--html. If your message contains ANY of:<b>,<i>,<code>,<pre>,<a href>, bold headers, inline code, or markdown-style**bold**/`code`, you MUST either pass--html(and translate markdown → HTML tags first) or strip the decoration. Sending Telegram-style markdown without--htmlrenders the asterisks and backticks literally to the recipient. For multi-section messages with headers, separators, and code spans — always use--html.Recovery pattern when you've already sent a mangled message: send a follow-up prefixed
Correction — earlier message rendered as raw text, corrected version below:then the correctly-HTML-formatted content. Do NOT silently edit if the message has been read (see "Editing Discipline" below).
/usr/bin/env bash << 'SEND_EOF'
ROOT="$(cc-plugin-root tlg)"
SCRIPT="$ROOT/scripts/tg-cli.ts"
# Default: plain text (use only for single-line unformatted messages)
bun "$SCRIPT" send @username "Hello"
# HTML formatting — the recommended default for any structured message
bun "$SCRIPT" send --html -1003958083153 "<b>Bold header</b>
Body with <code>inline code</code> and <a href='https://github.com/example/repo/issues/1'>What the issue is about (#1)</a>."
# Show the address itself on purpose (otherwise refused)
bun "$SCRIPT" send --html --show-url @username "Clone it: <code>git clone</code> https://github.com/example/repo"
# By chat ID (groups use negative IDs)
bun "$SCRIPT" send -1003958083153 "Hello group"
# Specific profile
bun "$SCRIPT" -p personal send @username "Hello"
# Edit a message by ID
bun "$SCRIPT" edit -1003958083153 12345 "<b>Updated text</b>"
# Make the links of sent messages exact (text unchanged; see "Exact links")
bun "$SCRIPT" relink "$CHAT_ID" 12345,12346
# Delete a message by ID
bun "$SCRIPT" delete -1003958083153 12345
SEND_EOF
Long HTML messages: tg-cli.ts send --html auto-splits at the 3900-plain-char threshold. Compose the full HTML as one string and let the splitter handle it. See "Auto-split for long messages" above.
Editing Discipline — unread vs. read
The core principle: edit silently only when you are confident the recipient has NOT read the message yet. Once someone has seen a message, editing it risks creating a false record and confusing them (they remember the original text; the chat now shows different text).
| Situation | Action |
|---|---|
| You sent a message <30s ago in an active async chat and nobody has touched Telegram since | Edit is safe — iterate freely |
| You just sent a message with a typo or factual error and the recipient has not responded | Edit is safe — they likely have not read it yet |
| The recipient has replied to your message | Do NOT edit silently — send a supplement |
| The recipient has read the message but not yet replied (you see read receipts or their typing indicator came/went) | Do NOT edit silently — send a supplement |
| You're not sure whether the recipient has read it | Default to supplement — safer than confusing them |
| The message has been cited or quoted by others in the chat | Do NOT edit — the citation is now stale context; supplement instead |
Supplement pattern (when edit is unsafe):
Correction on my previous message: <specific change>
or
Update to what I said above: <new info that supersedes>
Make the supplement self-contained so a reader scrolling back understands without having to cross-reference.
Why this matters: silent edits of read messages are one of the most confusing UX anti-patterns in chat systems. The recipient remembers "Terry told me X", sees "X'" now, and wonders if their memory is wrong or if they're being gaslit. Edits are a privilege to use before observation, not to rewrite history.
How to tell if it's been read: Telegram's MTProto exposes read receipts in 1:1 and small group chats via messages.readHistoryOutbox updates, but in large groups this is unreliable. The safest heuristic is time + activity: if more than ~60 seconds have elapsed and/or the recipient has been active in the chat, assume they saw it.
Telegram HTML Formatting Reference
GramJS uses HTML, not Markdown:
| Tag | Renders As |
|---|---|
<b>text</b> |
Bold |
<i>text</i> |
Italic |
<u>text</u> |
Underline |
<s>text</s> |
|
<code>text</code> |
Inline code |
<pre>text</pre> |
Code block |
<a href="url">text</a> |
Hyperlink |
<tg-spoiler>text</tg-spoiler> |
Spoiler |
Horizontal separator rules (enforced convention)
Use ━ (U+2501) for horizontal rules between sections in long messages.
Length rule: 14 characters preferred, 22 characters absolute maximum.
- Preferred:
━━━━━━━━━━━━━━(14 ×━) - Acceptable ceiling:
━━━━━━━━━━━━━━━━━━━━━━(22 ×━, = 14 + 8) - Never exceed 22 characters — longer separators look visually unbalanced on mobile clients and push body content off-screen.
Rationale: Telegram's mobile client reflows body text but does NOT wrap separator lines of box-drawing characters. A 28-char separator forces horizontal scrolling on narrow phones; 14 char fits cleanly in every viewport and still reads as a clear section break. If you need more visual weight, use a heading (<b>...</b>) above the separator rather than making the separator longer.
Emojis are supported but user may prefer decorations without emojis — use <pre> blocks and box-drawing characters instead.
Profiles
| Profile | Account | User ID |
|---|---|---|
work (default) |
@ExampleOpsAccount | |
personal |
@personal_account |
Known Group Chat IDs
| Group | Chat ID | Type |
|---|---|---|
| Terry & MD (Bruntwork) | -1003958083153 | Supergroup |
| Terry & MD (Bruntwork) | -1003958083153 | Legacy basic chat (pre-2026-04-16, read-only for old messages) |
Topic Registry (Bruntwork Supergroup)
To send a message to a specific topic, pass reply_to=<root_msg_id> in send_message() or use --reply-to in tg-cli.ts.
| Topic | root_msg_id | Scope |
|---|---|---|
| General | 1 | Catch-all, quick questions |
| Assignments & Deliverables | 2 | Task definitions, PR reviews, Block check-ins |
| Daily Operations | 3 | Commencement/disembarkation, shift status |
| Onboarding & Access | 4 | Repo access, SSH/Tailscale, tool provisioning |
| Policy & Standards | 5 | cc-skills carve-out, conventions, discipline |
| Bug Reports & Incidents | 6 | Merge conflicts, hook bugs, pipeline breaks |
| Tool Setup & Config | 7 | example-service, example-app, example-pipeline |
| Knowledge Base & Learning | 8 | KB pages, research material, skill references |
| HR & Scheduling | 9 | Shift hours, Bruntwork coordination |
| Session Monitor | 185 | Real-time Claude Code session summaries (CC Nasim Bot) |
Anti-Patterns (NEVER DO)
| Anti-Pattern | Why It Fails |
|---|---|
Running bun "$SCRIPT" without checking auth first |
If session expired, auth will fail |
| Checking only session file existence in preflight | Session file can exist but be expired — must check with check-auth |
| Using plain text for formatted messages | GramJS uses HTML, not Markdown. Use --html flag for formatting |
A bare URL, "click here" or a bare #N as link text |
The reader sees an address, not what it is; GitHub ones are refused |
Error Handling
| Error | Cause | Fix |
|---|---|---|
Unknown profile |
Invalid -p value |
Use work or personal |
Cannot find any entity |
Bad username/ID | Verify with dialogs command or use find-user to resolve |
message cannot be empty |
Empty string passed | Provide message text |
Session expired |
Session no longer valid | Run /tlg:setup to re-authenticate non-interactively |
refusing to send bare GitHub link(s) |
A github.com URL or #N shown as raw text (exit 2, nothing sent) |
Write linked text with --html (see "Linked text"), or pass --show-url |
Telegram stored a link that covers more than its URL |
The server linked more than the URL (exit 1, message already sent) | Run relink <chat> <id>; if it persists, report the text, it is a gap in safe-links.ts |
Post-Execution Reflection
After this skill completes, check before closing:
- Did the command succeed? — If not, fix the instruction or error table that caused the failure.
- Did parameters or output change? — If tg-cli.ts's interface drifted, update Usage examples and Parameters table to match.
- Was a workaround needed? — If you had to improvise (different flags, extra steps), update this SKILL.md so the next invocation doesn't need the same workaround.
Only update if the issue is real and reproducible — not speculative.
