npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

pi-telegram-bot

v1.0.6

Published

Telegram bot powered by pi coding agent

Downloads

216

Readme

Pi Telegram Bot

CI npm version License: MIT

A production-ready Telegram bot powered by the pi coding agent, following the official pi-mono architecture.

Features

  • Full pi integration: Uses @mariozechner/pi-coding-agent package for agent functionality
  • Session persistence: Conversations are saved and resumed across restarts
  • Tools available: bash, read, write, edit
  • Per-chat isolation: Each Telegram chat has its own workspace and context
  • Memory system: Bot can remember things across sessions via MEMORY.md
  • Health checks: HTTP endpoints for monitoring
  • Structured logging: JSON logs with configurable levels
  • Docker support: Easy deployment with Docker Compose

Prerequisites

  • Node.js 18+
  • Bun (recommended) or npm
  • Telegram Bot Token (from @BotFather)
  • OpenAI OAuth via pi CLI

Installation

Option 1: npm (for use as a library)

npm install pi-telegram-bot

Option 2: Clone and run locally

  1. Clone the repository:
git clone https://github.com/queuephil/pi-telegram-bot.git
cd pi-telegram-bot
  1. Install dependencies:
bun install
  1. Set up environment variables:
cp .env.example .env
# Edit .env with your credentials
  1. Get Telegram Bot Token:

    • Message @BotFather on Telegram
    • Send /newbot and follow instructions
    • Copy the bot token to your .env file
  2. Get your Telegram User ID:

    • Message @userinfobot on Telegram
    • Copy your user ID to ALLOWED_USERS in .env
  3. Set up OpenAI OAuth:

    # Run pi CLI and login
    pi
    /login
    # Select OpenAI and follow browser instructions
       
    # Then copy the auth.json
    mkdir -p ~/.pi/telegram-bot
    cp ~/.pi/agent/auth.json ~/.pi/telegram-bot/auth.json

Usage

Development mode (with auto-restart):

bun run dev

Production mode:

bun run build
bun start

Using Docker:

# Build and run with Docker Compose
docker-compose up -d

# Or build manually
docker build -t pi-telegram-bot .
docker run -d --env-file .env -v $(pwd)/data:/app/data pi-telegram-bot

Environment Variables

| Variable | Description | Default | |----------|-------------|---------| | TELEGRAM_BOT_TOKEN | Required Bot token from @BotFather | - | | ALLOWED_USERS | Comma-separated list of allowed user IDs | (empty = allow all) | | WORKING_DIR | Directory for chat data | ./data | | PI_PROVIDER | AI provider (currently only openai supported) | openai | | PI_MODEL | Model to use | gpt-5.1-codex-mini | | LOG_LEVEL | Log level: trace, debug, info, warn, error | info | | HEALTH_CHECK_PORT | Health check server port | 3000 | | NODE_ENV | Environment: development, production, test | development |

Bot Commands

  • /start - Show welcome message
  • /new - Clear session and start fresh conversation
  • /help - Show available commands

Workspace Structure

Each chat gets its own directory:

data/
└── <chat_id>/
    ├── MEMORY.md          # Persistent memory
    ├── context.jsonl      # Conversation history
    └── files/             # Working files

Health Checks

The bot exposes health check endpoints for monitoring:

  • GET /health - Returns 200 when healthy, 503 when unhealthy
  • GET /ready - Returns 200 when ready to receive traffic

Development

Available Scripts

# Run tests
bun test

# Run tests with coverage
bun run test:coverage

# Lint code
bun run lint

# Fix linting issues
bun run lint:fix

# Format code
bun run format

# Type check
bun run typecheck

# Clean build files
bun run clean

Architecture

This bot follows the same architecture as the official mom (Slack bot) package:

  1. AgentRunner: Manages the pi agent session per chat
  2. SessionManager: Persists conversation context to context.jsonl
  3. Tools: bash, read, write, edit (same as pi CLI)
  4. Event system: Subscribes to agent events for real-time updates

The bot maintains conversation state using the same @mariozechner/pi-coding-agent package that powers the official pi CLI.

Security Notes

  • The bot runs bash commands on the host machine - use with caution
  • Each chat has isolated workspace (no cross-chat access)
  • Use ALLOWED_USERS to restrict access to specific users
  • Review what files/commands the bot has access to

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Run tests and linting (bun test && bun run lint)
  4. Commit your changes (git commit -m 'Add amazing feature')
  5. Push to the branch (git push origin feature/amazing-feature)
  6. Open a Pull Request

License

MIT