refactor(mattermost): type config seams

This commit is contained in:
Ayaan Zaidi
2026-03-27 11:58:52 +05:30
parent e58170ddc1
commit bd2c208689
3 changed files with 10 additions and 14 deletions

View File

@@ -51,6 +51,7 @@ import { getMattermostRuntime } from "./runtime.js";
import { resolveMattermostOutboundSessionRoute } from "./session-route.js";
import { mattermostSetupAdapter } from "./setup-core.js";
import { mattermostSetupWizard } from "./setup-surface.js";
import type { MattermostConfig } from "./types.js";
const mattermostSecurityAdapter = createRestrictSendersChannelSecurity<ResolvedMattermostAccount>({
channelKey: "mattermost",
@@ -112,14 +113,11 @@ const mattermostMessageActions: ChannelMessageActionAdapter = {
},
handleAction: async ({ action, params, cfg, accountId }) => {
if (action === "react") {
// Check reactions gate: per-account config takes precedence over base config
const mmBase = cfg?.channels?.mattermost as Record<string, unknown> | undefined;
const accounts = mmBase?.accounts as Record<string, Record<string, unknown>> | undefined;
const resolvedAccountId = accountId ?? resolveDefaultMattermostAccountId(cfg);
const acctConfig = accounts?.[resolvedAccountId];
const acctActions = acctConfig?.actions as { reactions?: boolean } | undefined;
const baseActions = mmBase?.actions as { reactions?: boolean } | undefined;
const reactionsEnabled = acctActions?.reactions ?? baseActions?.reactions ?? true;
const mattermostConfig = cfg.channels?.mattermost as MattermostConfig | undefined;
const account = resolveMattermostAccount({ cfg, accountId: resolvedAccountId });
const reactionsEnabled =
account.config.actions?.reactions ?? mattermostConfig?.actions?.reactions ?? true;
if (!reactionsEnabled) {
throw new Error("Mattermost reactions are disabled in config");
}

View File

@@ -365,7 +365,7 @@ export async function monitorMattermostProvider(opts: MonitorMattermostOpts = {}
response: {
update: {
message: post.message ?? "",
props: post.props as Record<string, unknown> | undefined,
props: post.props ?? undefined,
},
ephemeral_text: `OpenClaw ignored this action for ${decision.roomLabel}.`,
},

View File

@@ -11,6 +11,7 @@
import type { IncomingMessage, ServerResponse } from "node:http";
import type { OpenClawPluginApi } from "../runtime-api.js";
import type { MattermostConfig } from "../types.js";
import type { ResolvedMattermostAccount } from "./accounts.js";
import { resolveSlashCommandConfig, type MattermostRegisteredCommand } from "./slash-commands.js";
import { createSlashCommandHttpHandler } from "./slash-http.js";
@@ -149,7 +150,7 @@ export function deactivateSlashCommands(accountId?: string) {
* by matching the inbound token against each account's registered tokens.
*/
export function registerSlashCommandRoute(api: OpenClawPluginApi) {
const mmConfig = api.config.channels?.mattermost as Record<string, unknown> | undefined;
const mmConfig = api.config.channels?.mattermost as MattermostConfig | undefined;
// Collect callback paths from both top-level and per-account config.
// Command registration uses account.config.commands, so the HTTP route
@@ -180,12 +181,9 @@ export function registerSlashCommandRoute(api: OpenClawPluginApi) {
| undefined;
addCallbackPaths(commandsRaw);
const accountsRaw = (mmConfig?.accounts ?? {}) as Record<string, unknown>;
const accountsRaw = mmConfig?.accounts ?? {};
for (const accountId of Object.keys(accountsRaw)) {
const accountCfg = accountsRaw[accountId] as Record<string, unknown> | undefined;
const accountCommandsRaw = accountCfg?.commands as
| Partial<import("./slash-commands.js").MattermostSlashCommandConfig>
| undefined;
const accountCommandsRaw = accountsRaw[accountId]?.commands;
addCallbackPaths(accountCommandsRaw);
}