diff --git a/src/auto-reply/commands-registry.test.ts b/src/auto-reply/commands-registry.test.ts index 8860a02a7..8d9240cd3 100644 --- a/src/auto-reply/commands-registry.test.ts +++ b/src/auto-reply/commands-registry.test.ts @@ -20,6 +20,7 @@ describe("commands registry", () => { const specs = listNativeCommandSpecs(); expect(specs.find((spec) => spec.name === "help")).toBeTruthy(); expect(specs.find((spec) => spec.name === "stop")).toBeTruthy(); + expect(specs.find((spec) => spec.name === "whoami")).toBeTruthy(); expect(specs.find((spec) => spec.name === "compact")).toBeFalsy(); }); @@ -47,6 +48,8 @@ describe("commands registry", () => { const detection = getCommandDetection(); expect(detection.exact.has("/commands")).toBe(true); expect(detection.exact.has("/compact")).toBe(true); + expect(detection.exact.has("/whoami")).toBe(true); + expect(detection.exact.has("/id")).toBe(true); for (const command of listChatCommands()) { for (const alias of command.textAliases) { expect(detection.exact.has(alias.toLowerCase())).toBe(true); diff --git a/src/auto-reply/reply/commands.test.ts b/src/auto-reply/reply/commands.test.ts index d17e7f25c..624ebe829 100644 --- a/src/auto-reply/reply/commands.test.ts +++ b/src/auto-reply/reply/commands.test.ts @@ -5,7 +5,11 @@ import type { MsgContext } from "../templating.js"; import { buildCommandContext, handleCommands } from "./commands.js"; import { parseInlineDirectives } from "./directive-handling.js"; -function buildParams(commandBody: string, cfg: ClawdbotConfig) { +function buildParams( + commandBody: string, + cfg: ClawdbotConfig, + ctxOverrides?: Partial, +) { const ctx = { Body: commandBody, CommandBody: commandBody, @@ -13,6 +17,7 @@ function buildParams(commandBody: string, cfg: ClawdbotConfig) { CommandAuthorized: true, Provider: "whatsapp", Surface: "whatsapp", + ...ctxOverrides, } as MsgContext; const command = buildCommandContext({ @@ -64,3 +69,23 @@ describe("handleCommands gating", () => { expect(result.reply?.text).toContain("/debug is disabled"); }); }); + +describe("handleCommands identity", () => { + it("returns sender details for /whoami", async () => { + const cfg = { + commands: { text: true }, + whatsapp: { allowFrom: ["*"] }, + } as ClawdbotConfig; + const params = buildParams("/whoami", cfg, { + SenderId: "12345", + SenderUsername: "TestUser", + ChatType: "direct", + }); + const result = await handleCommands(params); + expect(result.shouldContinue).toBe(false); + expect(result.reply?.text).toContain("Provider: whatsapp"); + expect(result.reply?.text).toContain("User id: 12345"); + expect(result.reply?.text).toContain("Username: @TestUser"); + expect(result.reply?.text).toContain("AllowFrom: 12345"); + }); +});