mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 12:44:59 +00:00
fix: sanitize native command names for Telegram API (#19257)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: b608be3488
Co-authored-by: akramcodez <179671552+akramcodez@users.noreply.github.com>
Co-authored-by: obviyus <22031114+obviyus@users.noreply.github.com>
Reviewed-by: @obviyus
This commit is contained in:
@@ -149,6 +149,37 @@ describe("registerTelegramNativeCommands", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("normalizes hyphenated native command names for Telegram registration", async () => {
|
||||
const setMyCommands = vi.fn().mockResolvedValue(undefined);
|
||||
const command = vi.fn();
|
||||
|
||||
registerTelegramNativeCommands({
|
||||
...buildParams({}),
|
||||
bot: {
|
||||
api: {
|
||||
setMyCommands,
|
||||
sendMessage: vi.fn().mockResolvedValue(undefined),
|
||||
},
|
||||
command,
|
||||
} as unknown as Parameters<typeof registerTelegramNativeCommands>[0]["bot"],
|
||||
});
|
||||
|
||||
await vi.waitFor(() => {
|
||||
expect(setMyCommands).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
const registeredCommands = setMyCommands.mock.calls[0]?.[0] as Array<{
|
||||
command: string;
|
||||
description: string;
|
||||
}>;
|
||||
expect(registeredCommands.some((entry) => entry.command === "export_session")).toBe(true);
|
||||
expect(registeredCommands.some((entry) => entry.command === "export-session")).toBe(false);
|
||||
|
||||
const registeredHandlers = command.mock.calls.map(([name]) => name);
|
||||
expect(registeredHandlers).toContain("export_session");
|
||||
expect(registeredHandlers).not.toContain("export-session");
|
||||
});
|
||||
|
||||
it("passes agent-scoped media roots for plugin command replies with media", async () => {
|
||||
const commandHandlers = new Map<string, (ctx: unknown) => Promise<void>>();
|
||||
const sendMessage = vi.fn().mockResolvedValue(undefined);
|
||||
|
||||
Reference in New Issue
Block a user