@openclaw/slack 2026.5.12-beta.7
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/account-inspect-D7AZNs8C.js +77 -0
- package/dist/account-inspect-api.js +10 -0
- package/dist/accounts-ClAPP5ry.js +139 -0
- package/dist/accounts.runtime-DDVcLJUI.js +2 -0
- package/dist/action-runtime-e2UhRsNx.js +350 -0
- package/dist/action-runtime.runtime-BFcqMbOm.js +2 -0
- package/dist/actions-CYLFK-Zy.js +292 -0
- package/dist/actions.runtime-CO3OaTLb.js +2 -0
- package/dist/allow-list-BPnnlRPL.js +82 -0
- package/dist/api.js +21 -0
- package/dist/approval-handler.runtime-CmeRr9qA.js +256 -0
- package/dist/blocks-input-CwTFVImV.js +29 -0
- package/dist/blocks-render-BIDw-Pom.js +161 -0
- package/dist/channel-DRjHBTDB.js +1020 -0
- package/dist/channel-api-B_nZwosg.js +20 -0
- package/dist/channel-config-api.js +2 -0
- package/dist/channel-entry.js +22 -0
- package/dist/channel-plugin-api.js +2 -0
- package/dist/channel.setup-Cayn7afd.js +73 -0
- package/dist/client-CPe4GmDR.js +103 -0
- package/dist/config-api-B_jq4NJW.js +2 -0
- package/dist/config-schema-D9B5LB_L.js +167 -0
- package/dist/configured-state.js +11 -0
- package/dist/contract-api.js +5 -0
- package/dist/directory-config-B3JiHeB7.js +54 -0
- package/dist/directory-contract-api.js +2 -0
- package/dist/directory-live-Bf16GwDh.js +133 -0
- package/dist/doctor-contract-KUjHnkQm.js +147 -0
- package/dist/doctor-contract-api.js +2 -0
- package/dist/errors-BYFHR24f.js +109 -0
- package/dist/exec-approvals-7xUNgLi9.js +58 -0
- package/dist/group-policy-CyLUK6My.js +41 -0
- package/dist/http-routes-api.js +2 -0
- package/dist/inbound-contract-test-api.js +3 -0
- package/dist/index.js +33 -0
- package/dist/interactive-replies-api.js +2 -0
- package/dist/interactive-replies-qAIfuBor.js +173 -0
- package/dist/magic-string.es-BMaGRRZ1.js +1011 -0
- package/dist/media-D1XCd1uP.js +469 -0
- package/dist/message-tool-api-6lowf9zE.js +104 -0
- package/dist/message-tool-api.js +2 -0
- package/dist/monitor-a97o17G6.js +13 -0
- package/dist/mrkdwn-Cax-eSfK.js +6 -0
- package/dist/outbound-adapter-B_5sEhCg.js +174 -0
- package/dist/outbound-payload-test-api.js +2 -0
- package/dist/outbound-payload.test-harness-CVCamg1x.js +13558 -0
- package/dist/pipeline.runtime-DT0hLnq2.js +1379 -0
- package/dist/plugin-routes-DtTPmga1.js +20 -0
- package/dist/prepare-D3YqV8jB.js +1482 -0
- package/dist/prepare.test-helpers-DVcjRhfG.js +49 -0
- package/dist/probe-3eZf1FjI.js +42 -0
- package/dist/provider-D7uAN3Fq.js +3235 -0
- package/dist/registry-CeaoNfoP.js +39 -0
- package/dist/replies-Xe_jMR6o.js +139 -0
- package/dist/reply-blocks-Z5l6_R6H.js +14 -0
- package/dist/resolve-allowlist-common-Bk3clYPK.js +43 -0
- package/dist/resolve-channels-BRYqyNVJ.js +81 -0
- package/dist/resolve-users-Bd_SdP8j.js +113 -0
- package/dist/rolldown-runtime-CiIaOW0V.js +13 -0
- package/dist/room-context-0vovmZPU.js +787 -0
- package/dist/runtime-Bo-KHM-F.js +8 -0
- package/dist/runtime-api-Dd1xIV5v.js +9 -0
- package/dist/runtime-api.js +14 -0
- package/dist/runtime-setter-api.js +2 -0
- package/dist/scopes-CDevO8jg.js +74 -0
- package/dist/secret-contract-Bo6lbSkh.js +141 -0
- package/dist/secret-contract-api.js +2 -0
- package/dist/security-audit-BtHGnD3d.js +51 -0
- package/dist/security-contract-api.js +2 -0
- package/dist/send-D_A9kL-C.js +721 -0
- package/dist/send.runtime-BRE_ncCU.js +2 -0
- package/dist/send.runtime-_l76lUuL.js +2 -0
- package/dist/setup-core-B9NetDkM.js +320 -0
- package/dist/setup-entry.js +15 -0
- package/dist/setup-plugin-api.js +2 -0
- package/dist/setup-surface-D88QBVOW.js +128 -0
- package/dist/shared-D8U42xFL.js +208 -0
- package/dist/slash-commands.runtime-22kgyst2.js +19 -0
- package/dist/slash-dispatch.runtime-BJgT0jwV.js +32 -0
- package/dist/slash-plugin-commands.runtime-CF-n3MeP.js +2 -0
- package/dist/slash-skill-commands.runtime-BMs0VjTe.js +7 -0
- package/dist/streaming-compat-RkZgTmQ2.js +43 -0
- package/dist/target-parsing-CQmv-iSm.js +55 -0
- package/dist/targets-B1tYCAr6.js +2 -0
- package/dist/test-api.js +8 -0
- package/dist/thread-ts-C2x7c5PP.js +24 -0
- package/openclaw.plugin.json +2405 -0
- package/package.json +84 -0
|
@@ -0,0 +1,787 @@
|
|
|
1
|
+
import { a as normalizeSlackSlug, i as normalizeSlackAllowOwnerEntry, n as normalizeAllowList, o as resolveSlackAllowListMatch, r as normalizeAllowListLower, t as allowListMatches } from "./allow-list-BPnnlRPL.js";
|
|
2
|
+
import { t as formatSlackError } from "./errors-BYFHR24f.js";
|
|
3
|
+
import { normalizeLowercaseStringOrEmpty, normalizeOptionalLowercaseString, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
4
|
+
import { resolveAgentRoute, resolveThreadSessionKeys } from "openclaw/plugin-sdk/routing";
|
|
5
|
+
import { createChannelPairingChallengeIssuer } from "openclaw/plugin-sdk/channel-pairing";
|
|
6
|
+
import { formatAllowlistMatchMeta } from "openclaw/plugin-sdk/allow-from";
|
|
7
|
+
import { getChildLogger, logVerbose } from "openclaw/plugin-sdk/runtime-env";
|
|
8
|
+
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
|
|
9
|
+
import { createDedupeCache } from "openclaw/plugin-sdk/dedupe-runtime";
|
|
10
|
+
import { buildPluginBindingResolvedText, parsePluginBindingApprovalCustomId, recordInboundSession, resolveConversationLabel as resolveConversationLabel$1, resolvePluginConversationBindingApproval, resolveRuntimeConversationBindingRoute, upsertChannelPairingRequest } from "openclaw/plugin-sdk/conversation-runtime";
|
|
11
|
+
import { getRuntimeConfig as getRuntimeConfig$1 } from "openclaw/plugin-sdk/runtime-config-snapshot";
|
|
12
|
+
import { isDangerousNameMatchingEnabled } from "openclaw/plugin-sdk/dangerous-name-runtime";
|
|
13
|
+
import { readSessionUpdatedAt, resolveSessionKey, resolveStorePath as resolveStorePath$1, updateLastRoute } from "openclaw/plugin-sdk/session-store-runtime";
|
|
14
|
+
import { resolveChannelContextVisibilityMode } from "openclaw/plugin-sdk/context-visibility-runtime";
|
|
15
|
+
import { resolveDefaultGroupPolicy, resolveOpenProviderRuntimeGroupPolicy, warnMissingProviderGroupPolicyFallbackOnce } from "openclaw/plugin-sdk/runtime-group-policy";
|
|
16
|
+
import { resolveDefaultAgentId } from "openclaw/plugin-sdk/agent-runtime";
|
|
17
|
+
import { applyChannelMatchMeta, buildChannelKeyCandidates, resolveChannelEntryMatchWithFallback } from "openclaw/plugin-sdk/channel-targets";
|
|
18
|
+
import { createChannelIngressResolver, defineStableChannelIngressIdentity, readChannelIngressStoreAllowFromForDmPolicy } from "openclaw/plugin-sdk/channel-ingress-runtime";
|
|
19
|
+
import { buildUntrustedChannelMetadata } from "openclaw/plugin-sdk/security-runtime";
|
|
20
|
+
//#region extensions/slack/src/monitor/commands.ts
|
|
21
|
+
/**
|
|
22
|
+
* Strip Slack mentions (<@U123>, <@U123|name>) so command detection works on
|
|
23
|
+
* normalized text. Use in both prepare and debounce gate for consistency.
|
|
24
|
+
*/
|
|
25
|
+
function stripSlackMentionsForCommandDetection(text) {
|
|
26
|
+
return (text ?? "").replace(/<@[^>]+>/g, " ").replace(/\s+/g, " ").trim();
|
|
27
|
+
}
|
|
28
|
+
function normalizeSlackSlashCommandName(raw) {
|
|
29
|
+
return raw.replace(/^\/+/, "");
|
|
30
|
+
}
|
|
31
|
+
function resolveSlackSlashCommandConfig(raw) {
|
|
32
|
+
const name = normalizeSlackSlashCommandName(normalizeOptionalString(raw?.name) ?? "openclaw") || "openclaw";
|
|
33
|
+
return {
|
|
34
|
+
enabled: raw?.enabled === true,
|
|
35
|
+
name,
|
|
36
|
+
sessionPrefix: normalizeOptionalString(raw?.sessionPrefix) ?? "slack:slash",
|
|
37
|
+
ephemeral: raw?.ephemeral !== false
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function buildSlackSlashCommandMatcher(name) {
|
|
41
|
+
const escaped = normalizeSlackSlashCommandName(name).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
42
|
+
return new RegExp(`^/?${escaped}$`);
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region extensions/slack/src/monitor/channel-config.ts
|
|
46
|
+
function firstDefined(...values) {
|
|
47
|
+
for (const value of values) if (value !== void 0) return value;
|
|
48
|
+
}
|
|
49
|
+
function resolveSlackChannelLabel(params) {
|
|
50
|
+
const channelName = params.channelName?.trim();
|
|
51
|
+
if (channelName) return `#${normalizeSlackSlug(channelName) || channelName}`;
|
|
52
|
+
const channelId = params.channelId?.trim();
|
|
53
|
+
return channelId ? `#${channelId}` : "unknown channel";
|
|
54
|
+
}
|
|
55
|
+
function resolveSlackChannelConfig(params) {
|
|
56
|
+
const { channelId, channelName, channels, channelKeys, defaultRequireMention, allowNameMatching } = params;
|
|
57
|
+
const entries = channels ?? {};
|
|
58
|
+
const keys = channelKeys ?? Object.keys(entries);
|
|
59
|
+
const normalizedName = channelName ? normalizeSlackSlug(channelName) : "";
|
|
60
|
+
const directName = channelName ? channelName.trim() : "";
|
|
61
|
+
const channelIdLower = normalizeLowercaseStringOrEmpty(channelId);
|
|
62
|
+
const channelIdUpper = channelId.toUpperCase();
|
|
63
|
+
const channelTarget = `channel:${channelId}`;
|
|
64
|
+
const channelTargetLower = `channel:${channelIdLower}`;
|
|
65
|
+
const channelTargetUpper = `channel:${channelIdUpper}`;
|
|
66
|
+
const match = resolveChannelEntryMatchWithFallback({
|
|
67
|
+
entries,
|
|
68
|
+
keys: buildChannelKeyCandidates(channelId, channelIdLower !== channelId ? channelIdLower : void 0, channelIdUpper !== channelId ? channelIdUpper : void 0, channelTarget, channelTargetLower !== channelTarget ? channelTargetLower : void 0, channelTargetUpper !== channelTarget ? channelTargetUpper : void 0, allowNameMatching ? channelName ? `#${directName}` : void 0 : void 0, allowNameMatching ? directName : void 0, allowNameMatching ? normalizedName : void 0),
|
|
69
|
+
wildcardKey: "*"
|
|
70
|
+
});
|
|
71
|
+
const { entry: matched, wildcardEntry: fallback } = match;
|
|
72
|
+
const requireMentionDefault = defaultRequireMention ?? true;
|
|
73
|
+
if (keys.length === 0) return {
|
|
74
|
+
allowed: true,
|
|
75
|
+
requireMention: requireMentionDefault
|
|
76
|
+
};
|
|
77
|
+
if (!matched && !fallback) return {
|
|
78
|
+
allowed: false,
|
|
79
|
+
requireMention: requireMentionDefault
|
|
80
|
+
};
|
|
81
|
+
const resolved = matched ?? fallback ?? {};
|
|
82
|
+
return applyChannelMatchMeta({
|
|
83
|
+
allowed: firstDefined(resolved.enabled, fallback?.enabled, true) ?? true,
|
|
84
|
+
requireMention: firstDefined(resolved.requireMention, fallback?.requireMention, requireMentionDefault) ?? requireMentionDefault,
|
|
85
|
+
allowBots: firstDefined(resolved.allowBots, fallback?.allowBots),
|
|
86
|
+
users: firstDefined(resolved.users, fallback?.users),
|
|
87
|
+
skills: firstDefined(resolved.skills, fallback?.skills),
|
|
88
|
+
systemPrompt: firstDefined(resolved.systemPrompt, fallback?.systemPrompt)
|
|
89
|
+
}, match);
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region extensions/slack/src/monitor/channel-type.ts
|
|
93
|
+
function inferSlackChannelType(channelId) {
|
|
94
|
+
const trimmed = channelId?.trim();
|
|
95
|
+
if (!trimmed) return;
|
|
96
|
+
if (trimmed.startsWith("D")) return "im";
|
|
97
|
+
if (trimmed.startsWith("C")) return "channel";
|
|
98
|
+
if (trimmed.startsWith("G")) return "group";
|
|
99
|
+
}
|
|
100
|
+
function normalizeSlackChannelType(channelType, channelId) {
|
|
101
|
+
const normalized = normalizeOptionalLowercaseString(channelType);
|
|
102
|
+
const inferred = inferSlackChannelType(channelId);
|
|
103
|
+
if (normalized === "im" || normalized === "mpim" || normalized === "channel" || normalized === "group") {
|
|
104
|
+
if (inferred === "im" && normalized !== "im") return "im";
|
|
105
|
+
return normalized;
|
|
106
|
+
}
|
|
107
|
+
return inferred ?? "channel";
|
|
108
|
+
}
|
|
109
|
+
function resolveSlackChatType(channelType) {
|
|
110
|
+
if (channelType === "im") return "direct";
|
|
111
|
+
if (channelType === "mpim") return "group";
|
|
112
|
+
return "channel";
|
|
113
|
+
}
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region extensions/slack/src/monitor/policy.ts
|
|
116
|
+
function isSlackChannelAllowedByPolicy(params) {
|
|
117
|
+
if (params.groupPolicy === "disabled") return false;
|
|
118
|
+
return params.groupPolicy !== "allowlist" || params.channelAllowlistConfigured && params.channelAllowed;
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region extensions/slack/src/monitor/context.ts
|
|
122
|
+
function createSlackMonitorContext(params) {
|
|
123
|
+
const channelHistories = /* @__PURE__ */ new Map();
|
|
124
|
+
const logger = getChildLogger({ module: "slack-auto-reply" });
|
|
125
|
+
const channelCache = /* @__PURE__ */ new Map();
|
|
126
|
+
const userCache = /* @__PURE__ */ new Map();
|
|
127
|
+
const seenMessages = createDedupeCache({
|
|
128
|
+
ttlMs: 6e4,
|
|
129
|
+
maxSize: 500
|
|
130
|
+
});
|
|
131
|
+
const allowFrom = normalizeAllowList(params.allowFrom);
|
|
132
|
+
const groupDmChannels = normalizeAllowList(params.groupDmChannels);
|
|
133
|
+
const groupDmChannelsLower = normalizeAllowListLower(groupDmChannels);
|
|
134
|
+
const defaultRequireMention = params.defaultRequireMention ?? true;
|
|
135
|
+
const hasChannelAllowlistConfig = Object.keys(params.channelsConfig ?? {}).length > 0;
|
|
136
|
+
const channelsConfigKeys = Object.keys(params.channelsConfig ?? {});
|
|
137
|
+
const markMessageSeen = (channelId, ts) => {
|
|
138
|
+
if (!channelId || !ts) return false;
|
|
139
|
+
return seenMessages.check(`${channelId}:${ts}`);
|
|
140
|
+
};
|
|
141
|
+
const releaseSeenMessage = (channelId, ts) => {
|
|
142
|
+
if (!channelId || !ts) return;
|
|
143
|
+
seenMessages.delete(`${channelId}:${ts}`);
|
|
144
|
+
};
|
|
145
|
+
const resolveSlackSystemEventSessionKey = (p) => {
|
|
146
|
+
const channelId = normalizeOptionalString(p.channelId) ?? "";
|
|
147
|
+
if (!channelId) return params.mainKey;
|
|
148
|
+
const channelType = normalizeSlackChannelType(p.channelType, channelId);
|
|
149
|
+
const isDirectMessage = channelType === "im";
|
|
150
|
+
const isGroup = channelType === "mpim";
|
|
151
|
+
const from = isDirectMessage ? `slack:${channelId}` : isGroup ? `slack:group:${channelId}` : `slack:channel:${channelId}`;
|
|
152
|
+
const chatType = isDirectMessage ? "direct" : isGroup ? "group" : "channel";
|
|
153
|
+
const senderId = normalizeOptionalString(p.senderId) ?? "";
|
|
154
|
+
try {
|
|
155
|
+
const peerKind = isDirectMessage ? "direct" : isGroup ? "group" : "channel";
|
|
156
|
+
const peerId = isDirectMessage ? senderId : channelId;
|
|
157
|
+
if (peerId) {
|
|
158
|
+
const route = resolveAgentRoute({
|
|
159
|
+
cfg: params.cfg,
|
|
160
|
+
channel: "slack",
|
|
161
|
+
accountId: params.accountId,
|
|
162
|
+
teamId: params.teamId,
|
|
163
|
+
peer: {
|
|
164
|
+
kind: peerKind,
|
|
165
|
+
id: peerId
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
const threadTs = normalizeOptionalString(p.threadTs);
|
|
169
|
+
const baseConversationId = isDirectMessage ? `user:${senderId}` : channelId;
|
|
170
|
+
const threadBindingRoute = threadTs ? resolveRuntimeConversationBindingRoute({
|
|
171
|
+
route,
|
|
172
|
+
conversation: {
|
|
173
|
+
channel: "slack",
|
|
174
|
+
accountId: params.accountId,
|
|
175
|
+
conversationId: threadTs,
|
|
176
|
+
parentConversationId: baseConversationId
|
|
177
|
+
}
|
|
178
|
+
}) : null;
|
|
179
|
+
const runtimeRoute = threadBindingRoute?.boundSessionKey || threadBindingRoute?.bindingRecord ? threadBindingRoute : resolveRuntimeConversationBindingRoute({
|
|
180
|
+
route,
|
|
181
|
+
conversation: {
|
|
182
|
+
channel: "slack",
|
|
183
|
+
accountId: params.accountId,
|
|
184
|
+
conversationId: baseConversationId
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
if (runtimeRoute.boundSessionKey) return runtimeRoute.route.sessionKey;
|
|
188
|
+
return resolveThreadSessionKeys({
|
|
189
|
+
baseSessionKey: runtimeRoute.route.sessionKey,
|
|
190
|
+
threadId: threadTs,
|
|
191
|
+
parentSessionKey: threadTs && params.threadInheritParent ? runtimeRoute.route.sessionKey : void 0
|
|
192
|
+
}).sessionKey;
|
|
193
|
+
}
|
|
194
|
+
} catch {}
|
|
195
|
+
const legacySessionKey = resolveSessionKey(params.sessionScope, {
|
|
196
|
+
From: from,
|
|
197
|
+
ChatType: chatType,
|
|
198
|
+
Provider: "slack"
|
|
199
|
+
}, params.mainKey, resolveDefaultAgentId(params.cfg));
|
|
200
|
+
return resolveThreadSessionKeys({
|
|
201
|
+
baseSessionKey: legacySessionKey,
|
|
202
|
+
threadId: normalizeOptionalString(p.threadTs),
|
|
203
|
+
parentSessionKey: normalizeOptionalString(p.threadTs) && params.threadInheritParent ? legacySessionKey : void 0
|
|
204
|
+
}).sessionKey;
|
|
205
|
+
};
|
|
206
|
+
const resolveChannelName = async (channelId) => {
|
|
207
|
+
const cached = channelCache.get(channelId);
|
|
208
|
+
if (cached) return cached;
|
|
209
|
+
try {
|
|
210
|
+
const info = await params.app.client.conversations.info({
|
|
211
|
+
token: params.botToken,
|
|
212
|
+
channel: channelId
|
|
213
|
+
});
|
|
214
|
+
const name = info.channel && "name" in info.channel ? info.channel.name : void 0;
|
|
215
|
+
const channel = info.channel ?? void 0;
|
|
216
|
+
const entry = {
|
|
217
|
+
name,
|
|
218
|
+
type: channel?.is_im ? "im" : channel?.is_mpim ? "mpim" : channel?.is_channel ? "channel" : channel?.is_group ? "group" : void 0,
|
|
219
|
+
topic: channel && "topic" in channel ? channel.topic?.value ?? void 0 : void 0,
|
|
220
|
+
purpose: channel && "purpose" in channel ? channel.purpose?.value ?? void 0 : void 0
|
|
221
|
+
};
|
|
222
|
+
channelCache.set(channelId, entry);
|
|
223
|
+
return entry;
|
|
224
|
+
} catch {
|
|
225
|
+
return {};
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
const resolveUserName = async (userId) => {
|
|
229
|
+
const cached = userCache.get(userId);
|
|
230
|
+
if (cached) return cached;
|
|
231
|
+
try {
|
|
232
|
+
const info = await params.app.client.users.info({
|
|
233
|
+
token: params.botToken,
|
|
234
|
+
user: userId
|
|
235
|
+
});
|
|
236
|
+
const profile = info.user?.profile;
|
|
237
|
+
const entry = { name: profile?.display_name || profile?.real_name || info.user?.name || void 0 };
|
|
238
|
+
userCache.set(userId, entry);
|
|
239
|
+
return entry;
|
|
240
|
+
} catch {
|
|
241
|
+
return {};
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
const setSlackThreadStatus = async (p) => {
|
|
245
|
+
if (!p.threadTs) return;
|
|
246
|
+
try {
|
|
247
|
+
await params.app.client.assistant.threads.setStatus({
|
|
248
|
+
token: params.botToken,
|
|
249
|
+
channel_id: p.channelId,
|
|
250
|
+
thread_ts: p.threadTs,
|
|
251
|
+
status: p.status
|
|
252
|
+
});
|
|
253
|
+
} catch (err) {
|
|
254
|
+
logVerbose(`slack status update failed for channel ${p.channelId}: ${formatSlackError(err)}`);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
const isChannelAllowed = (p) => {
|
|
258
|
+
const channelType = normalizeSlackChannelType(p.channelType, p.channelId);
|
|
259
|
+
const isDirectMessage = channelType === "im";
|
|
260
|
+
const isGroupDm = channelType === "mpim";
|
|
261
|
+
const isRoom = channelType === "channel" || channelType === "group";
|
|
262
|
+
if (isDirectMessage && !params.dmEnabled) return false;
|
|
263
|
+
if (isGroupDm && !params.groupDmEnabled) return false;
|
|
264
|
+
if (isGroupDm && groupDmChannels.length > 0) {
|
|
265
|
+
const candidates = [
|
|
266
|
+
p.channelId,
|
|
267
|
+
p.channelName ? `#${p.channelName}` : void 0,
|
|
268
|
+
p.channelName,
|
|
269
|
+
p.channelName ? normalizeSlackSlug(p.channelName) : void 0
|
|
270
|
+
].filter((value) => Boolean(value)).map((value) => normalizeLowercaseStringOrEmpty(value));
|
|
271
|
+
if (!(groupDmChannelsLower.includes("*") || candidates.some((candidate) => groupDmChannelsLower.includes(candidate)))) return false;
|
|
272
|
+
}
|
|
273
|
+
if (isRoom && p.channelId) {
|
|
274
|
+
const channelConfig = resolveSlackChannelConfig({
|
|
275
|
+
channelId: p.channelId,
|
|
276
|
+
channelName: p.channelName,
|
|
277
|
+
channels: params.channelsConfig,
|
|
278
|
+
channelKeys: channelsConfigKeys,
|
|
279
|
+
defaultRequireMention,
|
|
280
|
+
allowNameMatching: params.allowNameMatching
|
|
281
|
+
});
|
|
282
|
+
const channelMatchMeta = formatAllowlistMatchMeta(channelConfig);
|
|
283
|
+
const channelAllowed = channelConfig?.allowed !== false;
|
|
284
|
+
const channelAllowlistConfigured = hasChannelAllowlistConfig;
|
|
285
|
+
if (!isSlackChannelAllowedByPolicy({
|
|
286
|
+
groupPolicy: params.groupPolicy,
|
|
287
|
+
channelAllowlistConfigured,
|
|
288
|
+
channelAllowed
|
|
289
|
+
})) {
|
|
290
|
+
logVerbose(`slack: drop channel ${p.channelId} (groupPolicy=${params.groupPolicy}, ${channelMatchMeta})`);
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
const hasExplicitConfig = Boolean(channelConfig?.matchSource);
|
|
294
|
+
if (!channelAllowed && (params.groupPolicy !== "open" || hasExplicitConfig)) {
|
|
295
|
+
logVerbose(`slack: drop channel ${p.channelId} (${channelMatchMeta})`);
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
logVerbose(`slack: allow channel ${p.channelId} (${channelMatchMeta})`);
|
|
299
|
+
}
|
|
300
|
+
return true;
|
|
301
|
+
};
|
|
302
|
+
const shouldDropMismatchedSlackEvent = (body) => {
|
|
303
|
+
if (!body || typeof body !== "object") return false;
|
|
304
|
+
const raw = body;
|
|
305
|
+
const incomingApiAppId = typeof raw.api_app_id === "string" ? raw.api_app_id : "";
|
|
306
|
+
const incomingTeamId = typeof raw.team_id === "string" ? raw.team_id : typeof raw.team?.id === "string" ? raw.team.id : "";
|
|
307
|
+
if (params.apiAppId && incomingApiAppId && incomingApiAppId !== params.apiAppId) {
|
|
308
|
+
logVerbose(`slack: drop event with api_app_id=${incomingApiAppId} (expected ${params.apiAppId})`);
|
|
309
|
+
return true;
|
|
310
|
+
}
|
|
311
|
+
if (params.teamId && incomingTeamId && incomingTeamId !== params.teamId) {
|
|
312
|
+
logVerbose(`slack: drop event with team_id=${incomingTeamId} (expected ${params.teamId})`);
|
|
313
|
+
return true;
|
|
314
|
+
}
|
|
315
|
+
return false;
|
|
316
|
+
};
|
|
317
|
+
return {
|
|
318
|
+
cfg: params.cfg,
|
|
319
|
+
accountId: params.accountId,
|
|
320
|
+
botToken: params.botToken,
|
|
321
|
+
app: params.app,
|
|
322
|
+
runtime: params.runtime,
|
|
323
|
+
botUserId: params.botUserId,
|
|
324
|
+
botId: params.botId,
|
|
325
|
+
teamId: params.teamId,
|
|
326
|
+
apiAppId: params.apiAppId,
|
|
327
|
+
historyLimit: params.historyLimit,
|
|
328
|
+
dmHistoryLimit: Math.max(0, params.dmHistoryLimit ?? 0),
|
|
329
|
+
channelHistories,
|
|
330
|
+
sessionScope: params.sessionScope,
|
|
331
|
+
mainKey: params.mainKey,
|
|
332
|
+
dmEnabled: params.dmEnabled,
|
|
333
|
+
dmPolicy: params.dmPolicy,
|
|
334
|
+
allowFrom,
|
|
335
|
+
allowNameMatching: params.allowNameMatching,
|
|
336
|
+
groupDmEnabled: params.groupDmEnabled,
|
|
337
|
+
groupDmChannels,
|
|
338
|
+
defaultRequireMention,
|
|
339
|
+
channelsConfig: params.channelsConfig,
|
|
340
|
+
channelsConfigKeys,
|
|
341
|
+
groupPolicy: params.groupPolicy,
|
|
342
|
+
useAccessGroups: params.useAccessGroups,
|
|
343
|
+
reactionMode: params.reactionMode,
|
|
344
|
+
reactionAllowlist: params.reactionAllowlist,
|
|
345
|
+
replyToMode: params.replyToMode,
|
|
346
|
+
threadHistoryScope: params.threadHistoryScope,
|
|
347
|
+
threadInheritParent: params.threadInheritParent,
|
|
348
|
+
threadRequireExplicitMention: params.threadRequireExplicitMention,
|
|
349
|
+
slashCommand: params.slashCommand,
|
|
350
|
+
textLimit: params.textLimit,
|
|
351
|
+
ackReactionScope: params.ackReactionScope,
|
|
352
|
+
typingReaction: params.typingReaction,
|
|
353
|
+
mediaMaxBytes: params.mediaMaxBytes,
|
|
354
|
+
removeAckAfterReply: params.removeAckAfterReply,
|
|
355
|
+
logger,
|
|
356
|
+
markMessageSeen,
|
|
357
|
+
releaseSeenMessage,
|
|
358
|
+
shouldDropMismatchedSlackEvent,
|
|
359
|
+
resolveSlackSystemEventSessionKey,
|
|
360
|
+
isChannelAllowed,
|
|
361
|
+
resolveChannelName,
|
|
362
|
+
resolveUserName,
|
|
363
|
+
setSlackThreadStatus
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
//#endregion
|
|
367
|
+
//#region extensions/slack/src/monitor/auth.ts
|
|
368
|
+
let slackChannelMembersCache = /* @__PURE__ */ new WeakMap();
|
|
369
|
+
const DEFAULT_CHANNEL_MEMBERS_CACHE_TTL_MS = 6e4;
|
|
370
|
+
const CHANNEL_MEMBERS_CACHE_MAX = 512;
|
|
371
|
+
const SLACK_CHANNEL_ID = "slack";
|
|
372
|
+
const SLACK_USER_NAME_KIND = "plugin:slack-user-name";
|
|
373
|
+
function normalizeSlackUserId(raw) {
|
|
374
|
+
const value = (raw ?? "").trim().toLowerCase();
|
|
375
|
+
if (!value) return "";
|
|
376
|
+
const mention = value.match(/^<@([a-z0-9_]+)>$/i);
|
|
377
|
+
if (mention?.[1]) return mention[1];
|
|
378
|
+
return value.replace(/^(slack:|user:)/, "");
|
|
379
|
+
}
|
|
380
|
+
function isSlackStableUserId(value) {
|
|
381
|
+
return /^[ubw][a-z0-9_]+$/i.test(value);
|
|
382
|
+
}
|
|
383
|
+
function normalizeSlackStableEntry(entry) {
|
|
384
|
+
const normalized = entry.trim().toLowerCase();
|
|
385
|
+
if (!normalized) return null;
|
|
386
|
+
const userId = normalizeSlackUserId(normalized);
|
|
387
|
+
return isSlackStableUserId(userId) ? userId : null;
|
|
388
|
+
}
|
|
389
|
+
function normalizeSlackNameEntry(entry) {
|
|
390
|
+
const normalized = entry.trim().toLowerCase();
|
|
391
|
+
if (!normalized || normalizeSlackStableEntry(normalized)) return null;
|
|
392
|
+
return normalized.replace(/^slack:/, "") || null;
|
|
393
|
+
}
|
|
394
|
+
function normalizeSlackNameSubject(value) {
|
|
395
|
+
return value.trim().toLowerCase() || null;
|
|
396
|
+
}
|
|
397
|
+
function normalizeSlackNameSlugEntry(entry) {
|
|
398
|
+
const name = normalizeSlackNameEntry(entry);
|
|
399
|
+
if (!name) return null;
|
|
400
|
+
const slug = normalizeSlackSlug(name);
|
|
401
|
+
return slug && slug !== name ? slug : null;
|
|
402
|
+
}
|
|
403
|
+
const slackIngressIdentity = defineStableChannelIngressIdentity({
|
|
404
|
+
key: "senderId",
|
|
405
|
+
kind: "stable-id",
|
|
406
|
+
normalizeEntry: normalizeSlackStableEntry,
|
|
407
|
+
normalizeSubject: normalizeSlackUserId,
|
|
408
|
+
sensitivity: "pii",
|
|
409
|
+
aliases: [["senderName", normalizeSlackNameEntry], ["senderNameSlug", normalizeSlackNameSlugEntry]].map(([key, normalizeEntry]) => ({
|
|
410
|
+
key,
|
|
411
|
+
kind: SLACK_USER_NAME_KIND,
|
|
412
|
+
normalizeEntry,
|
|
413
|
+
normalizeSubject: normalizeSlackNameSubject,
|
|
414
|
+
dangerous: true,
|
|
415
|
+
sensitivity: "pii"
|
|
416
|
+
}))
|
|
417
|
+
});
|
|
418
|
+
function createSlackIngressSubject(params) {
|
|
419
|
+
const senderId = normalizeSlackUserId(params.senderId);
|
|
420
|
+
const senderName = params.senderName?.trim().toLowerCase();
|
|
421
|
+
return {
|
|
422
|
+
stableId: senderId,
|
|
423
|
+
aliases: {
|
|
424
|
+
senderName,
|
|
425
|
+
senderNameSlug: senderName ? normalizeSlackSlug(senderName) : void 0
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
function createSlackIngressResolver(ctx) {
|
|
430
|
+
return createChannelIngressResolver({
|
|
431
|
+
channelId: SLACK_CHANNEL_ID,
|
|
432
|
+
accountId: ctx.accountId,
|
|
433
|
+
identity: slackIngressIdentity,
|
|
434
|
+
cfg: ctx.cfg
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
function readSlackCacheTtlMs(envName, fallback) {
|
|
438
|
+
const raw = process.env[envName]?.trim();
|
|
439
|
+
if (!raw) return fallback;
|
|
440
|
+
const parsed = Number(raw);
|
|
441
|
+
return Number.isFinite(parsed) ? Math.max(0, Math.floor(parsed)) : fallback;
|
|
442
|
+
}
|
|
443
|
+
function getChannelMembersCache(ctx) {
|
|
444
|
+
const existing = slackChannelMembersCache.get(ctx);
|
|
445
|
+
if (existing) return existing;
|
|
446
|
+
const next = /* @__PURE__ */ new Map();
|
|
447
|
+
slackChannelMembersCache.set(ctx, next);
|
|
448
|
+
return next;
|
|
449
|
+
}
|
|
450
|
+
function pruneChannelMembersCache(cache) {
|
|
451
|
+
while (cache.size > CHANNEL_MEMBERS_CACHE_MAX) {
|
|
452
|
+
const oldest = cache.keys().next();
|
|
453
|
+
if (oldest.done) return;
|
|
454
|
+
cache.delete(oldest.value);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
function buildBaseAllowFrom(ctx) {
|
|
458
|
+
return normalizeAllowListLower(normalizeAllowList(ctx.allowFrom));
|
|
459
|
+
}
|
|
460
|
+
async function resolveSlackEffectiveAllowFrom(ctx, options) {
|
|
461
|
+
const base = buildBaseAllowFrom(ctx);
|
|
462
|
+
if (options?.includePairingStore !== true) return base;
|
|
463
|
+
let storeAllowFrom = [];
|
|
464
|
+
try {
|
|
465
|
+
const resolved = await readChannelIngressStoreAllowFromForDmPolicy({
|
|
466
|
+
provider: "slack",
|
|
467
|
+
accountId: ctx.accountId,
|
|
468
|
+
dmPolicy: ctx.dmPolicy
|
|
469
|
+
});
|
|
470
|
+
storeAllowFrom = Array.isArray(resolved) ? resolved : [];
|
|
471
|
+
} catch {
|
|
472
|
+
storeAllowFrom = [];
|
|
473
|
+
}
|
|
474
|
+
return normalizeAllowListLower([...base, ...storeAllowFrom]);
|
|
475
|
+
}
|
|
476
|
+
async function fetchSlackChannelMemberIds(ctx, channelId) {
|
|
477
|
+
const members = /* @__PURE__ */ new Set();
|
|
478
|
+
let cursor;
|
|
479
|
+
do {
|
|
480
|
+
const response = await ctx.app.client.conversations.members({
|
|
481
|
+
token: ctx.botToken,
|
|
482
|
+
channel: channelId,
|
|
483
|
+
limit: 999,
|
|
484
|
+
...cursor ? { cursor } : {}
|
|
485
|
+
});
|
|
486
|
+
for (const member of normalizeAllowListLower(response.members)) members.add(member);
|
|
487
|
+
const nextCursor = response.response_metadata?.next_cursor?.trim();
|
|
488
|
+
cursor = nextCursor ? nextCursor : void 0;
|
|
489
|
+
} while (cursor);
|
|
490
|
+
return members;
|
|
491
|
+
}
|
|
492
|
+
async function resolveSlackChannelMemberIds(ctx, channelId) {
|
|
493
|
+
const cache = getChannelMembersCache(ctx);
|
|
494
|
+
const key = `${ctx.accountId}:${channelId}`;
|
|
495
|
+
const ttlMs = readSlackCacheTtlMs("OPENCLAW_SLACK_CHANNEL_MEMBERS_CACHE_TTL_MS", DEFAULT_CHANNEL_MEMBERS_CACHE_TTL_MS);
|
|
496
|
+
const nowMs = Date.now();
|
|
497
|
+
const cached = cache.get(key);
|
|
498
|
+
if (ttlMs > 0 && cached?.members && cached.expiresAtMs >= nowMs) return cached.members;
|
|
499
|
+
if (cached?.pending) return await cached.pending;
|
|
500
|
+
const pending = fetchSlackChannelMemberIds(ctx, channelId);
|
|
501
|
+
cache.set(key, {
|
|
502
|
+
expiresAtMs: ttlMs > 0 ? nowMs + ttlMs : 0,
|
|
503
|
+
pending
|
|
504
|
+
});
|
|
505
|
+
pruneChannelMembersCache(cache);
|
|
506
|
+
try {
|
|
507
|
+
const members = await pending;
|
|
508
|
+
if (ttlMs > 0) {
|
|
509
|
+
cache.set(key, {
|
|
510
|
+
expiresAtMs: Date.now() + ttlMs,
|
|
511
|
+
members
|
|
512
|
+
});
|
|
513
|
+
pruneChannelMembersCache(cache);
|
|
514
|
+
} else cache.delete(key);
|
|
515
|
+
return members;
|
|
516
|
+
} finally {
|
|
517
|
+
if (cache.get(key)?.pending === pending) cache.delete(key);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
function resolveExplicitSlackOwnerIds(allowFromLower) {
|
|
521
|
+
const ownerIds = /* @__PURE__ */ new Set();
|
|
522
|
+
for (const entry of allowFromLower) {
|
|
523
|
+
const ownerId = normalizeSlackAllowOwnerEntry(entry);
|
|
524
|
+
if (ownerId) ownerIds.add(ownerId);
|
|
525
|
+
}
|
|
526
|
+
return [...ownerIds];
|
|
527
|
+
}
|
|
528
|
+
async function authorizeSlackBotRoomMessage(params) {
|
|
529
|
+
const channelUserAllowList = normalizeAllowListLower(params.channelUsers).filter((entry) => entry !== "*");
|
|
530
|
+
if (channelUserAllowList.length > 0 && allowListMatches({
|
|
531
|
+
allowList: channelUserAllowList,
|
|
532
|
+
id: params.senderId,
|
|
533
|
+
name: params.senderName,
|
|
534
|
+
allowNameMatching: params.ctx.allowNameMatching
|
|
535
|
+
})) return true;
|
|
536
|
+
const explicitOwnerIds = resolveExplicitSlackOwnerIds(params.allowFromLower);
|
|
537
|
+
if (explicitOwnerIds.length === 0) {
|
|
538
|
+
logVerbose(`slack: drop bot message ${params.senderId} in ${params.channelId} (no explicit owner id for presence check)`);
|
|
539
|
+
return false;
|
|
540
|
+
}
|
|
541
|
+
try {
|
|
542
|
+
const channelMemberIds = await resolveSlackChannelMemberIds(params.ctx, params.channelId);
|
|
543
|
+
if (explicitOwnerIds.some((ownerId) => channelMemberIds.has(ownerId))) return true;
|
|
544
|
+
logVerbose(`slack: drop bot message ${params.senderId} in ${params.channelId} (no owner present)`);
|
|
545
|
+
} catch (error) {
|
|
546
|
+
logVerbose(`slack: drop bot message ${params.senderId} in ${params.channelId} (owner presence lookup failed: ${formatErrorMessage(error)})`);
|
|
547
|
+
}
|
|
548
|
+
return false;
|
|
549
|
+
}
|
|
550
|
+
function wildcardWhenOpen(entries) {
|
|
551
|
+
return entries.length > 0 ? [...entries] : ["*"];
|
|
552
|
+
}
|
|
553
|
+
function slackIngressConversationKind(channelType) {
|
|
554
|
+
return channelType === "im" ? "direct" : channelType === "mpim" ? "group" : "channel";
|
|
555
|
+
}
|
|
556
|
+
async function resolveSlackCommandIngress(params) {
|
|
557
|
+
const isDirectMessage = params.channelType === "im";
|
|
558
|
+
const channelUsers = normalizeAllowListLower(params.channelUsers);
|
|
559
|
+
const channelUsersConfigured = !isDirectMessage && channelUsers.length > 0;
|
|
560
|
+
return await createSlackIngressResolver(params.ctx).message({
|
|
561
|
+
subject: createSlackIngressSubject({
|
|
562
|
+
senderId: params.senderId,
|
|
563
|
+
senderName: params.senderName
|
|
564
|
+
}),
|
|
565
|
+
conversation: {
|
|
566
|
+
kind: slackIngressConversationKind(params.channelType),
|
|
567
|
+
id: params.channelId
|
|
568
|
+
},
|
|
569
|
+
event: {
|
|
570
|
+
kind: params.eventKind ?? "message",
|
|
571
|
+
authMode: "inbound",
|
|
572
|
+
mayPair: false
|
|
573
|
+
},
|
|
574
|
+
dmPolicy: isDirectMessage ? "open" : "disabled",
|
|
575
|
+
groupPolicy: channelUsersConfigured ? "allowlist" : "open",
|
|
576
|
+
policy: {
|
|
577
|
+
groupAllowFromFallbackToAllowFrom: false,
|
|
578
|
+
mutableIdentifierMatching: params.ctx.allowNameMatching ? "enabled" : "disabled",
|
|
579
|
+
...params.activation ? { activation: params.activation } : {}
|
|
580
|
+
},
|
|
581
|
+
mentionFacts: params.mentionFacts,
|
|
582
|
+
allowFrom: isDirectMessage ? ["*"] : params.ownerAllowFromLower,
|
|
583
|
+
groupAllowFrom: channelUsersConfigured ? channelUsers : [],
|
|
584
|
+
command: {
|
|
585
|
+
allowTextCommands: params.allowTextCommands,
|
|
586
|
+
hasControlCommand: params.hasControlCommand,
|
|
587
|
+
modeWhenAccessGroupsOff: params.modeWhenAccessGroupsOff,
|
|
588
|
+
...isDirectMessage ? { commandOwnerAllowFrom: params.ownerAllowFromLower } : {}
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
async function decideSlackSystemIngress(params) {
|
|
593
|
+
const isDirectMessage = params.channelType === "im";
|
|
594
|
+
const channelUsers = normalizeAllowListLower(params.channelUsers);
|
|
595
|
+
const channelUsersConfigured = !isDirectMessage && channelUsers.length > 0;
|
|
596
|
+
const ownerAllowFrom = params.interactiveEvent && channelUsersConfigured ? params.ownerAllowFromLower.filter((entry) => entry !== "*") : params.ownerAllowFromLower;
|
|
597
|
+
const hasAnyCommandAllowlist = ownerAllowFrom.length > 0 || channelUsersConfigured;
|
|
598
|
+
const groupAllowFrom = (() => {
|
|
599
|
+
if (isDirectMessage) return [];
|
|
600
|
+
if (params.interactiveEvent && hasAnyCommandAllowlist) return channelUsersConfigured ? channelUsers : [];
|
|
601
|
+
if (channelUsersConfigured) return channelUsers;
|
|
602
|
+
return params.channelId ? ["*"] : wildcardWhenOpen(params.ownerAllowFromLower);
|
|
603
|
+
})();
|
|
604
|
+
return (await createSlackIngressResolver(params.ctx).message({
|
|
605
|
+
subject: createSlackIngressSubject({
|
|
606
|
+
senderId: params.senderId,
|
|
607
|
+
senderName: params.senderName
|
|
608
|
+
}),
|
|
609
|
+
conversation: {
|
|
610
|
+
kind: slackIngressConversationKind(params.channelType),
|
|
611
|
+
id: params.channelId ?? "slack-system"
|
|
612
|
+
},
|
|
613
|
+
event: {
|
|
614
|
+
kind: params.interactiveEvent ? "button" : "system",
|
|
615
|
+
authMode: params.interactiveEvent && hasAnyCommandAllowlist ? "command" : "inbound",
|
|
616
|
+
mayPair: false
|
|
617
|
+
},
|
|
618
|
+
dmPolicy: isDirectMessage ? "open" : "disabled",
|
|
619
|
+
groupPolicy: params.interactiveEvent && hasAnyCommandAllowlist ? "open" : channelUsersConfigured || !params.channelId && params.ownerAllowFromLower.length > 0 ? "allowlist" : "open",
|
|
620
|
+
policy: {
|
|
621
|
+
groupAllowFromFallbackToAllowFrom: false,
|
|
622
|
+
mutableIdentifierMatching: params.ctx.allowNameMatching ? "enabled" : "disabled"
|
|
623
|
+
},
|
|
624
|
+
allowFrom: isDirectMessage ? wildcardWhenOpen(params.ownerAllowFromLower) : ownerAllowFrom,
|
|
625
|
+
groupAllowFrom,
|
|
626
|
+
command: params.interactiveEvent && hasAnyCommandAllowlist ? {
|
|
627
|
+
useAccessGroups: true,
|
|
628
|
+
allowTextCommands: true,
|
|
629
|
+
modeWhenAccessGroupsOff: "configured",
|
|
630
|
+
commandOwnerAllowFrom: ownerAllowFrom
|
|
631
|
+
} : void 0
|
|
632
|
+
})).ingress;
|
|
633
|
+
}
|
|
634
|
+
async function authorizeSlackSystemEventSender(params) {
|
|
635
|
+
const senderId = params.senderId?.trim();
|
|
636
|
+
if (!senderId) return {
|
|
637
|
+
allowed: false,
|
|
638
|
+
reason: "missing-sender"
|
|
639
|
+
};
|
|
640
|
+
const expectedSenderId = params.expectedSenderId?.trim();
|
|
641
|
+
if (expectedSenderId && expectedSenderId !== senderId) return {
|
|
642
|
+
allowed: false,
|
|
643
|
+
reason: "sender-mismatch"
|
|
644
|
+
};
|
|
645
|
+
if (params.interactiveEvent && !expectedSenderId) return {
|
|
646
|
+
allowed: false,
|
|
647
|
+
reason: "missing-expected-sender"
|
|
648
|
+
};
|
|
649
|
+
const channelId = params.channelId?.trim();
|
|
650
|
+
let channelType = normalizeSlackChannelType(params.channelType, channelId);
|
|
651
|
+
let channelName;
|
|
652
|
+
if (channelId) {
|
|
653
|
+
const info = await params.ctx.resolveChannelName(channelId).catch(() => ({}));
|
|
654
|
+
channelName = info.name;
|
|
655
|
+
const resolvedTypeSource = params.channelType ?? info.type;
|
|
656
|
+
channelType = normalizeSlackChannelType(resolvedTypeSource, channelId);
|
|
657
|
+
if (!params.ctx.isChannelAllowed({
|
|
658
|
+
channelId,
|
|
659
|
+
channelName,
|
|
660
|
+
channelType
|
|
661
|
+
})) return {
|
|
662
|
+
allowed: false,
|
|
663
|
+
reason: "channel-not-allowed",
|
|
664
|
+
channelType,
|
|
665
|
+
channelName
|
|
666
|
+
};
|
|
667
|
+
if (params.interactiveEvent) {
|
|
668
|
+
const inferredFromId = inferSlackChannelType(channelId);
|
|
669
|
+
const sourceNormalized = typeof resolvedTypeSource === "string" ? resolvedTypeSource.toLowerCase().trim() : void 0;
|
|
670
|
+
if (inferredFromId === void 0 && !(sourceNormalized === "im" || sourceNormalized === "mpim" || sourceNormalized === "channel" || sourceNormalized === "group")) return {
|
|
671
|
+
allowed: false,
|
|
672
|
+
reason: "ambiguous-channel-type",
|
|
673
|
+
channelType,
|
|
674
|
+
channelName
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
const senderName = (await params.ctx.resolveUserName(senderId).catch(() => ({}))).name;
|
|
679
|
+
const ingressChannelType = channelType ?? "channel";
|
|
680
|
+
if (ingressChannelType === "im") {
|
|
681
|
+
if (!params.ctx.dmEnabled || params.ctx.dmPolicy === "disabled") return {
|
|
682
|
+
allowed: false,
|
|
683
|
+
reason: "dm-disabled",
|
|
684
|
+
channelType,
|
|
685
|
+
channelName
|
|
686
|
+
};
|
|
687
|
+
}
|
|
688
|
+
const allowFromLower = await resolveSlackEffectiveAllowFrom(params.ctx, { includePairingStore: ingressChannelType === "im" });
|
|
689
|
+
const channelConfig = channelId ? resolveSlackChannelConfig({
|
|
690
|
+
channelId,
|
|
691
|
+
channelName,
|
|
692
|
+
channels: params.ctx.channelsConfig,
|
|
693
|
+
channelKeys: params.ctx.channelsConfigKeys,
|
|
694
|
+
defaultRequireMention: params.ctx.defaultRequireMention,
|
|
695
|
+
allowNameMatching: params.ctx.allowNameMatching
|
|
696
|
+
}) : null;
|
|
697
|
+
const channelUsersAllowlistConfigured = Array.isArray(channelConfig?.users) && channelConfig.users.length > 0;
|
|
698
|
+
if ((await decideSlackSystemIngress({
|
|
699
|
+
ctx: params.ctx,
|
|
700
|
+
senderId,
|
|
701
|
+
senderName,
|
|
702
|
+
channelType: ingressChannelType,
|
|
703
|
+
channelId,
|
|
704
|
+
ownerAllowFromLower: allowFromLower,
|
|
705
|
+
channelUsers: channelConfig?.users,
|
|
706
|
+
interactiveEvent: params.interactiveEvent === true
|
|
707
|
+
})).decision === "allow") return {
|
|
708
|
+
allowed: true,
|
|
709
|
+
channelType,
|
|
710
|
+
channelName
|
|
711
|
+
};
|
|
712
|
+
if (channelType === "im" || !channelId) return {
|
|
713
|
+
allowed: false,
|
|
714
|
+
reason: "sender-not-allowlisted",
|
|
715
|
+
...channelId ? {
|
|
716
|
+
channelType,
|
|
717
|
+
channelName
|
|
718
|
+
} : {}
|
|
719
|
+
};
|
|
720
|
+
return {
|
|
721
|
+
allowed: false,
|
|
722
|
+
reason: params.interactiveEvent && channelUsersAllowlistConfigured && allowFromLower.length > 0 ? "sender-not-authorized" : channelUsersAllowlistConfigured ? "sender-not-channel-allowed" : "sender-not-allowlisted",
|
|
723
|
+
channelType,
|
|
724
|
+
channelName
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
//#endregion
|
|
728
|
+
//#region extensions/slack/src/monitor/dm-auth.ts
|
|
729
|
+
async function authorizeSlackDirectMessage(params) {
|
|
730
|
+
if (!params.ctx.dmEnabled || params.ctx.dmPolicy === "disabled") {
|
|
731
|
+
await params.onDisabled();
|
|
732
|
+
return false;
|
|
733
|
+
}
|
|
734
|
+
const senderName = (await params.resolveSenderName(params.senderId))?.name ?? void 0;
|
|
735
|
+
const allowMatch = resolveSlackAllowListMatch({
|
|
736
|
+
allowList: params.allowFromLower,
|
|
737
|
+
id: params.senderId,
|
|
738
|
+
name: senderName,
|
|
739
|
+
allowNameMatching: params.ctx.allowNameMatching
|
|
740
|
+
});
|
|
741
|
+
const allowMatchMeta = formatAllowlistMatchMeta(allowMatch);
|
|
742
|
+
if (allowMatch.allowed) return true;
|
|
743
|
+
if (params.ctx.dmPolicy === "pairing") {
|
|
744
|
+
await createChannelPairingChallengeIssuer({
|
|
745
|
+
channel: "slack",
|
|
746
|
+
upsertPairingRequest: async ({ id, meta }) => await upsertChannelPairingRequest({
|
|
747
|
+
channel: "slack",
|
|
748
|
+
id,
|
|
749
|
+
accountId: params.accountId,
|
|
750
|
+
meta
|
|
751
|
+
})
|
|
752
|
+
})({
|
|
753
|
+
senderId: params.senderId,
|
|
754
|
+
senderIdLine: `Your Slack user id: ${params.senderId}`,
|
|
755
|
+
meta: { name: senderName },
|
|
756
|
+
sendPairingReply: params.sendPairingReply,
|
|
757
|
+
onCreated: () => {
|
|
758
|
+
params.log(`slack pairing request sender=${params.senderId} name=${senderName ?? "unknown"} (${allowMatchMeta})`);
|
|
759
|
+
},
|
|
760
|
+
onReplyError: (err) => {
|
|
761
|
+
params.log(`slack pairing reply failed for ${params.senderId}: ${formatErrorMessage(err)}`);
|
|
762
|
+
}
|
|
763
|
+
});
|
|
764
|
+
return false;
|
|
765
|
+
}
|
|
766
|
+
await params.onUnauthorized({
|
|
767
|
+
allowMatchMeta,
|
|
768
|
+
senderName
|
|
769
|
+
});
|
|
770
|
+
return false;
|
|
771
|
+
}
|
|
772
|
+
//#endregion
|
|
773
|
+
//#region extensions/slack/src/monitor/room-context.ts
|
|
774
|
+
function resolveSlackRoomContextHints(params) {
|
|
775
|
+
const untrustedChannelMetadata = params.isRoomish ? buildUntrustedChannelMetadata({
|
|
776
|
+
source: "slack",
|
|
777
|
+
label: "Slack channel description",
|
|
778
|
+
entries: [params.channelInfo?.topic, params.channelInfo?.purpose]
|
|
779
|
+
}) : void 0;
|
|
780
|
+
const systemPromptParts = [params.isRoomish ? normalizeOptionalString(params.channelConfig?.systemPrompt) ?? null : null].filter((entry) => Boolean(entry));
|
|
781
|
+
return {
|
|
782
|
+
untrustedChannelMetadata,
|
|
783
|
+
groupSystemPrompt: systemPromptParts.length > 0 ? systemPromptParts.join("\n\n") : void 0
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
//#endregion
|
|
787
|
+
export { resolveOpenProviderRuntimeGroupPolicy as C, buildSlackSlashCommandMatcher as D, warnMissingProviderGroupPolicyFallbackOnce as E, resolveSlackSlashCommandConfig as O, resolveDefaultGroupPolicy as S, updateLastRoute as T, resolveSlackChannelLabel as _, recordInboundSession as a, readSessionUpdatedAt as b, authorizeSlackBotRoomMessage as c, resolveSlackEffectiveAllowFrom as d, createSlackMonitorContext as f, resolveSlackChannelConfig as g, resolveSlackChatType as h, parsePluginBindingApprovalCustomId as i, stripSlackMentionsForCommandDetection as k, authorizeSlackSystemEventSender as l, normalizeSlackChannelType as m, authorizeSlackDirectMessage as n, resolveConversationLabel$1 as o, isSlackChannelAllowedByPolicy as p, buildPluginBindingResolvedText as r, resolvePluginConversationBindingApproval as s, resolveSlackRoomContextHints as t, resolveSlackCommandIngress as u, getRuntimeConfig$1 as v, resolveStorePath$1 as w, resolveChannelContextVisibilityMode as x, isDangerousNameMatchingEnabled as y };
|