Skip to content

Back to Roadmap Index

Phase 7: Telegram Integration ✅ COMPLETED

Goal: Migrate Telegram listener to use new architecture.

Status: ✅ Completed

Tasks

  1. New Telegram Listener (src/reeve/integrations/telegram/listener.py) ✅
  2. Implemented TelegramListener class (595 lines)
  3. Async polling-based integration with Telegram Bot API
  4. Long polling (100s timeout) for efficient resource usage
  5. Offset persistence to prevent duplicate message processing
  6. Chat ID filtering (only processes authorized user)
  7. Exponential backoff error handling (up to 5 minutes)
  8. See Daemon & API

  9. Testing

  10. 35 comprehensive unit tests (tests/test_telegram_listener.py)
  11. 2 integration/validation tests (tests/test_phase7_validation.py)
  12. All tests pass: 191/191

  13. Entry Point (src/reeve/integrations/telegram/__main__.py) ✅

  14. Run as module: python -m reeve.integrations.telegram
  15. Configuration loading and validation
  16. Graceful KeyboardInterrupt handling

Deliverables

  • ✅ Production-ready Telegram listener
  • ✅ End-to-end message flow working
  • ✅ Comprehensive test suite

Validation

# Terminal 1: Start daemon
uv run python -m reeve.pulse

# Terminal 2: Start Telegram listener
uv run python -m reeve.integrations.telegram

# Terminal 3: Send Telegram message
# Should see:
# - Listener: "📩 Telegram message from User: hello"
# - Listener: "✓ Pulse 123 triggered"
# - Daemon: "Executing pulse 123: Telegram message from User: hello"
# - Daemon: "Pulse 123 completed successfully"

Demo

Prerequisites

# Ensure Telegram credentials are in .env
# TELEGRAM_BOT_TOKEN=your_bot_token
# TELEGRAM_CHAT_ID=your_chat_id
# PULSE_API_TOKEN=your_secret_token

Step 1: Start daemon (Terminal 1)

uv run python -m reeve.pulse

# Expected output:
# 2026-01-19 10:30:00 | INFO | Starting Pulse Daemon...
# 2026-01-19 10:30:00 | INFO | Starting HTTP API on port 8765...
# 2026-01-19 10:30:00 | INFO | Scheduler loop started

Step 2: Start Telegram listener (Terminal 2)

uv run python -m reeve.integrations.telegram

# Expected output:
# 2026-01-19 10:30:05 | INFO | Starting Telegram Listener...
# 2026-01-19 10:30:05 | INFO | Bot username: @YourBotName
# 2026-01-19 10:30:05 | INFO | Listening for messages from chat_id: 123456789
# 2026-01-19 10:30:05 | INFO | Polling for updates...

Step 3: Run demo script (Terminal 3)

uv run python demos/phase7_telegram_demo.py

# The script will:
# 1. Send a test message to the bot
# 2. Verify the listener receives it
# 3. Verify a pulse is triggered via API
# 4. Verify the daemon executes it
# 5. Verify Reeve responds back via Telegram

Expected output across terminals

Terminal 2 (Telegram Listener):

2026-01-19 10:30:10 | INFO | 📩 Telegram message from User (123456789): hello
2026-01-19 10:30:10 | INFO | Triggering pulse via API...
2026-01-19 10:30:10 | INFO | ✓ Pulse 42 triggered

Terminal 1 (Daemon):

2026-01-19 10:30:10 | INFO | API: Received pulse trigger from telegram
2026-01-19 10:30:10 | INFO | Executing pulse #42 (CRITICAL): "Telegram message from User: hello"
2026-01-19 10:30:10 | INFO | Launching Hapi session...
2026-01-19 10:30:13 | INFO | Pulse #42 completed successfully (3.1s)

Your Telegram App:

[Your message]
hello

[Bot's response]
Hi! I received your message. How can I help you today?

💬 View in Claude Code: https://hapi.example.com/session/abc123

Step 4: Test complex interactions

# Send: "What's on my calendar today?"
# Expected: Bot responds with your calendar summary

# Send: "Remind me to call John in 2 hours"
# Expected: Bot confirms and schedules a pulse

# Send: "What's the weather like?"
# Expected: Bot fetches weather and responds

Previous: Phase 6: HTTP API

Next: Phase 8: Deployment