Files
openclaw/extensions/telegram/src/bot-message-context.thread-binding.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

117 lines
3.8 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
const hoisted = vi.hoisted(() => {
const resolveByConversationMock = vi.fn();
const touchMock = vi.fn();
return {
resolveByConversationMock,
touchMock,
};
});
vi.mock("../../../src/infra/outbound/session-binding-service.js", async (importOriginal) => {
const actual =
await importOriginal<typeof import("../../../src/infra/outbound/session-binding-service.js")>();
return {
...actual,
getSessionBindingService: () => ({
bind: vi.fn(),
getCapabilities: vi.fn(),
listBySession: vi.fn(),
resolveByConversation: (ref: unknown) => hoisted.resolveByConversationMock(ref),
touch: (bindingId: string, at?: number) => hoisted.touchMock(bindingId, at),
unbind: vi.fn(),
}),
};
});
const { buildTelegramMessageContextForTest } =
await import("./bot-message-context.test-harness.js");
describe("buildTelegramMessageContext bound conversation override", () => {
beforeEach(() => {
hoisted.resolveByConversationMock.mockReset().mockReturnValue(null);
hoisted.touchMock.mockReset();
});
it("routes forum topic messages to the bound session", async () => {
hoisted.resolveByConversationMock.mockReturnValue({
bindingId: "default:-100200300:topic:77",
targetSessionKey: "agent:codex-acp:session-1",
});
const ctx = await buildTelegramMessageContextForTest({
message: {
message_id: 1,
chat: { id: -100200300, type: "supergroup", is_forum: true },
message_thread_id: 77,
date: 1_700_000_000,
text: "hello",
from: { id: 42, first_name: "Alice" },
},
options: { forceWasMentioned: true },
resolveGroupActivation: () => true,
});
expect(hoisted.resolveByConversationMock).toHaveBeenCalledWith({
channel: "telegram",
accountId: "default",
conversationId: "-100200300:topic:77",
});
expect(ctx?.ctxPayload?.SessionKey).toBe("agent:codex-acp:session-1");
expect(hoisted.touchMock).toHaveBeenCalledWith("default:-100200300:topic:77", undefined);
});
it("treats named-account bound conversations as explicit route matches", async () => {
hoisted.resolveByConversationMock.mockReturnValue({
bindingId: "work:-100200300:topic:77",
targetSessionKey: "agent:codex-acp:session-2",
});
const ctx = await buildTelegramMessageContextForTest({
accountId: "work",
message: {
message_id: 1,
chat: { id: -100200300, type: "supergroup", is_forum: true },
message_thread_id: 77,
date: 1_700_000_000,
text: "hello",
from: { id: 42, first_name: "Alice" },
},
options: { forceWasMentioned: true },
resolveGroupActivation: () => true,
});
expect(ctx).not.toBeNull();
expect(ctx?.route.accountId).toBe("work");
expect(ctx?.route.matchedBy).toBe("binding.channel");
expect(ctx?.ctxPayload?.SessionKey).toBe("agent:codex-acp:session-2");
expect(hoisted.touchMock).toHaveBeenCalledWith("work:-100200300:topic:77", undefined);
});
it("routes dm messages to the bound session", async () => {
hoisted.resolveByConversationMock.mockReturnValue({
bindingId: "default:1234",
targetSessionKey: "agent:codex-acp:session-dm",
});
const ctx = await buildTelegramMessageContextForTest({
message: {
message_id: 1,
chat: { id: 1234, type: "private" },
date: 1_700_000_000,
text: "hello",
from: { id: 42, first_name: "Alice" },
},
});
expect(hoisted.resolveByConversationMock).toHaveBeenCalledWith({
channel: "telegram",
accountId: "default",
conversationId: "1234",
});
expect(ctx?.ctxPayload?.SessionKey).toBe("agent:codex-acp:session-dm");
expect(hoisted.touchMock).toHaveBeenCalledWith("default:1234", undefined);
});
});