mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-25 11:55:47 -06:00
99d662473c
* fix(channels): validate headless channel setup * docs(channels): document headless provisioning * fix(channels): repair setup metadata typing * chore(channels): regenerate official channel catalog for env metadata * fix(slack): keep mode-conditional env contract plugin-owned Static --use-env declaration keeps only the unconditional SLACK_BOT_TOKEN; socket-vs-HTTP conditional requirements (app token, signing secret) stay in Slack's own setup validation so HTTP mode no longer demands an irrelevant SLACK_APP_TOKEN. * chore(sdk): regenerate api baselines and catalog after rebase * fix(slack): align manifest env declaration with runtime contract * chore(sdk): regenerate api baselines after rebase * chore(sdk): regenerate api baselines after rebase * chore(sdk): regenerate api baselines after rebase
142 lines
4.5 KiB
TypeScript
142 lines
4.5 KiB
TypeScript
// Mattermost plugin module implements setup core behavior.
|
|
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id";
|
|
import {
|
|
defineChannelSetupContract,
|
|
type ChannelSetupAdapter,
|
|
type ChannelSetupInput,
|
|
} from "openclaw/plugin-sdk/channel-setup";
|
|
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
|
|
import {
|
|
applyAccountNameToChannelSection,
|
|
applySetupAccountConfigPatch,
|
|
migrateBaseNameToDefaultAccount,
|
|
} from "openclaw/plugin-sdk/setup";
|
|
import { createSetupInputPresenceValidator } from "openclaw/plugin-sdk/setup-runtime";
|
|
import {
|
|
inspectMattermostAccount,
|
|
type ResolvedMattermostAccount,
|
|
} from "./setup.accounts.runtime.js";
|
|
import { normalizeMattermostBaseUrl } from "./setup.client.runtime.js";
|
|
import { hasConfiguredSecretInput } from "./setup.secret-input.runtime.js";
|
|
|
|
const channel = "mattermost" as const;
|
|
|
|
type MattermostSetupInput = ChannelSetupInput & {
|
|
botToken?: string;
|
|
httpUrl?: string;
|
|
};
|
|
|
|
export function isMattermostConfigured(account: ResolvedMattermostAccount): boolean {
|
|
const tokenConfigured =
|
|
Boolean(account.botToken?.trim()) || hasConfiguredSecretInput(account.config.botToken);
|
|
return tokenConfigured && Boolean(account.baseUrl);
|
|
}
|
|
|
|
export function resolveMattermostAccountWithSecrets(cfg: OpenClawConfig, accountId: string) {
|
|
return inspectMattermostAccount({ cfg, accountId });
|
|
}
|
|
|
|
export function applyMattermostSetupConfigPatch(params: {
|
|
cfg: OpenClawConfig;
|
|
accountId: string;
|
|
name?: string;
|
|
patch: Record<string, unknown>;
|
|
}): OpenClawConfig {
|
|
const namedConfig = applyAccountNameToChannelSection({
|
|
cfg: params.cfg,
|
|
channelKey: channel,
|
|
accountId: params.accountId,
|
|
name: params.name,
|
|
});
|
|
const next =
|
|
params.accountId !== DEFAULT_ACCOUNT_ID
|
|
? migrateBaseNameToDefaultAccount({
|
|
cfg: namedConfig,
|
|
channelKey: channel,
|
|
})
|
|
: namedConfig;
|
|
return applySetupAccountConfigPatch({
|
|
cfg: next,
|
|
channelKey: channel,
|
|
accountId: params.accountId,
|
|
patch: params.patch,
|
|
});
|
|
}
|
|
|
|
export const mattermostSetupAdapter: ChannelSetupAdapter = {
|
|
resolveAccountId: ({ accountId }) => normalizeAccountId(accountId),
|
|
applyAccountName: ({ cfg, accountId, name }) =>
|
|
applyAccountNameToChannelSection({
|
|
cfg,
|
|
channelKey: channel,
|
|
accountId,
|
|
name,
|
|
}),
|
|
validateInput: createSetupInputPresenceValidator({
|
|
defaultAccountOnlyEnvError: "Mattermost env vars can only be used for the default account.",
|
|
whenNotUseEnv: [
|
|
{
|
|
someOf: ["botToken", "token"],
|
|
message: "Mattermost requires --bot-token and --http-url (or --use-env).",
|
|
},
|
|
{
|
|
someOf: ["httpUrl"],
|
|
message: "Mattermost requires --bot-token and --http-url (or --use-env).",
|
|
},
|
|
],
|
|
validate: ({ input }) => {
|
|
const setupInput = input as MattermostSetupInput;
|
|
const token = setupInput.botToken ?? setupInput.token;
|
|
const baseUrl = normalizeMattermostBaseUrl(setupInput.httpUrl);
|
|
if (!setupInput.useEnv && (!token || !baseUrl)) {
|
|
return "Mattermost requires --bot-token and --http-url (or --use-env).";
|
|
}
|
|
if (setupInput.httpUrl && !baseUrl) {
|
|
return "Mattermost --http-url must include a valid base URL.";
|
|
}
|
|
return null;
|
|
},
|
|
}),
|
|
applyAccountConfig: ({ cfg, accountId, input }) => {
|
|
const setupInput = input as MattermostSetupInput;
|
|
const token = setupInput.botToken ?? setupInput.token;
|
|
const baseUrl = normalizeMattermostBaseUrl(setupInput.httpUrl);
|
|
return applyMattermostSetupConfigPatch({
|
|
cfg,
|
|
accountId,
|
|
name: setupInput.name,
|
|
patch: setupInput.useEnv
|
|
? {}
|
|
: {
|
|
...(token ? { botToken: token } : {}),
|
|
...(baseUrl ? { baseUrl } : {}),
|
|
},
|
|
});
|
|
},
|
|
};
|
|
|
|
export const mattermostSetupContract = defineChannelSetupContract({
|
|
fields: {
|
|
token: {
|
|
kind: "string",
|
|
sensitive: true,
|
|
cli: { flags: "--token <token>", description: "Mattermost bot token" },
|
|
},
|
|
botToken: {
|
|
kind: "string",
|
|
sensitive: true,
|
|
cli: { flags: "--bot-token <token>", description: "Mattermost bot token" },
|
|
},
|
|
httpUrl: {
|
|
kind: "string",
|
|
cli: { flags: "--http-url <url>", description: "Mattermost server URL" },
|
|
},
|
|
useEnv: {
|
|
kind: "boolean",
|
|
cli: { flags: "--use-env", description: "Use Mattermost environment credentials" },
|
|
envVars: ["MATTERMOST_BOT_TOKEN", "MATTERMOST_URL"],
|
|
},
|
|
},
|
|
legacyAdapter: mattermostSetupAdapter,
|
|
});
|