From bd2c208689ba50310b90c276f29e02c1deec407f Mon Sep 17 00:00:00 2001 From: Ayaan Zaidi Date: Fri, 27 Mar 2026 11:58:52 +0530 Subject: [PATCH] refactor(mattermost): type config seams --- extensions/mattermost/src/channel.ts | 12 +++++------- extensions/mattermost/src/mattermost/monitor.ts | 2 +- extensions/mattermost/src/mattermost/slash-state.ts | 10 ++++------ 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/extensions/mattermost/src/channel.ts b/extensions/mattermost/src/channel.ts index 20fb2676708..790be122f77 100644 --- a/extensions/mattermost/src/channel.ts +++ b/extensions/mattermost/src/channel.ts @@ -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({ 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 | undefined; - const accounts = mmBase?.accounts as Record> | 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"); } diff --git a/extensions/mattermost/src/mattermost/monitor.ts b/extensions/mattermost/src/mattermost/monitor.ts index e286b89cb09..256d41fde5d 100644 --- a/extensions/mattermost/src/mattermost/monitor.ts +++ b/extensions/mattermost/src/mattermost/monitor.ts @@ -365,7 +365,7 @@ export async function monitorMattermostProvider(opts: MonitorMattermostOpts = {} response: { update: { message: post.message ?? "", - props: post.props as Record | undefined, + props: post.props ?? undefined, }, ephemeral_text: `OpenClaw ignored this action for ${decision.roomLabel}.`, }, diff --git a/extensions/mattermost/src/mattermost/slash-state.ts b/extensions/mattermost/src/mattermost/slash-state.ts index 8e5fe1f08b3..9a21781b63c 100644 --- a/extensions/mattermost/src/mattermost/slash-state.ts +++ b/extensions/mattermost/src/mattermost/slash-state.ts @@ -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 | 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; + const accountsRaw = mmConfig?.accounts ?? {}; for (const accountId of Object.keys(accountsRaw)) { - const accountCfg = accountsRaw[accountId] as Record | undefined; - const accountCommandsRaw = accountCfg?.commands as - | Partial - | undefined; + const accountCommandsRaw = accountsRaw[accountId]?.commands; addCallbackPaths(accountCommandsRaw); }