Skip to content

Conversation

@remote-swe-user
Copy link
Contributor

Problem

The sendMessageToUser tool encounters Slack API errors when messages exceed 3000 characters.

Solution

This PR implements message splitting functionality in the sendMessageToSlack function to handle long messages:

Changes Made

  • Added splitMessageByNewlines function: Splits messages at newline boundaries when they exceed the 3000 character limit
  • Modified sendMessageToSlack function: Now sends multiple messages sequentially when content is too long
  • Smart splitting logic:
    • Prioritizes splitting at newline characters within the 3000 character limit
    • Falls back to hard cut if no newlines are found (safety measure)
    • Preserves message formatting and readability

Implementation Details

  1. Character limit check: Messages ≤ 3000 chars are sent as before (no change in behavior)
  2. Newline-based splitting: For longer messages, finds the last newline within 3000 chars
  3. Sequential sending: Each chunk is sent as a separate Slack message in the same thread
  4. Error prevention: Eliminates the 3000 character limit errors from Slack API

Testing

  • ✅ TypeScript compilation passes
  • ✅ Prettier formatting applied
  • ✅ All existing tests pass
  • ✅ No breaking changes to existing functionality

This ensures that long AI responses and code outputs are properly delivered to users without API failures.

remote-swe-app[bot] added 4 commits December 13, 2025 03:04
- Add splitMessageByNewlines function to handle message chunking
- Split messages at newline boundaries when exceeding 3000 characters
- Send multiple messages sequentially to avoid Slack API errors
- Fallback to hard cut if no newlines found within limit
…hunks

- Change from section blocks to rich_text blocks to avoid 3000 char limit
- Increase chunk size from 3000 to 12000 characters
- Remove unnecessary slice() operations in API calls
- Use rich_text_section elements for better message formatting
- Change from rich_text back to section blocks with type: 'mrkdwn'
- Rich text blocks don't render markdown, but section blocks do
- Keep 12000 character chunk size and removed slice operations
- Maintain proper markdown formatting in Slack messages
- Change splitMessageByNewlines default parameter from 12000 to 3000
- Update comment and function call to match 3000 char limit
- Keep section blocks with markdown rendering support
@tmokmss tmokmss merged commit 9dc860e into aws-samples:main Dec 13, 2025
8 checks passed
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