fix(telegram): post stale/missed alerts as new messages instead of editing bubble - #37
fix(telegram): post stale/missed alerts as new messages instead of editing bubble#37robster7674 wants to merge 2 commits into
Conversation
…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>
|
| 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
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>
|
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. |
Summary
Previously
TelegramStaleCheckWorkedited 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:
What changed
postEdit()→postSend(): uses/sendMessageinstead of/editMessageText;message_idnot sent in bodymessageIdandlastSentAtMsstate left intact on stale/missed success, so readings resuming after the refresh window start a fresh bubble naturally (via thewithinWindowexpiry)postSend(bot blocked, chat not found) still clears stateTest plan
🤖 Generated with Claude Code