fix(telegram): land #38906 from @gambletan

Landed from contributor PR #38906 by @gambletan.

Co-authored-by: gambletan <ethanchang32@gmail.com>
This commit is contained in:
Peter Steinberger
2026-03-08 00:54:49 +00:00
parent 4869e24915
commit a505be78ab
3 changed files with 11 additions and 5 deletions

View File

@@ -321,6 +321,7 @@ Docs: https://docs.openclaw.ai
- Exec approvals/allow-always shell scripts: persist and match script paths for wrapper invocations like `bash scripts/foo.sh` while still blocking `-c`/`-s` wrapper bypasses. Landed from contributor PR #35137 by @yuweuii. Thanks @yuweuii. - Exec approvals/allow-always shell scripts: persist and match script paths for wrapper invocations like `bash scripts/foo.sh` while still blocking `-c`/`-s` wrapper bypasses. Landed from contributor PR #35137 by @yuweuii. Thanks @yuweuii.
- Queue/followup dedupe across drain restarts: dedupe queued redelivery `message_id` values after queue recreation so busy-session followups no longer duplicate on replayed inbound events. Landed from contributor PR #33168 by @rylena. Thanks @rylena. - Queue/followup dedupe across drain restarts: dedupe queued redelivery `message_id` values after queue recreation so busy-session followups no longer duplicate on replayed inbound events. Landed from contributor PR #33168 by @rylena. Thanks @rylena.
- Telegram/preview-final edit idempotence: treat `message is not modified` errors during preview finalization as delivered so partial-stream final replies do not fall back to duplicate sends. Landed from contributor PR #34983 by @HOYALIM. Thanks @HOYALIM. - Telegram/preview-final edit idempotence: treat `message is not modified` errors during preview finalization as delivered so partial-stream final replies do not fall back to duplicate sends. Landed from contributor PR #34983 by @HOYALIM. Thanks @HOYALIM.
- Telegram/DM streaming transport parity: use message preview transport for all DM streaming lanes so final delivery can edit the active preview instead of sending duplicate finals. Landed from contributor PR #38906 by @gambletan. Thanks @gambletan.
## 2026.3.2 ## 2026.3.2

View File

@@ -1171,7 +1171,7 @@ describe("dispatchTelegramMessage draft streaming", () => {
}, },
); );
it("uses message preview transport for DM reasoning lane when answer preview lane is active", async () => { it("uses message preview transport for all DM lanes when streaming is active", async () => {
setupDraftStreams({ answerMessageId: 999, reasoningMessageId: 111 }); setupDraftStreams({ answerMessageId: 999, reasoningMessageId: 111 });
dispatchReplyWithBufferedBlockDispatcher.mockImplementation( dispatchReplyWithBufferedBlockDispatcher.mockImplementation(
async ({ dispatcherOptions, replyOptions }) => { async ({ dispatcherOptions, replyOptions }) => {
@@ -1187,10 +1187,12 @@ describe("dispatchTelegramMessage draft streaming", () => {
await dispatchWithContext({ context: createReasoningStreamContext(), streamMode: "partial" }); await dispatchWithContext({ context: createReasoningStreamContext(), streamMode: "partial" });
expect(createTelegramDraftStream).toHaveBeenCalledTimes(2); expect(createTelegramDraftStream).toHaveBeenCalledTimes(2);
// Both answer (call[0]) and reasoning (call[1]) lanes should use message
// transport in DMs to prevent duplicate messages. (Fixes #33453)
expect(createTelegramDraftStream.mock.calls[0]?.[0]).toEqual( expect(createTelegramDraftStream.mock.calls[0]?.[0]).toEqual(
expect.objectContaining({ expect.objectContaining({
thread: { id: 777, scope: "dm" }, thread: { id: 777, scope: "dm" },
previewTransport: "auto", previewTransport: "message",
}), }),
); );
expect(createTelegramDraftStream.mock.calls[1]?.[0]).toEqual( expect(createTelegramDraftStream.mock.calls[1]?.[0]).toEqual(

View File

@@ -194,15 +194,18 @@ export const dispatchTelegramMessage = async ({
const archivedAnswerPreviews: ArchivedPreview[] = []; const archivedAnswerPreviews: ArchivedPreview[] = [];
const archivedReasoningPreviewIds: number[] = []; const archivedReasoningPreviewIds: number[] = [];
const createDraftLane = (laneName: LaneName, enabled: boolean): DraftLaneState => { const createDraftLane = (laneName: LaneName, enabled: boolean): DraftLaneState => {
const useMessagePreviewTransportForDmReasoning = // Use message transport (sendMessage + editMessageText) for all lanes in
laneName === "reasoning" && threadSpec?.scope === "dm" && canStreamAnswerDraft; // DMs so that streamMessageId is tracked. Draft transport doesn't track a
// messageId, causing resolvePreviewTarget() to miss the preview on final
// delivery — which sends a duplicate message. (Fixes #33453)
const useMessagePreviewTransportForDm = threadSpec?.scope === "dm" && canStreamAnswerDraft;
const stream = enabled const stream = enabled
? createTelegramDraftStream({ ? createTelegramDraftStream({
api: bot.api, api: bot.api,
chatId, chatId,
maxChars: draftMaxChars, maxChars: draftMaxChars,
thread: threadSpec, thread: threadSpec,
previewTransport: useMessagePreviewTransportForDmReasoning ? "message" : "auto", previewTransport: useMessagePreviewTransportForDm ? "message" : "auto",
replyToMessageId: draftReplyToMessageId, replyToMessageId: draftReplyToMessageId,
minInitialChars: draftMinInitialChars, minInitialChars: draftMinInitialChars,
renderText: renderDraftPreview, renderText: renderDraftPreview,