@openclaw/mattermost 2026.7.2-beta.7 → 2026.7.33
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/{client-CqqzTcno.js → .setup/accounts-CkvUBI7I.mjs} +101 -55
- package/dist/.setup/channel-plugin-api-DQ6gNcH0.mjs +31 -0
- package/dist/.setup/channel-plugin-api-jFFWYXht.mjs +3 -0
- package/dist/{channel-plugin-runtime-DlrMaSIu.js → .setup/channel-plugin-runtime-BLOKRsgT.mjs} +260 -344
- package/dist/.setup/channel.runtime-CK6s04r7.mjs +2653 -0
- package/dist/.setup/doctor-contract-ttH0DCuq.mjs +7 -0
- package/dist/{gateway-auth-bypass-CL1PxV3z.js → .setup/gateway-auth-bypass-BIXLORHU.mjs} +2 -3
- package/dist/{monitor-auth-rctDliGZ.js → .setup/monitor-auth-CeakcTAO.mjs} +13 -14
- package/dist/.setup/secret-contract-Cx0LUNXy.mjs +44 -0
- package/dist/.setup/secret-contract-api-BLTnjVCZ.mjs +3 -0
- package/dist/{slash-state-DM8qmFJR.js → .setup/slash-state-D1e1_KaK.mjs} +572 -311
- package/dist/api.js +2 -3
- package/dist/channel-plugin-api.js +2 -38
- package/dist/channel-plugin-runtime.js +1 -1
- package/dist/doctor-contract-api.js +1 -1
- package/dist/gateway-auth-api.js +1 -1
- package/dist/policy-api.js +1 -1
- package/dist/runtime-api.js +3 -2
- package/dist/secret-contract-api.js +1 -1
- package/dist/setup-entry.js +3 -2
- package/dist/slash-route-api.js +1 -1
- package/node_modules/ws/lib/permessage-deflate.js +3 -1
- package/node_modules/ws/package.json +1 -1
- package/openclaw.plugin.json +231 -277
- package/package.json +6 -52
- package/dist/accounts-NaMdx9yF.js +0 -86
- package/dist/channel.runtime-DndW9G7T.js +0 -3207
- package/dist/doctor-contract-BaUvVh8e.js +0 -19
- package/dist/interactions-BQXY_48h.js +0 -375
- package/dist/secret-contract-B4R5Bmhv.js +0 -28
- /package/dist/{runtime-CNB4YGqJ.js → .setup/runtime-CNB4YGqJ.mjs} +0 -0
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { createLegacyPrivateNetworkDoctorContract } from "openclaw/plugin-sdk/ssrf-runtime";
|
|
2
|
-
import { defineChannelAliasMigration } from "openclaw/plugin-sdk/runtime-doctor";
|
|
3
|
-
//#region extensions/mattermost/src/doctor-contract.ts
|
|
4
|
-
const networkContract = createLegacyPrivateNetworkDoctorContract({ channelKey: "mattermost" });
|
|
5
|
-
const streamingAliasMigration = defineChannelAliasMigration({
|
|
6
|
-
channelId: "mattermost",
|
|
7
|
-
streaming: { defaultMode: "partial" },
|
|
8
|
-
accountStreamingReplacesRoot: true
|
|
9
|
-
});
|
|
10
|
-
const legacyConfigRules = [...networkContract.legacyConfigRules, ...streamingAliasMigration.legacyConfigRules];
|
|
11
|
-
function normalizeCompatibilityConfig({ cfg }) {
|
|
12
|
-
const network = networkContract.normalizeCompatibilityConfig({ cfg });
|
|
13
|
-
return streamingAliasMigration.normalizeChannelConfig({
|
|
14
|
-
cfg: network.config,
|
|
15
|
-
changes: network.changes
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
//#endregion
|
|
19
|
-
export { normalizeCompatibilityConfig as n, legacyConfigRules as t };
|
|
@@ -1,375 +0,0 @@
|
|
|
1
|
-
import { t as getMattermostRuntime } from "./runtime-CNB4YGqJ.js";
|
|
2
|
-
import { v as updateMattermostPost } from "./client-CqqzTcno.js";
|
|
3
|
-
import { b as readRequestBodyWithLimit, m as isTrustedProxyAddress, w as resolveClientIp } from "./monitor-auth-rctDliGZ.js";
|
|
4
|
-
import { createHmac } from "node:crypto";
|
|
5
|
-
import { safeEqualSecret } from "openclaw/plugin-sdk/security-runtime";
|
|
6
|
-
import { normalizeOptionalString, normalizeStringifiedOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
7
|
-
//#region extensions/mattermost/src/mattermost/interactions.ts
|
|
8
|
-
const INTERACTION_MAX_BODY_BYTES = 64 * 1024;
|
|
9
|
-
const INTERACTION_BODY_TIMEOUT_MS = 1e4;
|
|
10
|
-
const SIGNED_CHANNEL_ID_CONTEXT_KEY = "__openclaw_channel_id";
|
|
11
|
-
const callbackUrls = /* @__PURE__ */ new Map();
|
|
12
|
-
function setInteractionCallbackUrl(accountId, url) {
|
|
13
|
-
callbackUrls.set(accountId, url);
|
|
14
|
-
}
|
|
15
|
-
function resolveInteractionCallbackPath(accountId) {
|
|
16
|
-
return `/mattermost/interactions/${accountId}`;
|
|
17
|
-
}
|
|
18
|
-
function isWildcardBindHost(rawHost) {
|
|
19
|
-
const trimmed = rawHost.trim();
|
|
20
|
-
if (!trimmed) return false;
|
|
21
|
-
const host = trimmed.startsWith("[") && trimmed.endsWith("]") ? trimmed.slice(1, -1) : trimmed;
|
|
22
|
-
return host === "0.0.0.0" || host === "::" || host === "0:0:0:0:0:0:0:0" || host === "::0";
|
|
23
|
-
}
|
|
24
|
-
function normalizeCallbackBaseUrl(baseUrl) {
|
|
25
|
-
return baseUrl.trim().replace(/\/+$/, "");
|
|
26
|
-
}
|
|
27
|
-
function headerValue(value) {
|
|
28
|
-
if (Array.isArray(value)) return normalizeOptionalString(value[0]);
|
|
29
|
-
return normalizeOptionalString(value);
|
|
30
|
-
}
|
|
31
|
-
function isAllowedInteractionSource(params) {
|
|
32
|
-
const { allowedSourceIps } = params;
|
|
33
|
-
if (!allowedSourceIps?.length) return true;
|
|
34
|
-
return isTrustedProxyAddress(resolveClientIp({
|
|
35
|
-
remoteAddr: params.req.socket?.remoteAddress,
|
|
36
|
-
forwardedFor: headerValue(params.req.headers["x-forwarded-for"]),
|
|
37
|
-
realIp: headerValue(params.req.headers["x-real-ip"]),
|
|
38
|
-
trustedProxies: params.trustedProxies,
|
|
39
|
-
allowRealIpFallback: params.allowRealIpFallback
|
|
40
|
-
}), allowedSourceIps);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Resolve the interaction callback URL for an account.
|
|
44
|
-
* Falls back to computing it from interactions.callbackBaseUrl or gateway host config.
|
|
45
|
-
*/
|
|
46
|
-
function computeInteractionCallbackUrl(accountId, cfg) {
|
|
47
|
-
const path = resolveInteractionCallbackPath(accountId);
|
|
48
|
-
const callbackBaseUrl = normalizeOptionalString(cfg?.interactions?.callbackBaseUrl) ?? normalizeOptionalString(cfg?.channels?.mattermost?.interactions?.callbackBaseUrl);
|
|
49
|
-
if (callbackBaseUrl) return `${normalizeCallbackBaseUrl(callbackBaseUrl)}${path}`;
|
|
50
|
-
const port = typeof cfg?.gateway?.port === "number" ? cfg.gateway.port : 18789;
|
|
51
|
-
let host = cfg?.gateway?.customBindHost && !isWildcardBindHost(cfg.gateway.customBindHost) ? cfg.gateway.customBindHost.trim() : "localhost";
|
|
52
|
-
if (host.includes(":") && !(host.startsWith("[") && host.endsWith("]"))) host = `[${host}]`;
|
|
53
|
-
return `http://${host}:${port}${path}`;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Resolve the interaction callback URL for an account.
|
|
57
|
-
* Prefers the in-memory registered URL (set by the gateway monitor) so callers outside the
|
|
58
|
-
* monitor lifecycle can reuse the runtime-validated callback destination.
|
|
59
|
-
*/
|
|
60
|
-
function resolveInteractionCallbackUrl(accountId, cfg) {
|
|
61
|
-
const cached = callbackUrls.get(accountId);
|
|
62
|
-
if (cached) return cached;
|
|
63
|
-
return computeInteractionCallbackUrl(accountId, cfg);
|
|
64
|
-
}
|
|
65
|
-
const interactionSecrets = /* @__PURE__ */ new Map();
|
|
66
|
-
let defaultInteractionSecret;
|
|
67
|
-
function deriveInteractionSecret(botToken) {
|
|
68
|
-
return createHmac("sha256", "openclaw-mattermost-interactions").update(botToken).digest("hex");
|
|
69
|
-
}
|
|
70
|
-
function setInteractionSecret(accountIdOrBotToken, botToken) {
|
|
71
|
-
if (typeof botToken === "string") {
|
|
72
|
-
interactionSecrets.set(accountIdOrBotToken, deriveInteractionSecret(botToken));
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
defaultInteractionSecret = deriveInteractionSecret(accountIdOrBotToken);
|
|
76
|
-
}
|
|
77
|
-
function getInteractionSecret(accountId) {
|
|
78
|
-
const scoped = accountId ? interactionSecrets.get(accountId) : void 0;
|
|
79
|
-
if (scoped) return scoped;
|
|
80
|
-
if (defaultInteractionSecret) return defaultInteractionSecret;
|
|
81
|
-
if (interactionSecrets.size === 1) {
|
|
82
|
-
const first = interactionSecrets.values().next().value;
|
|
83
|
-
if (typeof first === "string") return first;
|
|
84
|
-
}
|
|
85
|
-
throw new Error("Interaction secret not initialized — call setInteractionSecret(accountId, botToken) first");
|
|
86
|
-
}
|
|
87
|
-
function canonicalizeInteractionContext(value) {
|
|
88
|
-
if (Array.isArray(value)) return value.map((item) => canonicalizeInteractionContext(item));
|
|
89
|
-
if (value && typeof value === "object") {
|
|
90
|
-
const entries = Object.entries(value).filter(([, entryValue]) => entryValue !== void 0).toSorted(([left], [right]) => left.localeCompare(right)).map(([key, entryValue]) => [key, canonicalizeInteractionContext(entryValue)]);
|
|
91
|
-
return Object.fromEntries(entries);
|
|
92
|
-
}
|
|
93
|
-
return value;
|
|
94
|
-
}
|
|
95
|
-
function generateInteractionToken(context, accountId) {
|
|
96
|
-
const secret = getInteractionSecret(accountId);
|
|
97
|
-
const payload = JSON.stringify(canonicalizeInteractionContext(context));
|
|
98
|
-
return createHmac("sha256", secret).update(payload).digest("hex");
|
|
99
|
-
}
|
|
100
|
-
function verifyInteractionToken(context, token, accountId) {
|
|
101
|
-
return safeEqualSecret(generateInteractionToken(context, accountId), token);
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Build Mattermost `props.attachments` with interactive buttons.
|
|
105
|
-
*
|
|
106
|
-
* Each button includes an HMAC token in its integration context so the
|
|
107
|
-
* callback handler can verify the request originated from a legitimate
|
|
108
|
-
* button click (Mattermost's recommended security pattern).
|
|
109
|
-
*/
|
|
110
|
-
/**
|
|
111
|
-
* Sanitize a button ID so Mattermost's action router can match it.
|
|
112
|
-
* Mattermost uses the action ID in the URL path `/api/v4/posts/{id}/actions/{actionId}`
|
|
113
|
-
* and IDs containing hyphens or underscores break the server-side routing.
|
|
114
|
-
* See: https://github.com/mattermost/mattermost/issues/25747
|
|
115
|
-
*/
|
|
116
|
-
function sanitizeActionId(id) {
|
|
117
|
-
return id.replace(/[-_]/g, "");
|
|
118
|
-
}
|
|
119
|
-
function buildButtonAttachments(params) {
|
|
120
|
-
const actions = params.buttons.map((btn) => {
|
|
121
|
-
const safeId = sanitizeActionId(btn.id);
|
|
122
|
-
const context = {
|
|
123
|
-
action_id: safeId,
|
|
124
|
-
...btn.context
|
|
125
|
-
};
|
|
126
|
-
const token = generateInteractionToken(context, params.accountId);
|
|
127
|
-
return {
|
|
128
|
-
id: safeId,
|
|
129
|
-
type: "button",
|
|
130
|
-
name: btn.name,
|
|
131
|
-
style: btn.style,
|
|
132
|
-
integration: {
|
|
133
|
-
url: params.callbackUrl,
|
|
134
|
-
context: {
|
|
135
|
-
...context,
|
|
136
|
-
_token: token
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
};
|
|
140
|
-
});
|
|
141
|
-
return [{
|
|
142
|
-
text: params.text ?? "",
|
|
143
|
-
actions
|
|
144
|
-
}];
|
|
145
|
-
}
|
|
146
|
-
function buildButtonProps(params) {
|
|
147
|
-
const buttons = params.buttons.flatMap((item) => Array.isArray(item) ? item : [item]).map((btn) => ({
|
|
148
|
-
id: normalizeStringifiedOptionalString(btn.id ?? btn.callback_data) ?? "",
|
|
149
|
-
name: normalizeStringifiedOptionalString(btn.text ?? btn.name ?? btn.label) ?? "",
|
|
150
|
-
style: btn.style ?? "default",
|
|
151
|
-
context: typeof btn.context === "object" && btn.context !== null ? {
|
|
152
|
-
...btn.context,
|
|
153
|
-
[SIGNED_CHANNEL_ID_CONTEXT_KEY]: params.channelId
|
|
154
|
-
} : { [SIGNED_CHANNEL_ID_CONTEXT_KEY]: params.channelId }
|
|
155
|
-
})).filter((btn) => btn.id && btn.name);
|
|
156
|
-
if (buttons.length === 0) return;
|
|
157
|
-
return { attachments: buildButtonAttachments({
|
|
158
|
-
callbackUrl: params.callbackUrl,
|
|
159
|
-
accountId: params.accountId,
|
|
160
|
-
buttons,
|
|
161
|
-
text: params.text
|
|
162
|
-
}) };
|
|
163
|
-
}
|
|
164
|
-
function readInteractionBody(req) {
|
|
165
|
-
return readRequestBodyWithLimit(req, {
|
|
166
|
-
maxBytes: INTERACTION_MAX_BODY_BYTES,
|
|
167
|
-
timeoutMs: INTERACTION_BODY_TIMEOUT_MS
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
function createMattermostInteractionHandler(params) {
|
|
171
|
-
const { client, accountId, log } = params;
|
|
172
|
-
const core = getMattermostRuntime();
|
|
173
|
-
function parseInteractionPayload(raw) {
|
|
174
|
-
try {
|
|
175
|
-
return JSON.parse(raw);
|
|
176
|
-
} catch {
|
|
177
|
-
throw new Error("Mattermost interaction body was malformed JSON");
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return async (req, res) => {
|
|
181
|
-
if (req.method !== "POST") {
|
|
182
|
-
res.statusCode = 405;
|
|
183
|
-
res.setHeader("Allow", "POST");
|
|
184
|
-
res.setHeader("Content-Type", "application/json");
|
|
185
|
-
res.end(JSON.stringify({ error: "Method Not Allowed" }));
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
if (!isAllowedInteractionSource({
|
|
189
|
-
req,
|
|
190
|
-
allowedSourceIps: params.allowedSourceIps,
|
|
191
|
-
trustedProxies: params.trustedProxies,
|
|
192
|
-
allowRealIpFallback: params.allowRealIpFallback
|
|
193
|
-
})) {
|
|
194
|
-
log?.(`mattermost interaction: rejected callback source remote=${req.socket?.remoteAddress ?? "?"}`);
|
|
195
|
-
res.statusCode = 403;
|
|
196
|
-
res.setHeader("Content-Type", "application/json");
|
|
197
|
-
res.end(JSON.stringify({ error: "Forbidden origin" }));
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
let payload;
|
|
201
|
-
try {
|
|
202
|
-
payload = parseInteractionPayload(await readInteractionBody(req));
|
|
203
|
-
} catch (err) {
|
|
204
|
-
log?.(`mattermost interaction: failed to parse body: ${String(err)}`);
|
|
205
|
-
res.statusCode = 400;
|
|
206
|
-
res.setHeader("Content-Type", "application/json");
|
|
207
|
-
res.end(JSON.stringify({ error: "Invalid request body" }));
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
const context = payload.context;
|
|
211
|
-
if (!context) {
|
|
212
|
-
res.statusCode = 400;
|
|
213
|
-
res.setHeader("Content-Type", "application/json");
|
|
214
|
-
res.end(JSON.stringify({ error: "Missing context" }));
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
const token = context["_token"];
|
|
218
|
-
if (typeof token !== "string") {
|
|
219
|
-
log?.("mattermost interaction: missing _token in context");
|
|
220
|
-
res.statusCode = 403;
|
|
221
|
-
res.setHeader("Content-Type", "application/json");
|
|
222
|
-
res.end(JSON.stringify({ error: "Missing token" }));
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
const { _token, ...contextWithoutToken } = context;
|
|
226
|
-
if (!verifyInteractionToken(contextWithoutToken, token, accountId)) {
|
|
227
|
-
log?.("mattermost interaction: invalid _token");
|
|
228
|
-
res.statusCode = 403;
|
|
229
|
-
res.setHeader("Content-Type", "application/json");
|
|
230
|
-
res.end(JSON.stringify({ error: "Invalid token" }));
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
const actionId = context.action_id;
|
|
234
|
-
if (typeof actionId !== "string") {
|
|
235
|
-
res.statusCode = 400;
|
|
236
|
-
res.setHeader("Content-Type", "application/json");
|
|
237
|
-
res.end(JSON.stringify({ error: "Missing action_id in context" }));
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
const signedChannelId = typeof contextWithoutToken[SIGNED_CHANNEL_ID_CONTEXT_KEY] === "string" ? contextWithoutToken[SIGNED_CHANNEL_ID_CONTEXT_KEY].trim() : "";
|
|
241
|
-
if (signedChannelId && signedChannelId !== payload.channel_id) {
|
|
242
|
-
log?.(`mattermost interaction: signed channel mismatch payload=${payload.channel_id} signed=${signedChannelId}`);
|
|
243
|
-
res.statusCode = 403;
|
|
244
|
-
res.setHeader("Content-Type", "application/json");
|
|
245
|
-
res.end(JSON.stringify({ error: "Channel mismatch" }));
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
const userName = payload.user_name ?? payload.user_id;
|
|
249
|
-
let originalMessage;
|
|
250
|
-
let originalPost;
|
|
251
|
-
let clickedButtonName = null;
|
|
252
|
-
try {
|
|
253
|
-
originalPost = await client.request(`/posts/${payload.post_id}`);
|
|
254
|
-
const postChannelId = originalPost.channel_id?.trim();
|
|
255
|
-
if (!postChannelId || postChannelId !== payload.channel_id) {
|
|
256
|
-
log?.(`mattermost interaction: post channel mismatch payload=${payload.channel_id} post=${postChannelId ?? "<missing>"}`);
|
|
257
|
-
res.statusCode = 403;
|
|
258
|
-
res.setHeader("Content-Type", "application/json");
|
|
259
|
-
res.end(JSON.stringify({ error: "Post/channel mismatch" }));
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
originalMessage = originalPost.message ?? "";
|
|
263
|
-
const postAttachments = Array.isArray(originalPost?.props?.attachments) ? originalPost.props.attachments : [];
|
|
264
|
-
for (const att of postAttachments) {
|
|
265
|
-
const match = att.actions?.find((a) => a.id === actionId);
|
|
266
|
-
if (match?.name) {
|
|
267
|
-
clickedButtonName = match.name;
|
|
268
|
-
break;
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
if (clickedButtonName === null) {
|
|
272
|
-
log?.(`mattermost interaction: action ${actionId} not found in post ${payload.post_id}`);
|
|
273
|
-
res.statusCode = 403;
|
|
274
|
-
res.setHeader("Content-Type", "application/json");
|
|
275
|
-
res.end(JSON.stringify({ error: "Unknown action" }));
|
|
276
|
-
return;
|
|
277
|
-
}
|
|
278
|
-
} catch (err) {
|
|
279
|
-
log?.(`mattermost interaction: failed to validate post ${payload.post_id}: ${String(err)}`);
|
|
280
|
-
res.statusCode = 500;
|
|
281
|
-
res.setHeader("Content-Type", "application/json");
|
|
282
|
-
res.end(JSON.stringify({ error: "Failed to validate interaction" }));
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
285
|
-
if (!originalPost) {
|
|
286
|
-
log?.(`mattermost interaction: missing fetched post ${payload.post_id}`);
|
|
287
|
-
res.statusCode = 500;
|
|
288
|
-
res.setHeader("Content-Type", "application/json");
|
|
289
|
-
res.end(JSON.stringify({ error: "Failed to load interaction post" }));
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
292
|
-
log?.(`mattermost interaction: action=${actionId} user=${payload.user_name ?? payload.user_id} post=${payload.post_id} channel=${payload.channel_id}`);
|
|
293
|
-
if (params.authorizeButtonClick) try {
|
|
294
|
-
const authorization = await params.authorizeButtonClick({
|
|
295
|
-
payload,
|
|
296
|
-
post: originalPost
|
|
297
|
-
});
|
|
298
|
-
if (!authorization.ok) {
|
|
299
|
-
res.statusCode = authorization.statusCode ?? 200;
|
|
300
|
-
res.setHeader("Content-Type", "application/json");
|
|
301
|
-
res.end(JSON.stringify(authorization.response ?? { ephemeral_text: "You are not allowed to use this action here." }));
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
} catch (err) {
|
|
305
|
-
log?.(`mattermost interaction: authorization failed: ${String(err)}`);
|
|
306
|
-
res.statusCode = 500;
|
|
307
|
-
res.setHeader("Content-Type", "application/json");
|
|
308
|
-
res.end(JSON.stringify({ error: "Interaction authorization failed" }));
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
if (params.handleInteraction) try {
|
|
312
|
-
const response = await params.handleInteraction({
|
|
313
|
-
payload,
|
|
314
|
-
userName,
|
|
315
|
-
actionId,
|
|
316
|
-
actionName: clickedButtonName,
|
|
317
|
-
originalMessage,
|
|
318
|
-
context: contextWithoutToken,
|
|
319
|
-
post: originalPost
|
|
320
|
-
});
|
|
321
|
-
if (response !== null) {
|
|
322
|
-
res.statusCode = 200;
|
|
323
|
-
res.setHeader("Content-Type", "application/json");
|
|
324
|
-
res.end(JSON.stringify(response));
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
} catch (err) {
|
|
328
|
-
log?.(`mattermost interaction: custom handler failed: ${String(err)}`);
|
|
329
|
-
res.statusCode = 500;
|
|
330
|
-
res.setHeader("Content-Type", "application/json");
|
|
331
|
-
res.end(JSON.stringify({ error: "Interaction handler failed" }));
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
try {
|
|
335
|
-
const eventLabel = `Mattermost button click: action="${actionId}" by ${payload.user_name ?? payload.user_id} in channel ${payload.channel_id}`;
|
|
336
|
-
const sessionKey = params.resolveSessionKey ? await params.resolveSessionKey({
|
|
337
|
-
channelId: payload.channel_id,
|
|
338
|
-
userId: payload.user_id,
|
|
339
|
-
post: originalPost
|
|
340
|
-
}) : `agent:main:mattermost:${accountId}:${payload.channel_id}`;
|
|
341
|
-
core.system.enqueueSystemEvent(eventLabel, {
|
|
342
|
-
sessionKey,
|
|
343
|
-
contextKey: `mattermost:interaction:${payload.post_id}:${actionId}`
|
|
344
|
-
});
|
|
345
|
-
} catch (err) {
|
|
346
|
-
log?.(`mattermost interaction: system event dispatch failed: ${String(err)}`);
|
|
347
|
-
}
|
|
348
|
-
try {
|
|
349
|
-
await updateMattermostPost(client, payload.post_id, {
|
|
350
|
-
message: originalMessage,
|
|
351
|
-
props: { attachments: [{ text: `✓ **${clickedButtonName}** selected by @${userName}` }] }
|
|
352
|
-
});
|
|
353
|
-
} catch (err) {
|
|
354
|
-
log?.(`mattermost interaction: failed to update post ${payload.post_id}: ${String(err)}`);
|
|
355
|
-
}
|
|
356
|
-
res.statusCode = 200;
|
|
357
|
-
res.setHeader("Content-Type", "application/json");
|
|
358
|
-
res.end("{}");
|
|
359
|
-
if (params.dispatchButtonClick) try {
|
|
360
|
-
await params.dispatchButtonClick({
|
|
361
|
-
channelId: payload.channel_id,
|
|
362
|
-
userId: payload.user_id,
|
|
363
|
-
userName,
|
|
364
|
-
actionId,
|
|
365
|
-
actionName: clickedButtonName,
|
|
366
|
-
postId: payload.post_id,
|
|
367
|
-
post: originalPost
|
|
368
|
-
});
|
|
369
|
-
} catch (err) {
|
|
370
|
-
log?.(`mattermost interaction: dispatchButtonClick failed: ${String(err)}`);
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
//#endregion
|
|
375
|
-
export { resolveInteractionCallbackPath as a, setInteractionSecret as c, createMattermostInteractionHandler as i, buildButtonProps as n, resolveInteractionCallbackUrl as o, computeInteractionCallbackUrl as r, setInteractionCallbackUrl as s, buildButtonAttachments as t };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { collectSimpleChannelFieldAssignments, createChannelSecretTargetRegistryEntries, getChannelSurface } from "openclaw/plugin-sdk/channel-secret-basic-runtime";
|
|
2
|
-
//#region extensions/mattermost/src/secret-contract.ts
|
|
3
|
-
const secretTargetRegistryEntries = createChannelSecretTargetRegistryEntries({
|
|
4
|
-
channelKey: "mattermost",
|
|
5
|
-
account: ["botToken"],
|
|
6
|
-
channel: ["botToken"]
|
|
7
|
-
});
|
|
8
|
-
function collectRuntimeConfigAssignments(params) {
|
|
9
|
-
const resolved = getChannelSurface(params.config, "mattermost");
|
|
10
|
-
if (!resolved) return;
|
|
11
|
-
const { channel: mattermost, surface } = resolved;
|
|
12
|
-
collectSimpleChannelFieldAssignments({
|
|
13
|
-
channelKey: "mattermost",
|
|
14
|
-
field: "botToken",
|
|
15
|
-
channel: mattermost,
|
|
16
|
-
surface,
|
|
17
|
-
defaults: params.defaults,
|
|
18
|
-
context: params.context,
|
|
19
|
-
topInactiveReason: "no enabled account inherits this top-level Mattermost botToken.",
|
|
20
|
-
accountInactiveReason: "Mattermost account is disabled."
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
const channelSecrets = {
|
|
24
|
-
secretTargetRegistryEntries,
|
|
25
|
-
collectRuntimeConfigAssignments
|
|
26
|
-
};
|
|
27
|
-
//#endregion
|
|
28
|
-
export { collectRuntimeConfigAssignments as n, secretTargetRegistryEntries as r, channelSecrets as t };
|
|
File without changes
|