Skip to content

Commit 3a8580d

Browse files
author
R2
committed
Preserve Telegram hooks when flushing buffered finals
1 parent 8c2a390 commit 3a8580d

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

extensions/telegram/src/bot-message-dispatch.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,43 @@ describe("dispatchTelegramMessage draft streaming", () => {
965965
});
966966
});
967967

968+
it("emits hooks when flushing a buffered final answer after skipped reasoning", async () => {
969+
const { answerDraftStream } = setupDraftStreams({ answerMessageId: 2001 });
970+
const context = createContext();
971+
context.ctxPayload.SessionKey = "agent:default:telegram:direct:123";
972+
loadSessionStore.mockReturnValue({
973+
"agent:default:telegram:direct:123": { sessionId: "s1" },
974+
});
975+
deliverInboundReplyWithMessageSendContext.mockResolvedValueOnce({
976+
status: "handled_no_send",
977+
});
978+
dispatchReplyWithBufferedBlockDispatcher.mockImplementation(async ({ dispatcherOptions }) => {
979+
await dispatcherOptions.deliver(
980+
{ text: "<think>Hidden reasoning</think>Visible answer" },
981+
{ kind: "final" },
982+
);
983+
return { queuedFinal: true };
984+
});
985+
986+
await dispatchWithContext({ context });
987+
988+
expect(answerDraftStream.update).toHaveBeenCalledWith("Visible answer");
989+
expect(answerDraftStream.stop).toHaveBeenCalled();
990+
expectRecordFields(mockCallArg(emitInternalMessageSentHook), {
991+
content: "Visible answer",
992+
messageId: 2001,
993+
});
994+
const transcriptCall = expectRecordFields(mockCallArg(appendSessionTranscriptMessage), {
995+
transcriptPath: "/tmp/session.jsonl",
996+
});
997+
expectRecordFields(transcriptCall.message, {
998+
role: "assistant",
999+
provider: "openclaw",
1000+
model: "delivery-mirror",
1001+
content: [{ type: "text", text: "Visible answer" }],
1002+
});
1003+
});
1004+
9681005
it("does not mirror non-final tool progress into the session transcript", async () => {
9691006
const context = createContext();
9701007
context.ctxPayload.SessionKey = "agent:default:telegram:direct:123";

extensions/telegram/src/bot-message-dispatch.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1318,11 +1318,12 @@ export const dispatchTelegramMessage = async ({
13181318
return;
13191319
}
13201320
const bufferedButtons = resolvePayloadTelegramInlineButtons(buffered.payload);
1321-
await deliverFinalAnswerText(
1321+
const result = await deliverFinalAnswerText(
13221322
buffered.payload,
13231323
buffered.text,
13241324
bufferedButtons,
13251325
);
1326+
emitPreviewFinalizedHook(result);
13261327
reasoningStepState.resetForNextStep();
13271328
};
13281329

@@ -1384,6 +1385,9 @@ export const dispatchTelegramMessage = async ({
13841385
};
13851386

13861387
if (segments.length > 0) {
1388+
if (info.kind === "final") {
1389+
await flushBufferedFinalAnswer();
1390+
}
13871391
trackBlockMedia(blockDelivered);
13881392
return;
13891393
}

0 commit comments

Comments
 (0)