Skip to content

Telegram replyToMode 'first' applies reply-to to all chunks instead of only the first #31039

@xdanger

Description

@xdanger

Bug Description

When replyToMode is set to "first", all text chunks within a single reply payload carry the reply_to_message_id, instead of only the first chunk.

Expected Behavior

In "first" mode, when a reply is split into multiple Telegram messages (chunks), only the first chunk should quote the original message. Subsequent chunks should send without reply_to_message_id.

Actual Behavior

All chunks in the same reply reference the triggering message, making every outbound message appear as a quote/reply in the Telegram UI.

Root Cause

In dist/reply-Deht_wOB.js (Telegram reply delivery), replyToMessageIdForPayload is computed outside the chunk loop as a constant, so every chunk inherits the same value:

// Line ~46838: computed once per reply payload
const replyToMessageIdForPayload = replyToId && (replyToMode === "all" || !hasReplied) ? replyToId : void 0;

// Lines ~46846-46860: all chunks use the same value
for (let i = 0; i < chunks.length; i += 1) {
    await sendTelegramText(bot, chatId, chunk.html, runtime, {
        replyToMessageId: replyToMessageIdForPayload,  // same for every chunk
        ...
    });
}

// hasReplied only updated AFTER the chunk loop
if (replyToMessageIdForPayload && !hasReplied && sentTextChunk) hasReplied = true;

Suggested Fix

Move hasReplied update into the chunk loop so that after the first chunk is sent, subsequent chunks no longer carry replyToMessageId:

for (let i = 0; i < chunks.length; i += 1) {
    const chunk = chunks[i];
    if (!chunk) continue;
    const chunkReplyTo = (replyToMode === "all" || !hasReplied) ? replyToMessageIdForPayload : void 0;
    await sendTelegramText(bot, chatId, chunk.html, runtime, {
        replyToMessageId: chunkReplyTo,
        ...
    });
    sentTextChunk = true;
    if (chunkReplyTo && !hasReplied) hasReplied = true;
}

The same pattern should be applied to the media follow-up text chunks loop (~line 46974) which has the same issue.

Reproduction

  1. Configure channels.telegram.replyToMode: "first" (or per-account)
  2. Send a message that triggers a long reply (>4096 chars, causing chunking)
  3. Observe: all chunks show as replies to the original message in Telegram UI
  4. Expected: only the first chunk quotes the original

Environment

  • OpenClaw: 2026.2.26
  • Node: v24.12.0
  • Channel: Telegram (DM, but also applies to groups)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions