@capybara-hq/plugin-slack 0.1.0-rc.1 → 0.1.0-rc.3
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/.capybara-plugin/plugin.json +19 -6
- package/README.md +75 -10
- package/app-manifest.yaml +18 -0
- package/dist/index.mjs +267 -62
- package/icon.svg +1 -0
- package/package.json +1 -1
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
3
|
"name": "slack",
|
|
4
|
-
"version": "0.1.0-rc.
|
|
4
|
+
"version": "0.1.0-rc.3",
|
|
5
5
|
"publisher": "Capybara",
|
|
6
6
|
"description": "Slack (channel@1 bot over Socket Mode with Block Kit cards, identity-source@1 Sign in with Slack, directory@1)",
|
|
7
7
|
"displayName": {
|
|
8
8
|
"zh": "Slack",
|
|
9
9
|
"en": "Slack"
|
|
10
10
|
},
|
|
11
|
+
"icon": "./icon.svg",
|
|
11
12
|
"homepage": "https://github.com/capybara-hq/plugins/tree/main/plugins/slack#readme",
|
|
12
13
|
"extension": {
|
|
13
14
|
"entry": "./dist/index.mjs",
|
|
14
15
|
"manifest": {
|
|
15
16
|
"name": "slack",
|
|
16
|
-
"version": "0.1.0-rc.
|
|
17
|
+
"version": "0.1.0-rc.3",
|
|
17
18
|
"sdk": "^0.1.0-rc.0",
|
|
18
19
|
"provides": [
|
|
19
20
|
"channel@1",
|
|
@@ -128,9 +129,15 @@
|
|
|
128
129
|
"label": {
|
|
129
130
|
"zh": "工作区 ID",
|
|
130
131
|
"en": "Workspace ID"
|
|
131
|
-
}
|
|
132
|
+
},
|
|
133
|
+
"help": {
|
|
134
|
+
"zh": "选填:和机器人令牌一起用于把 Slack 成员同步到组织;只用机器人收发消息时不用填。",
|
|
135
|
+
"en": "Optional: used with the bot token to sync Slack members into the org. Leave empty if you only use the bot for chat."
|
|
136
|
+
},
|
|
137
|
+
"placeholder": "T0123ABCD"
|
|
132
138
|
},
|
|
133
|
-
"title": "Workspace ID"
|
|
139
|
+
"title": "Workspace ID",
|
|
140
|
+
"description": "Optional: used with the bot token to sync Slack members into the org. Leave empty if you only use the bot for chat."
|
|
134
141
|
},
|
|
135
142
|
"botToken": {
|
|
136
143
|
"type": "string",
|
|
@@ -140,9 +147,15 @@
|
|
|
140
147
|
"label": {
|
|
141
148
|
"zh": "机器人令牌",
|
|
142
149
|
"en": "Bot token"
|
|
143
|
-
}
|
|
150
|
+
},
|
|
151
|
+
"help": {
|
|
152
|
+
"zh": "选填,仅用于成员同步;聊天用的令牌在新建渠道连接时填。",
|
|
153
|
+
"en": "Optional, only for member sync. The tokens for chat go into the channel connection you create under Channels."
|
|
154
|
+
},
|
|
155
|
+
"placeholder": "xoxb-…"
|
|
144
156
|
},
|
|
145
|
-
"title": "Bot token"
|
|
157
|
+
"title": "Bot token",
|
|
158
|
+
"description": "Optional, only for member sync. The tokens for chat go into the channel connection you create under Channels."
|
|
146
159
|
}
|
|
147
160
|
}
|
|
148
161
|
}
|
package/README.md
CHANGED
|
@@ -18,11 +18,14 @@ The Slack docs cited here were consulted on 2026-10-20.
|
|
|
18
18
|
1. Open <https://api.slack.com/apps> → **Create New App** → **From a manifest**, pick the workspace, and paste this directory's
|
|
19
19
|
[`app-manifest.yaml`](./app-manifest.yaml) (format: [App manifest reference](https://docs.slack.dev/reference/app-manifest)).
|
|
20
20
|
It turns on Socket Mode and Interactivity, subscribes to the events `message.im`, `app_mention`, `message.channels`,
|
|
21
|
-
`message.groups`, `team_join` and `user_change`,
|
|
21
|
+
`message.groups`, `team_join` and `user_change`, registers the slash commands `/new`, `/env` and
|
|
22
|
+
`/capybara` (see [Commands](#commands)), and requests these bot scopes:
|
|
22
23
|
|
|
23
24
|
| scope | Purpose |
|
|
24
25
|
|---|---|
|
|
25
|
-
| `chat:write` | Send and update replies and cards |
|
|
26
|
+
| `chat:write` | Send and update replies and cards; post the visible echo of a slash command run in a channel |
|
|
27
|
+
| `commands` | Receive the slash commands `/new`, `/env`, `/capybara` |
|
|
28
|
+
| `im:write` | `conversations.open`: tell the bot's own DM from a DM between two people where a slash command was run |
|
|
26
29
|
| `im:history` | Receive DM messages |
|
|
27
30
|
| `app_mentions:read` | Receive messages that @-mention the bot in channels |
|
|
28
31
|
| `channels:history` / `groups:history` | Receive thread replies in public / private channels |
|
|
@@ -32,8 +35,10 @@ The Slack docs cited here were consulted on 2026-10-20.
|
|
|
32
35
|
2. **Basic Information → App-Level Tokens → Generate Token and Scopes**: add the scope `connections:write`
|
|
33
36
|
to get the app-level token `xapp-…` (Socket Mode uses it to call `apps.connections.open`).
|
|
34
37
|
3. **Install App → Install to Workspace** to get the bot token `xoxb-…`.
|
|
35
|
-
4. In the Capybara org settings, enable the `slack` plugin
|
|
36
|
-
|
|
38
|
+
4. In the Capybara org settings, enable the `slack` plugin (its org-level fields are optional and only for
|
|
39
|
+
[directory sync](#directory-directory1): leave them empty if you only chat with the bot), then **create a new channel
|
|
40
|
+
connection** under Channels: pick Slack as the plugin, fill in the app-level token (`appToken`, `xapp-…`) and
|
|
41
|
+
the bot token (`botToken`, `xoxb-…`), and bind an agent. Both are stored in the secret store, and the API only returns "set".
|
|
37
42
|
5. In Slack, DM the bot, or add the bot to a channel and @-mention it. The first conversation gets a binding card; click the button to confirm the binding on the web page.
|
|
38
43
|
|
|
39
44
|
Note: apps that use Socket Mode cannot currently be listed in the public Slack Marketplace, and one app can hold at most 10 concurrent
|
|
@@ -57,7 +62,10 @@ connection → Overview → Inbound mode); the connection page then shows its we
|
|
|
57
62
|
2. In the app settings, turn **Socket Mode** off, then use the webhook URL as the **Event
|
|
58
63
|
Subscriptions → Request URL** (Slack verifies it with a `url_verification` challenge, which the
|
|
59
64
|
plugin answers) and as the **Interactivity & Shortcuts → Request URL** (card buttons).
|
|
60
|
-
3.
|
|
65
|
+
3. Under **Slash Commands**, edit `/new`, `/env` and `/capybara` and set each one's **Request URL**
|
|
66
|
+
to the same webhook URL (the manifest leaves it out, since Socket Mode needs none). The plugin tells
|
|
67
|
+
a slash command from an event by its form body and answers it like Socket Mode does.
|
|
68
|
+
4. `appToken` is optional in webhook mode: only Socket Mode uses it.
|
|
61
69
|
|
|
62
70
|
Both modes parse events the same way (same message and card-click ids), so the kernel's dedupe
|
|
63
71
|
still drops a redelivery that arrives across a mode switch.
|
|
@@ -114,6 +122,51 @@ channel connection uses, but the config is stored separately and goes through th
|
|
|
114
122
|
- When `teamId` / `botToken` are not filled in (the org only uses the bot), the plugin's `configured()` returns false: the kernel does not scan or sync, and records no audit
|
|
115
123
|
or warning; a manual sync returns 409 `directory.not_configured`. It is not treated as an empty directory.
|
|
116
124
|
|
|
125
|
+
## Commands
|
|
126
|
+
|
|
127
|
+
The kernel parses commands from the message text: `/new` (DM: start a new conversation), `/env [name]`
|
|
128
|
+
(DM: list or set your default environment) and `/<skill> args` (invoke a skill). The Slack client,
|
|
129
|
+
however, treats any message starting with `/` as a slash command and refuses names no app registered
|
|
130
|
+
("/env is not a valid command"), so those messages never reach the bot. The app therefore registers
|
|
131
|
+
three slash commands, and the plugin turns each back into the text the kernel parses (it parses no
|
|
132
|
+
command itself):
|
|
133
|
+
|
|
134
|
+
| Slash command | Text the kernel gets |
|
|
135
|
+
|---|---|
|
|
136
|
+
| `/new` | `/new` |
|
|
137
|
+
| `/env [name]` | `/env [name]` |
|
|
138
|
+
| `/capybara <skill> [args]` | `/<skill> [args]` (`/capybara fix-issue 12` → `/fix-issue 12`; also `/capybara github:fix-issue 12`) |
|
|
139
|
+
|
|
140
|
+
`@capybara /fix-issue 12` in a channel still works as plain text, as before. Commands other than `/new`
|
|
141
|
+
and `/env` map like `/capybara`, so an admin may rename it (for example when another app already owns
|
|
142
|
+
`/capybara`). Slack lets several apps register `/new` or `/env`; a person who has two such apps picks
|
|
143
|
+
one in Slack's menu.
|
|
144
|
+
|
|
145
|
+
- **In your DM with the bot**: the command becomes a DM message from you, exactly as if you had typed
|
|
146
|
+
the text (binding, `/new`, `/env` and skills behave the same). Slack shows no slash command in the
|
|
147
|
+
conversation, so the ack carries an ephemeral echo of what you ran ("only visible to you"); the
|
|
148
|
+
kernel's reply follows as usual. The message id is `<DM channel>:cmd-<trigger_id>`.
|
|
149
|
+
- **In a channel**: the bot first posts a visible echo `@you: /capybara fix-issue 12` and the event is
|
|
150
|
+
that message, with `mentionsBot: true` (the same as `@capybara /fix-issue 12`): the kernel applies its
|
|
151
|
+
group rules (`/new` and `/env` are plain text in a group) and replies in the echo's thread, where you
|
|
152
|
+
can follow up by @-mentioning the bot. The bot must be in the channel; otherwise you get an
|
|
153
|
+
ephemeral "invite the app first" hint and nothing is sent to the kernel.
|
|
154
|
+
- **In a DM between two people** (where the bot cannot reply): an ephemeral hint to use your DM with
|
|
155
|
+
the app or a channel; nothing is sent. The plugin finds the bot's own DM with `conversations.open`
|
|
156
|
+
(cached in kv for a day; if the lookup fails it assumes the DM is the bot's).
|
|
157
|
+
- **`/capybara` without a skill**: an ephemeral usage line.
|
|
158
|
+
- **Ack**: Slack wants a slash command acked within 3 seconds and never redelivers one. The plugin acks
|
|
159
|
+
only after `onEvent` resolves, which is quick (the kernel dedupes and enqueues); before it, at most
|
|
160
|
+
one Web API call runs (the echo post, or the DM lookup), each with a 1.5 second timeout, in parallel
|
|
161
|
+
with the profile lookup. If `onEvent` rejects, nothing is acked and Slack shows the person a timeout
|
|
162
|
+
error, so they run the command again. A Socket Mode redelivery of the same command (same
|
|
163
|
+
`trigger_id`) reuses the cached echo, so it is posted once.
|
|
164
|
+
- The fixed hints are bilingual (English · 中文): the org's IM language is not known on inbound.
|
|
165
|
+
|
|
166
|
+
Existing apps: re-paste the manifest (**App Manifest** in the app settings) or add the three commands
|
|
167
|
+
by hand under **Slash Commands**, add the bot scopes `commands` and `im:write`, then **reinstall the
|
|
168
|
+
app** to the workspace (Slack asks for it because the scopes changed). The bot token stays the same.
|
|
169
|
+
|
|
117
170
|
## Behavior
|
|
118
171
|
|
|
119
172
|
- **DMs**: every text message goes to the kernel. **Channels**: only messages that @-mention the bot (a new message gets a thread reply under it), and replies inside threads
|
|
@@ -146,9 +199,13 @@ channel connection uses, but the config is stored separately and goes through th
|
|
|
146
199
|
|
|
147
200
|
| Field | Description |
|
|
148
201
|
|---|---|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
|
202
|
+
Shown in the form with zh / en labels and help.
|
|
203
|
+
|
|
204
|
+
| Field | Label | Description |
|
|
205
|
+
|---|---|---|
|
|
206
|
+
| `appToken` | App-level token / 应用令牌 | `xapp-…` (secret); required for Socket Mode (Basic Information → App-Level Tokens, scope `connections:write`), unused in webhook mode |
|
|
207
|
+
| `botToken` | Bot token / 机器人令牌 | `xoxb-…` (secret; Install App → Bot User OAuth Token) |
|
|
208
|
+
| `signingSecret` | Signing secret / 签名密钥 | Secret; only needed in webhook mode, leave empty for Socket Mode |
|
|
152
209
|
|
|
153
210
|
## Deployment-level config
|
|
154
211
|
|
|
@@ -165,5 +222,13 @@ The deployment-level config lives under the kernel config `extensionConfig.slack
|
|
|
165
222
|
|
|
166
223
|
| Field | Description |
|
|
167
224
|
|---|---|
|
|
168
|
-
| `teamId` |
|
|
169
|
-
| `botToken` |
|
|
225
|
+
| `teamId` | Optional: the Slack workspace id (`T…`) for syncing members into the org; leave empty if you only chat with the bot |
|
|
226
|
+
| `botToken` | Optional, only for member sync (`xoxb-…`, secret); the tokens for chat go into the channel connection |
|
|
227
|
+
|
|
228
|
+
## Icon
|
|
229
|
+
|
|
230
|
+
`icon.svg`: the Slack mark (owner: Slack (Salesforce)), downloaded on 2026-11-08 from the Slack media kit,
|
|
231
|
+
https://slack.com/media-kit (Logos: https://salesforce.widencollective.com/c/yn6bxnam, file
|
|
232
|
+
SLA-Slack-icon-RGB.svg). It is a trademark of its owner, used only to identify the service this
|
|
233
|
+
plugin connects to; the plugin is not affiliated with or endorsed by the owner. The artwork is
|
|
234
|
+
unchanged except for removing editor metadata and setting a square viewBox.
|
package/app-manifest.yaml
CHANGED
|
@@ -15,6 +15,22 @@ features:
|
|
|
15
15
|
bot_user:
|
|
16
16
|
display_name: capybara
|
|
17
17
|
always_online: true
|
|
18
|
+
# Slack rejects a message starting with an unregistered "/name", so the kernel's commands are
|
|
19
|
+
# registered here. The plugin turns each into the text the kernel parses: /new -> "/new",
|
|
20
|
+
# /env x -> "/env x", /capybara foo bar -> "/foo bar" (skill invocation). No url: Socket Mode
|
|
21
|
+
# delivers them; in webhook mode set each command's Request URL to the webhook URL.
|
|
22
|
+
slash_commands:
|
|
23
|
+
- command: /new
|
|
24
|
+
description: Start a new conversation (direct message)
|
|
25
|
+
should_escape: false
|
|
26
|
+
- command: /env
|
|
27
|
+
description: List or set your default environment (direct message)
|
|
28
|
+
usage_hint: "[name]"
|
|
29
|
+
should_escape: false
|
|
30
|
+
- command: /capybara
|
|
31
|
+
description: Run a skill
|
|
32
|
+
usage_hint: "<skill> [args]"
|
|
33
|
+
should_escape: false
|
|
18
34
|
oauth_config:
|
|
19
35
|
# Sign in with Slack (identity-source@1): uncomment and set to <http.publicUrl>/api/v1/auth/sso/slack/callback.
|
|
20
36
|
# The sign-in flow requests openid / email / profile itself; do not add them as scopes here (Slack wants
|
|
@@ -24,6 +40,8 @@ oauth_config:
|
|
|
24
40
|
scopes:
|
|
25
41
|
bot:
|
|
26
42
|
- chat:write # post and update replies and cards
|
|
43
|
+
- commands # slash commands /new, /env, /capybara
|
|
44
|
+
- im:write # conversations.open: tell the bot's own DM from other DMs a slash command runs in
|
|
27
45
|
- im:history # message.im: direct messages to the bot
|
|
28
46
|
- app_mentions:read # app_mention: @capybara in channels
|
|
29
47
|
- channels:history # message.channels: thread replies in public channels
|
package/dist/index.mjs
CHANGED
|
@@ -7345,25 +7345,25 @@ var require_infra = __commonJS({
|
|
|
7345
7345
|
return input;
|
|
7346
7346
|
}
|
|
7347
7347
|
var nonASCIIRegex = /[^\x00-\x7F]/;
|
|
7348
|
-
function asciiLowercase(
|
|
7349
|
-
return nonASCIIRegex.test(
|
|
7348
|
+
function asciiLowercase(str6) {
|
|
7349
|
+
return nonASCIIRegex.test(str6) ? str6.replace(/[A-Z]+/g, (upper) => upper.toLowerCase()) : str6.toLowerCase();
|
|
7350
7350
|
}
|
|
7351
7351
|
function parseJSONFromBytes(bytes) {
|
|
7352
7352
|
return JSON.parse(utf8DecodeBytes(bytes));
|
|
7353
7353
|
}
|
|
7354
|
-
function removeASCIIWhitespace(
|
|
7355
|
-
return removeChars(
|
|
7354
|
+
function removeASCIIWhitespace(str6, leading = true, trailing = true) {
|
|
7355
|
+
return removeChars(str6, leading, trailing, isASCIIWhitespace);
|
|
7356
7356
|
}
|
|
7357
|
-
function removeChars(
|
|
7357
|
+
function removeChars(str6, leading, trailing, predicate) {
|
|
7358
7358
|
let lead = 0;
|
|
7359
|
-
let trail =
|
|
7359
|
+
let trail = str6.length - 1;
|
|
7360
7360
|
if (leading) {
|
|
7361
|
-
while (lead <
|
|
7361
|
+
while (lead < str6.length && predicate(str6.charCodeAt(lead))) lead++;
|
|
7362
7362
|
}
|
|
7363
7363
|
if (trailing) {
|
|
7364
|
-
while (trail >= lead && predicate(
|
|
7364
|
+
while (trail >= lead && predicate(str6.charCodeAt(trail))) trail--;
|
|
7365
7365
|
}
|
|
7366
|
-
return lead === 0 && trail ===
|
|
7366
|
+
return lead === 0 && trail === str6.length - 1 ? str6 : str6.slice(lead, trail + 1);
|
|
7367
7367
|
}
|
|
7368
7368
|
function serializeJavascriptValueToJSONString(value) {
|
|
7369
7369
|
const result = JSON.stringify(value);
|
|
@@ -7615,8 +7615,8 @@ var require_data_url = __commonJS({
|
|
|
7615
7615
|
function isHTTPWhiteSpace(char) {
|
|
7616
7616
|
return char === 13 || char === 10 || char === 9 || char === 32;
|
|
7617
7617
|
}
|
|
7618
|
-
function removeHTTPWhitespace(
|
|
7619
|
-
return removeChars(
|
|
7618
|
+
function removeHTTPWhitespace(str6, leading = true, trailing = true) {
|
|
7619
|
+
return removeChars(str6, leading, trailing, isHTTPWhiteSpace);
|
|
7620
7620
|
}
|
|
7621
7621
|
function minimizeSupportedMimeType(mimeType) {
|
|
7622
7622
|
switch (mimeType.essence) {
|
|
@@ -9664,11 +9664,11 @@ var require_request2 = __commonJS({
|
|
|
9664
9664
|
} else if (typeof val[i] === "object") {
|
|
9665
9665
|
throw new InvalidArgumentError(`invalid ${key} header`);
|
|
9666
9666
|
} else {
|
|
9667
|
-
const
|
|
9668
|
-
if (!isValidHeaderValue(
|
|
9667
|
+
const str6 = `${val[i]}`;
|
|
9668
|
+
if (!isValidHeaderValue(str6)) {
|
|
9669
9669
|
throw new InvalidArgumentError(`invalid ${key} header`);
|
|
9670
9670
|
}
|
|
9671
|
-
arr.push(
|
|
9671
|
+
arr.push(str6);
|
|
9672
9672
|
}
|
|
9673
9673
|
}
|
|
9674
9674
|
val = arr;
|
|
@@ -13877,7 +13877,7 @@ var require_body = __commonJS({
|
|
|
13877
13877
|
const boundary = getFormDataBoundary(object);
|
|
13878
13878
|
const prefix = `--${boundary}\r
|
|
13879
13879
|
Content-Disposition: form-data`;
|
|
13880
|
-
const formdataEscape = (
|
|
13880
|
+
const formdataEscape = (str6) => str6.replace(/\n/g, "%0A").replace(/\r/g, "%0D").replace(/"/g, "%22");
|
|
13881
13881
|
const normalizeLinefeeds = (value) => value.replace(/\r?\n|\r/g, "\r\n");
|
|
13882
13882
|
const blobParts = [];
|
|
13883
13883
|
const rn = new Uint8Array([13, 10]);
|
|
@@ -32651,9 +32651,9 @@ var require_cookies = __commonJS({
|
|
|
32651
32651
|
webidl.argumentLengthCheck(arguments, 2, "setCookie");
|
|
32652
32652
|
brandCheckHeaders(headers);
|
|
32653
32653
|
cookie = webidl.converters.Cookie(cookie);
|
|
32654
|
-
const
|
|
32655
|
-
if (
|
|
32656
|
-
headers.append("set-cookie",
|
|
32654
|
+
const str6 = stringify(cookie);
|
|
32655
|
+
if (str6) {
|
|
32656
|
+
headers.append("set-cookie", str6, true);
|
|
32657
32657
|
}
|
|
32658
32658
|
}
|
|
32659
32659
|
webidl.converters.DeleteCookieAttributes = webidl.dictionaryConverter([
|
|
@@ -36822,7 +36822,8 @@ var import_web_api = __toESM(require_dist4(), 1);
|
|
|
36822
36822
|
import { createHash } from "node:crypto";
|
|
36823
36823
|
import {
|
|
36824
36824
|
ChannelSendError as ChannelSendError3,
|
|
36825
|
-
secret as secret2
|
|
36825
|
+
secret as secret2,
|
|
36826
|
+
ui as ui2
|
|
36826
36827
|
} from "@capybara-hq/plugin-sdk";
|
|
36827
36828
|
import { z as z2 } from "zod";
|
|
36828
36829
|
|
|
@@ -37391,6 +37392,49 @@ function renderUpdate(message2, locale) {
|
|
|
37391
37392
|
return only;
|
|
37392
37393
|
}
|
|
37393
37394
|
|
|
37395
|
+
// src/commands.ts
|
|
37396
|
+
var str2 = (v) => typeof v === "string" && v !== "" ? v : void 0;
|
|
37397
|
+
var GENERIC_COMMAND = "/capybara";
|
|
37398
|
+
function parseSlashCommand(body) {
|
|
37399
|
+
if (typeof body !== "object" || body === null || Array.isArray(body)) return null;
|
|
37400
|
+
const b = body;
|
|
37401
|
+
const command = str2(b.command);
|
|
37402
|
+
const userId = str2(b.user_id);
|
|
37403
|
+
const channelId = str2(b.channel_id);
|
|
37404
|
+
const teamId = str2(b.team_id);
|
|
37405
|
+
const triggerId = str2(b.trigger_id);
|
|
37406
|
+
if (!command?.startsWith("/") || !userId || !channelId || !teamId || !triggerId) return null;
|
|
37407
|
+
return {
|
|
37408
|
+
command,
|
|
37409
|
+
text: typeof b.text === "string" ? b.text : "",
|
|
37410
|
+
userId,
|
|
37411
|
+
userName: str2(b.user_name),
|
|
37412
|
+
channelId,
|
|
37413
|
+
teamId,
|
|
37414
|
+
triggerId
|
|
37415
|
+
};
|
|
37416
|
+
}
|
|
37417
|
+
var unescapeSlack = (s) => s.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
|
|
37418
|
+
function slashCommandText(command, text) {
|
|
37419
|
+
const args = unescapeSlack(text).trim();
|
|
37420
|
+
const name = command.toLowerCase();
|
|
37421
|
+
if (name === "/new" || name === "/env") return args === "" ? name : `${name} ${args}`;
|
|
37422
|
+
const rest = args.replace(/^\/+/, "");
|
|
37423
|
+
return rest === "" ? null : `/${rest}`;
|
|
37424
|
+
}
|
|
37425
|
+
var escapeSlack = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
37426
|
+
var typedCommand = (c) => c.text.trim() === "" ? c.command : `${c.command} ${unescapeSlack(c.text).trim()}`;
|
|
37427
|
+
var ephemeral = (text) => ({
|
|
37428
|
+
response_type: "ephemeral",
|
|
37429
|
+
text
|
|
37430
|
+
});
|
|
37431
|
+
var SLASH_REPLIES = {
|
|
37432
|
+
usage: `Usage: ${GENERIC_COMMAND} <skill> [args] · 用法:${GENERIC_COMMAND} <技能> [参数]`,
|
|
37433
|
+
wrongDm: "Run Capybara commands in your direct message with the app, or in a channel it is in. · 请在与 Capybara 应用的私聊里,或在它所在的频道里使用命令。",
|
|
37434
|
+
notInChannel: "Invite the Capybara app to this channel first (/invite), then run the command again. · 请先把 Capybara 应用邀请进这个频道,再运行命令。",
|
|
37435
|
+
failed: "Slack could not take this command right now; try again in a moment. · Slack 暂时无法处理这条命令,请稍后再试。"
|
|
37436
|
+
};
|
|
37437
|
+
|
|
37394
37438
|
// src/config.ts
|
|
37395
37439
|
import { secret, ui } from "@capybara-hq/plugin-sdk";
|
|
37396
37440
|
import { z } from "zod";
|
|
@@ -37409,10 +37453,22 @@ var SlackDeployment = z.object({
|
|
|
37409
37453
|
var SlackDirectoryConfig = z.object({
|
|
37410
37454
|
teamId: ui(
|
|
37411
37455
|
z.string().regex(/^T[A-Z0-9]+$/, "must be a Slack workspace team id such as T0123ABCD").optional(),
|
|
37412
|
-
{
|
|
37456
|
+
{
|
|
37457
|
+
label: { zh: "工作区 ID", en: "Workspace ID" },
|
|
37458
|
+
help: {
|
|
37459
|
+
zh: "选填:和机器人令牌一起用于把 Slack 成员同步到组织;只用机器人收发消息时不用填。",
|
|
37460
|
+
en: "Optional: used with the bot token to sync Slack members into the org. Leave empty if you only use the bot for chat."
|
|
37461
|
+
},
|
|
37462
|
+
placeholder: "T0123ABCD"
|
|
37463
|
+
}
|
|
37413
37464
|
),
|
|
37414
37465
|
botToken: ui(secret(z.string().regex(/^xoxb-/, "must be a bot token starting with xoxb-")), {
|
|
37415
|
-
label: { zh: "机器人令牌", en: "Bot token" }
|
|
37466
|
+
label: { zh: "机器人令牌", en: "Bot token" },
|
|
37467
|
+
help: {
|
|
37468
|
+
zh: "选填,仅用于成员同步;聊天用的令牌在新建渠道连接时填。",
|
|
37469
|
+
en: "Optional, only for member sync. The tokens for chat go into the channel connection you create under Channels."
|
|
37470
|
+
},
|
|
37471
|
+
placeholder: "xoxb-…"
|
|
37416
37472
|
}).optional()
|
|
37417
37473
|
});
|
|
37418
37474
|
var SLACK_ISSUER = "https://slack.com";
|
|
@@ -37496,8 +37552,8 @@ function toChannelSendError(e) {
|
|
|
37496
37552
|
|
|
37497
37553
|
// src/inbound.ts
|
|
37498
37554
|
var obj2 = (v) => typeof v === "object" && v !== null && !Array.isArray(v) ? v : void 0;
|
|
37499
|
-
var
|
|
37500
|
-
var
|
|
37555
|
+
var str3 = (v) => typeof v === "string" && v !== "" ? v : void 0;
|
|
37556
|
+
var unescapeSlack2 = (s) => s.replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
|
|
37501
37557
|
function stripBotMention(text, botUserId) {
|
|
37502
37558
|
const id = botUserId.replace(/[^A-Za-z0-9]/g, "");
|
|
37503
37559
|
return text.replace(new RegExp(`[ \\t]*<@${id}(\\|[^>]*)?>[ \\t]*`, "g"), (m, _label, at, s) => {
|
|
@@ -37512,8 +37568,8 @@ var mentions = (text, botUserId) => new RegExp(`<@${botUserId.replace(/[^A-Za-z0
|
|
|
37512
37568
|
function profileOf(p) {
|
|
37513
37569
|
const o = obj2(p);
|
|
37514
37570
|
if (!o) return void 0;
|
|
37515
|
-
const displayName =
|
|
37516
|
-
const avatarUrl =
|
|
37571
|
+
const displayName = str3(o.display_name) ?? str3(o.real_name) ?? str3(o.name);
|
|
37572
|
+
const avatarUrl = str3(o.image_72) ?? str3(o.image_48) ?? str3(o.image_192);
|
|
37517
37573
|
if (displayName === void 0 && avatarUrl === void 0) return void 0;
|
|
37518
37574
|
return {
|
|
37519
37575
|
...displayName !== void 0 && { displayName },
|
|
@@ -37524,7 +37580,7 @@ function eventToInbound(body, botUserId) {
|
|
|
37524
37580
|
const b = obj2(body);
|
|
37525
37581
|
const e = obj2(b?.event);
|
|
37526
37582
|
if (!b || !e) return null;
|
|
37527
|
-
const teamId =
|
|
37583
|
+
const teamId = str3(b.team_id);
|
|
37528
37584
|
const type = e.type;
|
|
37529
37585
|
if (type === "team_join" || type === "user_change") {
|
|
37530
37586
|
if (!teamId) return null;
|
|
@@ -37536,19 +37592,19 @@ function eventToInbound(body, botUserId) {
|
|
|
37536
37592
|
}
|
|
37537
37593
|
if (e.bot_id !== void 0 || e.bot_profile !== void 0) return null;
|
|
37538
37594
|
if (type === "app_mention" && e.edited !== void 0) return null;
|
|
37539
|
-
const user =
|
|
37540
|
-
const channel =
|
|
37541
|
-
const ts =
|
|
37595
|
+
const user = str3(e.user);
|
|
37596
|
+
const channel = str3(e.channel);
|
|
37597
|
+
const ts = str3(e.ts);
|
|
37542
37598
|
const raw = typeof e.text === "string" ? e.text : "";
|
|
37543
37599
|
if (!user || !channel || !ts || user === botUserId) return null;
|
|
37544
|
-
const tenantId =
|
|
37600
|
+
const tenantId = str3(e.user_team) ?? str3(e.team) ?? teamId;
|
|
37545
37601
|
if (!tenantId) return null;
|
|
37546
37602
|
const mentioned = type === "app_mention" || mentions(raw, botUserId);
|
|
37547
|
-
const threadTs =
|
|
37603
|
+
const threadTs = str3(e.thread_ts);
|
|
37548
37604
|
const inThread = threadTs !== void 0 && threadTs !== ts;
|
|
37549
37605
|
const dm = type === "message" ? e.channel_type === "im" : channel.startsWith("D");
|
|
37550
37606
|
if (!dm && type === "message" && (mentioned || !inThread)) return null;
|
|
37551
|
-
const text =
|
|
37607
|
+
const text = unescapeSlack2(stripBotMention(raw, botUserId));
|
|
37552
37608
|
if (text === "") return null;
|
|
37553
37609
|
const target = dm ? { chatId: channel, chatType: "dm" } : {
|
|
37554
37610
|
chatId: channel,
|
|
@@ -37589,6 +37645,11 @@ function verifySlackSignature(h, body, signingSecret, nowMs) {
|
|
|
37589
37645
|
const got = Buffer.from(sig2);
|
|
37590
37646
|
return got.length === want.length && timingSafeEqual(got, want);
|
|
37591
37647
|
}
|
|
37648
|
+
var slackJsonAck = (body) => ({
|
|
37649
|
+
status: 200,
|
|
37650
|
+
headers: { "content-type": "application/json; charset=utf-8" },
|
|
37651
|
+
body: JSON.stringify(body)
|
|
37652
|
+
});
|
|
37592
37653
|
function readSlackWebhook(config, request) {
|
|
37593
37654
|
if (config.signingSecret === void 0) return { kind: "reject", status: 401 };
|
|
37594
37655
|
if (!verifySlackSignature(request.headers, request.body, config.signingSecret, request.receivedAt)) {
|
|
@@ -37597,8 +37658,12 @@ function readSlackWebhook(config, request) {
|
|
|
37597
37658
|
const text = new TextDecoder().decode(request.body);
|
|
37598
37659
|
const type = (request.headers["content-type"] ?? "").split(";")[0]?.trim().toLowerCase();
|
|
37599
37660
|
if (type === "application/x-www-form-urlencoded") {
|
|
37600
|
-
const
|
|
37601
|
-
|
|
37661
|
+
const form = new URLSearchParams(text);
|
|
37662
|
+
const payload = form.get("payload");
|
|
37663
|
+
if (payload === null) {
|
|
37664
|
+
if (form.get("command") === null) return { kind: "ignore" };
|
|
37665
|
+
return { kind: "command", body: Object.fromEntries(form) };
|
|
37666
|
+
}
|
|
37602
37667
|
let parsed2;
|
|
37603
37668
|
try {
|
|
37604
37669
|
parsed2 = JSON.parse(payload);
|
|
@@ -37636,6 +37701,11 @@ async function handleSlackWebhook(args) {
|
|
|
37636
37701
|
const r = readSlackWebhook(args.config, args.request);
|
|
37637
37702
|
if (r.kind === "respond" || r.kind === "reject") return r;
|
|
37638
37703
|
if (r.kind === "ignore") return { kind: "events", events: [], ack: SLACK_WEBHOOK_ACK };
|
|
37704
|
+
if (r.kind === "command") {
|
|
37705
|
+
const { event: event2, response } = await args.command(r.body);
|
|
37706
|
+
const ack = response !== void 0 ? slackJsonAck(response) : SLACK_WEBHOOK_ACK;
|
|
37707
|
+
return event2 ? { kind: "events", events: [event2], ack } : { kind: "respond", response: ack };
|
|
37708
|
+
}
|
|
37639
37709
|
const bot = r.envelope.type === "events_api" ? await args.botUserId() : "";
|
|
37640
37710
|
const event = await args.toEvent(r.envelope, bot);
|
|
37641
37711
|
return { kind: "events", events: event ? [event] : [], ack: SLACK_WEBHOOK_ACK };
|
|
@@ -37643,11 +37713,34 @@ async function handleSlackWebhook(args) {
|
|
|
37643
37713
|
|
|
37644
37714
|
// src/channel.ts
|
|
37645
37715
|
var SlackConnection = z2.object({
|
|
37646
|
-
appToken:
|
|
37647
|
-
|
|
37716
|
+
appToken: ui2(
|
|
37717
|
+
secret2(
|
|
37718
|
+
z2.string().regex(/^xapp-/, "must be an app-level token starting with xapp-").optional()
|
|
37719
|
+
),
|
|
37720
|
+
{
|
|
37721
|
+
label: { zh: "应用令牌", en: "App-level token" },
|
|
37722
|
+
help: {
|
|
37723
|
+
zh: "xapp-…,Socket Mode 必填(Basic Information → App-Level Tokens,权限 connections:write)。",
|
|
37724
|
+
en: "xapp-…, required for Socket Mode (Basic Information → App-Level Tokens, scope connections:write)."
|
|
37725
|
+
},
|
|
37726
|
+
placeholder: "xapp-…"
|
|
37727
|
+
}
|
|
37648
37728
|
),
|
|
37649
|
-
botToken: secret2(z2.string().regex(/^xoxb-/, "must be a bot token starting with xoxb-")),
|
|
37650
|
-
|
|
37729
|
+
botToken: ui2(secret2(z2.string().regex(/^xoxb-/, "must be a bot token starting with xoxb-")), {
|
|
37730
|
+
label: { zh: "机器人令牌", en: "Bot token" },
|
|
37731
|
+
help: {
|
|
37732
|
+
zh: "xoxb-…(Install App → Bot User OAuth Token)。",
|
|
37733
|
+
en: "xoxb-… (Install App → Bot User OAuth Token)."
|
|
37734
|
+
},
|
|
37735
|
+
placeholder: "xoxb-…"
|
|
37736
|
+
}),
|
|
37737
|
+
signingSecret: ui2(secret2(z2.string().min(1).optional()), {
|
|
37738
|
+
label: { zh: "签名密钥", en: "Signing secret" },
|
|
37739
|
+
help: {
|
|
37740
|
+
zh: "仅 webhook 模式需要;Socket Mode 留空。",
|
|
37741
|
+
en: "Only needed in webhook mode; leave empty for Socket Mode."
|
|
37742
|
+
}
|
|
37743
|
+
})
|
|
37651
37744
|
});
|
|
37652
37745
|
var SOCKET_MODE_NEEDS_APP_TOKEN = "Socket Mode needs an app-level token (xapp-…); set one or switch this connection to webhook mode";
|
|
37653
37746
|
var BOT_USER_CACHE_TTL_SECONDS = 3600;
|
|
@@ -37658,6 +37751,9 @@ var MAX_RECONNECT_DELAY_MS = 3e4;
|
|
|
37658
37751
|
var PROFILE_TTL_MS = 10 * 6e4;
|
|
37659
37752
|
var PROFILE_CACHE_MAX = 1e3;
|
|
37660
37753
|
var PROFILE_TIMEOUT_MS = 1500;
|
|
37754
|
+
var BOT_DM_CACHE_TTL_SECONDS = 86400;
|
|
37755
|
+
var COMMAND_ECHO_TTL_SECONDS = 3600;
|
|
37756
|
+
var COMMAND_CALL_TIMEOUT_MS = 1500;
|
|
37661
37757
|
var pause = (ms, signal) => new Promise((resolve) => {
|
|
37662
37758
|
const s = AbortSignal.any([signal, AbortSignal.timeout(ms)]);
|
|
37663
37759
|
if (s.aborted) resolve();
|
|
@@ -37792,6 +37888,101 @@ function createSlackChannel(opts) {
|
|
|
37792
37888
|
await rememberBotUser(connectionId, botToken, id);
|
|
37793
37889
|
return id;
|
|
37794
37890
|
};
|
|
37891
|
+
const isBotDm = async (c, connectionId, userId, channelId, signal) => {
|
|
37892
|
+
const key = `dm/${connectionId}/${userId}`;
|
|
37893
|
+
const hit = await opts.kv?.get(key).catch(() => null);
|
|
37894
|
+
if (hit) return hit === channelId;
|
|
37895
|
+
try {
|
|
37896
|
+
const s = AbortSignal.any([signal, AbortSignal.timeout(COMMAND_CALL_TIMEOUT_MS)]);
|
|
37897
|
+
const r = await web(c.botToken, s).apiCall("conversations.open", { users: userId });
|
|
37898
|
+
const id = r.channel?.id;
|
|
37899
|
+
if (!id) return true;
|
|
37900
|
+
await opts.kv?.set(key, id, { ttlSeconds: BOT_DM_CACHE_TTL_SECONDS }).catch(() => {
|
|
37901
|
+
});
|
|
37902
|
+
return id === channelId;
|
|
37903
|
+
} catch (e) {
|
|
37904
|
+
log.warn("slack: could not look up the bot's DM for a slash command; assuming it is", {
|
|
37905
|
+
connectionId,
|
|
37906
|
+
error: describe(e, "conversations.open").message
|
|
37907
|
+
});
|
|
37908
|
+
return true;
|
|
37909
|
+
}
|
|
37910
|
+
};
|
|
37911
|
+
const postEcho = async (c, connectionId, channelId, triggerId, text, signal) => {
|
|
37912
|
+
const key = `cmd-echo/${connectionId}/${createHash("sha256").update(triggerId).digest("hex").slice(0, 32)}`;
|
|
37913
|
+
const hit = await opts.kv?.get(key).catch(() => null);
|
|
37914
|
+
if (hit) return { ts: hit };
|
|
37915
|
+
try {
|
|
37916
|
+
const s = AbortSignal.any([signal, AbortSignal.timeout(COMMAND_CALL_TIMEOUT_MS)]);
|
|
37917
|
+
const r = await web(c.botToken, s).apiCall("chat.postMessage", {
|
|
37918
|
+
channel: channelId,
|
|
37919
|
+
text
|
|
37920
|
+
});
|
|
37921
|
+
if (!r.ts) return { error: "no_ts" };
|
|
37922
|
+
await opts.kv?.set(key, r.ts, { ttlSeconds: COMMAND_ECHO_TTL_SECONDS }).catch(() => {
|
|
37923
|
+
});
|
|
37924
|
+
return { ts: r.ts };
|
|
37925
|
+
} catch (e) {
|
|
37926
|
+
return { error: platformErrorCode(e) ?? "request_failed" };
|
|
37927
|
+
}
|
|
37928
|
+
};
|
|
37929
|
+
const toCommand = async (c, connectionId, body, signal) => {
|
|
37930
|
+
const cmd = parseSlashCommand(body);
|
|
37931
|
+
if (!cmd) return { event: null, response: void 0 };
|
|
37932
|
+
const text = slashCommandText(cmd.command, cmd.text);
|
|
37933
|
+
if (text === null) return { event: null, response: ephemeral(SLASH_REPLIES.usage) };
|
|
37934
|
+
const profile = lookupProfile(c.botToken, connectionId, cmd.userId, signal).then(
|
|
37935
|
+
(p2) => p2 ?? (cmd.userName !== void 0 ? { displayName: cmd.userName } : void 0)
|
|
37936
|
+
);
|
|
37937
|
+
const sender = { externalId: cmd.userId, tenantId: cmd.teamId };
|
|
37938
|
+
if (cmd.channelId.startsWith("D")) {
|
|
37939
|
+
const [own, p2] = await Promise.all([
|
|
37940
|
+
isBotDm(c, connectionId, cmd.userId, cmd.channelId, signal),
|
|
37941
|
+
profile
|
|
37942
|
+
]);
|
|
37943
|
+
if (!own) return { event: null, response: ephemeral(SLASH_REPLIES.wrongDm) };
|
|
37944
|
+
return {
|
|
37945
|
+
event: {
|
|
37946
|
+
type: "message",
|
|
37947
|
+
messageId: `${cmd.channelId}:cmd-${cmd.triggerId}`,
|
|
37948
|
+
target: { chatId: cmd.channelId, chatType: "dm" },
|
|
37949
|
+
sender: withProfile(sender, p2),
|
|
37950
|
+
text,
|
|
37951
|
+
mentionsBot: false
|
|
37952
|
+
},
|
|
37953
|
+
response: ephemeral(escapeSlack(typedCommand(cmd)))
|
|
37954
|
+
};
|
|
37955
|
+
}
|
|
37956
|
+
const echoText = `<@${cmd.userId}>: ${escapeSlack(typedCommand(cmd))}`;
|
|
37957
|
+
const [echo, p] = await Promise.all([
|
|
37958
|
+
postEcho(c, connectionId, cmd.channelId, cmd.triggerId, echoText, signal),
|
|
37959
|
+
profile
|
|
37960
|
+
]);
|
|
37961
|
+
if ("error" in echo) {
|
|
37962
|
+
const gone = ["not_in_channel", "channel_not_found", "is_archived"].includes(echo.error);
|
|
37963
|
+
if (!gone) {
|
|
37964
|
+
log.warn("slack: could not post a slash command's echo", {
|
|
37965
|
+
connectionId,
|
|
37966
|
+
error: echo.error
|
|
37967
|
+
});
|
|
37968
|
+
}
|
|
37969
|
+
return {
|
|
37970
|
+
event: null,
|
|
37971
|
+
response: ephemeral(gone ? SLASH_REPLIES.notInChannel : SLASH_REPLIES.failed)
|
|
37972
|
+
};
|
|
37973
|
+
}
|
|
37974
|
+
return {
|
|
37975
|
+
event: {
|
|
37976
|
+
type: "message",
|
|
37977
|
+
messageId: `${cmd.channelId}:${echo.ts}`,
|
|
37978
|
+
target: { chatId: cmd.channelId, chatType: "group" },
|
|
37979
|
+
sender: withProfile(sender, p),
|
|
37980
|
+
text,
|
|
37981
|
+
mentionsBot: true
|
|
37982
|
+
},
|
|
37983
|
+
response: void 0
|
|
37984
|
+
};
|
|
37985
|
+
};
|
|
37795
37986
|
return {
|
|
37796
37987
|
connectionSchema: SlackConnection,
|
|
37797
37988
|
features: { cards: true, edit: true, threads: true, minEditIntervalMs: MIN_EDIT_INTERVAL_MS },
|
|
@@ -37824,9 +38015,12 @@ function createSlackChannel(opts) {
|
|
|
37824
38015
|
await rememberBotUser(connectionId, c.botToken, botUserId);
|
|
37825
38016
|
const handle = async ({ ack, type, body }) => {
|
|
37826
38017
|
let event = null;
|
|
38018
|
+
let response;
|
|
37827
38019
|
try {
|
|
37828
38020
|
if (type === "events_api" || type === "interactive") {
|
|
37829
38021
|
event = await toEvent(c, connectionId, botUserId, { type, body }, signal);
|
|
38022
|
+
} else if (type === "slash_commands") {
|
|
38023
|
+
({ event, response } = await toCommand(c, connectionId, body, signal));
|
|
37830
38024
|
}
|
|
37831
38025
|
} catch (e) {
|
|
37832
38026
|
log.warn("slack: could not read an event; acknowledging and skipping it", {
|
|
@@ -37846,7 +38040,7 @@ function createSlackChannel(opts) {
|
|
|
37846
38040
|
return;
|
|
37847
38041
|
}
|
|
37848
38042
|
}
|
|
37849
|
-
await ack().catch((e) => {
|
|
38043
|
+
await ack(response).catch((e) => {
|
|
37850
38044
|
log.warn("slack: acknowledging an event failed; Slack will redeliver it", {
|
|
37851
38045
|
connectionId,
|
|
37852
38046
|
error: e instanceof Error ? e.message : String(e)
|
|
@@ -37934,6 +38128,17 @@ function createSlackChannel(opts) {
|
|
|
37934
38128
|
config: c,
|
|
37935
38129
|
request,
|
|
37936
38130
|
botUserId: () => botUserIdOf(connectionId, c.botToken, signal),
|
|
38131
|
+
command: async (body) => {
|
|
38132
|
+
try {
|
|
38133
|
+
return await toCommand(c, connectionId, body, signal);
|
|
38134
|
+
} catch (e) {
|
|
38135
|
+
log.warn("slack: could not read a webhook slash command; skipping it", {
|
|
38136
|
+
connectionId,
|
|
38137
|
+
error: e instanceof Error ? e.message : String(e)
|
|
38138
|
+
});
|
|
38139
|
+
return { event: null, response: ephemeral(SLASH_REPLIES.failed) };
|
|
38140
|
+
}
|
|
38141
|
+
},
|
|
37937
38142
|
toEvent: async (envelope, botUserId) => {
|
|
37938
38143
|
try {
|
|
37939
38144
|
return await toEvent(c, connectionId, botUserId, envelope, signal);
|
|
@@ -38000,7 +38205,7 @@ function createSlackChannel(opts) {
|
|
|
38000
38205
|
|
|
38001
38206
|
// src/directory.ts
|
|
38002
38207
|
var obj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v) ? v : void 0;
|
|
38003
|
-
var
|
|
38208
|
+
var str4 = (v) => typeof v === "string" && v !== "" ? v : void 0;
|
|
38004
38209
|
var pause2 = (ms, signal) => new Promise((resolve, reject) => {
|
|
38005
38210
|
if (signal.aborted) return reject(signal.reason);
|
|
38006
38211
|
const timer = AbortSignal.timeout(ms);
|
|
@@ -38052,7 +38257,7 @@ function createSlackDirectory(opts) {
|
|
|
38052
38257
|
}
|
|
38053
38258
|
const body = obj4(await res.json().catch(() => void 0));
|
|
38054
38259
|
if (body?.ok !== true) {
|
|
38055
|
-
throw new Error(`Slack ${method} failed: ${
|
|
38260
|
+
throw new Error(`Slack ${method} failed: ${str4(body?.error) ?? "malformed response"}`);
|
|
38056
38261
|
}
|
|
38057
38262
|
return body;
|
|
38058
38263
|
}
|
|
@@ -38072,7 +38277,7 @@ function createSlackDirectory(opts) {
|
|
|
38072
38277
|
const teamId = c.teamId;
|
|
38073
38278
|
const budget = { leftMs: maxWait };
|
|
38074
38279
|
const auth = await call("auth.test", c.botToken, {}, signal, budget);
|
|
38075
|
-
const tokenTeam =
|
|
38280
|
+
const tokenTeam = str4(auth.team_id);
|
|
38076
38281
|
const problem = workspaceTokenProblem(auth);
|
|
38077
38282
|
if (problem !== void 0) throw new Error(problem);
|
|
38078
38283
|
if (tokenTeam !== teamId) {
|
|
@@ -38097,23 +38302,23 @@ function createSlackDirectory(opts) {
|
|
|
38097
38302
|
const members = [];
|
|
38098
38303
|
for (const raw of page.members) {
|
|
38099
38304
|
const u = obj4(raw);
|
|
38100
|
-
const id =
|
|
38305
|
+
const id = str4(u?.id);
|
|
38101
38306
|
if (!u || !id || id === SLACKBOT || u.is_bot === true) continue;
|
|
38102
38307
|
if (u.is_restricted === true || u.is_ultra_restricted === true) continue;
|
|
38103
|
-
const ownTeam =
|
|
38308
|
+
const ownTeam = str4(u.team_id);
|
|
38104
38309
|
if (ownTeam !== void 0 && ownTeam !== teamId) continue;
|
|
38105
38310
|
const profile = obj4(u.profile);
|
|
38106
|
-
const email =
|
|
38311
|
+
const email = str4(profile?.email);
|
|
38107
38312
|
members.push({
|
|
38108
38313
|
externalId: id,
|
|
38109
38314
|
tenantId: teamId,
|
|
38110
38315
|
...email !== void 0 && { email },
|
|
38111
38316
|
emailVerified: false,
|
|
38112
|
-
displayName:
|
|
38317
|
+
displayName: str4(profile?.display_name) ?? str4(profile?.real_name) ?? str4(u.real_name) ?? str4(u.name) ?? id,
|
|
38113
38318
|
active: u.deleted !== true
|
|
38114
38319
|
});
|
|
38115
38320
|
}
|
|
38116
|
-
const next =
|
|
38321
|
+
const next = str4(obj4(page.response_metadata)?.next_cursor);
|
|
38117
38322
|
return { members, ...next !== void 0 && { next } };
|
|
38118
38323
|
}
|
|
38119
38324
|
};
|
|
@@ -38606,9 +38811,9 @@ var checkFailed = "check_failed";
|
|
|
38606
38811
|
function invalidDuration() {
|
|
38607
38812
|
throw new TypeError("Invalid time period format");
|
|
38608
38813
|
}
|
|
38609
|
-
function secs(
|
|
38610
|
-
typeof
|
|
38611
|
-
const matched = REGEX.exec(
|
|
38814
|
+
function secs(str6) {
|
|
38815
|
+
typeof str6 != "string" && invalidDuration();
|
|
38816
|
+
const matched = REGEX.exec(str6);
|
|
38612
38817
|
(!matched || matched[4] && matched[1]) && invalidDuration();
|
|
38613
38818
|
const value = parseFloat(matched[2]), numericDate2 = Math.round(value * multipliers[matched[3][0].toLowerCase()]);
|
|
38614
38819
|
return Number.isFinite(numericDate2) || invalidDuration(), matched[1] === "-" || matched[4] === "ago" ? -numericDate2 : numericDate2;
|
|
@@ -38840,7 +39045,7 @@ var SLACK_OIDC_SCOPES = "openid email profile";
|
|
|
38840
39045
|
var TEAM_CLAIM = "https://slack.com/team_id";
|
|
38841
39046
|
var USER_CLAIM = "https://slack.com/user_id";
|
|
38842
39047
|
var REQUEST_TIMEOUT_MS = 1e4;
|
|
38843
|
-
var
|
|
39048
|
+
var str5 = (v) => typeof v === "string" && v !== "" ? v : void 0;
|
|
38844
39049
|
var isHttpUrl2 = (v) => /^https?:\/\//i.test(v);
|
|
38845
39050
|
function loginConfig(config) {
|
|
38846
39051
|
const c = SlackDeployment.parse(config ?? {});
|
|
@@ -38872,7 +39077,7 @@ async function slackPost(apiUrl, method, form, signal, token) {
|
|
|
38872
39077
|
}
|
|
38873
39078
|
const body = await res.json().catch(() => void 0);
|
|
38874
39079
|
if (body?.ok !== true) {
|
|
38875
|
-
throw new Error(`Slack ${method} failed: ${
|
|
39080
|
+
throw new Error(`Slack ${method} failed: ${str5(body?.error) ?? "malformed response"}`);
|
|
38876
39081
|
}
|
|
38877
39082
|
return body;
|
|
38878
39083
|
}
|
|
@@ -38918,8 +39123,8 @@ function createSlackIdentitySource() {
|
|
|
38918
39123
|
},
|
|
38919
39124
|
signal
|
|
38920
39125
|
);
|
|
38921
|
-
const accessToken =
|
|
38922
|
-
const idToken =
|
|
39126
|
+
const accessToken = str5(token.access_token);
|
|
39127
|
+
const idToken = str5(token.id_token);
|
|
38923
39128
|
if (!accessToken || !idToken) {
|
|
38924
39129
|
throw new Error("Slack openid.connect.token failed: no access_token / id_token");
|
|
38925
39130
|
}
|
|
@@ -38937,23 +39142,23 @@ function createSlackIdentitySource() {
|
|
|
38937
39142
|
}
|
|
38938
39143
|
signal.throwIfAborted();
|
|
38939
39144
|
if (claims.nonce !== nonce) throw new Error("Slack ID token rejected: nonce mismatch");
|
|
38940
|
-
const teamId =
|
|
38941
|
-
const userId =
|
|
39145
|
+
const teamId = str5(claims[TEAM_CLAIM]);
|
|
39146
|
+
const userId = str5(claims[USER_CLAIM]) ?? str5(claims.sub);
|
|
38942
39147
|
if (!teamId || !userId) throw new Error("Slack ID token rejected: no team / user id");
|
|
38943
39148
|
const info = await slackPost(c.apiUrl, "openid.connect.userInfo", {}, signal, accessToken);
|
|
38944
|
-
const infoUser =
|
|
38945
|
-
if (infoUser !== userId ||
|
|
39149
|
+
const infoUser = str5(info[USER_CLAIM]) ?? str5(info.sub);
|
|
39150
|
+
if (infoUser !== userId || str5(info[TEAM_CLAIM]) !== teamId) {
|
|
38946
39151
|
throw new Error("Slack userInfo does not match the ID token (user / team)");
|
|
38947
39152
|
}
|
|
38948
|
-
const email =
|
|
38949
|
-
const picture =
|
|
39153
|
+
const email = str5(info.email);
|
|
39154
|
+
const picture = str5(info.picture);
|
|
38950
39155
|
return {
|
|
38951
39156
|
source: `slack:${teamId}`,
|
|
38952
39157
|
externalId: userId,
|
|
38953
39158
|
tenantId: teamId,
|
|
38954
39159
|
...email !== void 0 && { email },
|
|
38955
39160
|
emailVerified: email !== void 0 && info.email_verified === true,
|
|
38956
|
-
displayName:
|
|
39161
|
+
displayName: str5(info.name) ?? str5(info.given_name) ?? userId,
|
|
38957
39162
|
...picture !== void 0 && isHttpUrl2(picture) && { avatarUrl: picture }
|
|
38958
39163
|
};
|
|
38959
39164
|
}
|
|
@@ -38963,7 +39168,7 @@ function createSlackIdentitySource() {
|
|
|
38963
39168
|
// src/index.ts
|
|
38964
39169
|
var index_default = defineExtension({
|
|
38965
39170
|
name: "slack",
|
|
38966
|
-
version: "0.1.0-rc.
|
|
39171
|
+
version: "0.1.0-rc.3",
|
|
38967
39172
|
sdk: "^0.1.0-rc.0",
|
|
38968
39173
|
provides: [CHANNEL_EXTENSION_POINT, IDENTITY_SOURCE_EXTENSION_POINT, DIRECTORY_EXTENSION_POINT],
|
|
38969
39174
|
permissions: { network: ["slack.com", "wss-primary.slack.com"] },
|
package/icon.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="-12 -12 424 424"><title>Slack</title><path fill="#e3066a" d="M84.039,252.769c0,23.127-18.893,42.02-42.02,42.02S0,275.896,0,252.769s18.893-42.02,42.02-42.02h42.02v42.02Z"/><path fill="#e3066a" d="M105.212,252.769c0-23.127,18.893-42.02,42.02-42.02s42.02,18.893,42.02,42.02v105.212c0,23.127-18.893,42.02-42.02,42.02s-42.02-18.893-42.02-42.02c0,0,0-105.212,0-105.212Z"/><path fill="#00b3ff" d="M147.231,84.039c-23.127,0-42.02-18.893-42.02-42.02S124.104,0,147.231,0s42.02,18.893,42.02,42.02v42.02h-42.02Z"/><path fill="#00b3ff" d="M147.231,105.212c23.127,0,42.02,18.893,42.02,42.02s-18.893,42.02-42.02,42.02H42.02c-23.127,0-42.02-18.893-42.02-42.02s18.893-42.02,42.02-42.02c0,0,105.212,0,105.212,0Z"/><path fill="#41b658" d="M315.961,147.231c0-23.127,18.893-42.02,42.02-42.02s42.02,18.893,42.02,42.02-18.893,42.02-42.02,42.02h-42.02v-42.02Z"/><path fill="#41b658" d="M294.788,147.231c0,23.127-18.893,42.02-42.02,42.02s-42.02-18.893-42.02-42.02V42.02c0-23.127,18.893-42.02,42.02-42.02s42.02,18.893,42.02,42.02v105.212Z"/><path fill="#fcc003" d="M252.769,315.961c23.127,0,42.02,18.893,42.02,42.02s-18.893,42.02-42.02,42.02-42.02-18.893-42.02-42.02v-42.02h42.02Z"/><path fill="#fcc003" d="M252.769,294.788c-23.127,0-42.02-18.893-42.02-42.02s18.893-42.02,42.02-42.02h105.212c23.127,0,42.02,18.893,42.02,42.02s-18.893,42.02-42.02,42.02h-105.212Z"/></svg>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capybara-hq/plugin-slack",
|
|
3
|
-
"version": "0.1.0-rc.
|
|
3
|
+
"version": "0.1.0-rc.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"description": "Slack (channel@1 bot over Socket Mode with Block Kit cards, identity-source@1 Sign in with Slack, directory@1)",
|