From daa62d8d2d2baad1b9a16e48a79f644dd86d7fb3 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Fri, 13 Mar 2026 13:31:55 -0700 Subject: [PATCH] Telegram: test native command menu callback routing --- src/telegram/bot.create-telegram-bot.test.ts | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/telegram/bot.create-telegram-bot.test.ts b/src/telegram/bot.create-telegram-bot.test.ts index 378c1eb1065..c3284ae0634 100644 --- a/src/telegram/bot.create-telegram-bot.test.ts +++ b/src/telegram/bot.create-telegram-bot.test.ts @@ -143,6 +143,41 @@ describe("createTelegramBot", () => { expect(payload.Body).toContain("cmd:option_a"); expect(answerCallbackQuerySpy).toHaveBeenCalledWith("cbq-1"); }); + + it("preserves native command source for Telegram command-menu callbacks when text commands are disabled", async () => { + loadConfig.mockReturnValue({ + commands: { text: false }, + channels: { + telegram: { dmPolicy: "open", allowFrom: ["*"] }, + }, + }); + createTelegramBot({ token: "tok" }); + const callbackHandler = onSpy.mock.calls.find((call) => call[0] === "callback_query")?.[1] as ( + ctx: Record, + ) => Promise; + expect(callbackHandler).toBeDefined(); + + await callbackHandler({ + callbackQuery: { + id: "cbq-native-fast", + data: "tgcmd:/fast status", + from: { id: 9, first_name: "Ada", username: "ada_bot" }, + message: { + chat: { id: 1234, type: "private" }, + date: 1736380800, + message_id: 10, + }, + }, + me: { username: "openclaw_bot" }, + getFile: async () => ({ download: async () => new Uint8Array() }), + }); + + expect(replySpy).toHaveBeenCalledTimes(1); + const payload = replySpy.mock.calls[0][0]; + expect(payload.CommandBody).toBe("/fast status"); + expect(payload.CommandSource).toBe("native"); + expect(answerCallbackQuerySpy).toHaveBeenCalledWith("cbq-native-fast"); + }); it("wraps inbound message with Telegram envelope", async () => { await withEnvAsync({ TZ: "Europe/Vienna" }, async () => { createTelegramBot({ token: "tok" });