Files
openclaw/extensions/googlechat/src/setup-core.ts
Peter Steinberger f236e83de7 refactor(channels): shrink ChannelSetupInput to a generic envelope with a deprecated compatibility tier (#112319)
* refactor(channels)!: shrink ChannelSetupInput to a generic envelope with a deprecated compatibility tier

* fix(channels): keep ChannelSetupInput structurally assignable without an index signature

* docs: regenerate docs map
2026-07-21 22:17:03 -07:00

51 lines
1.6 KiB
TypeScript

// Googlechat plugin module implements setup core behavior.
import type { ChannelSetupInput } from "openclaw/plugin-sdk/channel-setup";
import {
createPatchedAccountSetupAdapter,
createSetupInputPresenceValidator,
} from "openclaw/plugin-sdk/setup-runtime";
const channel = "googlechat" as const;
type GoogleChatSetupInput = ChannelSetupInput & {
audienceType?: string;
audience?: string;
webhookPath?: string;
webhookUrl?: string;
};
export const googlechatSetupAdapter = createPatchedAccountSetupAdapter({
channelKey: channel,
validateInput: createSetupInputPresenceValidator({
defaultAccountOnlyEnvError:
"GOOGLE_CHAT_SERVICE_ACCOUNT env vars can only be used for the default account.",
whenNotUseEnv: [
{
someOf: ["token", "tokenFile"],
message: "Google Chat requires --token (service account JSON) or --token-file.",
},
],
}),
buildPatch: (input) => {
const setupInput = input as GoogleChatSetupInput;
const patch = setupInput.useEnv
? {}
: setupInput.tokenFile
? { serviceAccountFile: setupInput.tokenFile }
: setupInput.token
? { serviceAccount: setupInput.token }
: {};
const audienceType = setupInput.audienceType?.trim();
const audience = setupInput.audience?.trim();
const webhookPath = setupInput.webhookPath?.trim();
const webhookUrl = setupInput.webhookUrl?.trim();
return {
...patch,
...(audienceType ? { audienceType } : {}),
...(audience ? { audience } : {}),
...(webhookPath ? { webhookPath } : {}),
...(webhookUrl ? { webhookUrl } : {}),
};
},
});