@zhin.js/adapter-slack 1.0.78 → 1.1.2
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/CHANGELOG.md +731 -2
- package/PERMITS.md +24 -0
- package/README.md +111 -158
- package/adapters/slack/index.js +40 -0
- package/adapters/slack/index.ts +45 -0
- package/agents/slack/agent.json +20 -0
- package/agents/slack/boundaries.md +3 -0
- package/agents/slack/conventions.md +3 -0
- package/agents/slack/skills/slack-channels/SKILL.md +24 -0
- package/agents/slack/skills/slack-channels/tools/archive_channel/index.js +19 -0
- package/agents/slack/skills/slack-channels/tools/archive_channel/index.ts +21 -0
- package/agents/slack/skills/slack-channels/tools/invite_to_channel/index.js +20 -0
- package/agents/slack/skills/slack-channels/tools/invite_to_channel/index.ts +23 -0
- package/agents/slack/skills/slack-channels/tools/set_purpose/index.js +20 -0
- package/agents/slack/skills/slack-channels/tools/set_purpose/index.ts +23 -0
- package/agents/slack/skills/slack-channels/tools/set_topic/index.js +20 -0
- package/agents/slack/skills/slack-channels/tools/set_topic/index.ts +23 -0
- package/agents/slack/skills/slack-channels/tools/unarchive/index.js +19 -0
- package/agents/slack/skills/slack-channels/tools/unarchive/index.ts +21 -0
- package/agents/slack/skills/slack-channels/tools/user_info/index.js +27 -0
- package/agents/slack/skills/slack-channels/tools/user_info/index.ts +29 -0
- package/agents/slack/skills/slack-messages/SKILL.md +22 -0
- package/agents/slack/skills/slack-messages/tools/add_reaction/index.js +27 -0
- package/agents/slack/skills/slack-messages/tools/add_reaction/index.ts +29 -0
- package/agents/slack/skills/slack-messages/tools/edit_message/index.js +21 -0
- package/agents/slack/skills/slack-messages/tools/edit_message/index.ts +25 -0
- package/agents/slack/skills/slack-messages/tools/pin_message/index.js +20 -0
- package/agents/slack/skills/slack-messages/tools/pin_message/index.ts +23 -0
- package/agents/slack/skills/slack-messages/tools/remove_reaction/index.js +30 -0
- package/agents/slack/skills/slack-messages/tools/remove_reaction/index.ts +32 -0
- package/agents/slack/skills/slack-messages/tools/unpin_message/index.js +20 -0
- package/agents/slack/skills/slack-messages/tools/unpin_message/index.ts +23 -0
- package/agents/slack/system.md +3 -0
- package/commands/slack/endpoint/add/[id]/index.js +3 -0
- package/commands/slack/endpoint/add/[id]/index.ts +3 -0
- package/commands/slack/endpoint/definition.js +19 -0
- package/commands/slack/endpoint/definition.ts +19 -0
- package/commands/slack/endpoint/list/index.js +3 -0
- package/commands/slack/endpoint/list/index.ts +3 -0
- package/commands/slack/endpoint/remove/[id]/index.js +3 -0
- package/commands/slack/endpoint/remove/[id]/index.ts +3 -0
- package/lib/client.d.ts +25 -0
- package/lib/client.js +2 -0
- package/lib/endpoint.d.ts +153 -0
- package/lib/endpoint.js +425 -0
- package/lib/index.d.ts +10 -10
- package/lib/index.js +10 -242
- package/lib/markdown-to-mrkdwn.d.ts +9 -0
- package/lib/markdown-to-mrkdwn.js +121 -0
- package/lib/mrkdwn-to-markdown.d.ts +4 -0
- package/lib/mrkdwn-to-markdown.js +30 -0
- package/lib/platform-permit.d.ts +15 -0
- package/lib/platform-permit.js +43 -0
- package/lib/protocol.d.ts +144 -0
- package/lib/protocol.js +258 -0
- package/lib/side-event-dispatch.d.ts +4 -0
- package/lib/side-event-dispatch.js +45 -0
- package/lib/slack-inbound-filter.d.ts +12 -0
- package/lib/slack-inbound-filter.js +46 -0
- package/lib/slack-message-ref.d.ts +7 -0
- package/lib/slack-message-ref.js +17 -0
- package/lib/slack-outbound.d.ts +24 -0
- package/lib/slack-outbound.js +111 -0
- package/lib/slack-reaction.d.ts +1 -0
- package/lib/slack-reaction.js +26 -0
- package/lib/slack-response-url.d.ts +5 -0
- package/lib/slack-response-url.js +16 -0
- package/lib/slack-runtime-state.d.ts +1 -0
- package/lib/slack-runtime-state.js +6 -0
- package/lib/webhook.d.ts +14 -0
- package/lib/webhook.js +72 -0
- package/package.json +80 -16
- package/plugin.js +19 -0
- package/schema.json +108 -0
- package/src/client.ts +30 -0
- package/src/endpoint.ts +526 -0
- package/src/index.ts +59 -265
- package/src/markdown-to-mrkdwn.ts +117 -0
- package/src/mrkdwn-to-markdown.ts +29 -0
- package/src/platform-permit.ts +59 -0
- package/src/protocol.ts +406 -0
- package/src/side-event-dispatch.ts +54 -0
- package/src/slack-inbound-filter.ts +60 -0
- package/src/slack-message-ref.ts +18 -0
- package/src/slack-outbound.ts +170 -0
- package/src/slack-reaction.ts +23 -0
- package/src/slack-response-url.ts +26 -0
- package/src/slack-runtime-state.ts +7 -0
- package/src/webhook.ts +106 -0
- package/lib/adapter.d.ts +0 -16
- package/lib/adapter.d.ts.map +0 -1
- package/lib/adapter.js +0 -43
- package/lib/adapter.js.map +0 -1
- package/lib/bot.d.ts +0 -106
- package/lib/bot.d.ts.map +0 -1
- package/lib/bot.js +0 -628
- package/lib/bot.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/types.d.ts +0 -17
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -2
- package/lib/types.js.map +0 -1
- package/plugin.yml +0 -3
- package/skills/slack/SKILL.md +0 -91
- package/src/adapter.ts +0 -52
- package/src/bot.ts +0 -688
- package/src/types.ts +0 -18
package/lib/webhook.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { getLogger } from '@zhin.js/logger';
|
|
2
|
+
import { headerValue, readTextBody, verifySlackSignature, } from './protocol.js';
|
|
3
|
+
const logger = getLogger('slack');
|
|
4
|
+
export function registerSlackWebhookRoutes(http, handler) {
|
|
5
|
+
const path = handler.config.webhookPath;
|
|
6
|
+
return [
|
|
7
|
+
http.route('POST', path, async (request, response) => {
|
|
8
|
+
await handleSlackWebhookRequest(request, response, handler);
|
|
9
|
+
}, { summary: 'Slack Events API / Interactivity', tags: ['slack'] }),
|
|
10
|
+
];
|
|
11
|
+
}
|
|
12
|
+
export async function handleSlackWebhookRequest(request, response, handler) {
|
|
13
|
+
try {
|
|
14
|
+
const rawBody = await readTextBody(request);
|
|
15
|
+
const timestamp = headerValue(request.headers, 'x-slack-request-timestamp');
|
|
16
|
+
const signature = headerValue(request.headers, 'x-slack-signature');
|
|
17
|
+
if (!verifySlackSignature(handler.config.signingSecret, rawBody, timestamp, signature)) {
|
|
18
|
+
response.writeHead(401, { 'Content-Type': 'text/plain' });
|
|
19
|
+
response.end('Invalid signature');
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const contentType = headerValue(request.headers, 'content-type');
|
|
23
|
+
if (contentType.includes('application/x-www-form-urlencoded')) {
|
|
24
|
+
const params = new URLSearchParams(rawBody);
|
|
25
|
+
const payloadStr = params.get('payload');
|
|
26
|
+
if (payloadStr) {
|
|
27
|
+
const payload = JSON.parse(payloadStr);
|
|
28
|
+
response.writeHead(200);
|
|
29
|
+
response.end('');
|
|
30
|
+
handler.admitInteraction(payload);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const body = Object.fromEntries(params);
|
|
34
|
+
if (body.command) {
|
|
35
|
+
response.writeHead(200);
|
|
36
|
+
response.end('');
|
|
37
|
+
handler.admitSlashCommand(body);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
let envelope;
|
|
42
|
+
try {
|
|
43
|
+
envelope = JSON.parse(rawBody);
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
response.writeHead(200);
|
|
47
|
+
response.end('');
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (envelope.type === 'url_verification') {
|
|
51
|
+
const challenge = envelope.challenge;
|
|
52
|
+
response.writeHead(200, { 'Content-Type': 'application/json' });
|
|
53
|
+
response.end(JSON.stringify({ challenge }));
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (envelope.type === 'event_callback' && envelope.event) {
|
|
57
|
+
response.writeHead(200);
|
|
58
|
+
response.end('');
|
|
59
|
+
handler.handleEnvelope(envelope);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
response.writeHead(200);
|
|
63
|
+
response.end('');
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
logger.error('Slack webhook error:', error);
|
|
67
|
+
if (!response.headersSent) {
|
|
68
|
+
response.writeHead(200);
|
|
69
|
+
response.end('');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/adapter-slack",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Zhin.js adapter for
|
|
3
|
+
"version": "1.1.2",
|
|
4
|
+
"description": "Zhin.js Slack adapter for Plugin Runtime (Socket Mode / HTTP Events)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"types": "./lib/index.d.ts",
|
|
@@ -32,34 +32,98 @@
|
|
|
32
32
|
"directory": "plugins/adapters/slack"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@slack/
|
|
36
|
-
"@slack/web-api": "^7.
|
|
35
|
+
"@slack/socket-mode": "^2.0.7",
|
|
36
|
+
"@slack/web-api": "^7.19.0",
|
|
37
|
+
"@zhin.js/adapter": "1.1.14",
|
|
38
|
+
"@zhin.js/agent-feature": "1.1.1",
|
|
39
|
+
"@zhin.js/core": "1.1.37",
|
|
40
|
+
"@zhin.js/feature-kit": "1.1.1",
|
|
41
|
+
"@zhin.js/host-http": "1.1.1",
|
|
42
|
+
"@zhin.js/im-contract": "1.1.1",
|
|
43
|
+
"@zhin.js/logger": "1.1.1",
|
|
44
|
+
"@zhin.js/skill": "1.1.1",
|
|
45
|
+
"@zhin.js/tool": "1.1.1"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"zod": "^4.0.0",
|
|
49
|
+
"@zhin.js/adapter": "^1.1.14",
|
|
50
|
+
"@zhin.js/command": "^1.1.1",
|
|
51
|
+
"@zhin.js/core": "^1.1.37",
|
|
52
|
+
"@zhin.js/host-http": "^1.1.1",
|
|
53
|
+
"@zhin.js/permission": "^1.1.1",
|
|
54
|
+
"zhin.js": "^1.1.2"
|
|
55
|
+
},
|
|
56
|
+
"peerDependenciesMeta": {
|
|
57
|
+
"@zhin.js/command": {
|
|
58
|
+
"optional": true
|
|
59
|
+
},
|
|
60
|
+
"zhin.js": {
|
|
61
|
+
"optional": true
|
|
62
|
+
},
|
|
63
|
+
"zod": {
|
|
64
|
+
"optional": true
|
|
65
|
+
}
|
|
37
66
|
},
|
|
38
67
|
"devDependencies": {
|
|
39
|
-
"@types/node": "^
|
|
68
|
+
"@types/node": "^26.1.2",
|
|
40
69
|
"typescript": "^6.0.3",
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"zhin.js": "1.0.93"
|
|
70
|
+
"vitest": "^4.1.10",
|
|
71
|
+
"zod": "^4.4.3",
|
|
72
|
+
"zhin.js": "1.1.2"
|
|
45
73
|
},
|
|
46
74
|
"files": [
|
|
75
|
+
"adapters",
|
|
76
|
+
"commands",
|
|
77
|
+
"plugin.js",
|
|
78
|
+
"schema.json",
|
|
47
79
|
"src",
|
|
48
80
|
"lib",
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"skills",
|
|
52
|
-
"plugin.yml",
|
|
81
|
+
"tools",
|
|
82
|
+
"agents",
|
|
53
83
|
"README.md",
|
|
54
|
-
"CHANGELOG.md"
|
|
84
|
+
"CHANGELOG.md",
|
|
85
|
+
"PERMITS.md"
|
|
55
86
|
],
|
|
56
87
|
"publishConfig": {
|
|
57
88
|
"access": "public",
|
|
58
89
|
"registry": "https://registry.npmjs.org"
|
|
59
90
|
},
|
|
91
|
+
"engines": {
|
|
92
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
93
|
+
},
|
|
94
|
+
"zhin": {
|
|
95
|
+
"protocol": 1,
|
|
96
|
+
"type": "plugin",
|
|
97
|
+
"entry": "./plugin.js",
|
|
98
|
+
"engine": "^1.0.0",
|
|
99
|
+
"runtime": "trusted",
|
|
100
|
+
"features": [
|
|
101
|
+
{
|
|
102
|
+
"package": "@zhin.js/adapter",
|
|
103
|
+
"api": "^1.0.0"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"package": "@zhin.js/command",
|
|
107
|
+
"api": "^1.0.0"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"package": "@zhin.js/tool",
|
|
111
|
+
"api": "^1.0.0"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
"package": "@zhin.js/skill",
|
|
115
|
+
"api": "^1.0.0"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"package": "@zhin.js/agent-feature",
|
|
119
|
+
"api": "^1.0.0"
|
|
120
|
+
}
|
|
121
|
+
],
|
|
122
|
+
"plugins": []
|
|
123
|
+
},
|
|
60
124
|
"scripts": {
|
|
61
|
-
"build": "
|
|
125
|
+
"build": "tsc",
|
|
62
126
|
"clean": "rimraf lib",
|
|
63
|
-
"
|
|
127
|
+
"test": "NODE_OPTIONS=--experimental-strip-types vitest run --root ../../.. plugins/adapters/slack/tests"
|
|
64
128
|
}
|
|
65
129
|
}
|
package/plugin.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { createEndpointRuntimeState } from 'zhin.js/adapter';
|
|
3
|
+
import { definePlugin } from 'zhin.js';
|
|
4
|
+
import { permissionHostToken } from '@zhin.js/permission';
|
|
5
|
+
import { checkSlackPlatformPermit } from "./lib/platform-permit.js";
|
|
6
|
+
import { slackRuntimeStateToken } from "./lib/slack-runtime-state.js";
|
|
7
|
+
export default definePlugin({
|
|
8
|
+
name: 'slack',
|
|
9
|
+
metadata: {
|
|
10
|
+
displayName: 'Slack Adapter',
|
|
11
|
+
},
|
|
12
|
+
setup(context) {
|
|
13
|
+
context.resources.provide(slackRuntimeStateToken, createEndpointRuntimeState());
|
|
14
|
+
if (context.resources.has(permissionHostToken)) {
|
|
15
|
+
const host = context.resources.use(permissionHostToken);
|
|
16
|
+
return host.registerPlatform('slack', checkSlackPlatformPermit);
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
});
|
package/schema.json
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"additionalProperties": false,
|
|
5
|
+
"properties": {
|
|
6
|
+
"socketMode": {
|
|
7
|
+
"type": "boolean",
|
|
8
|
+
"default": true,
|
|
9
|
+
"description": "Prefer Socket Mode (default). Set false for HTTP Events via httpHostToken."
|
|
10
|
+
},
|
|
11
|
+
"webhookPath": {
|
|
12
|
+
"type": "string",
|
|
13
|
+
"default": "/slack/events"
|
|
14
|
+
},
|
|
15
|
+
"clientPingTimeout": {
|
|
16
|
+
"type": "number",
|
|
17
|
+
"default": 15000,
|
|
18
|
+
"description": "Socket Mode client ping timeout (ms)"
|
|
19
|
+
},
|
|
20
|
+
"master": {
|
|
21
|
+
"type": [
|
|
22
|
+
"string",
|
|
23
|
+
"number"
|
|
24
|
+
],
|
|
25
|
+
"description": "框架 master(Slack user id;AI/工具权限、endpoint 管理)。endpoints[i].master 可逐项覆盖"
|
|
26
|
+
},
|
|
27
|
+
"trusted": {
|
|
28
|
+
"type": "array",
|
|
29
|
+
"items": {
|
|
30
|
+
"type": [
|
|
31
|
+
"string",
|
|
32
|
+
"number"
|
|
33
|
+
],
|
|
34
|
+
"description": "Trusted Slack user id"
|
|
35
|
+
},
|
|
36
|
+
"description": "框架 trusted 用户列表(弱于 master)。endpoints[i].trusted 可逐项追加"
|
|
37
|
+
},
|
|
38
|
+
"endpoints": {
|
|
39
|
+
"type": "array",
|
|
40
|
+
"minItems": 1,
|
|
41
|
+
"description": "多账号:一个插件实例挂多个 endpoint。每项与顶层字段同构(id 必填,其余覆盖顶层)",
|
|
42
|
+
"items": {
|
|
43
|
+
"type": "object",
|
|
44
|
+
"additionalProperties": false,
|
|
45
|
+
"properties": {
|
|
46
|
+
"master": {
|
|
47
|
+
"type": [
|
|
48
|
+
"string",
|
|
49
|
+
"number"
|
|
50
|
+
],
|
|
51
|
+
"description": "本 endpoint 的框架 master(Slack user id);覆盖顶层 master"
|
|
52
|
+
},
|
|
53
|
+
"trusted": {
|
|
54
|
+
"type": "array",
|
|
55
|
+
"items": {
|
|
56
|
+
"type": [
|
|
57
|
+
"string",
|
|
58
|
+
"number"
|
|
59
|
+
],
|
|
60
|
+
"description": "Trusted Slack user id"
|
|
61
|
+
},
|
|
62
|
+
"description": "本 endpoint 的 trusted 列表"
|
|
63
|
+
},
|
|
64
|
+
"token": {
|
|
65
|
+
"type": "string",
|
|
66
|
+
"description": "Bot User OAuth Token (xoxb-...)"
|
|
67
|
+
},
|
|
68
|
+
"signingSecret": {
|
|
69
|
+
"type": "string",
|
|
70
|
+
"description": "Required for HTTP Events API (socketMode: false)"
|
|
71
|
+
},
|
|
72
|
+
"appToken": {
|
|
73
|
+
"type": "string",
|
|
74
|
+
"description": "App-Level Token (xapp-...) for Socket Mode"
|
|
75
|
+
},
|
|
76
|
+
"socketMode": {
|
|
77
|
+
"type": "boolean"
|
|
78
|
+
},
|
|
79
|
+
"webhookPath": {
|
|
80
|
+
"type": "string"
|
|
81
|
+
},
|
|
82
|
+
"clientPingTimeout": {
|
|
83
|
+
"type": "number"
|
|
84
|
+
},
|
|
85
|
+
"commandPrefix": {
|
|
86
|
+
"type": "string"
|
|
87
|
+
},
|
|
88
|
+
"id": {
|
|
89
|
+
"type": "string",
|
|
90
|
+
"description": "Slack bot name"
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"required": [
|
|
94
|
+
"id",
|
|
95
|
+
"token"
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
"commandPrefix": {
|
|
100
|
+
"type": "string",
|
|
101
|
+
"default": "",
|
|
102
|
+
"description": "命令前缀(默认 '' 无前缀,任意文本按命令匹配;如 '/' 要求 / 开头)。endpoints[i] 可逐项覆盖"
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
"required": [
|
|
106
|
+
"endpoints"
|
|
107
|
+
]
|
|
108
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { defineEndpointClient } from 'zhin.js/adapter';
|
|
2
|
+
import type { SlackWebClientLike } from './endpoint.js';
|
|
3
|
+
import type { SlackEvent } from './protocol.js';
|
|
4
|
+
|
|
5
|
+
/** Slack users.info response fields projected by the bundled tools. */
|
|
6
|
+
export interface SlackUserInfo {
|
|
7
|
+
id?: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
real_name?: string;
|
|
10
|
+
is_admin?: boolean;
|
|
11
|
+
is_bot?: boolean;
|
|
12
|
+
profile?: {
|
|
13
|
+
display_name?: string;
|
|
14
|
+
email?: string;
|
|
15
|
+
status_text?: string;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type SlackClientEventMap = Record<string, SlackEvent>;
|
|
20
|
+
|
|
21
|
+
declare module '@zhin.js/feature-kit' {
|
|
22
|
+
interface AdapterClientRegistry {
|
|
23
|
+
readonly slack: {
|
|
24
|
+
readonly client: SlackWebClientLike;
|
|
25
|
+
readonly events: SlackClientEventMap;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const slackClient = defineEndpointClient<SlackWebClientLike, SlackClientEventMap>('slack');
|