Back to projects

Telegram Agent Kit

Turns an AI agent's Markdown into HTML that Telegram accepts and streams its reply into a live draft.

TypeScriptLLM agentsTelegram

Hooking an AI agent up to a Telegram bot has a few hard parts:

  • Models write Markdown, but Telegram accepts only a small, strict subset of HTML. One unclosed tag and the whole message is rejected.
  • Streaming a reply into a live draft means rendering half-finished Markdown several times a second.
  • When a turn fails, the conversation has to roll back cleanly, or the agent’s memory drifts away from what really happened.

Telegram Agent Kit handles these cases, so your bot code does not have to. Its core has no runtime dependencies and runs on Node 20+, Bun and Deno, and the formatting part in the browser too. It makes no network calls of its own: you give it a few small functions that call the Bot API, and it handles everything around them.

Markdown to Telegram HTML

mdToTelegramHtml turns whatever the model wrote into HTML that Telegram accepts, and it never throws:

import { mdToTelegramHtml } from 'telegram-agent-kit';

mdToTelegramHtml('**Done.** Saved to `notes.md`.');
// '<b>Done.</b> Saved to <code>notes.md</code>.'

// In a live draft, partial mode closes whatever the stream left open.
mdToTelegramHtml('Here is **the plan', { partial: true });
// 'Here is <b>the plan</b>'

What the user sees

While the agent works, its draft shows the plan and each tool call above the growing answer. Once the reply is sent, the draft disappears on its own:

📋 Plan
✔️ f̶i̶n̶d̶ ̶t̶h̶e̶ ̶w̶e̶e̶k̶'̶s̶ ̶e̶n̶t̶r̶i̶e̶s̶
🔘 total the calories
⬜ compare against the target
🔧 `query_journal`…
─────
Over the week you ate 14,200 kcal

With the optional telegram-agent-kit/deepagents adapter this feed needs no wiring at all.

Get started

npm install telegram-agent-kit

The README walks through a full bot turn, from the Bot API calls to rollback on failure.

Related posts

ai

The Best Pull Request Deletes More Than It Adds

How Ponytail became a useful cleanup stage in my Claude Code review workflow.

Jul 30, 2026 · 4 min readclaude-code

Automating monorepo tasks with Claude Code slash commands

Using Claude Code custom commands to replace manual dependency updates and tool upgrades in a monorepo.

Apr 2, 2026 · 4 min readclaude-code

Generating commit messages with Copilot in Neovim

A Neovim setup that uses Copilot Chat to generate commit messages with the right format, branch name, and project rules.

Feb 16, 2026 · 3 min readneovim