@openclaw/mattermost 2026.11.3 → 2026.11.5-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.setup/channel-plugin-api-ClU67Wyc.mjs +1 -0
- package/dist/.setup/{channel-plugin-runtime-DJgVmmbD.mjs → channel-plugin-api-CuxSSPV8.mjs} +146 -130
- package/dist/.setup/{channel.runtime-Cl_09ZUI.mjs → channel.runtime-B3RvYLQi.mjs} +28 -34
- package/dist/.setup/{client-B_4C9q6z.mjs → client-CR-hGmGr.mjs} +11 -84
- package/dist/.setup/{interactions-LQ_rJSdf.mjs → interactions-D5hhyPam.mjs} +23 -36
- package/dist/.setup/{monitor-CmsQnrEk.mjs → monitor-Bw_pTSF8.mjs} +292 -400
- package/dist/.setup/{monitor-auth-rr4M-8gH.mjs → monitor-auth-BxpEUfvc.mjs} +5 -11
- package/dist/.setup/{normalize-Dli2PK7k.mjs → normalize-CNFRtT1O.mjs} +21 -7
- package/dist/.setup/secret-contract-api-Drz4m5pq.mjs +2 -0
- package/dist/.setup/{send-C_-GT5iF.mjs → send-BSae9PKV.mjs} +100 -198
- package/dist/.setup/{slash-state-DJN_cER0.mjs → slash-state-DpZH2wr6.mjs} +362 -409
- package/dist/.source-module-urls/8fb0cb1067b83fd2cf3f3ba0f7a23e627c27e8e3adf1a4ea18753ddb884ff71e.json +1 -0
- package/dist/api.js +2 -2
- package/dist/channel-plugin-api.js +1 -2
- package/dist/doctor-contract-api.js +1 -2
- package/dist/gateway-auth-api.js +1 -2
- package/dist/policy-api.js +1 -2
- package/dist/runtime-api.js +1 -2
- package/dist/secret-contract-api.js +1 -2
- package/dist/setup-entry.js +2 -2
- package/dist/slash-route-api.js +1 -2
- package/node_modules/zod/package.json +1 -1
- package/node_modules/zod/src/v4/classic/tests/array.test.ts +27 -0
- package/node_modules/zod/src/v4/classic/tests/map.test.ts +7 -0
- package/node_modules/zod/src/v4/classic/tests/set.test.ts +6 -0
- package/node_modules/zod/src/v4/core/compile.ts +9 -0
- package/node_modules/zod/src/v4/core/schemas.ts +35 -1
- package/node_modules/zod/src/v4/core/util.ts +13 -0
- package/node_modules/zod/src/v4/core/versions.ts +1 -1
- package/node_modules/zod/v4/core/compile.cjs +8 -0
- package/node_modules/zod/v4/core/compile.js +8 -0
- package/node_modules/zod/v4/core/schemas.cjs +30 -0
- package/node_modules/zod/v4/core/schemas.d.cts +3 -1
- package/node_modules/zod/v4/core/schemas.d.ts +3 -1
- package/node_modules/zod/v4/core/schemas.js +30 -0
- package/node_modules/zod/v4/core/util.cjs +15 -0
- package/node_modules/zod/v4/core/util.d.cts +2 -0
- package/node_modules/zod/v4/core/util.d.ts +2 -0
- package/node_modules/zod/v4/core/util.js +14 -0
- package/node_modules/zod/v4/core/versions.cjs +1 -1
- package/node_modules/zod/v4/core/versions.js +1 -1
- package/openclaw.plugin.json +172 -0
- package/package.json +5 -5
- package/dist/.setup/channel-plugin-api-BKpd51G7.mjs +0 -3
- package/dist/.setup/secret-contract-api-BGz5_6WD.mjs +0 -3
- package/dist/channel-plugin-runtime.js +0 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { t as getMattermostRuntime } from "./runtime-CNB4YGqJ.mjs";
|
|
2
2
|
import { n as normalizeMattermostAllowEntry, t as mattermostIngressIdentity } from "./ingress-identity-D6hxfxvo.mjs";
|
|
3
3
|
import { uniqueStrings } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
4
|
+
import { createWebhookInFlightLimiter, readRequestBodyWithLimit, sendHttpRequestRejection } from "openclaw/plugin-sdk/webhook-request-guards";
|
|
4
5
|
import { logInboundDrop } from "openclaw/plugin-sdk/channel-inbound";
|
|
5
6
|
import { resolveAllowlistMatchSimple } from "openclaw/plugin-sdk/allow-from";
|
|
6
7
|
import { createChannelPairingController } from "openclaw/plugin-sdk/channel-pairing";
|
|
@@ -15,7 +16,6 @@ import { loadOutboundMediaFromUrl } from "openclaw/plugin-sdk/outbound-media";
|
|
|
15
16
|
import { DEFAULT_GROUP_HISTORY_LIMIT, createChannelHistoryWindow } from "openclaw/plugin-sdk/reply-history";
|
|
16
17
|
import { registerPluginHttpRoute } from "openclaw/plugin-sdk/webhook-targets";
|
|
17
18
|
import { isRequestBodyLimitError } from "openclaw/plugin-sdk/webhook-ingress";
|
|
18
|
-
import { createWebhookInFlightLimiter, readRequestBodyWithLimit, sendHttpRequestRejection } from "openclaw/plugin-sdk/webhook-request-guards";
|
|
19
19
|
import { isTrustedProxyAddress, resolveClientIp } from "openclaw/plugin-sdk/core";
|
|
20
20
|
import { resolveChannelContextVisibilityMode, shouldIncludeSupplementalContext } from "openclaw/plugin-sdk/context-visibility-runtime";
|
|
21
21
|
//#region extensions/mattermost/src/mattermost/monitor-auth.ts
|
|
@@ -38,17 +38,13 @@ function isMattermostSenderAllowed(params) {
|
|
|
38
38
|
allowNameMatching: params.allowNameMatching
|
|
39
39
|
}).allowed;
|
|
40
40
|
}
|
|
41
|
-
function
|
|
42
|
-
const normalized = channelType?.trim().toUpperCase();
|
|
41
|
+
function resolveMattermostTrustedChatKind(params) {
|
|
42
|
+
const normalized = params.channelType?.trim().toUpperCase();
|
|
43
43
|
if (!normalized) return "direct";
|
|
44
44
|
if (normalized === "D") return "direct";
|
|
45
45
|
if (normalized === "G" || normalized === "P") return "group";
|
|
46
46
|
return "channel";
|
|
47
47
|
}
|
|
48
|
-
function resolveMattermostTrustedChatKind(params) {
|
|
49
|
-
const channelType = params.channelType?.trim();
|
|
50
|
-
return channelType ? mapMattermostChannelTypeToChatType(channelType) : params.fallback ?? "direct";
|
|
51
|
-
}
|
|
52
48
|
async function resolveMattermostMonitorInboundAccess(params) {
|
|
53
49
|
const { account, cfg, senderId, senderName, channelId, kind, groupPolicy, storeAllowFrom, allowTextCommands, hasControlCommand } = params;
|
|
54
50
|
const dmPolicy = account.config.dmPolicy ?? "pairing";
|
|
@@ -59,7 +55,6 @@ async function resolveMattermostMonitorInboundAccess(params) {
|
|
|
59
55
|
return await getMattermostRuntime().channel.inbound.ingress.resolveStable({
|
|
60
56
|
channelId: "mattermost",
|
|
61
57
|
accountId: account.accountId,
|
|
62
|
-
contextBinding: params.contextBinding,
|
|
63
58
|
identity: mattermostIngressIdentity,
|
|
64
59
|
cfg,
|
|
65
60
|
...readStoreAllowFrom ? { readStoreAllowFrom } : {},
|
|
@@ -70,8 +65,7 @@ async function resolveMattermostMonitorInboundAccess(params) {
|
|
|
70
65
|
},
|
|
71
66
|
conversation: {
|
|
72
67
|
kind,
|
|
73
|
-
id: channelId
|
|
74
|
-
threadId: params.threadId
|
|
68
|
+
id: channelId
|
|
75
69
|
},
|
|
76
70
|
event: {
|
|
77
71
|
kind: params.eventKind ?? "message",
|
|
@@ -129,7 +123,7 @@ async function authorizeMattermostCommandInvocation(params) {
|
|
|
129
123
|
channelDisplay: "",
|
|
130
124
|
roomLabel: `#${channelId}`
|
|
131
125
|
};
|
|
132
|
-
const kind =
|
|
126
|
+
const kind = resolveMattermostTrustedChatKind({ channelType: channelInfo.type });
|
|
133
127
|
const chatType = kind;
|
|
134
128
|
const channelName = channelInfo.name ?? "";
|
|
135
129
|
const channelDisplay = channelInfo.display_name ?? channelName;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { h as normalizeMattermostBaseUrl } from "./client-
|
|
1
|
+
import { h as normalizeMattermostBaseUrl, r as createMattermostClient } from "./client-CR-hGmGr.mjs";
|
|
2
2
|
import { normalizeLowercaseStringOrEmpty, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
3
|
-
import { resolveChannelPreviewStreamMode,
|
|
3
|
+
import { resolveChannelPreviewStreamMode, resolveChannelStreamingBlockEnabled } from "openclaw/plugin-sdk/channel-outbound";
|
|
4
4
|
import { createAccountListHelpers, hasConfiguredAccountValue } from "openclaw/plugin-sdk/account-helpers";
|
|
5
5
|
import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id";
|
|
6
6
|
import { normalizeMessagePresentation, renderMessagePresentationFallbackText, resolveMessagePresentationControlValue } from "openclaw/plugin-sdk/interactive-runtime";
|
|
@@ -9,7 +9,7 @@ import { resolveSecretInputString } from "openclaw/plugin-sdk/secret-input";
|
|
|
9
9
|
//#region extensions/mattermost/src/mattermost/accounts.ts
|
|
10
10
|
const { listAccountIds: listMattermostAccountIds, resolveDefaultAccountId: resolveDefaultMattermostAccountId, resolveAccountConfig: mergeMattermostAccountConfig } = createAccountListHelpers("mattermost", {
|
|
11
11
|
omitKeys: ["defaultAccount"],
|
|
12
|
-
nestedObjectKeys: ["commands"],
|
|
12
|
+
nestedObjectKeys: ["commands", "botLoopProtection"],
|
|
13
13
|
hasImplicitDefaultAccount: (cfg) => {
|
|
14
14
|
const mattermost = cfg.channels?.mattermost;
|
|
15
15
|
return Boolean(mattermost?.baseUrl?.trim() && (hasConfiguredAccountValue(mattermost.botToken) || process.env.MATTERMOST_BOT_TOKEN?.trim()));
|
|
@@ -55,10 +55,8 @@ function resolveMattermostAccountWithMode(params) {
|
|
|
55
55
|
oncharPrefixes: merged.oncharPrefixes,
|
|
56
56
|
requireMention,
|
|
57
57
|
textChunkLimit: merged.textChunkLimit,
|
|
58
|
-
chunkMode: resolveChannelStreamingChunkMode(merged),
|
|
59
58
|
streamingMode: resolveChannelPreviewStreamMode(merged, "partial"),
|
|
60
|
-
blockStreaming: resolveChannelStreamingBlockEnabled(merged)
|
|
61
|
-
blockStreamingCoalesce: resolveChannelStreamingBlockCoalesce(merged)
|
|
59
|
+
blockStreaming: resolveChannelStreamingBlockEnabled(merged)
|
|
62
60
|
};
|
|
63
61
|
}
|
|
64
62
|
function resolveMattermostAccount(params) {
|
|
@@ -67,6 +65,22 @@ function resolveMattermostAccount(params) {
|
|
|
67
65
|
mode: "strict"
|
|
68
66
|
});
|
|
69
67
|
}
|
|
68
|
+
function createMattermostAccountClient(account, overrides, assertRequestCurrent) {
|
|
69
|
+
const botToken = normalizeOptionalString(overrides.botToken) ?? normalizeOptionalString(account.botToken);
|
|
70
|
+
if (!botToken) throw new Error(`Mattermost bot token missing for account "${account.accountId}" (set channels.mattermost.accounts.${account.accountId}.botToken or MATTERMOST_BOT_TOKEN for default).`);
|
|
71
|
+
const baseUrl = normalizeMattermostBaseUrl(overrides.baseUrl ?? account.baseUrl);
|
|
72
|
+
if (!baseUrl) throw new Error(`Mattermost baseUrl missing for account "${account.accountId}" (set channels.mattermost.accounts.${account.accountId}.baseUrl or MATTERMOST_URL for default).`);
|
|
73
|
+
return {
|
|
74
|
+
baseUrl,
|
|
75
|
+
botToken,
|
|
76
|
+
client: createMattermostClient({
|
|
77
|
+
baseUrl,
|
|
78
|
+
botToken,
|
|
79
|
+
allowPrivateNetwork: account.config.network?.dangerouslyAllowPrivateNetwork === true,
|
|
80
|
+
assertRequestCurrent
|
|
81
|
+
})
|
|
82
|
+
};
|
|
83
|
+
}
|
|
70
84
|
function inspectMattermostAccount(params) {
|
|
71
85
|
const account = resolveMattermostAccountWithMode({
|
|
72
86
|
...params,
|
|
@@ -186,4 +200,4 @@ function looksLikeMattermostTargetId(raw, _normalized) {
|
|
|
186
200
|
return /^[a-z0-9]{26}$/i.test(trimmed) || /^[a-z0-9]{26}__[a-z0-9]{26}$/i.test(trimmed);
|
|
187
201
|
}
|
|
188
202
|
//#endregion
|
|
189
|
-
export { resolveMattermostPresentation as a,
|
|
203
|
+
export { resolveMattermostPresentation as a, isMattermostConfigured as c, resolveMattermostAccount as d, resolveMattermostReplyToMode as f, requiresMattermostMediaUpload as i, listMattermostAccountIds as l, normalizeMattermostMessagingTarget as n, createMattermostAccountClient as o, parseMattermostQuestionContext as r, inspectMattermostAccount as s, looksLikeMattermostTargetId as t, resolveDefaultMattermostAccountId as u };
|
|
@@ -1,37 +1,24 @@
|
|
|
1
|
-
import { c as setInteractionSecret, n as buildButtonProps, o as resolveInteractionCallbackUrl } from "./interactions-
|
|
1
|
+
import { c as setInteractionSecret, n as buildButtonProps, o as resolveInteractionCallbackUrl } from "./interactions-D5hhyPam.mjs";
|
|
2
2
|
import { n as getOptionalMattermostRuntime, t as getMattermostRuntime } from "./runtime-CNB4YGqJ.mjs";
|
|
3
|
-
import { a as createMattermostPost, b as uploadMattermostFile, c as fetchMattermostChannelByName, d as fetchMattermostUser, f as fetchMattermostUserByUsername, g as parseMattermostApiStatus, h as normalizeMattermostBaseUrl, i as createMattermostDirectChannelWithRetry, p as fetchMattermostUserTeams, r as createMattermostClient, s as fetchMattermostChannel, u as fetchMattermostMe } from "./client-
|
|
4
|
-
import { s as resolveMattermostTrustedChatKind, v as loadOutboundMediaFromUrl } from "./monitor-auth-
|
|
5
|
-
import {
|
|
3
|
+
import { a as createMattermostPost, b as uploadMattermostFile, c as fetchMattermostChannelByName, d as fetchMattermostUser, f as fetchMattermostUserByUsername, g as parseMattermostApiStatus, h as normalizeMattermostBaseUrl, i as createMattermostDirectChannelWithRetry, p as fetchMattermostUserTeams, r as createMattermostClient, s as fetchMattermostChannel, u as fetchMattermostMe } from "./client-CR-hGmGr.mjs";
|
|
4
|
+
import { s as resolveMattermostTrustedChatKind, v as loadOutboundMediaFromUrl } from "./monitor-auth-BxpEUfvc.mjs";
|
|
5
|
+
import { d as resolveMattermostAccount, o as createMattermostAccountClient } from "./normalize-CNFRtT1O.mjs";
|
|
6
6
|
import { normalizeLowercaseStringOrEmpty, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
7
7
|
import { createChannelPartialDeliveryError } from "openclaw/plugin-sdk/channel-inbound";
|
|
8
8
|
import { createMessageReceiptFromOutboundResults, listMessageReceiptPlatformIds } from "openclaw/plugin-sdk/channel-outbound";
|
|
9
9
|
import { resolveChannelMediaMaxBytes } from "openclaw/plugin-sdk/account-helpers";
|
|
10
10
|
import { convertMarkdownTables } from "openclaw/plugin-sdk/text-chunking";
|
|
11
|
-
import { pruneMapToMaxSize } from "openclaw/plugin-sdk/collection-runtime";
|
|
11
|
+
import { createStaleWhileRevalidateCache, pruneMapToMaxSize } from "openclaw/plugin-sdk/collection-runtime";
|
|
12
12
|
import { resolveMarkdownTableMode } from "openclaw/plugin-sdk/markdown-table-runtime";
|
|
13
13
|
import { extensionForMime } from "openclaw/plugin-sdk/media-mime";
|
|
14
14
|
import { requireRuntimeConfig } from "openclaw/plugin-sdk/plugin-config-runtime";
|
|
15
15
|
//#region extensions/mattermost/src/mattermost/target-resolution.ts
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
expiresAt: Date.now() + MATTERMOST_OPAQUE_TARGET_CACHE_TTL_MS
|
|
23
|
-
});
|
|
24
|
-
pruneMapToMaxSize(mattermostOpaqueTargetCache, MATTERMOST_OPAQUE_TARGET_CACHE_MAX_ENTRIES);
|
|
25
|
-
}
|
|
26
|
-
function getCachedMattermostOpaqueTargetKind(key) {
|
|
27
|
-
const cached = mattermostOpaqueTargetCache.get(key);
|
|
28
|
-
if (!cached) return;
|
|
29
|
-
if (cached.expiresAt <= Date.now()) {
|
|
30
|
-
mattermostOpaqueTargetCache.delete(key);
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
return cached.kind;
|
|
34
|
-
}
|
|
16
|
+
const mattermostOpaqueTargetCache = createStaleWhileRevalidateCache({
|
|
17
|
+
maxEntries: 1024,
|
|
18
|
+
maxPending: Number.POSITIVE_INFINITY,
|
|
19
|
+
ttlMs: 3e5,
|
|
20
|
+
cacheable: (kind) => kind !== void 0
|
|
21
|
+
});
|
|
35
22
|
function cacheKey$1(baseUrl, token, id) {
|
|
36
23
|
return `${baseUrl}::${token}::${id}`;
|
|
37
24
|
}
|
|
@@ -40,38 +27,20 @@ function isMattermostId(value) {
|
|
|
40
27
|
return /^[a-z0-9]{26}$/.test(value);
|
|
41
28
|
}
|
|
42
29
|
function parseMattermostTarget(raw) {
|
|
43
|
-
|
|
30
|
+
let trimmed = raw.trim();
|
|
44
31
|
if (!trimmed) throw new Error("Recipient is required for Mattermost sends");
|
|
45
32
|
const lower = normalizeLowercaseStringOrEmpty(trimmed);
|
|
46
33
|
if (lower.startsWith("channel:")) {
|
|
47
|
-
|
|
48
|
-
if (!
|
|
49
|
-
|
|
50
|
-
const name = id.slice(1).trim();
|
|
51
|
-
if (!name) throw new Error("Channel name is required for Mattermost sends");
|
|
52
|
-
return {
|
|
53
|
-
kind: "channel-name",
|
|
54
|
-
name
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
if (!isMattermostId(id)) return {
|
|
58
|
-
kind: "channel-name",
|
|
59
|
-
name: id
|
|
60
|
-
};
|
|
61
|
-
return {
|
|
62
|
-
kind: "channel",
|
|
63
|
-
id
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
if (lower.startsWith("user:") || lower.startsWith("mattermost:")) {
|
|
34
|
+
trimmed = trimmed.slice(8).trim();
|
|
35
|
+
if (!trimmed) throw new Error("Channel id is required for Mattermost sends");
|
|
36
|
+
} else if (lower.startsWith("user:") || lower.startsWith("mattermost:")) {
|
|
67
37
|
const id = trimmed.slice(trimmed.indexOf(":") + 1).trim();
|
|
68
38
|
if (!id) throw new Error("User id is required for Mattermost sends");
|
|
69
39
|
return {
|
|
70
40
|
kind: "user",
|
|
71
41
|
id
|
|
72
42
|
};
|
|
73
|
-
}
|
|
74
|
-
if (trimmed.startsWith("@")) {
|
|
43
|
+
} else if (trimmed.startsWith("@")) {
|
|
75
44
|
const username = trimmed.slice(1).trim();
|
|
76
45
|
if (!username) throw new Error("Username is required for Mattermost sends");
|
|
77
46
|
return {
|
|
@@ -117,43 +86,25 @@ async function resolveMattermostOpaqueTarget(params) {
|
|
|
117
86
|
});
|
|
118
87
|
}
|
|
119
88
|
const key = cacheKey$1(client.baseUrl, client.token, input);
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
89
|
+
const { value } = await mattermostOpaqueTargetCache.read(key, async () => {
|
|
90
|
+
try {
|
|
91
|
+
await fetchMattermostUser(client, input);
|
|
92
|
+
return "user";
|
|
93
|
+
} catch (err) {
|
|
94
|
+
if (parseMattermostApiStatus(err) !== 404) return;
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const channel = await fetchMattermostChannel(client, input);
|
|
98
|
+
return resolveMattermostTrustedChatKind({ channelType: channel.type }) === "group" ? "group" : "channel";
|
|
99
|
+
} catch {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
}, { allowStale: false });
|
|
103
|
+
const kind = value ?? "channel";
|
|
104
|
+
return {
|
|
105
|
+
kind,
|
|
106
|
+
to: `${kind === "user" ? "user" : "channel"}:${input}`
|
|
125
107
|
};
|
|
126
|
-
try {
|
|
127
|
-
await fetchMattermostUser(client, input);
|
|
128
|
-
cacheMattermostOpaqueTarget(key, "user");
|
|
129
|
-
return {
|
|
130
|
-
kind: "user",
|
|
131
|
-
id: input,
|
|
132
|
-
to: `user:${input}`
|
|
133
|
-
};
|
|
134
|
-
} catch (err) {
|
|
135
|
-
if (parseMattermostApiStatus(err) !== 404) return {
|
|
136
|
-
kind: "channel",
|
|
137
|
-
id: input,
|
|
138
|
-
to: `channel:${input}`
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
try {
|
|
142
|
-
const channel = await fetchMattermostChannel(client, input);
|
|
143
|
-
const channelKind = resolveMattermostTrustedChatKind({ channelType: channel.type }) === "group" ? "group" : "channel";
|
|
144
|
-
cacheMattermostOpaqueTarget(key, channelKind);
|
|
145
|
-
return {
|
|
146
|
-
kind: channelKind,
|
|
147
|
-
id: input,
|
|
148
|
-
to: `channel:${input}`
|
|
149
|
-
};
|
|
150
|
-
} catch {
|
|
151
|
-
return {
|
|
152
|
-
kind: "channel",
|
|
153
|
-
id: input,
|
|
154
|
-
to: `channel:${input}`
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
108
|
}
|
|
158
109
|
//#endregion
|
|
159
110
|
//#region extensions/mattermost/src/mattermost/send.ts
|
|
@@ -168,73 +119,10 @@ function cacheOutboundEntry(cache, key, value, maxEntries) {
|
|
|
168
119
|
cache.set(key, value);
|
|
169
120
|
pruneMapToMaxSize(cache, maxEntries);
|
|
170
121
|
}
|
|
171
|
-
function resolveMattermostReceiptKind(params) {
|
|
172
|
-
if (params.fileIds?.length) return "media";
|
|
173
|
-
if (params.buttons?.length || params.props) return "card";
|
|
174
|
-
return "text";
|
|
175
|
-
}
|
|
176
122
|
function cacheKey(baseUrl, token) {
|
|
177
123
|
return `${baseUrl}::${token}`;
|
|
178
124
|
}
|
|
179
|
-
async function
|
|
180
|
-
const key = cacheKey(client.baseUrl, client.token);
|
|
181
|
-
const cached = botUserCache.get(key);
|
|
182
|
-
if (cached) return cached;
|
|
183
|
-
const user = await fetchMattermostMe(client);
|
|
184
|
-
cacheOutboundEntry(botUserCache, key, user, MATTERMOST_BOT_USER_CACHE_MAX_ENTRIES);
|
|
185
|
-
return user;
|
|
186
|
-
}
|
|
187
|
-
async function resolveUserIdByUsername(params) {
|
|
188
|
-
const { client, username } = params;
|
|
189
|
-
const key = `${cacheKey(client.baseUrl, client.token)}::${normalizeLowercaseStringOrEmpty(username)}`;
|
|
190
|
-
const cached = userByNameCache.get(key);
|
|
191
|
-
if (cached?.id) return cached.id;
|
|
192
|
-
const user = await fetchMattermostUserByUsername(client, username);
|
|
193
|
-
cacheOutboundEntry(userByNameCache, key, user, MATTERMOST_TARGET_CACHE_MAX_ENTRIES);
|
|
194
|
-
return user.id;
|
|
195
|
-
}
|
|
196
|
-
async function resolveChannelIdByName(params) {
|
|
197
|
-
const { client, name } = params;
|
|
198
|
-
const key = `${cacheKey(client.baseUrl, client.token)}::channel::${normalizeLowercaseStringOrEmpty(name)}`;
|
|
199
|
-
const cached = channelByNameCache.get(key);
|
|
200
|
-
if (cached) return cached;
|
|
201
|
-
const me = await fetchMattermostMe(client);
|
|
202
|
-
const teams = await fetchMattermostUserTeams(client, me.id);
|
|
203
|
-
for (const team of teams) try {
|
|
204
|
-
const channel = await fetchMattermostChannelByName(client, team.id, name);
|
|
205
|
-
if (channel?.id) {
|
|
206
|
-
cacheOutboundEntry(channelByNameCache, key, channel.id, MATTERMOST_TARGET_CACHE_MAX_ENTRIES);
|
|
207
|
-
return channel.id;
|
|
208
|
-
}
|
|
209
|
-
} catch (error) {
|
|
210
|
-
if (parseMattermostApiStatus(error) !== 404) throw error;
|
|
211
|
-
}
|
|
212
|
-
throw new Error(`Mattermost channel "#${name}" not found in any team the bot belongs to`);
|
|
213
|
-
}
|
|
214
|
-
async function resolveTargetChannelId(params) {
|
|
215
|
-
if (params.target.kind === "channel") return params.target.id;
|
|
216
|
-
if (params.target.kind === "channel-name") return await resolveChannelIdByName({
|
|
217
|
-
client: params.client,
|
|
218
|
-
name: params.target.name
|
|
219
|
-
});
|
|
220
|
-
const userId = params.target.id ? params.target.id : await resolveUserIdByUsername({
|
|
221
|
-
client: params.client,
|
|
222
|
-
username: params.target.username ?? ""
|
|
223
|
-
});
|
|
224
|
-
const dmKey = `${cacheKey(params.client.baseUrl, params.client.token)}::dm::${userId}`;
|
|
225
|
-
const cachedDm = dmChannelCache.get(dmKey);
|
|
226
|
-
if (cachedDm) return cachedDm;
|
|
227
|
-
const botUser = await resolveBotUser(params.client);
|
|
228
|
-
const channel = await createMattermostDirectChannelWithRetry(params.client, [botUser.id, userId], {
|
|
229
|
-
...params.dmRetryOptions,
|
|
230
|
-
onRetry: (attempt, delayMs, error) => {
|
|
231
|
-
params.logger?.warn?.(`DM channel creation retry ${attempt} after ${delayMs}ms: ${error.message}`);
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
cacheOutboundEntry(dmChannelCache, dmKey, channel.id, MATTERMOST_TARGET_CACHE_MAX_ENTRIES);
|
|
235
|
-
return channel.id;
|
|
236
|
-
}
|
|
237
|
-
async function resolveMattermostSendContext(to, opts) {
|
|
125
|
+
async function sendMessageMattermost(to, text, opts) {
|
|
238
126
|
const core = getMattermostRuntime();
|
|
239
127
|
const logger = core.logging.getChildLogger({ module: "mattermost" });
|
|
240
128
|
const cfg = requireRuntimeConfig(opts?.cfg, "Mattermost send");
|
|
@@ -242,66 +130,84 @@ async function resolveMattermostSendContext(to, opts) {
|
|
|
242
130
|
cfg,
|
|
243
131
|
accountId: opts.accountId
|
|
244
132
|
});
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
const baseUrl = normalizeMattermostBaseUrl(opts.baseUrl ?? account.baseUrl);
|
|
248
|
-
if (!baseUrl) throw new Error(`Mattermost baseUrl missing for account "${account.accountId}" (set channels.mattermost.accounts.${account.accountId}.baseUrl or MATTERMOST_URL for default).`);
|
|
249
|
-
const client = createMattermostClient({
|
|
250
|
-
baseUrl,
|
|
251
|
-
botToken: token,
|
|
252
|
-
allowPrivateNetwork: account.config.network?.dangerouslyAllowPrivateNetwork === true,
|
|
253
|
-
assertRequestCurrent: opts.assertDirectAdapterHandoff
|
|
254
|
-
});
|
|
255
|
-
const retry = account.config.dmChannelRetry;
|
|
256
|
-
const dmRetryOptions = retry && {
|
|
257
|
-
maxRetries: retry.maxRetries,
|
|
258
|
-
initialDelayMs: retry.initialDelayMs,
|
|
259
|
-
maxDelayMs: retry.maxDelayMs,
|
|
260
|
-
timeoutMs: retry.timeoutMs
|
|
261
|
-
};
|
|
133
|
+
const { client } = createMattermostAccountClient(account, opts, opts.assertDirectAdapterHandoff);
|
|
134
|
+
const dmRetryOptions = account.config.dmChannelRetry;
|
|
262
135
|
let channelId;
|
|
263
136
|
try {
|
|
264
137
|
const trimmedTo = normalizeOptionalString(to) ?? "";
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
138
|
+
const target = parseMattermostTarget((await resolveMattermostOpaqueTarget({
|
|
139
|
+
input: trimmedTo,
|
|
140
|
+
client
|
|
141
|
+
}))?.to ?? trimmedTo);
|
|
142
|
+
const targetLogger = core.logging.shouldLogVerbose() ? logger : void 0;
|
|
143
|
+
channelId = await (async () => {
|
|
144
|
+
if (target.kind === "channel") return target.id;
|
|
145
|
+
if (target.kind === "channel-name") {
|
|
146
|
+
const name = target.name;
|
|
147
|
+
const key = `${cacheKey(client.baseUrl, client.token)}::channel::${normalizeLowercaseStringOrEmpty(name)}`;
|
|
148
|
+
const cached = channelByNameCache.get(key);
|
|
149
|
+
if (cached) return cached;
|
|
150
|
+
const me = await fetchMattermostMe(client);
|
|
151
|
+
const teams = await fetchMattermostUserTeams(client, me.id);
|
|
152
|
+
for (const team of teams) try {
|
|
153
|
+
const channel = await fetchMattermostChannelByName(client, team.id, name);
|
|
154
|
+
if (channel?.id) {
|
|
155
|
+
cacheOutboundEntry(channelByNameCache, key, channel.id, MATTERMOST_TARGET_CACHE_MAX_ENTRIES);
|
|
156
|
+
return channel.id;
|
|
157
|
+
}
|
|
158
|
+
} catch (error) {
|
|
159
|
+
if (parseMattermostApiStatus(error) !== 404) throw error;
|
|
160
|
+
}
|
|
161
|
+
throw new Error(`Mattermost channel "#${name}" not found in any team the bot belongs to`);
|
|
162
|
+
}
|
|
163
|
+
let userId = target.id;
|
|
164
|
+
if (!userId) {
|
|
165
|
+
const username = target.username ?? "";
|
|
166
|
+
const key = `${cacheKey(client.baseUrl, client.token)}::${normalizeLowercaseStringOrEmpty(username)}`;
|
|
167
|
+
const cached = userByNameCache.get(key);
|
|
168
|
+
if (cached?.id) userId = cached.id;
|
|
169
|
+
else {
|
|
170
|
+
const user = await fetchMattermostUserByUsername(client, username);
|
|
171
|
+
cacheOutboundEntry(userByNameCache, key, user, MATTERMOST_TARGET_CACHE_MAX_ENTRIES);
|
|
172
|
+
userId = user.id;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const dmKey = `${cacheKey(client.baseUrl, client.token)}::dm::${userId}`;
|
|
176
|
+
const cachedDm = dmChannelCache.get(dmKey);
|
|
177
|
+
if (cachedDm) return cachedDm;
|
|
178
|
+
const botKey = cacheKey(client.baseUrl, client.token);
|
|
179
|
+
let botUser = botUserCache.get(botKey);
|
|
180
|
+
if (!botUser) {
|
|
181
|
+
botUser = await fetchMattermostMe(client);
|
|
182
|
+
cacheOutboundEntry(botUserCache, botKey, botUser, MATTERMOST_BOT_USER_CACHE_MAX_ENTRIES);
|
|
183
|
+
}
|
|
184
|
+
const channel = await createMattermostDirectChannelWithRetry(client, [botUser.id, userId], {
|
|
185
|
+
...dmRetryOptions,
|
|
186
|
+
onRetry: (attempt, delayMs, error) => {
|
|
187
|
+
targetLogger?.warn?.(`DM channel creation retry ${attempt} after ${delayMs}ms: ${error.message}`);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
cacheOutboundEntry(dmChannelCache, dmKey, channel.id, MATTERMOST_TARGET_CACHE_MAX_ENTRIES);
|
|
191
|
+
return channel.id;
|
|
192
|
+
})();
|
|
274
193
|
} catch (error) {
|
|
275
194
|
client.assertRequestCurrent?.();
|
|
276
195
|
throw error;
|
|
277
196
|
}
|
|
278
|
-
|
|
197
|
+
const accountId = account.accountId;
|
|
198
|
+
const mediaMaxBytes = resolveChannelMediaMaxBytes({
|
|
279
199
|
cfg,
|
|
280
200
|
accountId: account.accountId,
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
mediaMaxBytes: resolveChannelMediaMaxBytes({
|
|
284
|
-
cfg,
|
|
285
|
-
accountId: account.accountId,
|
|
286
|
-
resolveChannelLimitMb: () => account.config.mediaMaxMb
|
|
287
|
-
})
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
async function sendMessageMattermost(to, text, opts) {
|
|
291
|
-
const core = getMattermostRuntime();
|
|
292
|
-
const logger = core.logging.getChildLogger({ module: "mattermost" });
|
|
293
|
-
const { cfg, accountId, client, channelId, mediaMaxBytes } = await resolveMattermostSendContext(to, opts);
|
|
201
|
+
resolveChannelLimitMb: () => account.config.mediaMaxMb
|
|
202
|
+
});
|
|
294
203
|
client.assertRequestCurrent?.();
|
|
295
204
|
let props = opts.props;
|
|
296
|
-
if (!props &&
|
|
205
|
+
if (!props && opts.buttons?.length) {
|
|
297
206
|
setInteractionSecret(accountId, client.token);
|
|
298
207
|
props = buildButtonProps({
|
|
299
208
|
callbackUrl: resolveInteractionCallbackUrl(accountId, {
|
|
300
209
|
gateway: cfg.gateway,
|
|
301
|
-
interactions:
|
|
302
|
-
cfg,
|
|
303
|
-
accountId
|
|
304
|
-
}).config?.interactions
|
|
210
|
+
interactions: account.config.interactions
|
|
305
211
|
}),
|
|
306
212
|
accountId,
|
|
307
213
|
channelId,
|
|
@@ -324,7 +230,7 @@ async function sendMessageMattermost(to, text, opts) {
|
|
|
324
230
|
channelId,
|
|
325
231
|
buffer: media.buffer,
|
|
326
232
|
fileName: media.fileName ?? `upload${extensionForMime(media.contentType) ?? ""}`,
|
|
327
|
-
contentType: media.contentType
|
|
233
|
+
contentType: media.contentType
|
|
328
234
|
})).id];
|
|
329
235
|
} catch (err) {
|
|
330
236
|
client.assertRequestCurrent?.();
|
|
@@ -366,11 +272,7 @@ async function sendMessageMattermost(to, text, opts) {
|
|
|
366
272
|
messageId,
|
|
367
273
|
channelId
|
|
368
274
|
}],
|
|
369
|
-
kind:
|
|
370
|
-
fileIds,
|
|
371
|
-
buttons: opts.buttons,
|
|
372
|
-
props
|
|
373
|
-
}),
|
|
275
|
+
kind: fileIds?.length ? "media" : opts.buttons?.length || props ? "card" : "text",
|
|
374
276
|
...opts.replyToId ? { replyToId: opts.replyToId } : {}
|
|
375
277
|
});
|
|
376
278
|
const result = {
|