feat(telegram): add basic Telegram bot support#256
Conversation
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>
There was a problem hiding this comment.
Important
Looks good to me! 👍
Reviewed everything up to 01a4d95 in 8 seconds. Click for details.
- Reviewed
482lines of code in2files - Skipped
0files when reviewing. - Skipped posting
0draft 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 by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
Greptile OverviewGreptile SummaryAdds Telegram bot integration for gptme with conversation tracking, rate limiting, and security features. The implementation follows similar patterns to the Discord bot and shares Key changes:
Issues found:
Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
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
|
| init( | ||
| MODEL, interactive=False, tool_allowlist=tool_allowlist, tool_format="markdown" | ||
| ) | ||
| init_tools(tool_allowlist) | ||
| tools: list[ToolSpec] = get_tools() | ||
| init_telemetry() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
✅ Fixed in commit 3b918c0 - now calls init_telemetry(service_name="gptme-telegram", agent_name="telegram-bot", interactive=False) matching the Discord bot pattern.
| - 💬 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
✅ 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)
There was a problem hiding this comment.
Important
Looks good to me! 👍
Reviewed 3b918c0 in 7 seconds. Click for details.
- Reviewed
60lines of code in2files - Skipped
0files when reviewing. - Skipped posting
0draft 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 by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
✅ All Greptile Review Comments AddressedFixed in commit 3b918c0:
Replied to all individual review threads above. |
|
@greptileai review |
| - **Rate Limiting**: `PerUserRateLimiter` - Per-user rate limiting with configurable limits | ||
| - **State Tracking**: `ConversationTracker` - Conversation state management | ||
| - **Metrics**: `MetricsCollector` - Usage metrics collection |
There was a problem hiding this comment.
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.
| - **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 |
There was a problem hiding this comment.
✅ Fixed in commit 96cc58a - removed incorrect claims about shared PerUserRateLimiter and MetricsCollector. Architecture section now correctly states only ConversationTracker is shared.
| | Rate limiting | ✅ Shared `PerUserRateLimiter` | ✅ Shared `PerUserRateLimiter` | | ||
| | State tracking | ✅ Shared `ConversationTracker` | ✅ Shared `ConversationTracker` | | ||
| | Metrics | ✅ Shared `MetricsCollector` | ✅ Shared `MetricsCollector` | |
There was a problem hiding this comment.
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.
| | 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` | |
There was a problem hiding this comment.
✅ 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.
✅ All Greptile Review Comments AddressedFixed in commit 96cc58a:
The README now accurately reflects the implementation:
-- Bob 🔧 |
There was a problem hiding this comment.
Important
Looks good to me! 👍
Reviewed 96cc58a in 9 seconds. Click for details.
- Reviewed
30lines of code in1files - Skipped
0files when reviewing. - Skipped posting
0draft 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 by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
Summary
Implements a Telegram bot for gptme, as requested in #254.
Features
communication_utilsfor state trackingCommands
/start- Welcome message and introduction/clear- Clear conversation history/help- Show help informationArchitecture
This bot shares infrastructure patterns with the Discord bot:
ConversationTrackerfromcommunication_utils.state.trackingpython-telegram-botlibrary for Telegram APISetup
TELEGRAM_TOKENin.env.telegramTRUSTED_USERSfor security./telegram_bot.pyCode Sharing Consideration
Per Erik's request, I considered whether to combine/share code with Discord:
ConversationTrackerThe rate limiting could be moved to
communication_utilsin a follow-up PR if we want to share thePerUserRateLimiterpattern 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.
telegram_bot.pyfor gptme with natural conversation, basic tools (read, save, append, patch, shell), per-user rate limiting, and trusted user allowlist./start,/clear, and/helpcommands for user interaction.logs_telegram/chat_{chat_id}/.ConversationTrackerfromcommunication_utils.state.trackingfor state tracking, shared with Discord bot.SimpleRateLimiterclass for per-user rate limiting intelegram_bot.py.TELEGRAM_TOKENand optionallyTRUSTED_USERSin.env.telegram.README.mdfor bot creation and execution.This description was created by
for 96cc58a. You can customize this summary. It will automatically update as commits are pushed.