diff --git a/extensions/googlechat/src/setup-surface.ts b/extensions/googlechat/src/setup-surface.ts index 0d54f53f537..6375844ca07 100644 --- a/extensions/googlechat/src/setup-surface.ts +++ b/extensions/googlechat/src/setup-surface.ts @@ -1,7 +1,7 @@ import { addWildcardAllowFrom, applySetupAccountConfigPatch, - createNestedChannelParsedAllowFromPrompt, + createPromptParsedAllowFromForAccount, createStandardChannelSetupStatus, DEFAULT_ACCOUNT_ID, formatDocsLink, @@ -25,16 +25,27 @@ const ENV_SERVICE_ACCOUNT_FILE = "GOOGLE_CHAT_SERVICE_ACCOUNT_FILE"; const USE_ENV_FLAG = "__googlechatUseEnv"; const AUTH_METHOD_FLAG = "__googlechatAuthMethod"; -const promptAllowFrom = createNestedChannelParsedAllowFromPrompt({ - channel, - section: "dm", - defaultAccountId: DEFAULT_ACCOUNT_ID, - enabled: true, +const promptAllowFrom = createPromptParsedAllowFromForAccount({ + defaultAccountId: resolveDefaultGoogleChatAccountId, message: "Google Chat allowFrom (users/ or raw email; avoid users/)", placeholder: "users/123456789, name@example.com", parseEntries: (raw) => ({ entries: mergeAllowFromEntries(undefined, splitSetupEntries(raw)), }), + getExistingAllowFrom: ({ cfg, accountId }) => + resolveGoogleChatAccount({ cfg, accountId }).config.dm?.allowFrom ?? [], + applyAllowFrom: ({ cfg, accountId, allowFrom }) => + applySetupAccountConfigPatch({ + cfg, + channelKey: channel, + accountId, + patch: { + dm: { + ...(resolveGoogleChatAccount({ cfg, accountId }).config.dm ?? {}), + allowFrom, + }, + }, + }), }); const googlechatDmPolicy: ChannelSetupDmPolicy = { diff --git a/extensions/googlechat/src/setup.test.ts b/extensions/googlechat/src/setup.test.ts index bbd65123bef..5d0a4c18d8b 100644 --- a/extensions/googlechat/src/setup.test.ts +++ b/extensions/googlechat/src/setup.test.ts @@ -249,6 +249,41 @@ describe("googlechat setup", () => { expect(next?.channels?.googlechat?.accounts?.alerts?.dm?.policy).toBe("open"); }); + it("uses configured defaultAccount for omitted allowFrom prompt context", async () => { + const prompter = { + note: vi.fn(async () => {}), + text: vi.fn(async () => "users/123456789"), + }; + + const next = await googlechatPlugin.setupWizard?.dmPolicy?.promptAllowFrom?.({ + cfg: { + channels: { + googlechat: { + defaultAccount: "alerts", + dm: { + allowFrom: ["users/root"], + }, + accounts: { + alerts: { + serviceAccount: { client_email: "bot@example.com" }, + dm: { + allowFrom: ["users/alerts"], + }, + }, + }, + }, + }, + } as OpenClawConfig, + // oxlint-disable-next-line typescript/no-explicit-any + prompter: prompter as any, + }); + + expect(next?.channels?.googlechat?.dm?.allowFrom).toEqual(["users/root"]); + expect(next?.channels?.googlechat?.accounts?.alerts?.dm?.allowFrom).toEqual([ + "users/123456789", + ]); + }); + it('writes open DM policy to the named account and preserves inherited allowFrom with "*"', () => { const next = googlechatPlugin.setupWizard?.dmPolicy?.setPolicy( { diff --git a/src/channels/plugins/setup-wizard-helpers.ts b/src/channels/plugins/setup-wizard-helpers.ts index a8846f93972..35d085170dd 100644 --- a/src/channels/plugins/setup-wizard-helpers.ts +++ b/src/channels/plugins/setup-wizard-helpers.ts @@ -1344,7 +1344,7 @@ export function createTopLevelChannelParsedAllowFromPrompt(params: { export function createNestedChannelParsedAllowFromPrompt(params: { channel: string; section: string; - defaultAccountId: string; + defaultAccountId: string | ((cfg: OpenClawConfig) => string); enabled?: boolean; noteTitle?: string; noteLines?: string[]; @@ -1360,7 +1360,10 @@ export function createNestedChannelParsedAllowFromPrompt(params: { ...(params.enabled ? { enabled: true } : {}), }); return createPromptParsedAllowFromForAccount({ - defaultAccountId: params.defaultAccountId, + defaultAccountId: + typeof params.defaultAccountId === "function" + ? params.defaultAccountId + : () => params.defaultAccountId, ...(params.noteTitle ? { noteTitle: params.noteTitle } : {}), ...(params.noteLines ? { noteLines: params.noteLines } : {}), message: params.message,