Skip to content

Telegram message splitting breaks mid-word #36644

@CobbFu

Description

@CobbFu

Bug

Long Telegram messages are split at exact character boundaries instead of word/sentence boundaries, producing broken fragments like:

...Regulatory overhang lifts b
e
ta for UK banks

("beta" split into three separate messages)

Root Cause

splitMarkdownIRPreserveWhitespace in send-qsA2ijse.js (lines 1043-1058) uses naive text.slice(cursor, cursor + limit) — it cuts at the exact character position without looking back for the nearest whitespace.

// Current (buggy):
const end = Math.min(ir.text.length, cursor + normalizedLimit);
chunks.push({ text: ir.text.slice(cursor, end), ... });

Despite the function name suggesting it preserves whitespace, it only preserves style/link metadata across splits — not word boundaries.

Suggested Fix

Find the last whitespace before the limit and split there:

let end = Math.min(ir.text.length, cursor + normalizedLimit);
if (end < ir.text.length) {
  const lastSpace = ir.text.lastIndexOf(' ', end);
  if (lastSpace > cursor) end = lastSpace;
}

Environment

  • OpenClaw version: 2026.3.2
  • Platform: macOS (Homebrew install)
  • Telegram bot API

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions