Install
Install with PiG
pig install npm:@qusic/pi-telegramInstall with Pi
pi install npm:@qusic/pi-telegramPackages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.
Pi manifest JSON
The pi field of package.json.
{
"extensions": [
"./src/index.ts"
]
}README
Written by the package's publisher, shown as published in version 0.3.0 (README.md). PiG does not review it.
pi-telegram
A Telegram DM bridge for pi — chat with your pi coding agent from anywhere through a Telegram bot. Based on badlogic/pi-telegram, rewritten with AI to better fit my personal preferences and needs.
Features
- Two-way Telegram ↔ pi bridge over long-polling
getUpdates - Streamed replies with live previews, including extended thinking (separated from the answer by 💭 / ✏️ markers); long answers grow incrementally instead of only appearing at the end
- Markdown rendering to native Telegram formatting (headings, bold, italics, links, inline & fenced code, blockquotes, lists, tables, task lists, footnotes, LaTeX), robust to partial mid-stream snippets
- Attachments in: photos, albums, documents, video, audio, voice, animations and stickers; images are inlined as image inputs, everything else is referenced by local path
- Attachments out: ask for a file and the agent sends it with an
attachtool - Tool call breadcrumbs: grouped progress that updates as tools run
- Mid-turn steering: messages sent while the agent is busy are injected into the running turn
- Typing indicator while the agent is working
- Single-user authorization by Telegram user id
Telegram-side commands
Auto-published as the bot menu at boot. Anything else is forwarded to pi as a user turn.
| Command | Description |
|---|---|
/new | Start a new pi session |
/resume | List recent sessions; /resumeN to switch |
/stop | Abort the current turn |
/status | Model, token usage, cost and context window |
/compact | Compact the conversation |
/skills | List skills available to the agent |
Resuming a session echoes that session's last reply back to the chat, so it reflects where you left off (the TUI already shows the full history).
Differences vs. upstream badlogic/pi-telegram
| Area | Upstream | This fork |
|---|---|---|
| Setup & lifecycle | /telegram-setup / /telegram-connect / /telegram-disconnect commands; explicit per-session connect | No pi-side commands; you write ~/.pi/agent/telegram.json yourself, polling auto-starts per session |
| Authorization | First DM user is auto-paired | First DM sender id is shown as a warning in pi; unauthorized senders receive no response |
| Commands & bot menu | Telegram-side commands limited to /status, /compact, stop, /help, /start; no menu published | Adds /new, /resume, /skills and publishes the menu via setMyCommands; session switching from Telegram |
| Concurrency | Extra messages while busy are queued and dispatched after the current turn ends | Extra messages are steered into the running turn |
| Aborted-turn replay | After stop, queued messages are re-injected as a synthetic history block | No replay — stop just aborts |
| Prompt prefix | Each message prefixed with [telegram], plus a system-prompt suffix | Forwarded as-is |
| Rendering | Plain text only; URL preview cards enabled | Native Rich Message (sendRichMessage, GitHub-Flavored Markdown) for every outgoing message |
| Streaming | Probes sendMessageDraft, falls back to sendMessage + editMessageText; previews truncated at 4096 chars, full answer only appears at agent_end | sendRichMessageDraft live previews committed with sendRichMessage; oversized previews are promoted into real messages mid-stream so long answers grow live |
| Tool call breadcrumbs | None | Grouped progress that updates as tools run |
| Thinking blocks | Stripped | Streamed, separated by 💭 / ✏️ markers |
| Status bar | Rich colored status | Only transient polling errors |
| Outgoing files | telegram_attach, prompted for [telegram] messages; files wait for the reply | attach, used when you ask; files are sent immediately, even from the TUI |
Media-group debouncing matches upstream. Internally the fork is split into small manager closures instead of a single file.
Install
Only one pi session should poll a given bot token at a time, so load this per-session instead of installing globally:
pi -e npm:@qusic/pi-telegram
To use the Git checkout instead:
pi -e git:github.com/Qusic/pi-telegram
Configure
Talk to @BotFather, run
/newbot, copy the bot token.Create
~/.pi/agent/telegram.json:{ "botToken": "123456:ABC-your-token-here" }Start pi — polling starts automatically.
DM your bot once. pi shows a warning with your Telegram user id; add
"allowedUserId": <id>to the config and restart. The bot stays silent until authorized.
Usage
Just chat with your bot. Text becomes the next pi turn; photos/files are downloaded and referenced in the prompt (images also inlined); ask pi to send you a file and it calls attach; /stop aborts.
License
MIT. See LICENSE.