@capybara-hq/plugin-slack 0.1.0-rc.3 → 0.1.0-rc.5

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/index.mjs CHANGED
@@ -25872,9 +25872,9 @@ var require_cache_handler = __commonJS({
25872
25872
  function appendConnectionHeaderTokens(headersToRemove, connectionHeader) {
25873
25873
  const values = Array.isArray(connectionHeader) ? connectionHeader : [connectionHeader];
25874
25874
  for (let i = 0; i < values.length; i++) {
25875
- const tokens = values[i].split(",");
25876
- for (let j = 0; j < tokens.length; j++) {
25877
- headersToRemove.push(trimOWS(tokens[j]).toLowerCase());
25875
+ const tokens2 = values[i].split(",");
25876
+ for (let j = 0; j < tokens2.length; j++) {
25877
+ headersToRemove.push(trimOWS(tokens2[j]).toLowerCase());
25878
25878
  }
25879
25879
  }
25880
25880
  }
@@ -37078,7 +37078,7 @@ var T = {
37078
37078
  question: "Question",
37079
37079
  tool: "Tool",
37080
37080
  agent: "Agent",
37081
- input: "Input",
37081
+ summary: "Summary",
37082
37082
  status: "Status",
37083
37083
  reason: "Reason",
37084
37084
  expires: "Expires",
@@ -37116,7 +37116,7 @@ var T = {
37116
37116
  question: "提问",
37117
37117
  tool: "工具",
37118
37118
  agent: "Agent",
37119
- input: "输入",
37119
+ summary: "摘要",
37120
37120
  status: "状态",
37121
37121
  reason: "原因",
37122
37122
  expires: "过期时间",
@@ -37230,12 +37230,14 @@ ${esc2(c.agentName)}`, FIELD_LIMIT)
37230
37230
  }
37231
37231
  ];
37232
37232
  if (c.inputPreview !== "") {
37233
- const head = `*${t.input}*
37234
- \`\`\`
37235
- `;
37236
- const tail = "\n```";
37237
- const body = trunc(esc2(c.inputPreview), SECTION_TEXT_LIMIT - head.length - tail.length);
37238
- blocks.push(section(`${head}${body}${tail}`));
37233
+ blocks.push({
37234
+ type: "section",
37235
+ text: {
37236
+ type: "plain_text",
37237
+ text: trunc(`${t.summary}${t.sep}${c.inputPreview}`, SECTION_TEXT_LIMIT),
37238
+ emoji: false
37239
+ }
37240
+ });
37239
37241
  }
37240
37242
  if (c.state !== "pending") {
37241
37243
  const state = t.approvalStates[c.state];
@@ -37625,6 +37627,19 @@ function eventToInbound(body, botUserId) {
37625
37627
  }
37626
37628
  };
37627
37629
  }
37630
+ function userInfoProfile(u) {
37631
+ const o = obj2(u);
37632
+ if (!o) return void 0;
37633
+ const base = profileOf(o.profile) ?? profileOf({ real_name: o.real_name, name: o.name });
37634
+ const timeZone = str3(o.tz);
37635
+ const locale = str3(o.locale);
37636
+ if (base === void 0 && timeZone === void 0 && locale === void 0) return void 0;
37637
+ return {
37638
+ ...base,
37639
+ ...timeZone !== void 0 && { timeZone },
37640
+ ...locale !== void 0 && { locale }
37641
+ };
37642
+ }
37628
37643
 
37629
37644
  // src/webhook.ts
37630
37645
  import { createHmac, timingSafeEqual } from "node:crypto";
@@ -37748,8 +37763,7 @@ var MIN_EDIT_INTERVAL_MS = 2500;
37748
37763
  var SHORT_LIVED_MS = 1e4;
37749
37764
  var MAX_SHORT_LIVED = 5;
37750
37765
  var MAX_RECONNECT_DELAY_MS = 3e4;
37751
- var PROFILE_TTL_MS = 10 * 6e4;
37752
- var PROFILE_CACHE_MAX = 1e3;
37766
+ var PROFILE_CACHE_TTL_SECONDS = 600;
37753
37767
  var PROFILE_TIMEOUT_MS = 1500;
37754
37768
  var BOT_DM_CACHE_TTL_SECONDS = 86400;
37755
37769
  var COMMAND_ECHO_TTL_SECONDS = 3600;
@@ -37823,44 +37837,55 @@ function createSlackChannel(opts) {
37823
37837
  });
37824
37838
  };
37825
37839
  const parse = (config) => SlackConnection.parse(config);
37826
- const profiles = /* @__PURE__ */ new Map();
37827
- const lookupProfile = async (botToken, scope, userId, signal) => {
37828
- const key = `${scope}\0${userId}`;
37829
- const hit = profiles.get(key);
37830
- if (hit && Date.now() - hit.at < PROFILE_TTL_MS) return hit.profile;
37840
+ const lookupProfile = async (botToken, teamId, userId, signal) => {
37841
+ const key = `profile/${teamId}/${userId}`;
37842
+ const hit = await opts.kv?.get(key).catch(() => null);
37843
+ if (hit) {
37844
+ try {
37845
+ const cached = JSON.parse(hit);
37846
+ return Object.keys(cached).length > 0 ? cached : void 0;
37847
+ } catch {
37848
+ }
37849
+ }
37831
37850
  let profile;
37832
37851
  try {
37833
37852
  const s = AbortSignal.any([signal, AbortSignal.timeout(PROFILE_TIMEOUT_MS)]);
37834
- const r = await web(botToken, s).apiCall("users.info", { user: userId });
37835
- profile = profileOf(r.user?.profile) ?? profileOf({ real_name: r.user?.real_name, name: r.user?.name });
37853
+ const r = await web(botToken, s).apiCall("users.info", {
37854
+ user: userId,
37855
+ include_locale: true
37856
+ });
37857
+ profile = userInfoProfile(r.user);
37836
37858
  } catch (e) {
37837
- const code = platformErrorCode(e);
37838
- if (code !== "user_not_found") return void 0;
37839
- }
37840
- profiles.delete(key);
37841
- profiles.set(key, { at: Date.now(), profile });
37842
- if (profiles.size > PROFILE_CACHE_MAX) {
37843
- const oldest = profiles.keys().next().value;
37844
- if (oldest !== void 0) profiles.delete(oldest);
37859
+ if (platformErrorCode(e) !== "user_not_found") return void 0;
37845
37860
  }
37861
+ await opts.kv?.set(key, JSON.stringify(profile ?? {}), { ttlSeconds: PROFILE_CACHE_TTL_SECONDS }).catch(() => {
37862
+ });
37846
37863
  return profile;
37847
37864
  };
37848
37865
  const withProfile = (sender, p) => ({
37849
37866
  ...sender,
37850
37867
  ...p?.displayName !== void 0 && { displayName: p.displayName },
37851
- ...p?.avatarUrl !== void 0 && { avatarUrl: p.avatarUrl }
37868
+ ...p?.avatarUrl !== void 0 && { avatarUrl: p.avatarUrl },
37869
+ ...p?.timeZone !== void 0 && { timeZone: p.timeZone },
37870
+ ...p?.locale !== void 0 && { locale: p.locale }
37852
37871
  });
37853
- const toEvent = async (c, connectionId, botUserId, { type, body }, signal) => {
37872
+ const toEvent = async (c, botUserId, { type, body }, signal) => {
37854
37873
  if (type === "events_api") {
37855
37874
  const cand = eventToInbound(body, botUserId);
37856
37875
  if (!cand) return null;
37857
37876
  if (cand.kind === "directory") return cand.event;
37858
- const p2 = cand.profile ?? await lookupProfile(c.botToken, connectionId, cand.userId, signal);
37877
+ const looked = await lookupProfile(
37878
+ c.botToken,
37879
+ cand.event.sender.tenantId,
37880
+ cand.userId,
37881
+ signal
37882
+ );
37883
+ const p2 = looked || cand.profile ? { ...looked, ...cand.profile } : void 0;
37859
37884
  return { ...cand.event, sender: withProfile(cand.event.sender, p2) };
37860
37885
  }
37861
37886
  const a = parseBlockActions(body);
37862
37887
  if (!a) return null;
37863
- const p = await lookupProfile(c.botToken, connectionId, a.sender.externalId, signal) ?? (a.username !== void 0 ? { displayName: a.username } : void 0);
37888
+ const p = await lookupProfile(c.botToken, a.sender.tenantId, a.sender.externalId, signal) ?? (a.username !== void 0 ? { displayName: a.username } : void 0);
37864
37889
  return {
37865
37890
  type: "card_action",
37866
37891
  messageId: a.messageId,
@@ -37931,7 +37956,7 @@ function createSlackChannel(opts) {
37931
37956
  if (!cmd) return { event: null, response: void 0 };
37932
37957
  const text = slashCommandText(cmd.command, cmd.text);
37933
37958
  if (text === null) return { event: null, response: ephemeral(SLASH_REPLIES.usage) };
37934
- const profile = lookupProfile(c.botToken, connectionId, cmd.userId, signal).then(
37959
+ const profile = lookupProfile(c.botToken, cmd.teamId, cmd.userId, signal).then(
37935
37960
  (p2) => p2 ?? (cmd.userName !== void 0 ? { displayName: cmd.userName } : void 0)
37936
37961
  );
37937
37962
  const sender = { externalId: cmd.userId, tenantId: cmd.teamId };
@@ -38018,7 +38043,7 @@ function createSlackChannel(opts) {
38018
38043
  let response;
38019
38044
  try {
38020
38045
  if (type === "events_api" || type === "interactive") {
38021
- event = await toEvent(c, connectionId, botUserId, { type, body }, signal);
38046
+ event = await toEvent(c, botUserId, { type, body }, signal);
38022
38047
  } else if (type === "slash_commands") {
38023
38048
  ({ event, response } = await toCommand(c, connectionId, body, signal));
38024
38049
  }
@@ -38141,7 +38166,7 @@ function createSlackChannel(opts) {
38141
38166
  },
38142
38167
  toEvent: async (envelope, botUserId) => {
38143
38168
  try {
38144
- return await toEvent(c, connectionId, botUserId, envelope, signal);
38169
+ return await toEvent(c, botUserId, envelope, signal);
38145
38170
  } catch (e) {
38146
38171
  log.warn("slack: could not read a webhook event; acknowledging and skipping it", {
38147
38172
  connectionId,
@@ -39165,26 +39190,355 @@ function createSlackIdentitySource() {
39165
39190
  };
39166
39191
  }
39167
39192
 
39193
+ // src/setup-checks.ts
39194
+ var REQUIRED_BOT_SCOPES = [
39195
+ "chat:write",
39196
+ "commands",
39197
+ "im:write",
39198
+ "im:history",
39199
+ "app_mentions:read",
39200
+ "channels:history",
39201
+ "groups:history",
39202
+ "users:read",
39203
+ "users:read.email"
39204
+ ];
39205
+ var ERROR_CODE_RE = /^[a-z][a-z0-9_.]{0,63}$/;
39206
+ async function slackCall(apiUrl, method, token, signal) {
39207
+ let res;
39208
+ try {
39209
+ res = await fetch(new URL(method, apiUrl), {
39210
+ method: "POST",
39211
+ headers: {
39212
+ "content-type": "application/x-www-form-urlencoded",
39213
+ authorization: `Bearer ${token}`
39214
+ },
39215
+ body: "",
39216
+ redirect: "manual",
39217
+ signal
39218
+ });
39219
+ } catch {
39220
+ return { kind: "network" };
39221
+ }
39222
+ if (res.status !== 200) {
39223
+ await res.body?.cancel().catch(() => void 0);
39224
+ return { kind: "http", status: res.status };
39225
+ }
39226
+ let body;
39227
+ try {
39228
+ body = await res.json();
39229
+ } catch {
39230
+ return { kind: "network" };
39231
+ }
39232
+ if (typeof body !== "object" || body === null) return { kind: "error", code: "invalid_response" };
39233
+ const b = body;
39234
+ if (b.ok === true) return { kind: "ok", body: b, headers: res.headers };
39235
+ const code = typeof b.error === "string" && ERROR_CODE_RE.test(b.error) ? b.error : "unknown_error";
39236
+ return { kind: "error", code };
39237
+ }
39238
+ var unknown = (reason) => ({ status: "unknown", reason });
39239
+ var failing = (reason, fix) => ({ status: "failing", reason, fix });
39240
+ var TRANSIENT = /* @__PURE__ */ new Set([
39241
+ "ratelimited",
39242
+ "rate_limited",
39243
+ "internal_error",
39244
+ "fatal_error",
39245
+ "service_unavailable",
39246
+ "request_timeout"
39247
+ ]);
39248
+ var REFUSED = /* @__PURE__ */ new Set([
39249
+ "invalid_auth",
39250
+ "not_authed",
39251
+ "token_revoked",
39252
+ "token_expired",
39253
+ "account_inactive",
39254
+ "no_permission",
39255
+ "ekm_access_denied"
39256
+ ]);
39257
+ function notAnswered(r) {
39258
+ if (r.kind === "network")
39259
+ return unknown({
39260
+ en: "Could not reach Slack (network error or timeout); check again later.",
39261
+ zh: "无法连接 Slack(网络错误或超时),请稍后再检查。"
39262
+ });
39263
+ if (r.kind === "http") {
39264
+ if (r.status === 429)
39265
+ return unknown({
39266
+ en: "Slack is rate limiting requests; check again in a minute.",
39267
+ zh: "Slack 正在限流,请一分钟后再检查。"
39268
+ });
39269
+ return unknown({
39270
+ en: `Slack answered HTTP ${r.status}; check again later.`,
39271
+ zh: `Slack 返回 HTTP ${r.status},请稍后再检查。`
39272
+ });
39273
+ }
39274
+ if (r.code === "ratelimited" || r.code === "rate_limited")
39275
+ return unknown({
39276
+ en: "Slack is rate limiting requests; check again in a minute.",
39277
+ zh: "Slack 正在限流,请一分钟后再检查。"
39278
+ });
39279
+ if (TRANSIENT.has(r.code))
39280
+ return unknown({
39281
+ en: `Slack is temporarily unavailable (${r.code}); check again later.`,
39282
+ zh: `Slack 暂时不可用(${r.code}),请稍后再检查。`
39283
+ });
39284
+ return unknown({
39285
+ en: `Slack answered ${r.code}; the check could not tell whether the setup is right.`,
39286
+ zh: `Slack 返回 ${r.code},无法判断设置是否正确。`
39287
+ });
39288
+ }
39289
+ var BOT_TOKEN_FIX = {
39290
+ en: "Under Install App, reinstall the app to the workspace and copy the new Bot User OAuth Token (xoxb-…) into the Bot token field.",
39291
+ zh: "在 Install App 中把应用重新安装到工作区,再把新的 Bot User OAuth Token(xoxb-…)填进「机器人令牌」。"
39292
+ };
39293
+ var MANIFEST_FIX = {
39294
+ en: "Open the app at https://api.slack.com/apps, paste the manifest from this guide under App Manifest, save, then reinstall the app under Install App.",
39295
+ zh: "在 https://api.slack.com/apps 打开该应用,在 App Manifest 粘贴本指南中的 manifest 并保存,然后在 Install App 中重新安装应用。"
39296
+ };
39297
+ function botTokenRefused(code) {
39298
+ if (REFUSED.has(code))
39299
+ return failing(
39300
+ {
39301
+ en: `Slack refused the bot token (${code}); it may have been revoked or the app uninstalled.`,
39302
+ zh: `Slack 拒绝了机器人令牌(${code}),令牌可能已被撤销或应用已被卸载。`
39303
+ },
39304
+ BOT_TOKEN_FIX
39305
+ );
39306
+ if (code === "not_allowed_token_type")
39307
+ return failing(
39308
+ {
39309
+ en: "The Bot token field holds a token of the wrong type (not_allowed_token_type).",
39310
+ zh: "「机器人令牌」中的令牌类型不对(not_allowed_token_type)。"
39311
+ },
39312
+ {
39313
+ en: "Copy the Bot User OAuth Token (xoxb-…) from Install App, not a user or app-level token.",
39314
+ zh: "从 Install App 复制 Bot User OAuth Token(xoxb-…),不要用用户令牌或应用级令牌。"
39315
+ }
39316
+ );
39317
+ if (code === "missing_scope")
39318
+ return failing(
39319
+ {
39320
+ en: "Slack refused the call for a missing scope (missing_scope).",
39321
+ zh: "Slack 因缺少权限拒绝了调用(missing_scope)。"
39322
+ },
39323
+ MANIFEST_FIX
39324
+ );
39325
+ return void 0;
39326
+ }
39327
+ function plain2(s, max = 80) {
39328
+ if (typeof s !== "string") return void 0;
39329
+ const t = s.replace(/[\p{C}\p{Zl}\p{Zp}]/gu, "").trim().slice(0, max);
39330
+ return t === "" ? void 0 : t;
39331
+ }
39332
+ function tokens(args) {
39333
+ if (args.target.kind !== "channel-connection") return void 0;
39334
+ const c = args.target.config;
39335
+ if (typeof c !== "object" || c === null) return {};
39336
+ const x = c;
39337
+ return {
39338
+ ...typeof x.botToken === "string" && x.botToken !== "" && { botToken: x.botToken },
39339
+ ...typeof x.appToken === "string" && x.appToken !== "" && { appToken: x.appToken }
39340
+ };
39341
+ }
39342
+ var NOT_A_CONNECTION = unknown({
39343
+ en: "This check applies to Slack channel connections only.",
39344
+ zh: "此检查只适用于 Slack 渠道连接。"
39345
+ });
39346
+ var NO_BOT_TOKEN = failing(
39347
+ { en: "No bot token is set on this connection.", zh: "这个渠道连接还没有填写机器人令牌。" },
39348
+ {
39349
+ en: "Install the app under Install App and copy the Bot User OAuth Token (xoxb-…) into the Bot token field.",
39350
+ zh: "在 Install App 安装应用,把 Bot User OAuth Token(xoxb-…)填进「机器人令牌」。"
39351
+ }
39352
+ );
39353
+ function botTokenCheck(opts) {
39354
+ return {
39355
+ place: "channel-connection",
39356
+ async run(args) {
39357
+ const t = tokens(args);
39358
+ if (t === void 0) return NOT_A_CONNECTION;
39359
+ if (t.botToken === void 0) return NO_BOT_TOKEN;
39360
+ const r = await slackCall(opts.apiUrl(), "auth.test", t.botToken, args.signal);
39361
+ if (r.kind !== "ok") {
39362
+ return r.kind === "error" && botTokenRefused(r.code) || notAnswered(r);
39363
+ }
39364
+ const problem = workspaceTokenProblem(r.body);
39365
+ if (problem !== void 0)
39366
+ return failing(
39367
+ {
39368
+ en: `${problem}.`,
39369
+ zh: "这个机器人令牌不是工作区令牌(来自组织级安装或企业 ID)。"
39370
+ },
39371
+ {
39372
+ en: "Install the app to one workspace (not org-wide) and copy that workspace's Bot User OAuth Token.",
39373
+ zh: "把应用安装到单个工作区(不要组织级安装),再复制该工作区的 Bot User OAuth Token。"
39374
+ }
39375
+ );
39376
+ if (typeof r.body.bot_id !== "string" || r.body.bot_id === "")
39377
+ return failing(
39378
+ {
39379
+ en: "Slack accepted the token, but it is not a bot token.",
39380
+ zh: "Slack 接受了该令牌,但它不是机器人令牌。"
39381
+ },
39382
+ {
39383
+ en: "Copy the Bot User OAuth Token (xoxb-…) from Install App into the Bot token field.",
39384
+ zh: "从 Install App 复制 Bot User OAuth Token(xoxb-…)填进「机器人令牌」。"
39385
+ }
39386
+ );
39387
+ const teamId = plain2(r.body.team_id, 32) ?? "";
39388
+ const team = plain2(r.body.team);
39389
+ const where = team !== void 0 ? `${team} (${teamId})` : teamId;
39390
+ return {
39391
+ status: "ok",
39392
+ reason: {
39393
+ en: `Slack accepted the bot token for workspace ${where}.`,
39394
+ zh: `Slack 接受了工作区 ${where} 的机器人令牌。`
39395
+ }
39396
+ };
39397
+ }
39398
+ };
39399
+ }
39400
+ function botScopesCheck(opts) {
39401
+ return {
39402
+ place: "channel-connection",
39403
+ async run(args) {
39404
+ const t = tokens(args);
39405
+ if (t === void 0) return NOT_A_CONNECTION;
39406
+ if (t.botToken === void 0)
39407
+ return unknown({
39408
+ en: "No bot token is set yet, so the scopes cannot be read.",
39409
+ zh: "还没有填写机器人令牌,无法读取权限。"
39410
+ });
39411
+ const r = await slackCall(opts.apiUrl(), "auth.test", t.botToken, args.signal);
39412
+ if (r.kind !== "ok") {
39413
+ if (r.kind === "error" && (REFUSED.has(r.code) || r.code === "not_allowed_token_type"))
39414
+ return unknown({
39415
+ en: `Slack refused the bot token (${r.code}), so the scopes cannot be read; see the bot token row.`,
39416
+ zh: `Slack 拒绝了机器人令牌(${r.code}),无法读取权限;请看「机器人令牌」一行。`
39417
+ });
39418
+ return notAnswered(r);
39419
+ }
39420
+ const header = r.headers.get("x-oauth-scopes");
39421
+ if (header === null)
39422
+ return unknown({
39423
+ en: "Slack did not report the token's scopes; check again later.",
39424
+ zh: "Slack 没有返回令牌的权限,请稍后再检查。"
39425
+ });
39426
+ const granted = new Set(
39427
+ header.split(",").map((s) => s.trim()).filter((s) => s !== "")
39428
+ );
39429
+ const missing = REQUIRED_BOT_SCOPES.filter((s) => !granted.has(s));
39430
+ if (missing.length > 0)
39431
+ return failing(
39432
+ {
39433
+ en: `The app is missing the bot scopes ${missing.join(", ")}.`,
39434
+ zh: `应用缺少机器人权限 ${missing.join("、")}。`
39435
+ },
39436
+ MANIFEST_FIX
39437
+ );
39438
+ return {
39439
+ status: "ok",
39440
+ reason: {
39441
+ en: `The bot token has all ${REQUIRED_BOT_SCOPES.length} scopes the manifest asks for.`,
39442
+ zh: `机器人令牌具备 manifest 要求的全部 ${REQUIRED_BOT_SCOPES.length} 项权限。`
39443
+ }
39444
+ };
39445
+ }
39446
+ };
39447
+ }
39448
+ var APP_TOKEN_FIX = {
39449
+ en: "Under Basic Information → App-Level Tokens choose Generate Token and Scopes, add the scope connections:write and copy the xapp-… token into the App-level token field.",
39450
+ zh: "在 Basic Information → App-Level Tokens 选择 Generate Token and Scopes,添加权限 connections:write,把 xapp-… 令牌填进「应用令牌」。"
39451
+ };
39452
+ function appTokenCheck(opts) {
39453
+ return {
39454
+ place: "channel-connection",
39455
+ async run(args) {
39456
+ const t = tokens(args);
39457
+ if (t === void 0) return NOT_A_CONNECTION;
39458
+ if (args.mode !== null && args.mode !== "long_connection")
39459
+ return unknown({
39460
+ en: "Webhook mode does not use an app-level token.",
39461
+ zh: "Webhook 模式不使用应用级令牌。"
39462
+ });
39463
+ if (t.appToken === void 0)
39464
+ return failing(
39465
+ {
39466
+ en: "No app-level token is set; Socket Mode needs one.",
39467
+ zh: "还没有填写应用令牌,Socket Mode 需要它。"
39468
+ },
39469
+ APP_TOKEN_FIX
39470
+ );
39471
+ const r = await slackCall(opts.apiUrl(), "apps.connections.open", t.appToken, args.signal);
39472
+ if (r.kind === "ok")
39473
+ return {
39474
+ status: "ok",
39475
+ reason: {
39476
+ en: "Slack accepted the app-level token and offered a Socket Mode connection.",
39477
+ zh: "Slack 接受了应用令牌,并提供了 Socket Mode 连接。"
39478
+ }
39479
+ };
39480
+ if (r.kind === "error") {
39481
+ if (REFUSED.has(r.code))
39482
+ return failing(
39483
+ {
39484
+ en: `Slack refused the app-level token (${r.code}); it may have been revoked.`,
39485
+ zh: `Slack 拒绝了应用令牌(${r.code}),令牌可能已被撤销。`
39486
+ },
39487
+ APP_TOKEN_FIX
39488
+ );
39489
+ if (r.code === "not_allowed_token_type")
39490
+ return failing(
39491
+ {
39492
+ en: "The App-level token field holds a token of the wrong type (not_allowed_token_type).",
39493
+ zh: "「应用令牌」中的令牌类型不对(not_allowed_token_type)。"
39494
+ },
39495
+ APP_TOKEN_FIX
39496
+ );
39497
+ if (r.code === "missing_scope")
39498
+ return failing(
39499
+ {
39500
+ en: "The app-level token lacks the scope connections:write (missing_scope).",
39501
+ zh: "应用令牌缺少权限 connections:write(missing_scope)。"
39502
+ },
39503
+ APP_TOKEN_FIX
39504
+ );
39505
+ }
39506
+ return notAnswered(r);
39507
+ }
39508
+ };
39509
+ }
39510
+
39168
39511
  // src/index.ts
39169
39512
  var index_default = defineExtension({
39170
39513
  name: "slack",
39171
- version: "0.1.0-rc.3",
39514
+ version: "0.1.0-rc.5",
39172
39515
  sdk: "^0.1.0-rc.0",
39173
39516
  provides: [CHANNEL_EXTENSION_POINT, IDENTITY_SOURCE_EXTENSION_POINT, DIRECTORY_EXTENSION_POINT],
39174
- permissions: { network: ["slack.com", "wss-primary.slack.com"] },
39517
+ permissions: {
39518
+ network: ["slack.com", "wss-primary.slack.com"],
39519
+ setupChecks: ["bot-token", "bot-scopes", "app-token"]
39520
+ },
39175
39521
  config: { deployment: SlackDeployment, org: SlackDirectoryConfig },
39176
39522
  setup(ctx) {
39177
39523
  const { apiUrl } = SlackDeployment.parse(ctx.config ?? {});
39178
39524
  ctx.provide(CHANNEL_EXTENSION_POINT, createSlackChannel({ apiUrl, log: ctx.log, kv: ctx.kv }));
39179
39525
  ctx.provide(IDENTITY_SOURCE_EXTENSION_POINT, createSlackIdentitySource());
39180
39526
  ctx.provide(DIRECTORY_EXTENSION_POINT, createSlackDirectory({ apiUrl }));
39527
+ const checks = { apiUrl: () => SlackDeployment.parse(ctx.config ?? {}).apiUrl };
39528
+ ctx.setup.check("bot-token", botTokenCheck(checks));
39529
+ ctx.setup.check("bot-scopes", botScopesCheck(checks));
39530
+ ctx.setup.check("app-token", appTokenCheck(checks));
39181
39531
  }
39182
39532
  });
39183
39533
  export {
39184
39534
  MIN_EDIT_INTERVAL_MS,
39535
+ REQUIRED_BOT_SCOPES,
39185
39536
  SlackConnection,
39186
39537
  SlackDeployment,
39187
39538
  SlackDirectoryConfig,
39539
+ appTokenCheck,
39540
+ botScopesCheck,
39541
+ botTokenCheck,
39188
39542
  createSlackChannel,
39189
39543
  createSlackDirectory,
39190
39544
  createSlackIdentitySource,