diff --git a/src/telegram/bot-native-commands.test.ts b/src/telegram/bot-native-commands.test.ts index eea0937ad0e..0d9c30f9998 100644 --- a/src/telegram/bot-native-commands.test.ts +++ b/src/telegram/bot-native-commands.test.ts @@ -5,7 +5,10 @@ import { STATE_DIR } from "../config/paths.js"; import { TELEGRAM_COMMAND_NAME_PATTERN } from "../config/telegram-custom-commands.js"; import type { TelegramAccountConfig } from "../config/types.js"; import type { RuntimeEnv } from "../runtime.js"; -import { registerTelegramNativeCommands } from "./bot-native-commands.js"; +import { + buildTelegramNativeCommandCallbackData, + registerTelegramNativeCommands, +} from "./bot-native-commands.js"; import { createNativeCommandTestParams } from "./bot-native-commands.test-helpers.js"; const { listSkillCommandsForAgents } = vi.hoisted(() => ({ @@ -213,6 +216,55 @@ describe("registerTelegramNativeCommands", () => { expect(registeredCommands.some((entry) => entry.command === "custom-bad")).toBe(false); }); + it("prefixes native command menu callbacks so Telegram callback routing preserves native mode", async () => { + const commandHandlers = new Map Promise>(); + const sendMessage = vi.fn().mockResolvedValue(undefined); + + registerTelegramNativeCommands({ + ...buildParams({}), + bot: { + api: { + setMyCommands: vi.fn().mockResolvedValue(undefined), + sendMessage, + }, + command: vi.fn((name: string, handler: (ctx: unknown) => Promise) => { + commandHandlers.set(name, handler); + }), + } as unknown as Parameters[0]["bot"], + allowFrom: ["*"], + }); + + const fastHandler = commandHandlers.get("fast"); + expect(fastHandler).toBeDefined(); + + await fastHandler?.({ + message: { + chat: { id: 1234, type: "private" }, + date: 1736380800, + from: { id: 9, first_name: "Ada", username: "ada_bot" }, + message_id: 44, + }, + me: { username: "openclaw_bot" }, + match: "", + }); + + expect(sendMessage).toHaveBeenCalledTimes(1); + const [, , params] = sendMessage.mock.calls[0] ?? []; + expect(params).toEqual( + expect.objectContaining({ + reply_markup: expect.objectContaining({ + inline_keyboard: expect.arrayContaining([ + expect.arrayContaining([ + expect.objectContaining({ + callback_data: buildTelegramNativeCommandCallbackData("/fast status"), + }), + ]), + ]), + }), + }), + ); + }); + it("passes agent-scoped media roots for plugin command replies with media", async () => { const commandHandlers = new Map Promise>(); const sendMessage = vi.fn().mockResolvedValue(undefined);