Real agentic conversations between Telegram and pi coding agent with full OMC orchestration.
Bridge Telegram directly to pi for authentic agent interactions with streaming responses, persistent sessions, and access to all OMC engine commands.
β
Real Agentic Conversations - Full pi agent capabilities via Telegram
β
Streaming Responses - Updates appear in real-time as pi processes
β
Persistent Sessions - Per-user/thread conversation history
β
OMC Full Access - tap, tav, tvs, rawr, rawrs, swarm commands available
β
Thread/Topic Support - Works with Telegram topics and threads
β
Rate Limiting - Built-in security and rate limiting
β
Easy Deployment - tmux-based management for 24/7 operation
Based on Claude Code Telegram Plugin but adapted for pi SDK instead of Claude Code SDK.
Telegram Message
β
Pi Telegram Bot
β
Pi SDK Integration
β
Pi Agent + pi-agent-teams Extension
β
OMC Engines (RALPH, AUTOPILOT, ULTRAWORK, SWARM)
β
Streaming Response Back to Telegram
git clone https://github.com/hscheema1979/pi-telegram.git
cd pi-telegram# Copy example config
cp .env.telegram.example .env.telegram
# Edit with your values
nano .env.telegramEdit .env.telegram:
# Get token from @BotFather in Telegram
TELEGRAM_BOT_TOKEN=YOUR_TOKEN_HERE
TELEGRAM_BOT_USERNAME=your_bot_name
# Pi will use ANTHROPIC_API_KEY from environment
# Make sure it's set: export ANTHROPIC_API_KEY=sk-ant-...npm install
npm run build# Start bot in tmux session
./scripts/start.sh
# View logs
tmux attach -t pi-telegram
# Stop bot
./scripts/stop.sh
# Check status
./scripts/status.shOr run directly:
npm startTELEGRAM_BOT_TOKEN- Your Telegram bot token from @BotFatherTELEGRAM_BOT_USERNAME- Bot's username (without @)ANTHROPIC_API_KEY- Your Anthropic API key (for pi agent)
PI_WORKING_DIRECTORY- Working directory for pi agent (default:./)LOG_LEVEL- Logging level: debug, info, warn, error (default:info)ENABLE_RATE_LIMIT- Enable rate limiting (default:true)RATE_LIMIT_PER_MINUTE- Rate limit threshold (default:30)MAX_CONVERSATION_HISTORY- Messages to keep per session (default:50)NODE_ENV- Environment: development or production (default:development)
/help - Show help message
/status - Check bot and session status
/clear - Clear conversation history
/about - About this bot
All OMC commands from pi-agent-teams are available:
/tap "Add OAuth2" - AUTOPILOT autonomous execution
/tav "Optimize DB" - RALPH verification loops
/tvs "Refactor code" - RALPH + SWARM (verified teams)
/rawr "Build feature" - Triple engine power (r@lph + @utopilot + ultrawork)
/rawrs "Big project" - ULTIMATE power (all 4 engines)
/swarm "Scale task" - Multi-team coordination
Or just send any message and pi will respond with full agent capabilities!
"How can I refactor my authentication module?"
"Add error handling to this function"
"What's wrong with my database query?"
- Handles Telegram message polling
- Registers command handlers
- Bridges messages to pi SDK
- Manages streaming responses
- Creates and manages pi SDK sessions
- Sends prompts to pi agent
- Handles agent responses
- Maintains per-user session state
- Tracks conversation history per user/thread
- Implements trimming for memory efficiency
- Supports persistent storage (SQLite ready)
- Real-time message updates to Telegram
- Chunks large responses (Telegram 4096 char limit)
- Updates message as pi processes
npm run dev# Start in background
./scripts/start.sh
# Keeps running even if terminal closes
# Access with: tmux attach -t pi-telegramnpm install -g pm2
pm2 start "npm start" --name "pi-telegram"
pm2 save
pm2 startup# tmux session
tmux attach -t pi-telegram
# Or with npm run in foreground
npm startSend /status to the bot in Telegram to see:
- Active sessions count
- Pi integration status
- Bot connectivity
- Telegram Bot Token - Keep in
.env.telegram, never commit to git - API Key - Set
ANTHROPIC_API_KEYenvironment variable, never hardcode - User Isolation - Each user/thread gets separate pi session
- Rate Limiting - Enabled by default to prevent abuse
- Approved Directory - Pi agent restricted to configured working directory
# Restrict .env.telegram permissions
chmod 600 .env.telegram
# Never commit secrets
echo ".env.telegram" >> .gitignore
# Use environment variables for secrets
export ANTHROPIC_API_KEY=sk-ant-...
export TELEGRAM_BOT_TOKEN=123456:ABC...This bot has full access to the pi-agent-teams extension which provides:
- π― RAWR (Triple Engine) - RALPH + AUTOPILOT + ULTRAWORK
- π―π RAWRS (Ultimate Power) - All 4 OMC engines
- π RALPH - Verification loops
- π€ AUTOPILOT - Autonomous planning
- β‘ ULTRAWORK - 10+ parallel operations
- π SWARM - Multi-team coordination
All commands are available through the /tap, /tav, /rawr, /rawrs shortcuts or full names.
-
Check token is correct:
curl -s -X POST https://api.telegram.org/botYOUR_TOKEN/getMe
-
Check pi is working:
pi /help
-
Check ANTHROPIC_API_KEY is set:
echo $ANTHROPIC_API_KEY
- Verify
ENABLE_STREAMING=truein config - Check bot has message_thread_id permissions
- Check Telegram rate limits
- Verify write permissions to working directory
- Check database file isn't locked
- Clear
./.dbfiles and restart
- Simple question: 5-15 seconds
- Code analysis: 15-30 seconds
- OMC commands: 30-60 seconds
- Complex tasks (RAWRS): 60+ seconds
- Use specific OMC commands (
/tap,/rawr) for tasks - Keep messages focused and concise
- Use
/clearto reset session if memory grows - Monitor session count with
/status
npm run buildnpm run type-checknpm run devpi-telegram/
βββ src/
β βββ bot/
β β βββ core.ts # Main bot implementation
β β βββ streaming.ts # Streaming response handler
β βββ pi/
β β βββ integration.ts # Pi SDK integration
β βββ session/
β β βββ manager.ts # Session/history management
β βββ config/
β β βββ settings.ts # Configuration loader
β βββ utils/
β β βββ logger.ts # Logging utilities
β βββ main.ts # Entry point
βββ scripts/
β βββ start.sh # Start with tmux
β βββ stop.sh # Stop bot
β βββ status.sh # Check status
βββ .env.telegram.example # Config template
βββ package.json
βββ tsconfig.json
βββ README.md
- Add database persistence for sessions (SQLite)
- Add user authorization levels
- Add inline query buttons for common commands
- Add conversation export to file
- Add webhook mode for scalability
- Add metrics/monitoring dashboard
- Add multi-language support
- Add custom pi prompt templates
MIT
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
- π Issues: GitHub Issues
- π¬ Questions: Discord
- π Documentation: This README
Status: Beta
Version: 0.1.0
Last Updated: February 25, 2026