Add Telegram rich report rendering#184
Conversation
|
Warning Review limit reached
More reviews will be available in 47 minutes and 55 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds opt-in Telegram Bot API rich message sending ( ChangesTelegram Rich Messages Feature
Sequence Diagram(s)sequenceDiagram
participant Server as cmd/server/main.go
participant Report as report.go<br/>SendMorningSmartOpts
participant Renderer as report_rich.go
participant Helper as sendReportHTML
participant Bot as telegram.go Bot
participant TG as Telegram API
rect rgba(100, 149, 237, 0.5)
Note over Server: startup
Server->>Server: getEnvBool("TELEGRAM_RICH_MESSAGES", false)
Server->>Report: notify.Config{TelegramRichMessages: true}
end
rect rgba(144, 238, 144, 0.5)
Note over Report: morning report send
Report->>Renderer: formatMorningRich(briefing)
Renderer-->>Report: richHTML
Report->>Helper: sendReportHTML(bot, fallbackHTML, richHTML, true)
Helper->>Bot: SendRichHTML(richHTML)
Bot->>TG: POST /sendRichMessage
alt ok:true
TG-->>Bot: success
Bot-->>Helper: nil
else ok:false or HTTP error
TG-->>Bot: error
Bot-->>Helper: error
Helper->>Helper: log.Printf rich failure
Helper->>Bot: Send(fallbackHTML)
Bot->>TG: POST /sendMessage
end
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f357f4957f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| fmt.Fprintf(sb, "<tr><td>😴 Sleep</td><td>%s</td><td>%s</td></tr>\n", richEsc(sleepValue), richText(stripSimpleTags(sleepRead))) | ||
| fmt.Fprintf(sb, "<tr><td>❤️ Recovery</td><td>%d%%</td><td>%s</td></tr>\n", b.RecoveryPct, richText(stripSimpleTags(recoveryRead))) |
There was a problem hiding this comment.
Suppress stale metrics in rich summary
When f.sleepStale() or f.watchOff() is true, the detailed Sleep/Recovery sections below are replaced by freshness banners, but these summary rows still print sleepValue from b.Sleep.TotalAvg and b.RecoveryPct. For rich-message users with a 36h+ sensor sync gap, the top table can show days-old sleep/recovery numbers before warning that the section is stale, which undermines the freshness-banner contract; gate these rows on the same freshness checks or show the banner/placeholder instead.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
internal/notify/telegram.go (1)
82-109: 💤 Low valueConsider checking io.ReadAll error for completeness.
Line 94 ignores the error from
io.ReadAll(resp.Body). While unlikely to fail in practice (reading from an already-closed or fully-buffered HTTP response body), checking the error would make the code more defensive and consistent with robust error handling.🛡️ Proposed defensive improvement
- body, _ := io.ReadAll(resp.Body) + body, readErr := io.ReadAll(resp.Body) + if readErr != nil { + return fmt.Errorf("telegram sendRichMessage: read body: %w", readErr) + } if resp.StatusCode != http.StatusOK {🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/notify/telegram.go` around lines 82 - 109, In the SendRichHTML method, the error returned from io.ReadAll(resp.Body) is currently ignored by assigning it to the blank identifier. Check this error explicitly and return a formatted error if it occurs, similar to how other errors in this function are handled (e.g., using fmt.Errorf with appropriate context). This improves defensive programming and ensures any unexpected issues reading the response body are properly surfaced.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@internal/notify/telegram.go`:
- Around line 82-109: In the SendRichHTML method, the error returned from
io.ReadAll(resp.Body) is currently ignored by assigning it to the blank
identifier. Check this error explicitly and return a formatted error if it
occurs, similar to how other errors in this function are handled (e.g., using
fmt.Errorf with appropriate context). This improves defensive programming and
ensures any unexpected issues reading the response body are properly surfaced.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: fb39e13e-1dac-4072-9891-c01c743282ab
📒 Files selected for processing (11)
AGENTS.mdCLAUDE.mdcmd/server/main.godocs/ai-plans/2026-06-14-telegram-rich-messages.htmlinternal/notify/digest.gointernal/notify/report.gointernal/notify/report_rich.gointernal/notify/report_test.gointernal/notify/telegram.gointernal/notify/telegram_test.gointernal/storage/settings.go
Summary
Closes #183.
Verification
Notes
Summary by CodeRabbit
Release Notes
New Features
TELEGRAM_RICH_MESSAGESenvironment variable) with automatic fallback to standard HTML if rich sending fails.Documentation
TELEGRAM_RICH_MESSAGESsetting.Tests