# TelePi
[](https://crates.io/crates/telepi)
[](https://rust-lang.org)
[](LICENSE)
[]()
**Telegram bridge for the Pi coding agent.** Send messages to a Telegram bot, get streamed responses from `pi` CLI. Built on teloxide + tokio. Supports per-chat sessions, voice transcription, image processing, and background service management.
[π§ Quick Start](#quick-start) Β· [π‘ Commands](#commands) Β· [βοΈ Configuration](#configuration) Β· [ποΈ Architecture](#architecture) Β· [π§ Building](#building)
## Quick Start
```bash
# Install from crates.io
cargo install telepi
# Create config
mkdir -p ~/.config/telepi
cat > ~/.config/telepi/config.toml << 'EOF'
[telegram]
bot_token = "your-bot-token"
allowed_user_ids = [your-user-id]
[pi]
tool_verbosity = "summary"
EOF
# Run
telepi start
```
Or run as a background service:
```bash
telepi gateway start # Install and start
telepi gateway stop # Stop
telepi gateway restart # Restart
```
## Commands
### CLI
| `telepi start` | Start the Telegram bot (default) |
| `telepi gateway start` | Install and start as background service |
| `telepi gateway stop` | Stop the background service |
| `telepi gateway restart` | Restart the background service |
| `telepi status` | Show version, config, service status |
| `telepi setup` | Show config template |
### Telegram Bot
| `/start`, `/help` | Welcome message and command list |
| `/new` | Create a fresh session |
| `/sessions` | List and switch sessions |
| `/handback` | Resume session in terminal |
| `/abort` | Cancel running operation |
| `/retry` | Re-send last prompt |
| `/model` | Show/set current AI model |
| `/context` | Show session stats |
| `/tree` | View conversation tree |
## Configuration
TelePi loads config from (in order of priority):
1. `TELEPI_CONFIG` environment variable
2. `./telepi.toml` (current directory)
3. `~/.config/telepi/config.toml`
Environment variables override individual TOML fields.
```toml
# HTTP proxy for Telegram API (http/https/socks5)
proxy = "http://127.0.0.1:7890"
# Log level: trace, debug, info, warn, error
log_level = "info"
[telegram]
bot_token = "your-bot-token"
allowed_user_ids = [123456789]
[pi]
tool_verbosity = "summary" # all, summary, errors-only, none
[voice]
backend = "openai-whisper" # openai-whisper, parakeet, sherpa-onnx
[prompt_inbox]
enabled = false
poll_interval_secs = 5
```
## Architecture
```
βββββββββββββββββββββββββββββββββββββββββββββββ
β Telegram β
ββββββββββββββββββββ¬βββββββββββββββββββββββββββ
β
ββββββββββββββββββββΌβββββββββββββββββββββββββββ
β Bot Layer β
β commands/ handler state transport β
β prompt_inbox/ model picker streaming β
ββββββββββββββββββββ¬βββββββββββββββββββββββββββ
β PiSession trait
ββββββββββββββββββββΌβββββββββββββββββββββββββββ
β Session Layer β
β CliSession (CLI subprocess + JSON stream) β
β SessionRegistry (per-context isolation) β
ββββββββββββββββββββ¬βββββββββββββββββββββββββββ
β
ββββββββββββββββββββΌβββββββββββββββββββββββββββ
β Support Modules β
β config paths error install voice formatβ
βββββββββββββββββββββββββββββββββββββββββββββββ
```
Three-layer design: **CLI entry** β **Bot layer** (Telegram handling) β **Session layer** (Pi agent abstraction). The `PiSession` trait enables swapping implementations without touching the bot layer.
## Building
- **Rust** β₯ 1.85 (edition 2024)
- **No C library required** β TelePi is pure Rust
```bash
# Debug build
cargo build
# Release build
cargo build --release
# Run tests
cargo test
# Docker
docker build -t telepi .
docker compose up -d
```
## Features
- **Per-chat sessions** β isolated conversation state per Telegram chat
- **Streaming responses** β real-time progress updates as Pi generates output
- **Voice transcription** β send voice messages, get transcribed and processed
- **Image processing** β send photos for visual analysis
- **Model picker** β switch AI models via inline keyboard
- **Prompt inbox** β inject prompts from filesystem (`.txt` polling)
- **Background service** β launchd (macOS) / systemd (Linux) integration
- **Conversation tree** β view full session history with box-drawing rendering
## License
MIT