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 installed version:
pi-gateway --version
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
/statuscurrent Pi session/model/stats/newfresh Pi session for this Telegram chat/name <name>name current Pi session/compact [instructions]compact current Pi context/stopabort current Pi operation/lastresend last assistant response/exportexport current session to HTML/sessionslist known sessions/switch <id>point this chat at another known Pi session/cloneclone current branch into a new session/modelslist 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pi_gateway-0.1.1.tar.gz.
File metadata
- Download URL: pi_gateway-0.1.1.tar.gz
- Upload date:
- Size: 27.5 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
264cfdb654a981e8caa0cd69284ec91f6a0fed98d7bef322037f9cf6b154a8e2
|
|
| MD5 |
7576002c12c753657c95649cff50e22a
|
|
| BLAKE2b-256 |
73c1ab148ce76a30d428a7fed5c5bda409640c08de609fd37bacb1810ffc1354
|
File details
Details for the file pi_gateway-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pi_gateway-0.1.1-py3-none-any.whl
- Upload date:
- Size: 19.2 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5c829cfa0d7ac784b2214c8244dd8ddbabe7ec0f02d40f9c5e7bc5b771340d8
|
|
| MD5 |
1eb843e25db96b935b9d8b73e09b0923
|
|
| BLAKE2b-256 |
93d4d17e2bb29277bd89d77c093c6cd591ff73e9bf456dcedd9888e5aa2dff1c
|