* 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
137 lines
4.5 KiB
TypeScript
137 lines
4.5 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const ensureConfiguredAcpBindingSessionMock = vi.hoisted(() => vi.fn());
|
|
const resolveConfiguredAcpBindingRecordMock = vi.hoisted(() => vi.fn());
|
|
|
|
vi.mock("../../../src/acp/persistent-bindings.js", () => ({
|
|
ensureConfiguredAcpBindingSession: (...args: unknown[]) =>
|
|
ensureConfiguredAcpBindingSessionMock(...args),
|
|
resolveConfiguredAcpBindingRecord: (...args: unknown[]) =>
|
|
resolveConfiguredAcpBindingRecordMock(...args),
|
|
}));
|
|
|
|
import { buildTelegramMessageContextForTest } from "./bot-message-context.test-harness.js";
|
|
|
|
function createConfiguredTelegramBinding() {
|
|
return {
|
|
spec: {
|
|
channel: "telegram",
|
|
accountId: "work",
|
|
conversationId: "-1001234567890:topic:42",
|
|
parentConversationId: "-1001234567890",
|
|
agentId: "codex",
|
|
mode: "persistent",
|
|
},
|
|
record: {
|
|
bindingId: "config:acp:telegram:work:-1001234567890:topic:42",
|
|
targetSessionKey: "agent:codex:acp:binding:telegram:work:abc123",
|
|
targetKind: "session",
|
|
conversation: {
|
|
channel: "telegram",
|
|
accountId: "work",
|
|
conversationId: "-1001234567890:topic:42",
|
|
parentConversationId: "-1001234567890",
|
|
},
|
|
status: "active",
|
|
boundAt: 0,
|
|
metadata: {
|
|
source: "config",
|
|
mode: "persistent",
|
|
agentId: "codex",
|
|
},
|
|
},
|
|
} as const;
|
|
}
|
|
|
|
describe("buildTelegramMessageContext ACP configured bindings", () => {
|
|
beforeEach(() => {
|
|
ensureConfiguredAcpBindingSessionMock.mockReset();
|
|
resolveConfiguredAcpBindingRecordMock.mockReset();
|
|
resolveConfiguredAcpBindingRecordMock.mockReturnValue(createConfiguredTelegramBinding());
|
|
ensureConfiguredAcpBindingSessionMock.mockResolvedValue({
|
|
ok: true,
|
|
sessionKey: "agent:codex:acp:binding:telegram:work:abc123",
|
|
});
|
|
});
|
|
|
|
it("treats configured topic bindings as explicit route matches on non-default accounts", async () => {
|
|
const ctx = await buildTelegramMessageContextForTest({
|
|
accountId: "work",
|
|
message: {
|
|
chat: { id: -1001234567890, type: "supergroup", title: "OpenClaw", is_forum: true },
|
|
message_thread_id: 42,
|
|
text: "hello",
|
|
},
|
|
});
|
|
|
|
expect(ctx).not.toBeNull();
|
|
expect(ctx?.route.accountId).toBe("work");
|
|
expect(ctx?.route.matchedBy).toBe("binding.channel");
|
|
expect(ctx?.route.sessionKey).toBe("agent:codex:acp:binding:telegram:work:abc123");
|
|
expect(ensureConfiguredAcpBindingSessionMock).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("skips ACP session initialization when topic access is denied", async () => {
|
|
const ctx = await buildTelegramMessageContextForTest({
|
|
accountId: "work",
|
|
message: {
|
|
chat: { id: -1001234567890, type: "supergroup", title: "OpenClaw", is_forum: true },
|
|
message_thread_id: 42,
|
|
text: "hello",
|
|
},
|
|
resolveTelegramGroupConfig: () => ({
|
|
groupConfig: { requireMention: false },
|
|
topicConfig: { enabled: false },
|
|
}),
|
|
});
|
|
|
|
expect(ctx).toBeNull();
|
|
expect(resolveConfiguredAcpBindingRecordMock).toHaveBeenCalledTimes(1);
|
|
expect(ensureConfiguredAcpBindingSessionMock).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("defers ACP session initialization for unauthorized control commands", async () => {
|
|
const ctx = await buildTelegramMessageContextForTest({
|
|
accountId: "work",
|
|
message: {
|
|
chat: { id: -1001234567890, type: "supergroup", title: "OpenClaw", is_forum: true },
|
|
message_thread_id: 42,
|
|
text: "/new",
|
|
},
|
|
cfg: {
|
|
channels: {
|
|
telegram: {},
|
|
},
|
|
commands: {
|
|
useAccessGroups: true,
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(ctx).toBeNull();
|
|
expect(resolveConfiguredAcpBindingRecordMock).toHaveBeenCalledTimes(1);
|
|
expect(ensureConfiguredAcpBindingSessionMock).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("drops inbound processing when configured ACP binding initialization fails", async () => {
|
|
ensureConfiguredAcpBindingSessionMock.mockResolvedValue({
|
|
ok: false,
|
|
sessionKey: "agent:codex:acp:binding:telegram:work:abc123",
|
|
error: "gateway unavailable",
|
|
});
|
|
|
|
const ctx = await buildTelegramMessageContextForTest({
|
|
accountId: "work",
|
|
message: {
|
|
chat: { id: -1001234567890, type: "supergroup", title: "OpenClaw", is_forum: true },
|
|
message_thread_id: 42,
|
|
text: "hello",
|
|
},
|
|
});
|
|
|
|
expect(ctx).toBeNull();
|
|
expect(resolveConfiguredAcpBindingRecordMock).toHaveBeenCalledTimes(1);
|
|
expect(ensureConfiguredAcpBindingSessionMock).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|