Files
openclaw/extensions/telegram/src/bot-message-context.dm-topic-threadid.test.ts
scoootscooob e5bca0832f refactor: move Telegram channel implementation to extensions/ (#45635)
* refactor: move Telegram channel implementation to extensions/telegram/src/

Move all Telegram channel code (123 files + 10 bot/ files + 8 channel plugin
files) from src/telegram/ and src/channels/plugins/*/telegram.ts to
extensions/telegram/src/. Leave thin re-export shims at original locations so
cross-cutting src/ imports continue to resolve.

- Fix all relative import paths in moved files (../X/ -> ../../../src/X/)
- Fix vi.mock paths in 60 test files
- Fix inline typeof import() expressions
- Update tsconfig.plugin-sdk.dts.json rootDir to "." for cross-directory DTS
- Update write-plugin-sdk-entry-dts.ts for new rootDir structure
- Move channel plugin files with correct path remapping

* fix: support keyed telegram send deps

* fix: sync telegram extension copies with latest main

* fix: correct import paths and remove misplaced files in telegram extension

* fix: sync outbound-adapter with main (add sendTelegramPayloadMessages) and fix delivery.test import path
2026-03-14 02:50:17 -07:00

85 lines
2.9 KiB
TypeScript

import { describe, expect, it, vi, beforeEach } from "vitest";
import { buildTelegramMessageContextForTest } from "./bot-message-context.test-harness.js";
// Mock recordInboundSession to capture updateLastRoute parameter
const recordInboundSessionMock = vi.fn().mockResolvedValue(undefined);
vi.mock("../../../src/channels/session.js", () => ({
recordInboundSession: (...args: unknown[]) => recordInboundSessionMock(...args),
}));
describe("buildTelegramMessageContext DM topic threadId in deliveryContext (#8891)", () => {
async function buildCtx(params: {
message: Record<string, unknown>;
options?: Record<string, unknown>;
resolveGroupActivation?: () => boolean | undefined;
}) {
return await buildTelegramMessageContextForTest({
message: params.message,
options: params.options,
resolveGroupActivation: params.resolveGroupActivation,
});
}
function getUpdateLastRoute(): unknown {
const callArgs = recordInboundSessionMock.mock.calls[0]?.[0] as { updateLastRoute?: unknown };
return callArgs?.updateLastRoute;
}
beforeEach(() => {
recordInboundSessionMock.mockClear();
});
it("passes threadId to updateLastRoute for DM topics", async () => {
const ctx = await buildCtx({
message: {
chat: { id: 1234, type: "private" },
message_thread_id: 42, // DM Topic ID
},
});
expect(ctx).not.toBeNull();
expect(recordInboundSessionMock).toHaveBeenCalled();
// Check that updateLastRoute includes threadId
const updateLastRoute = getUpdateLastRoute() as { threadId?: string; to?: string } | undefined;
expect(updateLastRoute).toBeDefined();
expect(updateLastRoute?.to).toBe("telegram:1234");
expect(updateLastRoute?.threadId).toBe("42");
});
it("does not pass threadId for regular DM without topic", async () => {
const ctx = await buildCtx({
message: {
chat: { id: 1234, type: "private" },
},
});
expect(ctx).not.toBeNull();
expect(recordInboundSessionMock).toHaveBeenCalled();
// Check that updateLastRoute does NOT include threadId
const updateLastRoute = getUpdateLastRoute() as { threadId?: string; to?: string } | undefined;
expect(updateLastRoute).toBeDefined();
expect(updateLastRoute?.to).toBe("telegram:1234");
expect(updateLastRoute?.threadId).toBeUndefined();
});
it("does not set updateLastRoute for group messages", async () => {
const ctx = await buildCtx({
message: {
chat: { id: -1001234567890, type: "supergroup", title: "Test Group" },
text: "@bot hello",
message_thread_id: 99,
},
options: { forceWasMentioned: true },
resolveGroupActivation: () => true,
});
expect(ctx).not.toBeNull();
expect(recordInboundSessionMock).toHaveBeenCalled();
// Check that updateLastRoute is undefined for groups
expect(getUpdateLastRoute()).toBeUndefined();
});
});