Skip to main content

Telegram gateway for controlling persistent Pi coding-agent sessions over RPC

Project description

pi-gateway

Telegram gateway for persistent Pi coding-agent sessions.

The gateway is a long-running process. Telegram conversations are mapped to Pi JSONL session files in SQLite, while Pi remains the source of truth for agent history.

Documentation

See docs/ for architecture, startup flow, Telegram gateway internals, Pi RPC integration, session mapping, deployment, and troubleshooting notes.

Install with uv

Directly from GitHub (no clone needed):

uv tool install git+https://github.com/YOUR_USERNAME/pi-gateway.git

Install a specific tag or branch:

uv tool install git+https://github.com/YOUR_USERNAME/pi-gateway.git@v0.1.0

Upgrade later:

uv tool install --force git+https://github.com/YOUR_USERNAME/pi-gateway.git
# or
uv tool upgrade pi-gateway

From a local checkout:

uv tool install .

Or for development:

uv sync
uv run pi-gateway --help

Pi must already be installed and authenticated on the machine as the same user that runs the gateway.

Configure Telegram

Create/update the default config at ~/.config/pi-gateway/config.yaml interactively:

pi-gateway configure telegram

It will ask for your BotFather token, your allowed Telegram user id, and the Pi working directory.

You can also configure non-interactively:

pi-gateway configure telegram \
  --allowed-user-id YOUR_TELEGRAM_USER_ID \
  --pi-cwd /home/agent/pi-workspace

By default the bot token can be read from TELEGRAM_BOT_TOKEN. You can also write it into the config:

pi-gateway configure telegram \
  --bot-token '123:abc' \
  --allowed-user-id YOUR_TELEGRAM_USER_ID \
  --pi-cwd /home/agent/pi-workspace

Security note: --allowed-user-id writes a single allowlisted Telegram user id. Messages from other users are ignored. Group chats are disabled unless you pass --allow-groups.

Print the default config path:

pi-gateway config-path

You can still maintain config manually; see examples/config.yaml.

Run

Foreground mode, useful for debugging or systemd:

export TELEGRAM_BOT_TOKEN=123:abc
pi-gateway run

Background mode, useful for a simple VPS setup without systemd:

pi-gateway start
pi-gateway status
pi-gateway logs -f
pi-gateway stop

start writes logs to:

~/.local/state/pi-gateway/pi-gateway.log

With an explicit config:

pi-gateway -c config.yaml start
pi-gateway -c config.yaml run
# or
pi-gateway run -c config.yaml

Development checkout:

uv run pi-gateway run

Telegram commands

  • /status current Pi session/model/stats
  • /new fresh Pi session for this Telegram chat
  • /name <name> name current Pi session
  • /compact [instructions] compact current Pi context
  • /stop abort current Pi operation
  • /last resend last assistant response
  • /export export current session to HTML
  • /sessions list known sessions
  • /switch <id> point this chat at another known Pi session
  • /clone clone current branch into a new session
  • /models list available models
  • /model <provider/model-id> switch model
  • /thinking <level> set thinking level
  • /queue <text> queue follow-up
  • /steer <text> steer current/next turn
  • /pi <text> send raw text to Pi, including Pi slash commands

Normal Telegram messages are sent to Pi as prompts.

Session mapping

Gateway key:

telegram:<chat_id>:<thread_id?>:<user_id?>

SQLite stores that key plus Pi's sessionId and sessionFile. On restart the gateway resumes with:

pi --mode rpc --session <stored-session-file>

systemd

See systemd/pi-gateway.service and adjust paths/user/env.

Example with uv tool install:

[Service]
User=agent
Environment=TELEGRAM_BOT_TOKEN=123:abc
ExecStart=/home/agent/.local/bin/pi-gateway run
Restart=always

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pi_gateway-0.1.0.tar.gz (27.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pi_gateway-0.1.0-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

Details for the file pi_gateway-0.1.0.tar.gz.

File metadata

  • Download URL: pi_gateway-0.1.0.tar.gz
  • Upload date:
  • Size: 27.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pi_gateway-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f3366857144d12b0c7b257adf91e70b8fa2cc70fe760cd429039778fe5b93f2e
MD5 895adae5c625f8fc679dc46075b5905b
BLAKE2b-256 f73b016fb790662a4a6c5f8c746faeb8b2b7970821821cbe962f401f670b2b0d

See more details on using hashes here.

File details

Details for the file pi_gateway-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pi_gateway-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pi_gateway-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7a54099517777ed8fd2a88d4054c0e692d96da2614e45414c187745d51c8ede4
MD5 c6a7c66fa995aa913b3129546b61ceab
BLAKE2b-256 15a60e1caf97b88b01bf0d0a314cadb391427d2588f0b1884f8138ece4665a23

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page