fix: honor mattermost action discovery account config

This commit is contained in:
Tak Hoffman
2026-04-03 11:26:52 -05:00
parent 09f66b0073
commit 226e2389f6
2 changed files with 38 additions and 4 deletions

View File

@@ -43,8 +43,8 @@ type MattermostSendTextParams = Parameters<MattermostSendText>[0];
type MattermostSendMedia = NonNullable<NonNullable<typeof mattermostPlugin.outbound>["sendMedia"]>;
type MattermostSendMediaParams = Parameters<MattermostSendMedia>[0];
function getDescribedActions(cfg: OpenClawConfig): string[] {
return [...(mattermostPlugin.actions?.describeMessageTool?.({ cfg })?.actions ?? [])];
function getDescribedActions(cfg: OpenClawConfig, accountId?: string): string[] {
return [...(mattermostPlugin.actions?.describeMessageTool?.({ cfg, accountId })?.actions ?? [])];
}
function requireMattermostNormalizeTarget() {
@@ -292,6 +292,34 @@ describe("mattermostPlugin", () => {
expect(actions).toContain("react");
});
it("honors the selected Mattermost account during discovery", () => {
const cfg: OpenClawConfig = {
channels: {
mattermost: {
enabled: true,
actions: { reactions: false },
accounts: {
default: {
enabled: true,
botToken: "test-token",
baseUrl: "https://chat.example.com",
actions: { reactions: false },
},
work: {
enabled: true,
botToken: "work-token",
baseUrl: "https://chat.example.com",
actions: { reactions: true },
},
},
},
},
};
expect(getDescribedActions(cfg, "default")).toEqual(["send"]);
expect(getDescribedActions(cfg, "work")).toEqual(["send", "react"]);
});
it("blocks react when default account disables reactions and accountId is omitted", async () => {
const cfg: OpenClawConfig = {
channels: {

View File

@@ -69,11 +69,17 @@ const mattermostSecurityAdapter = createRestrictSendersChannelSecurity<ResolvedM
function describeMattermostMessageTool({
cfg,
accountId,
}: Parameters<
NonNullable<ChannelMessageActionAdapter["describeMessageTool"]>
>[0]): ChannelMessageToolDiscovery {
const enabledAccounts = listMattermostAccountIds(cfg)
.map((accountId) => resolveMattermostAccount({ cfg, accountId }))
const enabledAccounts = (
accountId
? [resolveMattermostAccount({ cfg, accountId })]
: listMattermostAccountIds(cfg).map((listedAccountId) =>
resolveMattermostAccount({ cfg, accountId: listedAccountId }),
)
)
.filter((account) => account.enabled)
.filter((account) => Boolean(account.botToken?.trim() && account.baseUrl?.trim()));