breath103/serverless-agent/features

Claude Code and agent skill by breath103/serverless-agent

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Install

npx vskill@latest install breath103/serverless-agent/features

SKILL.md

The same SKILL.md was published earlier as breath103/serverless-agent/features.

Telegram — channel-style skill

Status: proposed Issue: #5 — Telegram as a channel-style skill (bidirectional mirror) Date: 2026-05-15 Prior art: documents/features/2026-05-15_google-calendar-skill.md — establishes the per-user user_skills row, install/uninstall hooks, and the InstallableSkillConfig tagged-union pattern. This doc reuses that foundation and adds the channel-vs-tool distinction.


Problem

Today every entry in user_skills is tool-style: instantiated via loadSkill(...) in agent-runtime/skills.ts, proxy-wrapped, declared in the LLM sandbox via a .generated.d.ts, and called as skill.method(...) from inside executeCode.

Telegram doesn't fit that shape. It's not a tool the LLM calls — it's a channel that:

  • ferries inbound user messages from Telegram into one of our chat sessions, and
  • mirrors outbound assistant messages back to the same Telegram chat.

The chat session is the source of truth; Telegram is a one-to-one mirror. So we need:

  1. A persistent binding between a user_skills row and a chat_sessions row.
  2. An inbound webhook that converts Telegram Updates into chat messages.
  3. An outbound hook that fires after the agent finishes a turn and posts the assistant text back to Telegram.
  4. A way to exclude channel-style skills from the LLM tool list — they must never appear in the agent's sandbox declarations.

Approach

Reuse the existing user_skills table and defineSkill abstraction. Add a new install.type === "telegram" variant alongside "builtin" and "oauth2". The discriminator on install.type is what cleanly partitions:

  • Tool skills (builtin, oauth2) — go through loadSkill, get a .generated.d.ts, appear in the sandbox.
  • Channel skills (telegram) — skipped by buildSkills, no declaration, never reach the LLM. Their behaviour is driven by webhook routes and a dispatch hook in orchestrate.ts.

No new table. No new abstraction layer. Just one more variant + two new files (route + dispatcher) + a one-line filter in buildSkills + a one-call hook in orchestrate.ts.

Why install.type as the discriminator (not a separate kind: "tool" | "channel" field)

The frontend already filters skills by install.type (InstallTypeFilteredSkillMap<"oauth2"> in skills/index.ts:30). Adding kind would create two parallel discriminators that have to stay aligned. Letting install.type carry the channel/tool distinction keeps a single source of truth: if you want a "send-and-receive" channel skill you write install: { type: "telegram", ... } and the type system carries it everywhere automatically.


Data shape

user_skills row — new tagged variant
ts
// In packages/backend/src/skills/telegram.ts
const TelegramSkillConfigSchema = z.object({
bot_token: z.string(),
telegram_chat_id: z.string().nullable(), // their side — captured on first inbound
chat_session_id: z.string().nullable(), // our side — set on first inbound (or null after explicit reset)
webhook_secret: z.string(), // random per-row, sent via X-Telegram-Bot-Api-Secret-Token
bot_username: z.string().nullable(), // captured from getMe() at install time, displayed in UI
});

InstallableSkillConfig gains a { skill_id: "telegram"; config: TelegramSkillConfig } arm automatically by the existing tagged-union machinery in skills/index.ts.

UserSkillRow shape is unchanged. The discriminated union does its job.

No new tables, no new GSIs

Inbound webhook path is /api/telegram/webhook/:userSkillId, so the row is fetched by (user_id, id) — but we don't have user_id in the URL.

Two options:

  • (A) Embed user_id in the URL: /api/telegram/webhook/:userId/:userSkillId. Two unpredictable segments. Fetch by primary key. Cheap.
  • (B) Add a GSI on `id` alone: lets us look up a skill row by id without knowing user_id. Costs one GSI.

Going with (A) — both segments are server-generated UUIDs and the user never sees the URL. The URL is what we hand to Telegram at install time. No GSI cost, no scan, two key lookups per webhook hit.


Inbound flow

1. User starts a chat in Telegram by messaging their bot.
2. Telegram POSTs to https://<edge>/api/telegram/webhook/<userId>/<userSkillId>
with header X-Telegram-Bot-Api-Secret-Token: <webhook_secret>
3. Backend:
a. Looks up user_skills row by (userId, userSkillId). 404 if missing.
b. Verifies the secret-token header matches row.data.config.webhook_secret. 401 if mismatch.
c. Extracts { chat.id (Telegram chat), text-or-placeholder } from the Update.
d. If row.data.config.telegram_chat_id is null OR different from update.chat.id → ignore
(the row is bound to a specific Telegram chat after first contact).
Edge: on the very first message, telegram_chat_id is null → store update.chat.id.
e. If row.data.config.chat_session_id is null → create a new chat session via
startChatSession({ userId, kind: "user", userMessageText }), then write
back the new sessionId into the skill row. The chat is a normal user chat;
the binding only lives on the skill row.
f. Otherwise: append the text as a user message to the existing chat session
and trigger runChatInBackground.
4. Return 200 OK to Telegram immediately. The agent turn runs in the background;
when assistant text is generated, the outbound hook posts it back to Telegram.
Unsupported media

Telegram Updates carry text for text messages, but photo/video/voice/audio/document/sticker for media. We render media as a single placeholder string and feed it to the chat session:

photo → "[image] - not supported yet"
video → "[video] - not supported yet"
voice → "[voice message] - not supported yet"
audio → "[audio] - not supported yet"
document → "[document] - not supported yet"
sticker → "[sticker] - not supported yet"

If a single Update has both text and media (e.g., a photo with a caption), join them: <caption>\n[image] - not supported yet.

The LLM sees the placeholder and replies naturally ("sorry, I can't read images yet"), which the outbound hook posts back to Telegram. No special prompting needed.

No new ChatSessionKind

A chat is a chat — Telegram is just another input device. A Telegram-initiated chat gets kind: "user", exactly as if the user had typed it into the web app. The user can keep going on the same chat from web OR from Telegram; nothing in the backend cares which client the latest message came through, and any assistant reply mirrors back to Telegram regardless of which side asked the question.

If we later want a "via Telegram" badge in the sidebar, it can be derived at render time by checking whether any installed Telegram skill row has chat_session_id === thisChat.id. That's a frontend concern, not a stored attribute. Deferring.


Outbound flow

After runChatTurn generates an assistant text block, the existing persistAssistantBlock(block) writes the row. We add one call right after the row write, only in the case "text" branch:

ts
// orchestrate.ts — case "text" inside persistAssistantBlock
await insertPart({ ... });
await dispatchAssistantTextToChannels({ userId, sessionId, text: block.text });

dispatchAssistantTextToChannels:

  1. Loads user_skills rows for the user (already cached for the turn? — no, the rows are loaded in buildSkills which has its own scope. A second read per turn is fine — a few items, single Query).
  2. Filters to rows where data.skill_id === "telegram" AND data.config.chat_session_id === sessionId.
  3. For each match, POSTs to https://api.telegram.org/bot<token>/sendMessage with { chat_id: telegram_chat_id, text, parse_mode: "HTML" }, where text is the agent's Markdown converted to Telegram's tiny HTML subset (<b>, <i>, <code>, <pre>, <a href>). On a parse-error 400 the helper retries once with the raw text and no parse_mode so delivery never drops.
  4. Per-row failures are logged + swallowed (a revoked bot token or a deleted Telegram chat must not crash the turn or affect web-UI delivery).
Why only text blocks

tool_use/tool_call rows are internal agent state — sending them to Telegram would surface raw executeCode { code: "..." } payloads to the user, which is noise. Only text is user-facing prose.

Recursion safety

User messages (role=user) are written before the agent loop starts in runChatInBackground. The outbound hook is in persistAssistantBlock, which only runs on assistant content. So inbound→outbound→inbound recursion can't happen by construction.

Markdown → Telegram HTML

The agent emits Markdown; Telegram renders either MarkdownV2 (finicky — every literal ., !, -, (, ), etc. must be escaped outside markers) or a small HTML subset. We picked HTML because it's a closed grammar that's easy to generate correctly:

  • HTML-escape the input (&, <, >) first, so any LLM-emitted <tag> shows as text.
  • Convert **bold** / __bold__ → <b>, *italic* / _italic_ → <i>, ~~s~~ → <s>, ` code → <code>, ``code` → <pre>, [label](url) → <a href="url">label</a>.
  • Headers (# x) collapse to <b>x</b> (Telegram has no header tag).
  • Bullets - item become • item (Telegram has no list tag).
  • Tables (| a | b |) flatten to a · b (Telegram has no table support at all).
  • Horizontal rules (---) become —.

Fallback: if Telegram still rejects (some pathological combination), the helper retries once without parse_mode — delivery survives, formatting is lost for that message only.


Excluding channel skills from the LLM

Single point of exclusion. In agent-runtime/skills.ts's loop over userSkillsRepo.listForUser(...):

ts
for (const row of rows) {
if (skillHandlers[row.data.skill_id].install.type === "telegram") continue;
// ... existing refresh + loadSkill path
}

Why this is enough:

  • loadSkill (in skill-runtimes/index.ts) never gets a telegram row → no runtime instance.
  • No telegram.generated.d.ts is written → nothing for the agent's sandbox to see.
  • No proxy binding → telegram methods aren't typeable inside executeCode.

The exhaustiveness check in loadSkill's switch keeps working: it's exhaustive over InstallableSkillConfig["skill_id"] minus the channel ones we've filtered above. Adding a second channel skill (Slack, Discord) means widening the filter, not the switch.

Type-level partition

Mirror the frontend's Oauth2InstallSkillMap with a sibling type:

ts
// skills/index.ts
export type TelegramInstallSkillMap = InstallTypeFilteredSkillMap<"telegram">;
export type ChannelInstallableSkillId = keyof TelegramInstallSkillMap;

This lets the route handler and the dispatcher narrow to telegram skill rows without as.


Install / uninstall

Install — token-based, not OAuth

A new route shape, since OAuth doesn't apply:

POST /api/skills/install/telegram
body: { botToken: string }

Handler:

  1. Generate webhook_secret (random 32 bytes hex).
  2. Call getMe on the Telegram Bot API to verify the token and capture bot_username. Fail 422 with Telegram's error if invalid.
  3. userSkillsRepo.upsert({ userId, skillId: "telegram", config: { bot_token, telegram_chat_id: null, chat_session_id: null, webhook_secret, bot_username } }).
  4. Register the webhook with Telegram: POST https://api.telegram.org/bot<token>/setWebhook { url: <edge>/api/telegram/webhook/<userId>/<userSkillId>, secret_token: webhook_secret, drop_pending_updates: true }.
  5. publishRealtimeEvent for the row → frontend settings page reflects connect.

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
16
Repository forks
3
7-day trend score
14

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/breath103/serverless-agent/features/badge)](https://verified-skill.com/skills/breath103/serverless-agent/features)

Something wrong with this skill or its page? Tell us.