telepi 0.1.0

Telegram bridge for the Pi coding agent β€” Rust implementation
Documentation
# TelePi

[![Crates.io](https://img.shields.io/crates/v/telepi?style=flat-square&logo=rust)](https://crates.io/crates/telepi)
[![Rust](https://img.shields.io/badge/rust-1.85+-ed8225?style=flat-square&logo=rust&logoColor=white)](https://rust-lang.org)
[![License](https://img.shields.io/badge/license-MIT-22C55E?style=flat-square)](LICENSE)
[![Platform](https://img.shields.io/badge/platform-macOS%20Β·%20Linux-8B5CF6?style=flat-square)]()

**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

| Command | Description |
|---------|-------------|
| `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

| Command | Description |
|---------|-------------|
| `/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