fix: scope telegram skill commands per bot (#4360) (thanks @robhparker)
This commit is contained in:
@@ -73,6 +73,7 @@ Status: stable.
|
||||
|
||||
### Fixes
|
||||
- Telegram: avoid silent empty replies by tracking normalization skips before fallback. (#3796)
|
||||
- Telegram: scope native skill commands to bound agent per bot. (#4360) Thanks @robhparker.
|
||||
- Mentions: honor mentionPatterns even when explicit mentions are present. (#3303) Thanks @HirokiKobayashi-R.
|
||||
- Discord: restore username directory lookup in target resolution. (#3131) Thanks @bonald.
|
||||
- Agents: align MiniMax base URL test expectation with default provider config. (#3131) Thanks @bonald.
|
||||
|
||||
82
src/telegram/bot-native-commands.test.ts
Normal file
82
src/telegram/bot-native-commands.test.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import type { TelegramAccountConfig } from "../config/types.js";
|
||||
import type { RuntimeEnv } from "../runtime.js";
|
||||
import { registerTelegramNativeCommands } from "./bot-native-commands.js";
|
||||
|
||||
const { listSkillCommandsForAgents } = vi.hoisted(() => ({
|
||||
listSkillCommandsForAgents: vi.fn(() => []),
|
||||
}));
|
||||
|
||||
vi.mock("../auto-reply/skill-commands.js", () => ({
|
||||
listSkillCommandsForAgents,
|
||||
}));
|
||||
|
||||
describe("registerTelegramNativeCommands", () => {
|
||||
beforeEach(() => {
|
||||
listSkillCommandsForAgents.mockReset();
|
||||
});
|
||||
|
||||
const buildParams = (cfg: OpenClawConfig, accountId = "default") => ({
|
||||
bot: {
|
||||
api: {
|
||||
setMyCommands: vi.fn().mockResolvedValue(undefined),
|
||||
sendMessage: vi.fn().mockResolvedValue(undefined),
|
||||
},
|
||||
command: vi.fn(),
|
||||
} as unknown as Parameters<typeof registerTelegramNativeCommands>[0]["bot"],
|
||||
cfg,
|
||||
runtime: {} as RuntimeEnv,
|
||||
accountId,
|
||||
telegramCfg: {} as TelegramAccountConfig,
|
||||
allowFrom: [],
|
||||
groupAllowFrom: [],
|
||||
replyToMode: "off" as const,
|
||||
textLimit: 4096,
|
||||
useAccessGroups: false,
|
||||
nativeEnabled: true,
|
||||
nativeSkillsEnabled: true,
|
||||
nativeDisabledExplicit: false,
|
||||
resolveGroupPolicy: () => ({ allowlistEnabled: false, allowed: true }),
|
||||
resolveTelegramGroupConfig: () => ({
|
||||
groupConfig: undefined,
|
||||
topicConfig: undefined,
|
||||
}),
|
||||
shouldSkipUpdate: () => false,
|
||||
opts: { token: "token" },
|
||||
});
|
||||
|
||||
it("scopes skill commands when account binding exists", () => {
|
||||
const cfg: OpenClawConfig = {
|
||||
agents: {
|
||||
list: [{ id: "main", default: true }, { id: "butler" }],
|
||||
},
|
||||
bindings: [
|
||||
{
|
||||
agentId: "butler",
|
||||
match: { channel: "telegram", accountId: "bot-a" },
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
registerTelegramNativeCommands(buildParams(cfg, "bot-a"));
|
||||
|
||||
expect(listSkillCommandsForAgents).toHaveBeenCalledWith({
|
||||
cfg,
|
||||
agentIds: ["butler"],
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps skill commands unscoped without a matching binding", () => {
|
||||
const cfg: OpenClawConfig = {
|
||||
agents: {
|
||||
list: [{ id: "main", default: true }, { id: "butler" }],
|
||||
},
|
||||
};
|
||||
|
||||
registerTelegramNativeCommands(buildParams(cfg, "bot-a"));
|
||||
|
||||
expect(listSkillCommandsForAgents).toHaveBeenCalledWith({ cfg });
|
||||
});
|
||||
});
|
||||
@@ -257,11 +257,15 @@ export const registerTelegramNativeCommands = ({
|
||||
shouldSkipUpdate,
|
||||
opts,
|
||||
}: RegisterTelegramNativeCommandsParams) => {
|
||||
const boundRoute = resolveAgentRoute({ cfg, channel: "telegram", accountId });
|
||||
const boundAgentIds = boundRoute?.agentId ? [boundRoute.agentId] : undefined;
|
||||
const boundRoute =
|
||||
nativeEnabled && nativeSkillsEnabled
|
||||
? resolveAgentRoute({ cfg, channel: "telegram", accountId })
|
||||
: null;
|
||||
const boundAgentIds =
|
||||
boundRoute && boundRoute.matchedBy.startsWith("binding.") ? [boundRoute.agentId] : null;
|
||||
const skillCommands =
|
||||
nativeEnabled && nativeSkillsEnabled
|
||||
? listSkillCommandsForAgents({ cfg, agentIds: boundAgentIds })
|
||||
? listSkillCommandsForAgents(boundAgentIds ? { cfg, agentIds: boundAgentIds } : { cfg })
|
||||
: [];
|
||||
const nativeCommands = nativeEnabled
|
||||
? listNativeCommandSpecsForConfig(cfg, { skillCommands, provider: "telegram" })
|
||||
|
||||
Reference in New Issue
Block a user