Skip to content

fix: split long Telegram captions into media + text messages#907

Closed
jalehman wants to merge 3 commits intoopenclaw:mainfrom
jalehman:fix/telegram-caption-split
Closed

fix: split long Telegram captions into media + text messages#907
jalehman wants to merge 3 commits intoopenclaw:mainfrom
jalehman:fix/telegram-caption-split

Conversation

@jalehman
Copy link
Copy Markdown
Contributor

@jalehman jalehman commented Jan 14, 2026

When sending media with text exceeding Telegram's 1024 character caption limit, the API returns message caption is too long error.

Problem

Sending audio/images with long text captions fails:

GrammyError: Call to 'sendAudio' failed! (400: Bad Request: message caption is too long)

Solution

This fix:

  • Adds TELEGRAM_MAX_CAPTION_LENGTH constant (1024)
  • Detects when text exceeds the limit while sending media
  • Sends media first without caption, then sends text as follow-up message
  • Preserves thread params, reply markup, and HTML parsing in follow-up
  • Returns the text message ID as the main message ID

Testing

  • Added unit tests for caption splitting behavior
  • All existing tests pass

Generated with Claude Code

Co-Authored-By: Claude [email protected]

jalehman and others added 3 commits January 14, 2026 06:48
When sending media with text exceeding Telegram's 1024 character caption
limit, the API returns 'message caption is too long' error.

This fix:
- Adds TELEGRAM_MAX_CAPTION_LENGTH constant (1024)
- Detects when text exceeds the limit while sending media
- Sends media first without caption, then sends text as follow-up message
- Preserves thread params, reply markup, and HTML parsing in follow-up
- Returns the text message ID as the main message ID

Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Address code review feedback:
- Follow-up text now uses plain text to match caption behavior (no HTML conversion)
- reply_markup (buttons) only appears on follow-up text when splitting,
  not on the media message
- Added tests for reply_markup behavior with split captions

Co-Authored-By: Claude <[email protected]>
steipete added a commit that referenced this pull request Jan 14, 2026
@steipete steipete closed this Jan 14, 2026
@steipete
Copy link
Copy Markdown
Contributor

Landed in main as 53465a4.

Tests: pnpm lint, pnpm build, pnpm test.

Thanks @jalehman!

zooqueen pushed a commit to hanzoai/bot that referenced this pull request Mar 6, 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.

2 participants