mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-18 13:30:48 +00:00
* 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
93 lines
3.4 KiB
TypeScript
93 lines
3.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import type { OpenClawConfig } from "../../../src/config/config.js";
|
|
import {
|
|
isTelegramExecApprovalApprover,
|
|
isTelegramExecApprovalClientEnabled,
|
|
resolveTelegramExecApprovalTarget,
|
|
shouldEnableTelegramExecApprovalButtons,
|
|
shouldInjectTelegramExecApprovalButtons,
|
|
} from "./exec-approvals.js";
|
|
|
|
function buildConfig(
|
|
execApprovals?: NonNullable<NonNullable<OpenClawConfig["channels"]>["telegram"]>["execApprovals"],
|
|
): OpenClawConfig {
|
|
return {
|
|
channels: {
|
|
telegram: {
|
|
botToken: "tok",
|
|
execApprovals,
|
|
},
|
|
},
|
|
} as OpenClawConfig;
|
|
}
|
|
|
|
describe("telegram exec approvals", () => {
|
|
it("requires enablement and at least one approver", () => {
|
|
expect(isTelegramExecApprovalClientEnabled({ cfg: buildConfig() })).toBe(false);
|
|
expect(
|
|
isTelegramExecApprovalClientEnabled({
|
|
cfg: buildConfig({ enabled: true }),
|
|
}),
|
|
).toBe(false);
|
|
expect(
|
|
isTelegramExecApprovalClientEnabled({
|
|
cfg: buildConfig({ enabled: true, approvers: ["123"] }),
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("matches approvers by normalized sender id", () => {
|
|
const cfg = buildConfig({ enabled: true, approvers: [123, "456"] });
|
|
expect(isTelegramExecApprovalApprover({ cfg, senderId: "123" })).toBe(true);
|
|
expect(isTelegramExecApprovalApprover({ cfg, senderId: "456" })).toBe(true);
|
|
expect(isTelegramExecApprovalApprover({ cfg, senderId: "789" })).toBe(false);
|
|
});
|
|
|
|
it("defaults target to dm", () => {
|
|
expect(
|
|
resolveTelegramExecApprovalTarget({ cfg: buildConfig({ enabled: true, approvers: ["1"] }) }),
|
|
).toBe("dm");
|
|
});
|
|
|
|
it("only injects approval buttons on eligible telegram targets", () => {
|
|
const dmCfg = buildConfig({ enabled: true, approvers: ["123"], target: "dm" });
|
|
const channelCfg = buildConfig({ enabled: true, approvers: ["123"], target: "channel" });
|
|
const bothCfg = buildConfig({ enabled: true, approvers: ["123"], target: "both" });
|
|
|
|
expect(shouldInjectTelegramExecApprovalButtons({ cfg: dmCfg, to: "123" })).toBe(true);
|
|
expect(shouldInjectTelegramExecApprovalButtons({ cfg: dmCfg, to: "-100123" })).toBe(false);
|
|
expect(shouldInjectTelegramExecApprovalButtons({ cfg: channelCfg, to: "-100123" })).toBe(true);
|
|
expect(shouldInjectTelegramExecApprovalButtons({ cfg: channelCfg, to: "123" })).toBe(false);
|
|
expect(shouldInjectTelegramExecApprovalButtons({ cfg: bothCfg, to: "123" })).toBe(true);
|
|
expect(shouldInjectTelegramExecApprovalButtons({ cfg: bothCfg, to: "-100123" })).toBe(true);
|
|
});
|
|
|
|
it("does not require generic inlineButtons capability to enable exec approval buttons", () => {
|
|
const cfg = {
|
|
channels: {
|
|
telegram: {
|
|
botToken: "tok",
|
|
capabilities: ["vision"],
|
|
execApprovals: { enabled: true, approvers: ["123"], target: "dm" },
|
|
},
|
|
},
|
|
} as OpenClawConfig;
|
|
|
|
expect(shouldEnableTelegramExecApprovalButtons({ cfg, to: "123" })).toBe(true);
|
|
});
|
|
|
|
it("still respects explicit inlineButtons off for exec approval buttons", () => {
|
|
const cfg = {
|
|
channels: {
|
|
telegram: {
|
|
botToken: "tok",
|
|
capabilities: { inlineButtons: "off" },
|
|
execApprovals: { enabled: true, approvers: ["123"], target: "dm" },
|
|
},
|
|
},
|
|
} as OpenClawConfig;
|
|
|
|
expect(shouldEnableTelegramExecApprovalButtons({ cfg, to: "123" })).toBe(false);
|
|
});
|
|
});
|