@zhin.js/adapter-slack 1.1.9 → 1.1.11
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 +33 -0
- package/README.md +29 -23
- package/lib/endpoint.js +4 -1
- package/lib/protocol.d.ts +1 -0
- package/package.json +15 -15
- package/src/endpoint.ts +4 -1
- package/src/protocol.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 064b06d: 保留 Slack 按钮回调所属的消息线程,使回调与普通消息使用一致的完整会话身份;普通频道消息不会误用按钮源消息时间戳创建线程。
|
|
8
|
+
- 9816c18: 将应用插件装配改为 configVersion: 2:主配置 plugins 映射实例名到包,disable_plugins 控制启停,业务配置使用顶层同名块。package.json 继续保留 features、entry、engine 等包契约,并支持静态 displayName/icon。
|
|
9
|
+
|
|
10
|
+
这是配置格式的破坏性更新:旧配置不能继续运行,请先停止 Bot,运行 `zhin migrate instances` 预览,再使用 `--apply` 转换;提供备份与中断继续/回滚,无法无损转换的嵌套、optional 和别名碰撞需人工迁移。Runtime、Console、CLI 与创建向导统一使用新声明。
|
|
11
|
+
|
|
12
|
+
保留框架顶层 `menuKeyword` / `menuStyle`,通过当前 generation 的 Root 配置视图供 Command Feature 消费;严格校验和配置修改不会丢失菜单设置,子实例配置保持隔离。
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [c407bd2]
|
|
15
|
+
- Updated dependencies [064b06d]
|
|
16
|
+
- Updated dependencies [2b4d6dc]
|
|
17
|
+
- Updated dependencies [b58548a]
|
|
18
|
+
- Updated dependencies [e914a93]
|
|
19
|
+
- Updated dependencies [e914a93]
|
|
20
|
+
- Updated dependencies [064b06d]
|
|
21
|
+
- @zhin.js/core@1.1.46
|
|
22
|
+
- @zhin.js/feature-kit@1.1.6
|
|
23
|
+
- @zhin.js/host-http@1.1.7
|
|
24
|
+
- @zhin.js/adapter@1.1.20
|
|
25
|
+
- @zhin.js/agent-feature@1.1.7
|
|
26
|
+
- @zhin.js/skill@1.1.7
|
|
27
|
+
- @zhin.js/tool@1.1.7
|
|
28
|
+
|
|
29
|
+
## 1.1.10
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- Updated dependencies [dd7f25f]
|
|
34
|
+
- @zhin.js/core@1.1.45
|
|
35
|
+
|
|
3
36
|
## 1.1.9
|
|
4
37
|
|
|
5
38
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ pnpm add @zhin.js/adapter-slack
|
|
|
22
22
|
- `@zhin.js/core` — `Endpoint.emit(...)` 入站、`outboundMessageToken` 出站
|
|
23
23
|
- `@zhin.js/host-http` — 仅 HTTP 模式需要 `httpHostToken` 注册 Events 路由
|
|
24
24
|
- `zhin.js` — `plugin.ts`(`definePlugin`)
|
|
25
|
-
- 配置经插件 `schema.json`
|
|
25
|
+
- 配置经插件 `schema.json` 落到顶层 `<instanceKey>`
|
|
26
26
|
|
|
27
27
|
入站:`gateway.receive({ conversation, message: { conversation, id }, content: text, sender, metadata })`(`conversation` 为 ConversationRef:`channel_type: im` → kind `private`,其余 → kind `group`;线程根 ts 进 `threadId`)
|
|
28
28
|
出站:`send({ conversation, payload })` → Web API(`conversation.id` 为 channel,`conversation.threadId` 为 thread_ts)
|
|
@@ -47,44 +47,50 @@ pnpm add @zhin.js/adapter-slack
|
|
|
47
47
|
## 最小配置(Socket Mode)
|
|
48
48
|
|
|
49
49
|
```yaml
|
|
50
|
+
configVersion: 2
|
|
50
51
|
# zhin.config.yml(Plugin Runtime)
|
|
51
52
|
plugins:
|
|
52
|
-
slack:
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
slack: "@zhin.js/adapter-slack"
|
|
54
|
+
slack:
|
|
55
|
+
socketMode: true # 默认 true,可省略
|
|
56
|
+
endpoints:
|
|
57
|
+
- id: my-slack-bot
|
|
58
|
+
token: ${SLACK_BOT_TOKEN}
|
|
59
|
+
appToken: ${SLACK_APP_TOKEN}
|
|
58
60
|
```
|
|
59
61
|
|
|
60
62
|
多 workspace:一个插件实例挂多个 endpoint(`endpoints` 数组逐项覆盖顶层字段,`id` 必填):
|
|
61
63
|
|
|
62
64
|
```yaml
|
|
65
|
+
configVersion: 2
|
|
63
66
|
plugins:
|
|
64
|
-
slack:
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
slack: "@zhin.js/adapter-slack"
|
|
68
|
+
slack:
|
|
69
|
+
endpoints:
|
|
70
|
+
- id: team-a
|
|
71
|
+
token: ${SLACK_BOT_TOKEN_A}
|
|
72
|
+
appToken: ${SLACK_APP_TOKEN_A}
|
|
73
|
+
- id: team-b
|
|
74
|
+
token: ${SLACK_BOT_TOKEN_B}
|
|
75
|
+
appToken: ${SLACK_APP_TOKEN_B}
|
|
72
76
|
```
|
|
73
77
|
|
|
74
78
|
## HTTP Events 配置
|
|
75
79
|
|
|
76
80
|
```yaml
|
|
81
|
+
configVersion: 2
|
|
77
82
|
plugins:
|
|
78
|
-
slack:
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
slack: "@zhin.js/adapter-slack"
|
|
84
|
+
slack:
|
|
85
|
+
socketMode: false
|
|
86
|
+
webhookPath: /slack/events # 可选,默认 /slack/events
|
|
87
|
+
endpoints:
|
|
88
|
+
- id: my-slack-bot
|
|
89
|
+
token: ${SLACK_BOT_TOKEN}
|
|
90
|
+
signingSecret: ${SLACK_SIGNING_SECRET}
|
|
85
91
|
```
|
|
86
92
|
|
|
87
|
-
|
|
93
|
+
主配置 `plugins` 映射需引用 `@zhin.js/adapter-slack`(`instanceKey: slack`)。
|
|
88
94
|
HTTP 模式下 Runtime Host(`http`)须已 listen;Slack App 的 Event Subscriptions / Interactivity / Slash Commands Request URL 指向 `https://your-domain/slack/events`。
|
|
89
95
|
|
|
90
96
|
## 环境变量
|
package/lib/endpoint.js
CHANGED
|
@@ -207,6 +207,8 @@ export class SlackEndpoint extends Endpoint {
|
|
|
207
207
|
const channelId = payload.channel?.id ?? '';
|
|
208
208
|
const userId = payload.user.id;
|
|
209
209
|
const messageTs = payload.message?.ts ?? '';
|
|
210
|
+
const sourceThread = payload.message?.thread_ts;
|
|
211
|
+
const threadTs = typeof sourceThread === 'string' && sourceThread && sourceThread !== messageTs ? sourceThread : undefined;
|
|
210
212
|
if (payload.response_url) {
|
|
211
213
|
postSlackEphemeral(payload.response_url, '已收到', this.#logger);
|
|
212
214
|
}
|
|
@@ -215,6 +217,7 @@ export class SlackEndpoint extends Endpoint {
|
|
|
215
217
|
channelId: channelId || userId,
|
|
216
218
|
// block_actions 无 channel_type;无 channel 时按与发起用户的 DM 处理
|
|
217
219
|
channelType: channelId ? undefined : 'im',
|
|
220
|
+
threadId: threadTs,
|
|
218
221
|
});
|
|
219
222
|
void this.emit('message.receive', {
|
|
220
223
|
conversation,
|
|
@@ -226,7 +229,7 @@ export class SlackEndpoint extends Endpoint {
|
|
|
226
229
|
metadata: Object.freeze({
|
|
227
230
|
eventType: 'block_actions',
|
|
228
231
|
actionId: payload.actions[0]?.action_id,
|
|
229
|
-
threadTs
|
|
232
|
+
threadTs,
|
|
230
233
|
}),
|
|
231
234
|
}).catch((err) => {
|
|
232
235
|
this.#logger.warn(formatCompact({
|
package/lib/protocol.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/adapter-slack",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.11",
|
|
4
4
|
"description": "Zhin.js Slack adapter for Plugin Runtime (Socket Mode / HTTP Events)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -33,24 +33,24 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@slack/socket-mode": "^2.0.7",
|
|
35
35
|
"@slack/web-api": "^7.19.0",
|
|
36
|
-
"@zhin.js/adapter": "1.1.
|
|
37
|
-
"@zhin.js/agent-feature": "1.1.
|
|
38
|
-
"@zhin.js/core": "1.1.
|
|
39
|
-
"@zhin.js/feature-kit": "1.1.
|
|
40
|
-
"@zhin.js/host-http": "1.1.
|
|
36
|
+
"@zhin.js/adapter": "1.1.20",
|
|
37
|
+
"@zhin.js/agent-feature": "1.1.7",
|
|
38
|
+
"@zhin.js/core": "1.1.46",
|
|
39
|
+
"@zhin.js/feature-kit": "1.1.6",
|
|
40
|
+
"@zhin.js/host-http": "1.1.7",
|
|
41
41
|
"@zhin.js/im-contract": "1.1.4",
|
|
42
42
|
"@zhin.js/logger": "1.1.2",
|
|
43
|
-
"@zhin.js/skill": "1.1.
|
|
44
|
-
"@zhin.js/tool": "1.1.
|
|
43
|
+
"@zhin.js/skill": "1.1.7",
|
|
44
|
+
"@zhin.js/tool": "1.1.7"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"zod": "^4.0.0",
|
|
48
|
-
"@zhin.js/adapter": "^1.1.
|
|
49
|
-
"@zhin.js/command": "^1.1.
|
|
50
|
-
"@zhin.js/core": "^1.1.
|
|
51
|
-
"@zhin.js/host-http": "^1.1.
|
|
52
|
-
"@zhin.js/permission": "^1.1.
|
|
53
|
-
"zhin.js": "^1.1.
|
|
48
|
+
"@zhin.js/adapter": "^1.1.20",
|
|
49
|
+
"@zhin.js/command": "^1.1.8",
|
|
50
|
+
"@zhin.js/core": "^1.1.46",
|
|
51
|
+
"@zhin.js/host-http": "^1.1.7",
|
|
52
|
+
"@zhin.js/permission": "^1.1.7",
|
|
53
|
+
"zhin.js": "^1.1.11"
|
|
54
54
|
},
|
|
55
55
|
"peerDependenciesMeta": {
|
|
56
56
|
"@zhin.js/command": {
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"typescript": "^6.0.3",
|
|
69
69
|
"vitest": "^4.1.10",
|
|
70
70
|
"zod": "^4.4.3",
|
|
71
|
-
"zhin.js": "1.1.
|
|
71
|
+
"zhin.js": "1.1.11"
|
|
72
72
|
},
|
|
73
73
|
"files": [
|
|
74
74
|
"adapters",
|
package/src/endpoint.ts
CHANGED
|
@@ -298,6 +298,8 @@ export class SlackEndpoint extends Endpoint<SlackWebClientLike> implements Slack
|
|
|
298
298
|
const channelId = payload.channel?.id ?? '';
|
|
299
299
|
const userId = payload.user.id;
|
|
300
300
|
const messageTs = payload.message?.ts ?? '';
|
|
301
|
+
const sourceThread = payload.message?.thread_ts;
|
|
302
|
+
const threadTs = typeof sourceThread === 'string' && sourceThread && sourceThread !== messageTs ? sourceThread : undefined;
|
|
301
303
|
if (payload.response_url) {
|
|
302
304
|
postSlackEphemeral(payload.response_url, '已收到', this.#logger);
|
|
303
305
|
}
|
|
@@ -306,6 +308,7 @@ export class SlackEndpoint extends Endpoint<SlackWebClientLike> implements Slack
|
|
|
306
308
|
channelId: channelId || userId,
|
|
307
309
|
// block_actions 无 channel_type;无 channel 时按与发起用户的 DM 处理
|
|
308
310
|
channelType: channelId ? undefined : 'im',
|
|
311
|
+
threadId: threadTs,
|
|
309
312
|
});
|
|
310
313
|
void this.emit('message.receive', {
|
|
311
314
|
conversation,
|
|
@@ -317,7 +320,7 @@ export class SlackEndpoint extends Endpoint<SlackWebClientLike> implements Slack
|
|
|
317
320
|
metadata: Object.freeze({
|
|
318
321
|
eventType: 'block_actions',
|
|
319
322
|
actionId: payload.actions[0]?.action_id,
|
|
320
|
-
threadTs
|
|
323
|
+
threadTs,
|
|
321
324
|
}),
|
|
322
325
|
}).catch((err) => {
|
|
323
326
|
this.#logger.warn(formatCompact({
|
package/src/protocol.ts
CHANGED
|
@@ -66,7 +66,7 @@ export interface SlackInteractionPayload {
|
|
|
66
66
|
readonly trigger_id?: string;
|
|
67
67
|
readonly user: { id: string; username?: string; name?: string; team_id?: string };
|
|
68
68
|
readonly channel?: { id: string; name?: string };
|
|
69
|
-
readonly message?: { ts: string; text?: string; [key: string]: unknown };
|
|
69
|
+
readonly message?: { ts: string; text?: string; thread_ts?: string; [key: string]: unknown };
|
|
70
70
|
readonly actions?: SlackBlockAction[];
|
|
71
71
|
readonly response_url?: string;
|
|
72
72
|
readonly [key: string]: unknown;
|