Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughReformats environment validation signature and switches ZodError handling to use Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant User
participant TelegramBot as Telegram Bot
participant MessageManager
participant MessageService
rect rgba(200,200,255,0.18)
note over MessageManager: Old flow (event-driven)
User->>TelegramBot: Send message
TelegramBot->>MessageManager: onMessage(...)
MessageManager->>MessageManager: Build memory/document info
MessageManager-->>MessageService: Emit MESSAGE_RECEIVED event
MessageService-->>MessageManager: Handled via listeners
end
sequenceDiagram
autonumber
participant User
participant TelegramBot as Telegram Bot
participant MessageManager
participant MessageService
rect rgba(200,255,200,0.18)
note over MessageManager: New flow (direct call)
User->>TelegramBot: Send message
TelegramBot->>MessageManager: onMessage(...)
MessageManager->>MessageManager: Build memory/document info
MessageManager->>MessageService: handleMessage(runtime, memory, callback)
MessageService-->>MessageManager: Returns/ invokes callback
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro Cache: Disabled due to data retention organization setting Knowledge base: Disabled due to data retention organization setting 📒 Files selected for processing (2)
🔇 Additional comments (6)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/environment.ts (1)
32-33: Avoid reverting toanywhen handling Zod errorsYou already narrowed the catch to
z.ZodError, so you can keep type safety without falling back toany.Apply this diff to preserve typing:
- const errorMessages = (error as any).errors - .map((err: any) => `${err.path.join('.')}: ${err.message}`) + const zodError = error as z.ZodError; + const errorMessages = zodError.errors + .map((issue) => `${issue.path.join('.')}: ${issue.message}`)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge base: Disabled due to data retention organization setting
📒 Files selected for processing (2)
src/environment.ts(2 hunks)src/messageManager.ts(12 hunks)
src/messageManager.ts
Outdated
| // Call the message handler directly instead of emitting events | ||
| // This provides a clearer, more traceable flow for message processing | ||
| await this.runtime.messageService!.handleMessage(this.runtime, memory, callback); |
There was a problem hiding this comment.
Guard against missing MessageService before using it
The new direct call assumes runtime.messageService is always defined. If the runtime hasn’t registered the service yet (or a downstream integrator upgrades the plugin before the core), this becomes a hard crash instead of the previous no-op event emission.
Add a defensive check so we fail gracefully:
- await this.runtime.messageService!.handleMessage(this.runtime, memory, callback);
+ const messageService = this.runtime.messageService;
+ if (!messageService) {
+ logger.error('Message service not available; skipping Telegram message handling');
+ return;
+ }
+ await messageService.handleMessage(this.runtime, memory, callback);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Call the message handler directly instead of emitting events | |
| // This provides a clearer, more traceable flow for message processing | |
| await this.runtime.messageService!.handleMessage(this.runtime, memory, callback); | |
| // Call the message handler directly instead of emitting events | |
| // This provides a clearer, more traceable flow for message processing | |
| const messageService = this.runtime.messageService; | |
| if (!messageService) { | |
| logger.error('Message service not available; skipping Telegram message handling'); | |
| return; | |
| } | |
| await messageService.handleMessage(this.runtime, memory, callback); |
🤖 Prompt for AI Agents
In src/messageManager.ts around lines 707 to 709, the direct call to
this.runtime.messageService!.handleMessage(...) assumes messageService is always
present and will crash if it is undefined; add a defensive check that verifies
this.runtime.messageService exists before calling handleMessage, and if it's
missing, gracefully handle the case (e.g., log a warning and return or fall back
to the previous emit-based no-op behavior) so the code does not throw when the
service is not registered yet.
Migrates Telegram plugin from event-based message handling to direct
MessageService calls, making message flow easier to trace and debug.
Changes:
Benefits:
Before:
this.runtime.emitEvent(EventType.MESSAGE_RECEIVED, {
runtime: this.runtime, message: memory, callback, source: 'telegram'
});
this.runtime.emitEvent(TelegramEventTypes.MESSAGE_RECEIVED, {...});
After:
await this.runtime.handleMessage(memory, callback);
Requires: feat/core-message-service-interface
Note
Replaces event-based Telegram message handling with direct MessageService.handleMessage calls, and cleans up Zod validation and document-processing logs/formatting.
runtime.emitEvent(...MESSAGE_RECEIVED...)with directruntime.messageService.handleMessage(runtime, memory, callback)and add missing-service guard.processMessage/document handlers: consistent quotes, multiline conditions, improved error logging, and attachment cleanup mapping style.src/environment.ts):ZodError.issuesovererrorswhen building error messages.Written by Cursor Bugbot for commit 0c887c5. This will update automatically on new commits. Configure here.
Summary by CodeRabbit
Refactor
Style
Chores