@openclaw/mattermost 2026.10.10 → 2026.11.5-beta.1
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-C5kL5jd0.mjs +1 -0
- package/dist/.setup/{channel-plugin-runtime-CLBgUA35.mjs → channel-plugin-api-CC8EU4bs.mjs} +147 -130
- package/dist/.setup/{channel.runtime-BBMzxlPB.mjs → channel.runtime-ukouI9k4.mjs} +37 -37
- package/dist/.setup/{client-VHp4VYIf.mjs → client-CVipK0N2.mjs} +11 -84
- package/dist/.setup/{interactions-7eWssSf1.mjs → interactions-cgV9-piH.mjs} +23 -36
- package/dist/.setup/{monitor-agLGA4lV.mjs → monitor-Bn-I4iu7.mjs} +292 -398
- package/dist/.setup/{monitor-auth-0gZXtoHv.mjs → monitor-auth-D7Fl9CyF.mjs} +5 -11
- package/dist/.setup/{normalize-C_DYEHki.mjs → normalize-DuLSV4tT.mjs} +21 -7
- package/dist/.setup/secret-contract-BkDCURCE.mjs +19 -0
- package/dist/.setup/{secret-contract-api-CmBND3cW.mjs → secret-contract-api-DydsmAPQ.mjs} +1 -1
- package/dist/.setup/{send-3ye1gFt3.mjs → send-CoWXMKnY.mjs} +100 -198
- package/dist/.setup/{slash-state-V13EaHX9.mjs → slash-state-CwLVacYg.mjs} +361 -408
- package/dist/.source-module-urls/8fb0cb1067b83fd2cf3f3ba0f7a23e627c27e8e3adf1a4ea18753ddb884ff71e.json +1 -0
- package/dist/api.js +2 -2
- package/dist/channel-plugin-api.js +1 -1
- package/dist/policy-api.js +1 -1
- package/dist/secret-contract-api.js +1 -1
- package/dist/setup-entry.js +2 -2
- package/dist/slash-route-api.js +1 -1
- 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-Vq9imWd1.mjs +0 -2
- package/dist/.setup/secret-contract-H9g0kHHQ.mjs +0 -11
- package/dist/.source-module-urls/9b327bbbce22c2cbef393c115f9a63999afd57e223aad992389710cb3f1e29cc.json +0 -1
- package/dist/channel-plugin-runtime.js +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { t as getMattermostRuntime } from "./runtime-y_L8jPMH.mjs";
|
|
2
2
|
import { n as normalizeMattermostAllowEntry, t as mattermostIngressIdentity } from "./ingress-identity-CtHiOUDu.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
|
// 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-CVipK0N2.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
|
// 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,
|
|
@@ -184,4 +198,4 @@ function looksLikeMattermostTargetId(raw, _normalized) {
|
|
|
184
198
|
if (trimmed.startsWith("@")) return true;
|
|
185
199
|
return /^[a-z0-9]{26}$/i.test(trimmed) || /^[a-z0-9]{26}__[a-z0-9]{26}$/i.test(trimmed);
|
|
186
200
|
}
|
|
187
|
-
export { resolveMattermostPresentation as a,
|
|
201
|
+
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 };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { hasConfiguredAccountValue } from "openclaw/plugin-sdk/account-helpers";
|
|
2
|
+
import { collectSimpleChannelFieldAssignments, createChannelSecretContract } from "openclaw/plugin-sdk/channel-secret-basic-runtime";
|
|
3
|
+
// extensions/mattermost/src/secret-contract.ts
|
|
4
|
+
const channelSecrets = createChannelSecretContract({
|
|
5
|
+
channelKey: "mattermost",
|
|
6
|
+
account: ["botToken"],
|
|
7
|
+
channel: ["botToken"],
|
|
8
|
+
hasImplicitDefaultAccount: ({ channel, context }) => Boolean(typeof channel.baseUrl === "string" && channel.baseUrl.trim() && (hasConfiguredAccountValue(channel.botToken) || context.env.MATTERMOST_BOT_TOKEN?.trim())),
|
|
9
|
+
collect(params) {
|
|
10
|
+
collectSimpleChannelFieldAssignments({
|
|
11
|
+
...params,
|
|
12
|
+
field: "botToken",
|
|
13
|
+
topInactiveReason: "no enabled account inherits this top-level Mattermost botToken.",
|
|
14
|
+
accountInactiveReason: "Mattermost account is disabled."
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const { secretTargetRegistryEntries, collectRuntimeConfigAssignments } = channelSecrets;
|
|
19
|
+
export { collectRuntimeConfigAssignments as n, secretTargetRegistryEntries as r, channelSecrets as t };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { t as channelSecrets, n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries } from "./secret-contract-
|
|
1
|
+
export { t as channelSecrets, n as collectRuntimeConfigAssignments, r as secretTargetRegistryEntries } from "./secret-contract-BkDCURCE.mjs";
|
|
2
2
|
import "../secret-contract-api.js";
|
|
@@ -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-cgV9-piH.mjs";
|
|
2
2
|
import { n as getOptionalMattermostRuntime, t as getMattermostRuntime } from "./runtime-y_L8jPMH.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-CVipK0N2.mjs";
|
|
4
|
+
import { s as resolveMattermostTrustedChatKind, v as loadOutboundMediaFromUrl } from "./monitor-auth-D7Fl9CyF.mjs";
|
|
5
|
+
import { d as resolveMattermostAccount, o as createMattermostAccountClient } from "./normalize-DuLSV4tT.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
|
// 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
|
// extensions/mattermost/src/mattermost/send.ts
|
|
159
110
|
const MATTERMOST_BOT_USER_CACHE_MAX_ENTRIES = 64;
|
|
@@ -167,73 +118,10 @@ function cacheOutboundEntry(cache, key, value, maxEntries) {
|
|
|
167
118
|
cache.set(key, value);
|
|
168
119
|
pruneMapToMaxSize(cache, maxEntries);
|
|
169
120
|
}
|
|
170
|
-
function resolveMattermostReceiptKind(params) {
|
|
171
|
-
if (params.fileIds?.length) return "media";
|
|
172
|
-
if (params.buttons?.length || params.props) return "card";
|
|
173
|
-
return "text";
|
|
174
|
-
}
|
|
175
121
|
function cacheKey(baseUrl, token) {
|
|
176
122
|
return `${baseUrl}::${token}`;
|
|
177
123
|
}
|
|
178
|
-
async function
|
|
179
|
-
const key = cacheKey(client.baseUrl, client.token);
|
|
180
|
-
const cached = botUserCache.get(key);
|
|
181
|
-
if (cached) return cached;
|
|
182
|
-
const user = await fetchMattermostMe(client);
|
|
183
|
-
cacheOutboundEntry(botUserCache, key, user, MATTERMOST_BOT_USER_CACHE_MAX_ENTRIES);
|
|
184
|
-
return user;
|
|
185
|
-
}
|
|
186
|
-
async function resolveUserIdByUsername(params) {
|
|
187
|
-
const { client, username } = params;
|
|
188
|
-
const key = `${cacheKey(client.baseUrl, client.token)}::${normalizeLowercaseStringOrEmpty(username)}`;
|
|
189
|
-
const cached = userByNameCache.get(key);
|
|
190
|
-
if (cached?.id) return cached.id;
|
|
191
|
-
const user = await fetchMattermostUserByUsername(client, username);
|
|
192
|
-
cacheOutboundEntry(userByNameCache, key, user, MATTERMOST_TARGET_CACHE_MAX_ENTRIES);
|
|
193
|
-
return user.id;
|
|
194
|
-
}
|
|
195
|
-
async function resolveChannelIdByName(params) {
|
|
196
|
-
const { client, name } = params;
|
|
197
|
-
const key = `${cacheKey(client.baseUrl, client.token)}::channel::${normalizeLowercaseStringOrEmpty(name)}`;
|
|
198
|
-
const cached = channelByNameCache.get(key);
|
|
199
|
-
if (cached) return cached;
|
|
200
|
-
const me = await fetchMattermostMe(client);
|
|
201
|
-
const teams = await fetchMattermostUserTeams(client, me.id);
|
|
202
|
-
for (const team of teams) try {
|
|
203
|
-
const channel = await fetchMattermostChannelByName(client, team.id, name);
|
|
204
|
-
if (channel?.id) {
|
|
205
|
-
cacheOutboundEntry(channelByNameCache, key, channel.id, MATTERMOST_TARGET_CACHE_MAX_ENTRIES);
|
|
206
|
-
return channel.id;
|
|
207
|
-
}
|
|
208
|
-
} catch (error) {
|
|
209
|
-
if (parseMattermostApiStatus(error) !== 404) throw error;
|
|
210
|
-
}
|
|
211
|
-
throw new Error(`Mattermost channel "#${name}" not found in any team the bot belongs to`);
|
|
212
|
-
}
|
|
213
|
-
async function resolveTargetChannelId(params) {
|
|
214
|
-
if (params.target.kind === "channel") return params.target.id;
|
|
215
|
-
if (params.target.kind === "channel-name") return await resolveChannelIdByName({
|
|
216
|
-
client: params.client,
|
|
217
|
-
name: params.target.name
|
|
218
|
-
});
|
|
219
|
-
const userId = params.target.id ? params.target.id : await resolveUserIdByUsername({
|
|
220
|
-
client: params.client,
|
|
221
|
-
username: params.target.username ?? ""
|
|
222
|
-
});
|
|
223
|
-
const dmKey = `${cacheKey(params.client.baseUrl, params.client.token)}::dm::${userId}`;
|
|
224
|
-
const cachedDm = dmChannelCache.get(dmKey);
|
|
225
|
-
if (cachedDm) return cachedDm;
|
|
226
|
-
const botUser = await resolveBotUser(params.client);
|
|
227
|
-
const channel = await createMattermostDirectChannelWithRetry(params.client, [botUser.id, userId], {
|
|
228
|
-
...params.dmRetryOptions,
|
|
229
|
-
onRetry: (attempt, delayMs, error) => {
|
|
230
|
-
params.logger?.warn?.(`DM channel creation retry ${attempt} after ${delayMs}ms: ${error.message}`);
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
cacheOutboundEntry(dmChannelCache, dmKey, channel.id, MATTERMOST_TARGET_CACHE_MAX_ENTRIES);
|
|
234
|
-
return channel.id;
|
|
235
|
-
}
|
|
236
|
-
async function resolveMattermostSendContext(to, opts) {
|
|
124
|
+
async function sendMessageMattermost(to, text, opts) {
|
|
237
125
|
const core = getMattermostRuntime();
|
|
238
126
|
const logger = core.logging.getChildLogger({ module: "mattermost" });
|
|
239
127
|
const cfg = requireRuntimeConfig(opts?.cfg, "Mattermost send");
|
|
@@ -241,66 +129,84 @@ async function resolveMattermostSendContext(to, opts) {
|
|
|
241
129
|
cfg,
|
|
242
130
|
accountId: opts.accountId
|
|
243
131
|
});
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
const baseUrl = normalizeMattermostBaseUrl(opts.baseUrl ?? account.baseUrl);
|
|
247
|
-
if (!baseUrl) throw new Error(`Mattermost baseUrl missing for account "${account.accountId}" (set channels.mattermost.accounts.${account.accountId}.baseUrl or MATTERMOST_URL for default).`);
|
|
248
|
-
const client = createMattermostClient({
|
|
249
|
-
baseUrl,
|
|
250
|
-
botToken: token,
|
|
251
|
-
allowPrivateNetwork: account.config.network?.dangerouslyAllowPrivateNetwork === true,
|
|
252
|
-
assertRequestCurrent: opts.assertDirectAdapterHandoff
|
|
253
|
-
});
|
|
254
|
-
const retry = account.config.dmChannelRetry;
|
|
255
|
-
const dmRetryOptions = retry && {
|
|
256
|
-
maxRetries: retry.maxRetries,
|
|
257
|
-
initialDelayMs: retry.initialDelayMs,
|
|
258
|
-
maxDelayMs: retry.maxDelayMs,
|
|
259
|
-
timeoutMs: retry.timeoutMs
|
|
260
|
-
};
|
|
132
|
+
const { client } = createMattermostAccountClient(account, opts, opts.assertDirectAdapterHandoff);
|
|
133
|
+
const dmRetryOptions = account.config.dmChannelRetry;
|
|
261
134
|
let channelId;
|
|
262
135
|
try {
|
|
263
136
|
const trimmedTo = normalizeOptionalString(to) ?? "";
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
137
|
+
const target = parseMattermostTarget((await resolveMattermostOpaqueTarget({
|
|
138
|
+
input: trimmedTo,
|
|
139
|
+
client
|
|
140
|
+
}))?.to ?? trimmedTo);
|
|
141
|
+
const targetLogger = core.logging.shouldLogVerbose() ? logger : void 0;
|
|
142
|
+
channelId = await (async () => {
|
|
143
|
+
if (target.kind === "channel") return target.id;
|
|
144
|
+
if (target.kind === "channel-name") {
|
|
145
|
+
const name = target.name;
|
|
146
|
+
const key = `${cacheKey(client.baseUrl, client.token)}::channel::${normalizeLowercaseStringOrEmpty(name)}`;
|
|
147
|
+
const cached = channelByNameCache.get(key);
|
|
148
|
+
if (cached) return cached;
|
|
149
|
+
const me = await fetchMattermostMe(client);
|
|
150
|
+
const teams = await fetchMattermostUserTeams(client, me.id);
|
|
151
|
+
for (const team of teams) try {
|
|
152
|
+
const channel = await fetchMattermostChannelByName(client, team.id, name);
|
|
153
|
+
if (channel?.id) {
|
|
154
|
+
cacheOutboundEntry(channelByNameCache, key, channel.id, MATTERMOST_TARGET_CACHE_MAX_ENTRIES);
|
|
155
|
+
return channel.id;
|
|
156
|
+
}
|
|
157
|
+
} catch (error) {
|
|
158
|
+
if (parseMattermostApiStatus(error) !== 404) throw error;
|
|
159
|
+
}
|
|
160
|
+
throw new Error(`Mattermost channel "#${name}" not found in any team the bot belongs to`);
|
|
161
|
+
}
|
|
162
|
+
let userId = target.id;
|
|
163
|
+
if (!userId) {
|
|
164
|
+
const username = target.username ?? "";
|
|
165
|
+
const key = `${cacheKey(client.baseUrl, client.token)}::${normalizeLowercaseStringOrEmpty(username)}`;
|
|
166
|
+
const cached = userByNameCache.get(key);
|
|
167
|
+
if (cached?.id) userId = cached.id;
|
|
168
|
+
else {
|
|
169
|
+
const user = await fetchMattermostUserByUsername(client, username);
|
|
170
|
+
cacheOutboundEntry(userByNameCache, key, user, MATTERMOST_TARGET_CACHE_MAX_ENTRIES);
|
|
171
|
+
userId = user.id;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const dmKey = `${cacheKey(client.baseUrl, client.token)}::dm::${userId}`;
|
|
175
|
+
const cachedDm = dmChannelCache.get(dmKey);
|
|
176
|
+
if (cachedDm) return cachedDm;
|
|
177
|
+
const botKey = cacheKey(client.baseUrl, client.token);
|
|
178
|
+
let botUser = botUserCache.get(botKey);
|
|
179
|
+
if (!botUser) {
|
|
180
|
+
botUser = await fetchMattermostMe(client);
|
|
181
|
+
cacheOutboundEntry(botUserCache, botKey, botUser, MATTERMOST_BOT_USER_CACHE_MAX_ENTRIES);
|
|
182
|
+
}
|
|
183
|
+
const channel = await createMattermostDirectChannelWithRetry(client, [botUser.id, userId], {
|
|
184
|
+
...dmRetryOptions,
|
|
185
|
+
onRetry: (attempt, delayMs, error) => {
|
|
186
|
+
targetLogger?.warn?.(`DM channel creation retry ${attempt} after ${delayMs}ms: ${error.message}`);
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
cacheOutboundEntry(dmChannelCache, dmKey, channel.id, MATTERMOST_TARGET_CACHE_MAX_ENTRIES);
|
|
190
|
+
return channel.id;
|
|
191
|
+
})();
|
|
273
192
|
} catch (error) {
|
|
274
193
|
client.assertRequestCurrent?.();
|
|
275
194
|
throw error;
|
|
276
195
|
}
|
|
277
|
-
|
|
196
|
+
const accountId = account.accountId;
|
|
197
|
+
const mediaMaxBytes = resolveChannelMediaMaxBytes({
|
|
278
198
|
cfg,
|
|
279
199
|
accountId: account.accountId,
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
mediaMaxBytes: resolveChannelMediaMaxBytes({
|
|
283
|
-
cfg,
|
|
284
|
-
accountId: account.accountId,
|
|
285
|
-
resolveChannelLimitMb: () => account.config.mediaMaxMb
|
|
286
|
-
})
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
async function sendMessageMattermost(to, text, opts) {
|
|
290
|
-
const core = getMattermostRuntime();
|
|
291
|
-
const logger = core.logging.getChildLogger({ module: "mattermost" });
|
|
292
|
-
const { cfg, accountId, client, channelId, mediaMaxBytes } = await resolveMattermostSendContext(to, opts);
|
|
200
|
+
resolveChannelLimitMb: () => account.config.mediaMaxMb
|
|
201
|
+
});
|
|
293
202
|
client.assertRequestCurrent?.();
|
|
294
203
|
let props = opts.props;
|
|
295
|
-
if (!props &&
|
|
204
|
+
if (!props && opts.buttons?.length) {
|
|
296
205
|
setInteractionSecret(accountId, client.token);
|
|
297
206
|
props = buildButtonProps({
|
|
298
207
|
callbackUrl: resolveInteractionCallbackUrl(accountId, {
|
|
299
208
|
gateway: cfg.gateway,
|
|
300
|
-
interactions:
|
|
301
|
-
cfg,
|
|
302
|
-
accountId
|
|
303
|
-
}).config?.interactions
|
|
209
|
+
interactions: account.config.interactions
|
|
304
210
|
}),
|
|
305
211
|
accountId,
|
|
306
212
|
channelId,
|
|
@@ -323,7 +229,7 @@ async function sendMessageMattermost(to, text, opts) {
|
|
|
323
229
|
channelId,
|
|
324
230
|
buffer: media.buffer,
|
|
325
231
|
fileName: media.fileName ?? `upload${extensionForMime(media.contentType) ?? ""}`,
|
|
326
|
-
contentType: media.contentType
|
|
232
|
+
contentType: media.contentType
|
|
327
233
|
})).id];
|
|
328
234
|
} catch (err) {
|
|
329
235
|
client.assertRequestCurrent?.();
|
|
@@ -365,11 +271,7 @@ async function sendMessageMattermost(to, text, opts) {
|
|
|
365
271
|
messageId,
|
|
366
272
|
channelId
|
|
367
273
|
}],
|
|
368
|
-
kind:
|
|
369
|
-
fileIds,
|
|
370
|
-
buttons: opts.buttons,
|
|
371
|
-
props
|
|
372
|
-
}),
|
|
274
|
+
kind: fileIds?.length ? "media" : opts.buttons?.length || props ? "card" : "text",
|
|
373
275
|
...opts.replyToId ? { replyToId: opts.replyToId } : {}
|
|
374
276
|
});
|
|
375
277
|
const result = {
|