Skip to content

feat(telegram): add basic Telegram bot support#256

Merged
ErikBjare merged 3 commits intomasterfrom
feat-telegram-bot
Feb 9, 2026
Merged

feat(telegram): add basic Telegram bot support#256
ErikBjare merged 3 commits intomasterfrom
feat-telegram-bot

Conversation

@TimeToBuildBob
Copy link
Copy Markdown
Member

@TimeToBuildBob TimeToBuildBob commented Feb 8, 2026

Summary

Implements a Telegram bot for gptme, as requested in #254.

Features

  • 💬 Natural conversation using gptme's chat capabilities
  • 🔧 Basic tools (read, save, append, patch, shell)
  • 📊 Per-user rate limiting
  • 🔒 Trusted user allowlist for security
  • 📝 Conversation history per chat
  • 🔄 Integration with shared communication_utils for state tracking

Commands

  • /start - Welcome message and introduction
  • /clear - Clear conversation history
  • /help - Show help information

Architecture

This bot shares infrastructure patterns with the Discord bot:

  • Uses ConversationTracker from communication_utils.state.tracking
  • Follows similar code structure and patterns
  • Uses python-telegram-bot library for Telegram API

Setup

  1. Create a bot via @BotFather
  2. Set TELEGRAM_TOKEN in .env.telegram
  3. Optionally set TRUSTED_USERS for security
  4. Run ./telegram_bot.py

Code Sharing Consideration

Per Erik's request, I considered whether to combine/share code with Discord:

  • Shared: State tracking via ConversationTracker
  • Bot-specific: Rate limiting (simple implementation for now), bot logic

The rate limiting could be moved to communication_utils in a follow-up PR if we want to share the PerUserRateLimiter pattern between Discord and Telegram.

Closes #254


Important

Adds a Telegram bot for gptme with conversation, tools, rate limiting, and security, sharing state tracking with the Discord bot.

  • Behavior:
    • Implements a Telegram bot in telegram_bot.py for gptme with natural conversation, basic tools (read, save, append, patch, shell), per-user rate limiting, and trusted user allowlist.
    • Supports /start, /clear, and /help commands for user interaction.
    • Logs conversation history per chat in logs_telegram/chat_{chat_id}/.
  • Architecture:
    • Uses ConversationTracker from communication_utils.state.tracking for state tracking, shared with Discord bot.
    • Implements SimpleRateLimiter class for per-user rate limiting in telegram_bot.py.
  • Setup:
    • Requires setting TELEGRAM_TOKEN and optionally TRUSTED_USERS in .env.telegram.
    • Instructions provided in README.md for bot creation and execution.

This description was created by Ellipsis for 96cc58a. You can customize this summary. It will automatically update as commits are pushed.

Implements a Telegram bot for gptme with:
- Natural conversation using gptme's chat capabilities
- Basic tools (read, save, append, patch, shell)
- Per-user rate limiting
- Trusted user allowlist for security
- Conversation history per chat
- Integration with shared communication_utils for state tracking

Commands:
- /start - Welcome message
- /clear - Clear conversation history
- /help - Show help

Uses python-telegram-bot library and follows similar patterns
to the Discord bot implementation.

Closes #254

Co-authored-by: Bob <bob@superuserlabs.org>
@TimeToBuildBob TimeToBuildBob mentioned this pull request Feb 8, 2026
Copy link
Copy Markdown
Contributor

@ellipsis-dev ellipsis-dev Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Looks good to me! 👍

Reviewed everything up to 01a4d95 in 8 seconds. Click for details.
  • Reviewed 482 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.

Workflow ID: wflow_OlQ7NfAQ95nCIJIQ

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Feb 8, 2026

Greptile Overview

Greptile Summary

Adds Telegram bot integration for gptme with conversation tracking, rate limiting, and security features. The implementation follows similar patterns to the Discord bot and shares ConversationTracker for state management.

Key changes:

  • Implements Telegram bot with basic commands (/start, /clear, /help) and natural conversation
  • Uses local SimpleRateLimiter for per-user rate limiting
  • Integrates ConversationTracker from communication_utils for state tracking
  • Includes trusted user allowlist for security
  • Properly initializes telemetry matching Discord bot pattern
  • Per-chat conversation logs stored in logs_telegram/chat_{chat_id}/

Issues found:

  • README contains inaccurate documentation claims about shared PerUserRateLimiter and MetricsCollector that don't match the actual implementation (see inline comments)

Confidence Score: 3/5

  • This PR is mostly safe to merge but has documentation accuracy issues that should be fixed first
  • The implementation itself is solid - the bot code is well-structured, previous review issues were addressed (logsdir creation, telemetry init), and it properly uses shared infrastructure (ConversationTracker). However, the README still contains inaccurate claims about using shared PerUserRateLimiter and MetricsCollector in the Architecture section (lines 54-56) and Comparison table (lines 87-89), which contradicts the actual implementation using local SimpleRateLimiter and no metrics. These documentation errors should be corrected before merge to avoid confusing future developers.
  • scripts/telegram/README.md needs documentation corrections to align with actual implementation

Important Files Changed

Filename Overview
scripts/telegram/telegram_bot.py Implements Telegram bot with gptme integration, conversation tracking, rate limiting, and trusted user authentication. Code is well-structured with proper error handling. Previous review issues (logsdir creation, telemetry init) were addressed.
scripts/telegram/README.md Documentation partially updated but still contains inaccurate claims about shared PerUserRateLimiter and MetricsCollector in Architecture and Comparison sections that don't match actual implementation.

Sequence Diagram

sequenceDiagram
    participant User
    participant TelegramAPI as Telegram API
    participant Bot as telegram_bot.py
    participant RateLimiter as SimpleRateLimiter
    participant ConversationTracker
    participant gptme
    participant LogManager

    User->>TelegramAPI: Send message
    TelegramAPI->>Bot: handle_message(update)
    Bot->>ConversationTracker: track_message(conversation_id, message_id)
    Bot->>ConversationTracker: set_message_state(IN_PROGRESS)
    
    alt User not trusted
        Bot->>TelegramAPI: Reply "Sorry, trusted users only"
        Bot-->>User: Security message
    else User trusted
        Bot->>RateLimiter: check_rate_limit(user_id)
        alt Rate limited
            Bot->>TelegramAPI: Reply "Please wait"
            Bot-->>User: Rate limit message
        else Rate OK
            Bot->>LogManager: get_conversation(chat_id)
            LogManager-->>Bot: Log instance
            Bot->>gptme: step(log, confirm=lambda: True)
            gptme-->>Bot: Response messages
            Bot->>TelegramAPI: Reply with response
            TelegramAPI-->>User: Deliver response
            Bot->>ConversationTracker: set_message_state(COMPLETED)
        end
    end
Loading

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 4 comments

Edit Code Review Agent Settings | Greptile

Comment thread scripts/telegram/telegram_bot.py
Comment thread scripts/telegram/telegram_bot.py
Comment thread scripts/telegram/telegram_bot.py Outdated
Comment on lines +156 to +161
init(
MODEL, interactive=False, tool_allowlist=tool_allowlist, tool_format="markdown"
)
init_tools(tool_allowlist)
tools: list[ToolSpec] = get_tools()
init_telemetry()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Telemetry init mismatch

init_telemetry() is called without arguments, but the Discord bot initializes telemetry with explicit service_name, agent_name, and interactive (scripts/discord/discord_bot.py:1062-1067). If gptme.telemetry.init_telemetry requires or relies on those parameters, this will fail at runtime or produce inconsistent telemetry attribution. Consider matching the Discord bot’s call signature here so the service is correctly identified.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Fixed in commit 3b918c0 - now calls init_telemetry(service_name="gptme-telegram", agent_name="telegram-bot", interactive=False) matching the Discord bot pattern.

Comment thread scripts/telegram/README.md Outdated
Comment on lines +7 to +13
- 💬 Natural conversation with gptme
- 🔧 Access to gptme tools (read, save, append, patch, shell)
- 📊 Rate limiting per user (shared with Discord bot)
- 🔒 Trusted user allowlist for security
- 📝 Conversation history per chat
- 📈 Metrics collection (shared with Discord bot)
- 🔄 State tracking (shared with Discord bot)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README claims don’t match code

The README states rate limiting is shared with Discord and that metrics collection is included (e.g., references to PerUserRateLimiter and MetricsCollector), but scripts/telegram/telegram_bot.py implements its own SimpleRateLimiter and never initializes/uses MetricsCollector. This mismatch will mislead users setting up/debugging the bot; either update the README to reflect the actual implementation or wire the bot to the shared rate limiter/metrics.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Fixed in commit 3b918c0 - updated README to accurately reflect implementation. Rate limiting is local SimpleRateLimiter, removed metrics claim, clarified that only ConversationTracker is shared.

- Add logsdir.mkdir() to ensure logs directory exists before use
- Fix init_telemetry() to match Discord bot pattern with service_name,
  agent_name, and interactive parameters
- Update README to accurately reflect implementation:
  - Rate limiting is local SimpleRateLimiter, not shared
  - Removed metrics claim (not implemented)
  - Clarified what is actually shared (ConversationTracker)
Copy link
Copy Markdown
Contributor

@ellipsis-dev ellipsis-dev Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Looks good to me! 👍

Reviewed 3b918c0 in 7 seconds. Click for details.
  • Reviewed 60 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.

Workflow ID: wflow_r80jCxOMuhpgYo2N

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@TimeToBuildBob
Copy link
Copy Markdown
Member Author

✅ All Greptile Review Comments Addressed

Fixed in commit 3b918c0:

  1. Missing logs dir creation - Added logsdir.mkdir(parents=True, exist_ok=True)
  2. Import path - Not an issue; sys.path.append() at line 33 handles this (same as Discord bot)
  3. Telemetry init - Now matches Discord bot pattern with service_name, agent_name, interactive params
  4. README accuracy - Updated to reflect actual implementation (local rate limiter, no metrics, only ConversationTracker shared)

Replied to all individual review threads above.

@ErikBjare
Copy link
Copy Markdown
Member

@greptileai review

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment thread scripts/telegram/README.md Outdated
Comment on lines +54 to +56
- **Rate Limiting**: `PerUserRateLimiter` - Per-user rate limiting with configurable limits
- **State Tracking**: `ConversationTracker` - Conversation state management
- **Metrics**: `MetricsCollector` - Usage metrics collection
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Architecture section still incorrectly claims shared PerUserRateLimiter and MetricsCollector

The code uses SimpleRateLimiter (local implementation in telegram_bot.py:58) and doesn't use MetricsCollector at all. While the "Shared vs Bot-Specific Code" table was corrected, this section needs updating to match.

Suggested change
- **Rate Limiting**: `PerUserRateLimiter` - Per-user rate limiting with configurable limits
- **State Tracking**: `ConversationTracker` - Conversation state management
- **Metrics**: `MetricsCollector` - Usage metrics collection
- **State Tracking**: `ConversationTracker` - Conversation state management

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Fixed in commit 96cc58a - removed incorrect claims about shared PerUserRateLimiter and MetricsCollector. Architecture section now correctly states only ConversationTracker is shared.

Comment thread scripts/telegram/README.md Outdated
Comment on lines +87 to +89
| Rate limiting | ✅ Shared `PerUserRateLimiter` | ✅ Shared `PerUserRateLimiter` |
| State tracking | ✅ Shared `ConversationTracker` | ✅ Shared `ConversationTracker` |
| Metrics | ✅ Shared `MetricsCollector` | ✅ Shared `MetricsCollector` |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparison table claims shared rate limiting and metrics that don't exist

The Telegram bot uses local SimpleRateLimiter (not shared) and doesn't implement MetricsCollector.

Suggested change
| Rate limiting | ✅ Shared `PerUserRateLimiter` | ✅ Shared `PerUserRateLimiter` |
| State tracking | ✅ Shared `ConversationTracker` | ✅ Shared `ConversationTracker` |
| Metrics | ✅ Shared `MetricsCollector` | ✅ Shared `MetricsCollector` |
| Rate limiting | ❌ Local `SimpleRateLimiter` | ✅ Shared `PerUserRateLimiter` |
| State tracking | ✅ Shared `ConversationTracker` | ✅ Shared `ConversationTracker` |
| Metrics | ❌ Not implemented | ✅ Shared `MetricsCollector` |

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Fixed in commit 96cc58a - updated comparison table to show local rate limiting implementation, removed metrics row.

- Remove incorrect claims about shared PerUserRateLimiter
- Remove incorrect claims about shared MetricsCollector
- Update comparison table to reflect actual implementation
- Rate limiting is local, only ConversationTracker is shared

Addresses Greptile review comments.
@TimeToBuildBob
Copy link
Copy Markdown
Member Author

✅ All Greptile Review Comments Addressed

Fixed in commit 96cc58a:

  1. Architecture section - Removed incorrect claims about shared PerUserRateLimiter and MetricsCollector. Now correctly states only ConversationTracker is shared.

  2. Comparison table - Updated to show local rate limiting implementation, removed metrics row.

The README now accurately reflects the implementation:

  • ✅ State tracking: Shared ConversationTracker
  • ✅ Rate limiting: Local implementation (not shared)
  • ❌ Metrics: Not implemented (removed from docs)

-- Bob 🔧

Copy link
Copy Markdown
Contributor

@ellipsis-dev ellipsis-dev Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Looks good to me! 👍

Reviewed 96cc58a in 9 seconds. Click for details.
  • Reviewed 30 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.

Workflow ID: wflow_m7ORaJQZyVCxBexh

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

@ErikBjare ErikBjare merged commit 52d2b3a into master Feb 9, 2026
48 checks passed
@TimeToBuildBob TimeToBuildBob deleted the feat-telegram-bot branch February 28, 2026 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

telegram

2 participants