Skip to content

fix(#34): split long Telegram messages at natural boundaries#35

Merged
arniesaha merged 1 commit intomainfrom
fix/issue-34-telegram-message-splitting
Apr 15, 2026
Merged

fix(#34): split long Telegram messages at natural boundaries#35
arniesaha merged 1 commit intomainfrom
fix/issue-34-telegram-message-splitting

Conversation

@arniesaha
Copy link
Copy Markdown
Owner

Summary

Fixes #34 — long responses were getting cut off mid-sentence with a cursor artifact.

Changes

  • findSplitPoint(text, maxLen) — new helper that finds the best split point using priority order: paragraph (\n\n) > newline (\n) > sentence end (. , ! , ? ) > word boundary (space) > hard cut
  • Streaming split loop — now uses findSplitPoint() instead of inline lastIndexOf("\n") logic
  • Continuation messages — now sent via sendWithFormat() (HTML-formatted) instead of raw sendMessage(), plus a 200ms delay before sending to preserve ordering
  • splitMessage() — updated to use findSplitPoint() and trim leading whitespace from remainder chunks

Acceptance Criteria

  • ✅ Responses longer than 4096 chars split into multiple sequential messages
  • ✅ Splits happen at natural boundaries (paragraph > sentence > word)
  • ✅ No cursor artifact or abrupt mid-sentence cutoff
  • ✅ Each chunk sent in order with short delay

Testing

Ran unit tests validating: short messages pass through, paragraph splits, sentence splits, no cursor artifacts in chunks, all chunks ≤ 4000 chars.

- Add findSplitPoint() helper: paragraph > sentence > word > hard cut
- Replace inline split logic in streaming loop with findSplitPoint()
- Use sendWithFormat() for continuation messages (was plain sendMessage)
- Add 200ms delay before sending continuation to preserve ordering
- Improve splitMessage() to use findSplitPoint() and trim leading
  whitespace from remainder chunks
- Eliminates mid-sentence cutoffs and cursor artifact (▍) on truncated
  messages

Fixes #34
@arniesaha arniesaha merged commit 26b19b8 into main Apr 15, 2026
1 check passed
@arniesaha arniesaha deleted the fix/issue-34-telegram-message-splitting branch May 9, 2026 21:23
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.

bug: long responses get cut off mid-sentence at Telegram message length limit

1 participant