Skip to content

fix(telegram): post stale/missed alerts as new messages instead of editing bubble - #37

Closed
robster7674 wants to merge 2 commits into
glucodroidfrom
fix/telegram-stale-new-message
Closed

fix(telegram): post stale/missed alerts as new messages instead of editing bubble#37
robster7674 wants to merge 2 commits into
glucodroidfrom
fix/telegram-stale-new-message

Conversation

@robster7674

Copy link
Copy Markdown
Owner

Summary

Previously TelegramStaleCheckWork edited the live bubble in-place when readings went stale or missed — overwriting the last valid glucose value. This made it impossible to tell from chat history whether any gaps occurred.

After this change, stale and missed alerts are posted as new Telegram messages. The original bubble keeps the last valid reading; each alert appears as a distinct, timestamped event in the chat timeline.

Example chat history after a gap:

🟢 7.3 mmol/L ↗ 08/06/2026 15:25   ← bubble (last real reading, unchanged)
⚠️ Stale — waiting for next reading. (15:35)   ← new message
⚪ Missed reading. (15:40)                       ← new message
🟢 7.1 mmol/L → 08/06/2026 16:05   ← new bubble when readings resume

What changed

  • postEdit()postSend(): uses /sendMessage instead of /editMessageText; message_id not sent in body
  • Bubble messageId and lastSentAtMs state left intact on stale/missed success, so readings resuming after the refresh window start a fresh bubble naturally (via the withinWindow expiry)
  • Definitive rejection from postSend (bot blocked, chat not found) still clears state

Test plan

  • Let readings go stale (wait past stale threshold) — verify a new "⚠️ Stale" message appears; original bubble unchanged
  • Wait past missed threshold — verify a new "⚪ Missed reading" message appears
  • Resume readings — verify a fresh bubble is started (new message)
  • Normal in-window readings still edit the bubble in-place (unaffected)

🤖 Generated with Claude Code

…ubble

Previously TelegramStaleCheckWork edited the existing bubble in-place for
stale and missed transitions. This meant the last valid reading was overwritten
and chat history gave no indication of when or how many gaps occurred.

Now stale and missed alerts are posted as new Telegram messages (sendMessage).
The original bubble retains the last reading, and each stale/missed event
appears as a distinct, timestamped message in the chat timeline — making it
easy to glance back and see if and when readings were interrupted.

The messageId guard is kept so alerts only fire when an active session exists.
State (lastSentAtMs, lastMessageId) is left intact on success so readings
resuming after the refresh window naturally start a fresh bubble.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Jun 8, 2026

Copy link
Copy Markdown

Greptile Summary

This PR changes TelegramStaleCheckWork so that stale and missed alerts are posted as new Telegram messages instead of overwriting the live glucose bubble via editMessageText. resolvedUrl() already returns the /sendMessage endpoint, so the method rename to postSend is straightforward with no URL rewriting needed. The two suggestions from the previous review round — renaming the messageId variable to hasActiveBubble and correcting the "bubble deleted" comment — are both already applied in this diff.

  • postEditpostSend: removes message_id from the request body and drops the /sendMessage/editMessageText URL rewrite, using the base URL directly.
  • State preservation: messageId and lastSentAtMs are intentionally left intact after a stale/missed send so that the withinWindow expiry in the normal reading path can decide whether to edit or start a fresh bubble when readings resume.
  • Error handling: definitive 4xx rejections still call clearRecipientState, preserving the existing recovery path; transient failures leave state intact as before.

Confidence Score: 5/5

Safe to merge — the change is a straightforward swap from editMessageText to sendMessage with no state regressions.

The diff is small and self-contained: one method renamed, one URL rewrite removed, message_id dropped from the request body. resolvedUrl() already returns the /sendMessage endpoint, so the simplification is correct. State management is preserved as described. The two previous review suggestions were both incorporated. No new edge-case risks are introduced.

No files require special attention.

Important Files Changed

Filename Overview
Common/src/main/java/tk/glucodata/TelegramStaleCheckWork.kt Switches stale/missed alerts from editing the live bubble (editMessageText) to posting new messages (sendMessage); state management correctly preserved. Previous review suggestions (hasActiveBubble rename, comment wording) are already incorporated.

Sequence Diagram

sequenceDiagram
    participant CGM as CGM Reading
    participant OA as OutboundApi
    participant SC as TelegramStaleCheckWork
    participant TG as Telegram API

    CGM->>OA: sendTelegram()
    OA->>TG: POST /sendMessage (bubble)
    TG-->>OA: 200 OK + message_id
    OA->>SC: schedule(destinationId, staleDelayMs)

    Note over SC: stale threshold fires
    SC->>TG: POST /sendMessage (Stale alert)
    TG-->>SC: 200 OK
    SC->>SC: recordStaleAt() and schedule missed check

    Note over SC: missed threshold fires
    SC->>TG: POST /sendMessage (Missed alert)
    TG-->>SC: 200 OK
    SC->>SC: recordStaleAt()

    Note over TG: Original bubble unchanged

    CGM->>OA: sendTelegram() readings resume
    OA->>TG: POST /sendMessage (fresh bubble)
    TG-->>OA: 200 OK + new message_id
Loading

Reviews (2): Last reviewed commit: "refactor(telegram): address greptile rev..." | Re-trigger Greptile

Rename messageId guard to hasActiveBubble to reflect that the message ID
is not passed to postSend and the check is purely a "bubble was sent"
sentinel. Update stale 4xx comment from "bubble deleted" (accurate for
editMessageText) to "bot blocked / wrong chat_id" (accurate for
sendMessage).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@robster7674

Copy link
Copy Markdown
Owner Author

Root cause fixed on glucodroid (563126f): the null branch in TelegramStaleCheckWork.run() was silently dropping notifications without scheduling a retry. Now a 60 s retry is scheduled on transient network error, so in-place stale/missed editing is preserved. The sendMessage approach in this PR is no longer needed.

@robster7674 robster7674 closed this Jun 8, 2026
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.

1 participant