From 35483b1a4a121c56ee795ad67ddf73a1ebc8eb94 Mon Sep 17 00:00:00 2001 From: Ayaan Zaidi Date: Mon, 11 May 2026 10:51:23 +0530 Subject: [PATCH] test(telegram): cover shared reply context path --- ...-message-context.dm-topic-threadid.test.ts | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/extensions/telegram/src/bot-message-context.dm-topic-threadid.test.ts b/extensions/telegram/src/bot-message-context.dm-topic-threadid.test.ts index 3d079be9076..59b46c6d34f 100644 --- a/extensions/telegram/src/bot-message-context.dm-topic-threadid.test.ts +++ b/extensions/telegram/src/bot-message-context.dm-topic-threadid.test.ts @@ -27,11 +27,13 @@ describe("buildTelegramMessageContext DM topic threadId in deliveryContext (#889 message: Record; options?: Record; resolveGroupActivation?: () => boolean | undefined; + sessionRuntime?: Parameters[0]["sessionRuntime"]; }) { return await buildTelegramMessageContextForTest({ message: params.message, options: params.options, resolveGroupActivation: params.resolveGroupActivation, + ...(params.sessionRuntime !== undefined ? { sessionRuntime: params.sessionRuntime } : {}), }); } @@ -75,6 +77,51 @@ describe("buildTelegramMessageContext DM topic threadId in deliveryContext (#889 expectRecordedRoute({ to: "telegram:1234", threadId: "42" }); }); + it("builds Telegram payloads through the shared channel turn context", async () => { + const { buildChannelTurnContext } = await import("openclaw/plugin-sdk/channel-inbound"); + const buildChannelTurnContextMock = vi.fn(buildChannelTurnContext); + + const ctx = await buildCtx({ + message: { + chat: { id: 1234, type: "private" }, + text: "hello", + reply_to_message: { + message_id: 9, + date: 1_700_000_001, + text: "parent", + from: { id: 99, first_name: "Bob" }, + }, + }, + sessionRuntime: { + buildChannelTurnContext: buildChannelTurnContextMock, + }, + }); + + expect(ctx?.ctxPayload.ReplyToBody).toBe("parent"); + expect(buildChannelTurnContextMock).toHaveBeenCalledOnce(); + expect(buildChannelTurnContextMock.mock.calls[0]?.[0]).toMatchObject({ + channel: "telegram", + from: "telegram:1234", + message: { + rawBody: "hello", + bodyForAgent: "hello", + }, + reply: { + to: "telegram:1234", + originatingTo: "telegram:1234", + replyToId: "9", + }, + supplemental: { + quote: { + id: "9", + body: "parent", + sender: "Bob", + senderAllowed: true, + }, + }, + }); + }); + it("does not pass threadId for regular DM without topic", async () => { const ctx = await buildCtx({ message: {