@zhin.js/adapter-slack 7.0.0 → 7.0.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 +30 -0
- package/README.md +17 -2
- package/adapters/slack.js +0 -5
- package/adapters/slack.ts +0 -5
- package/agent/tools/add_reaction.ts +11 -8
- package/agent/tools/archive_channel.ts +5 -8
- package/agent/tools/edit_message.ts +5 -8
- package/agent/tools/invite_to_channel.ts +5 -8
- package/agent/tools/pin_message.ts +5 -8
- package/agent/tools/remove_reaction.ts +14 -8
- package/agent/tools/set_purpose.ts +5 -8
- package/agent/tools/set_topic.ts +5 -8
- package/agent/tools/unarchive.ts +5 -8
- package/agent/tools/unpin_message.ts +5 -8
- package/agent/tools/user_info.ts +5 -8
- package/lib/client.d.ts +25 -0
- package/lib/client.js +2 -0
- package/lib/endpoint.d.ts +4 -22
- package/lib/endpoint.js +31 -76
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/protocol.d.ts +1 -1
- package/lib/protocol.js +1 -1
- package/lib/side-event-dispatch.d.ts +2 -2
- package/lib/side-event-dispatch.js +3 -3
- package/lib/slack-endpoint-commands.d.ts +1 -1
- package/package.json +15 -14
- package/src/client.ts +30 -0
- package/src/endpoint.ts +33 -93
- package/src/index.ts +4 -6
- package/src/protocol.ts +1 -1
- package/src/side-event-dispatch.ts +4 -4
- package/lib/slack-agent-deps.d.ts +0 -41
- package/lib/slack-agent-deps.js +0 -30
- package/src/slack-agent-deps.ts +0 -71
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 7.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [736fa04]
|
|
8
|
+
- @zhin.js/agent@1.1.17
|
|
9
|
+
- zhin.js@6.0.14
|
|
10
|
+
|
|
11
|
+
## 7.0.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 1fc78bc: Unify native platform Client access behind the literal `adapter` discriminant. Handlers infer both native events and Clients, while command, inbound/outbound middleware, and both Agent tool authoring surfaces expose the exact operation-scoped Client through a lazy `$client` getter. Definitions without `adapter` keep `$client` typed as `unknown`, and runtime dispatch rejects adapter mismatches before resolving the Client. Bundled platform tools now use this single path instead of model-provided endpoint ids and adapter-specific dependency wrappers. Every adapter registers one Client/EventMap contract, and protocol adapters including NapCat, Milky, OneBot and Satori now produce transport-independent Client objects rather than letting Endpoint instances impersonate Clients.
|
|
16
|
+
- Updated dependencies [e9c6a73]
|
|
17
|
+
- Updated dependencies [4e8117c]
|
|
18
|
+
- Updated dependencies [902fa35]
|
|
19
|
+
- Updated dependencies [54bfd6b]
|
|
20
|
+
- Updated dependencies [12025ee]
|
|
21
|
+
- Updated dependencies [09b14d6]
|
|
22
|
+
- Updated dependencies [1fc78bc]
|
|
23
|
+
- @zhin.js/agent@1.1.16
|
|
24
|
+
- @zhin.js/adapter@1.2.1
|
|
25
|
+
- @zhin.js/core@1.5.14
|
|
26
|
+
- @zhin.js/host-http@1.0.13
|
|
27
|
+
- @zhin.js/command@1.0.16
|
|
28
|
+
- @zhin.js/logger@1.0.77
|
|
29
|
+
- zhin.js@6.0.14
|
|
30
|
+
- @zhin.js/feature-kit@1.0.13
|
|
31
|
+
- @zhin.js/permission@1.0.4
|
|
32
|
+
|
|
3
33
|
## 7.0.0
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ Zhin.js Slack 适配器(Plugin Runtime),优先 Socket Mode,也可经 Run
|
|
|
6
6
|
|
|
7
7
|
- **Socket Mode**(默认):WebSocket 长连接,无需公网 URL
|
|
8
8
|
- **HTTP Events API**:`httpHostToken` POST(签名验证),**非** legacy host-router/Koa
|
|
9
|
-
- 入站经 `
|
|
9
|
+
- 入站经 `Endpoint.emit(...)`;出站 `send({ conversation, payload })` → `chat.postMessage` / Block Kit
|
|
10
10
|
- 约定式 `defineAdapter` / `definePlugin`(无需 `usePlugin`)
|
|
11
11
|
- Block Kit 按钮、斜杠命令、消息编辑、表情反应等(见 `agent/tools/`)
|
|
12
12
|
|
|
@@ -19,7 +19,7 @@ pnpm add @zhin.js/adapter-slack
|
|
|
19
19
|
## Plugin Runtime
|
|
20
20
|
|
|
21
21
|
- `@zhin.js/adapter` — 约定式 `adapters/slack.ts`(`defineAdapter`)
|
|
22
|
-
- `@zhin.js/core` — `
|
|
22
|
+
- `@zhin.js/core` — `Endpoint.emit(...)` 入站、`outboundMessageToken` 出站
|
|
23
23
|
- `@zhin.js/host-http` — 仅 HTTP 模式需要 `httpHostToken` 注册 Events 路由
|
|
24
24
|
- `zhin.js` — `plugin.ts`(`definePlugin`)
|
|
25
25
|
- 配置经插件 `schema.json` 落到 `plugins.<instanceKey>`
|
|
@@ -38,6 +38,12 @@ pnpm add @zhin.js/adapter-slack
|
|
|
38
38
|
| **Socket Mode**(默认) | `true` | 本地/内网,无需公网 URL | `appToken`(`xapp-...`) |
|
|
39
39
|
| **HTTP Events** | `false` | 生产环境有公网 HTTPS | `signingSecret` + Runtime Host |
|
|
40
40
|
|
|
41
|
+
## 前置条件
|
|
42
|
+
|
|
43
|
+
1. 创建 Slack App,安装到 Workspace,并授予收发消息所需 OAuth scopes。
|
|
44
|
+
2. Socket Mode 创建 `connections:write` App-Level Token;HTTP 模式配置 Signing Secret 与 Events URL。
|
|
45
|
+
3. 订阅需要的 bot events,并把应用加入目标频道。
|
|
46
|
+
|
|
41
47
|
## 最小配置(Socket Mode)
|
|
42
48
|
|
|
43
49
|
```yaml
|
|
@@ -120,6 +126,15 @@ HTTP 模式下 Runtime Host(`http`)须已 listen;Slack App 的 Event Subsc
|
|
|
120
126
|
- OAuth 安装流程 — 暂不支持
|
|
121
127
|
- 旧 `usePlugin` / `extends Adapter` / host-router 生产入口已删除
|
|
122
128
|
|
|
129
|
+
## 故障排查
|
|
130
|
+
|
|
131
|
+
| 现象 | 排查 |
|
|
132
|
+
| --- | --- |
|
|
133
|
+
| Socket Mode 无法连接 | 检查 `xapp-` Token、Socket Mode 与 `connections:write` scope |
|
|
134
|
+
| HTTP Events 返回 401 | 检查 Signing Secret、原始请求体、服务器时钟与反向代理 |
|
|
135
|
+
| 频道消息未触发 | 确认事件订阅、OAuth scopes,并邀请 App 进入频道 |
|
|
136
|
+
| 线程回复跑到主频道 | 检查入站 `thread_ts` 是否保留为 Conversation `threadId` |
|
|
137
|
+
|
|
123
138
|
## 许可证
|
|
124
139
|
|
|
125
140
|
MIT
|
package/adapters/slack.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* Convention entry: discover `adapters/slack.ts` → defineAdapter.
|
|
4
4
|
*/
|
|
5
5
|
import { defineAdapter } from 'zhin.js/adapter';
|
|
6
|
-
import { messageGatewayToken, sideEventGatewayToken } from '@zhin.js/core/runtime';
|
|
7
6
|
import { httpHostToken } from '@zhin.js/host-http';
|
|
8
7
|
import { SlackEndpoint } from "../lib/endpoint.js";
|
|
9
8
|
import { resolveSlackConfig, } from "../lib/protocol.js";
|
|
@@ -29,16 +28,12 @@ export default defineAdapter({
|
|
|
29
28
|
if (config.mode === 'http') {
|
|
30
29
|
return new SlackEndpoint({
|
|
31
30
|
id: context.id,
|
|
32
|
-
gateway: context.use(messageGatewayToken),
|
|
33
|
-
sideEvents: context.use(sideEventGatewayToken),
|
|
34
31
|
http: context.use(httpHostToken),
|
|
35
32
|
config,
|
|
36
33
|
});
|
|
37
34
|
}
|
|
38
35
|
return new SlackEndpoint({
|
|
39
36
|
id: context.id,
|
|
40
|
-
gateway: context.use(messageGatewayToken),
|
|
41
|
-
sideEvents: context.use(sideEventGatewayToken),
|
|
42
37
|
config,
|
|
43
38
|
});
|
|
44
39
|
},
|
package/adapters/slack.ts
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* Convention entry: discover `adapters/slack.ts` → defineAdapter.
|
|
3
3
|
*/
|
|
4
4
|
import { defineAdapter } from 'zhin.js/adapter';
|
|
5
|
-
import { messageGatewayToken, sideEventGatewayToken } from '@zhin.js/core/runtime';
|
|
6
5
|
import { httpHostToken } from '@zhin.js/host-http';
|
|
7
6
|
import { SlackEndpoint } from '../src/endpoint.js';
|
|
8
7
|
import {
|
|
@@ -34,16 +33,12 @@ export default defineAdapter<SlackAdapterConfig>({
|
|
|
34
33
|
if (config.mode === 'http') {
|
|
35
34
|
return new SlackEndpoint({
|
|
36
35
|
id: context.id,
|
|
37
|
-
gateway: context.use(messageGatewayToken),
|
|
38
|
-
sideEvents: context.use(sideEventGatewayToken),
|
|
39
36
|
http: context.use(httpHostToken),
|
|
40
37
|
config,
|
|
41
38
|
});
|
|
42
39
|
}
|
|
43
40
|
return new SlackEndpoint({
|
|
44
41
|
id: context.id,
|
|
45
|
-
gateway: context.use(messageGatewayToken),
|
|
46
|
-
sideEvents: context.use(sideEventGatewayToken),
|
|
47
42
|
config,
|
|
48
43
|
});
|
|
49
44
|
},
|
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
3
|
+
import { normalizeSlackReactionName } from '../../src/slack-reaction.js';
|
|
4
4
|
|
|
5
5
|
export default defineAgentTool<{
|
|
6
|
-
endpoint_id: string;
|
|
7
6
|
channel: string;
|
|
8
7
|
timestamp: string;
|
|
9
8
|
emoji: string;
|
|
10
9
|
}>({
|
|
11
10
|
description: '给 Slack 消息添加表情反应',
|
|
12
11
|
inputSchema: z.object({
|
|
13
|
-
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
14
12
|
channel: z.string().describe('频道 ID'),
|
|
15
13
|
timestamp: z.string().describe('消息时间戳'),
|
|
16
14
|
emoji: z.string().describe('表情名称(不含冒号)'),
|
|
17
15
|
}),
|
|
18
|
-
|
|
16
|
+
adapter: 'slack',
|
|
19
17
|
tags: ['slack'],
|
|
20
|
-
async execute({
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
18
|
+
async execute({ channel, timestamp, emoji }, context) {
|
|
19
|
+
const client = context.$client;
|
|
20
|
+
const name = normalizeSlackReactionName(emoji);
|
|
21
|
+
try {
|
|
22
|
+
await client.reactions.add({ channel, timestamp, name });
|
|
23
|
+
} catch (error) {
|
|
24
|
+
if ((error as { data?: { error?: string } })?.data?.error !== 'already_reacted') throw error;
|
|
25
|
+
}
|
|
26
|
+
const success = true;
|
|
24
27
|
return { success, message: success ? `已添加反应 :${emoji}:` : '操作失败' };
|
|
25
28
|
},
|
|
26
29
|
});
|
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { platformPermit } from '../../src/platform-permit.js';
|
|
4
|
-
import { getSlackAgentDeps } from '../../src/slack-agent-deps.js';
|
|
5
4
|
|
|
6
5
|
export default defineAgentTool<{
|
|
7
|
-
endpoint_id: string;
|
|
8
6
|
channel: string;
|
|
9
7
|
}>({
|
|
10
8
|
description: '归档 Slack 频道',
|
|
11
9
|
inputSchema: z.object({
|
|
12
|
-
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
13
10
|
channel: z.string().describe('频道 ID'),
|
|
14
11
|
}),
|
|
15
|
-
|
|
12
|
+
adapter: 'slack',
|
|
16
13
|
tags: ['slack'],
|
|
17
14
|
permissions: [platformPermit('workspace_admin')],
|
|
18
|
-
async execute({
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const success =
|
|
15
|
+
async execute({ channel }, context) {
|
|
16
|
+
const client = context.$client;
|
|
17
|
+
await client.conversations.archive({ channel });
|
|
18
|
+
const success = true;
|
|
22
19
|
return { success, message: success ? '已归档频道' : '操作失败' };
|
|
23
20
|
},
|
|
24
21
|
});
|
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
3
|
+
import { editSlackContent } from '../../src/slack-outbound.js';
|
|
4
4
|
|
|
5
5
|
export default defineAgentTool<{
|
|
6
|
-
endpoint_id: string;
|
|
7
6
|
channel: string;
|
|
8
7
|
message_ts: string;
|
|
9
8
|
text: string;
|
|
10
9
|
}>({
|
|
11
10
|
description: '编辑 Slack 消息',
|
|
12
11
|
inputSchema: z.object({
|
|
13
|
-
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
14
12
|
channel: z.string().describe('频道 ID'),
|
|
15
13
|
message_ts: z.string().describe('消息时间戳'),
|
|
16
14
|
text: z.string().describe('新的消息文本'),
|
|
17
15
|
}),
|
|
18
|
-
|
|
16
|
+
adapter: 'slack',
|
|
19
17
|
tags: ['slack'],
|
|
20
|
-
async execute({
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
await endpoint.editMessage(channel, message_ts, [
|
|
18
|
+
async execute({ channel, message_ts, text }, context) {
|
|
19
|
+
const client = context.$client;
|
|
20
|
+
await editSlackContent(client, channel, message_ts, [
|
|
24
21
|
{ type: 'text', data: { text } },
|
|
25
22
|
]);
|
|
26
23
|
return { success: true, message: '消息已编辑' };
|
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { platformPermit } from '../../src/platform-permit.js';
|
|
4
|
-
import { getSlackAgentDeps } from '../../src/slack-agent-deps.js';
|
|
5
4
|
|
|
6
5
|
export default defineAgentTool<{
|
|
7
|
-
endpoint_id: string;
|
|
8
6
|
channel: string;
|
|
9
7
|
users: string;
|
|
10
8
|
}>({
|
|
11
9
|
description: '邀请用户加入 Slack 频道',
|
|
12
10
|
inputSchema: z.object({
|
|
13
|
-
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
14
11
|
channel: z.string().describe('频道 ID'),
|
|
15
12
|
users: z.string().describe('用户 ID 列表(逗号分隔)'),
|
|
16
13
|
}),
|
|
17
|
-
|
|
14
|
+
adapter: 'slack',
|
|
18
15
|
tags: ['slack'],
|
|
19
16
|
permissions: [platformPermit('channel_manager')],
|
|
20
|
-
async execute({
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
const success =
|
|
17
|
+
async execute({ channel, users }, context) {
|
|
18
|
+
const client = context.$client;
|
|
19
|
+
await client.conversations.invite({ channel, users });
|
|
20
|
+
const success = true;
|
|
24
21
|
return { success, message: success ? '已邀请用户加入频道' : '操作失败' };
|
|
25
22
|
},
|
|
26
23
|
});
|
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { platformPermit } from '../../src/platform-permit.js';
|
|
4
|
-
import { getSlackAgentDeps } from '../../src/slack-agent-deps.js';
|
|
5
4
|
|
|
6
5
|
export default defineAgentTool<{
|
|
7
|
-
endpoint_id: string;
|
|
8
6
|
channel: string;
|
|
9
7
|
timestamp: string;
|
|
10
8
|
}>({
|
|
11
9
|
description: '置顶 Slack 消息',
|
|
12
10
|
inputSchema: z.object({
|
|
13
|
-
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
14
11
|
channel: z.string().describe('频道 ID'),
|
|
15
12
|
timestamp: z.string().describe('消息时间戳'),
|
|
16
13
|
}),
|
|
17
|
-
|
|
14
|
+
adapter: 'slack',
|
|
18
15
|
tags: ['slack'],
|
|
19
16
|
permissions: [platformPermit('channel_manager')],
|
|
20
|
-
async execute({
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
const success =
|
|
17
|
+
async execute({ channel, timestamp }, context) {
|
|
18
|
+
const client = context.$client;
|
|
19
|
+
await client.pins.add({ channel, timestamp });
|
|
20
|
+
const success = true;
|
|
24
21
|
return { success, message: success ? '已置顶消息' : '操作失败' };
|
|
25
22
|
},
|
|
26
23
|
});
|
|
@@ -1,26 +1,32 @@
|
|
|
1
1
|
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
3
|
+
import { normalizeSlackReactionName } from '../../src/slack-reaction.js';
|
|
4
4
|
|
|
5
5
|
export default defineAgentTool<{
|
|
6
|
-
endpoint_id: string;
|
|
7
6
|
channel_id: string;
|
|
8
7
|
timestamp: string;
|
|
9
8
|
name: string;
|
|
10
9
|
}>({
|
|
11
10
|
description: '移除 Slack 消息上的表情反应',
|
|
12
11
|
inputSchema: z.object({
|
|
13
|
-
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
14
12
|
channel_id: z.string().describe('频道 ID'),
|
|
15
13
|
timestamp: z.string().describe('消息时间戳'),
|
|
16
14
|
name: z.string().describe('表情名称(如 thumbsup、heart)'),
|
|
17
15
|
}),
|
|
18
|
-
|
|
16
|
+
adapter: 'slack',
|
|
19
17
|
tags: ['slack'],
|
|
20
|
-
async execute({
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
async execute({ channel_id, timestamp, name }, context) {
|
|
19
|
+
const client = context.$client;
|
|
20
|
+
try {
|
|
21
|
+
await client.reactions.remove({
|
|
22
|
+
channel: channel_id,
|
|
23
|
+
timestamp,
|
|
24
|
+
name: normalizeSlackReactionName(name),
|
|
25
|
+
});
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if ((error as { data?: { error?: string } })?.data?.error !== 'no_reaction') throw error;
|
|
28
|
+
}
|
|
29
|
+
const success = true;
|
|
24
30
|
return { success, message: success ? `已移除反应 :${name}:` : '操作失败' };
|
|
25
31
|
},
|
|
26
32
|
});
|
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { platformPermit } from '../../src/platform-permit.js';
|
|
4
|
-
import { getSlackAgentDeps } from '../../src/slack-agent-deps.js';
|
|
5
4
|
|
|
6
5
|
export default defineAgentTool<{
|
|
7
|
-
endpoint_id: string;
|
|
8
6
|
channel_id: string;
|
|
9
7
|
purpose: string;
|
|
10
8
|
}>({
|
|
11
9
|
description: '设置 Slack 频道的用途/目的',
|
|
12
10
|
inputSchema: z.object({
|
|
13
|
-
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
14
11
|
channel_id: z.string().describe('频道 ID'),
|
|
15
12
|
purpose: z.string().describe('频道用途描述'),
|
|
16
13
|
}),
|
|
17
|
-
|
|
14
|
+
adapter: 'slack',
|
|
18
15
|
tags: ['slack'],
|
|
19
16
|
permissions: [platformPermit('channel_manager')],
|
|
20
|
-
async execute({
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
const success =
|
|
17
|
+
async execute({ channel_id, purpose }, context) {
|
|
18
|
+
const client = context.$client;
|
|
19
|
+
await client.conversations.setPurpose({ channel: channel_id, purpose });
|
|
20
|
+
const success = true;
|
|
24
21
|
return { success, message: success ? '频道用途已更新' : '操作失败' };
|
|
25
22
|
},
|
|
26
23
|
});
|
package/agent/tools/set_topic.ts
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { platformPermit } from '../../src/platform-permit.js';
|
|
4
|
-
import { getSlackAgentDeps } from '../../src/slack-agent-deps.js';
|
|
5
4
|
|
|
6
5
|
export default defineAgentTool<{
|
|
7
|
-
endpoint_id: string;
|
|
8
6
|
channel: string;
|
|
9
7
|
topic: string;
|
|
10
8
|
}>({
|
|
11
9
|
description: '设置 Slack 频道话题',
|
|
12
10
|
inputSchema: z.object({
|
|
13
|
-
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
14
11
|
channel: z.string().describe('频道 ID'),
|
|
15
12
|
topic: z.string().describe('新话题'),
|
|
16
13
|
}),
|
|
17
|
-
|
|
14
|
+
adapter: 'slack',
|
|
18
15
|
tags: ['slack'],
|
|
19
16
|
permissions: [platformPermit('channel_manager')],
|
|
20
|
-
async execute({
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
const success =
|
|
17
|
+
async execute({ channel, topic }, context) {
|
|
18
|
+
const client = context.$client;
|
|
19
|
+
await client.conversations.setTopic({ channel, topic });
|
|
20
|
+
const success = true;
|
|
24
21
|
return { success, message: success ? '已设置频道话题' : '操作失败' };
|
|
25
22
|
},
|
|
26
23
|
});
|
package/agent/tools/unarchive.ts
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { platformPermit } from '../../src/platform-permit.js';
|
|
4
|
-
import { getSlackAgentDeps } from '../../src/slack-agent-deps.js';
|
|
5
4
|
|
|
6
5
|
export default defineAgentTool<{
|
|
7
|
-
endpoint_id: string;
|
|
8
6
|
channel_id: string;
|
|
9
7
|
}>({
|
|
10
8
|
description: '恢复已归档的 Slack 频道',
|
|
11
9
|
inputSchema: z.object({
|
|
12
|
-
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
13
10
|
channel_id: z.string().describe('频道 ID'),
|
|
14
11
|
}),
|
|
15
|
-
|
|
12
|
+
adapter: 'slack',
|
|
16
13
|
tags: ['slack'],
|
|
17
14
|
permissions: [platformPermit('workspace_admin')],
|
|
18
|
-
async execute({
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const success =
|
|
15
|
+
async execute({ channel_id }, context) {
|
|
16
|
+
const client = context.$client;
|
|
17
|
+
await client.conversations.unarchive({ channel: channel_id });
|
|
18
|
+
const success = true;
|
|
22
19
|
return { success, message: success ? '频道已恢复' : '操作失败' };
|
|
23
20
|
},
|
|
24
21
|
});
|
|
@@ -1,26 +1,23 @@
|
|
|
1
1
|
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { platformPermit } from '../../src/platform-permit.js';
|
|
4
|
-
import { getSlackAgentDeps } from '../../src/slack-agent-deps.js';
|
|
5
4
|
|
|
6
5
|
export default defineAgentTool<{
|
|
7
|
-
endpoint_id: string;
|
|
8
6
|
channel_id: string;
|
|
9
7
|
timestamp: string;
|
|
10
8
|
}>({
|
|
11
9
|
description: '取消 Slack 频道中消息的置顶',
|
|
12
10
|
inputSchema: z.object({
|
|
13
|
-
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
14
11
|
channel_id: z.string().describe('频道 ID'),
|
|
15
12
|
timestamp: z.string().describe('消息时间戳'),
|
|
16
13
|
}),
|
|
17
|
-
|
|
14
|
+
adapter: 'slack',
|
|
18
15
|
tags: ['slack'],
|
|
19
16
|
permissions: [platformPermit('channel_manager')],
|
|
20
|
-
async execute({
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
const success =
|
|
17
|
+
async execute({ channel_id, timestamp }, context) {
|
|
18
|
+
const client = context.$client;
|
|
19
|
+
await client.pins.remove({ channel: channel_id, timestamp });
|
|
20
|
+
const success = true;
|
|
24
21
|
return { success, message: success ? '已取消置顶' : '操作失败' };
|
|
25
22
|
},
|
|
26
23
|
});
|
package/agent/tools/user_info.ts
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
3
|
+
import type { SlackUserInfo } from '../../src/client.js';
|
|
4
4
|
|
|
5
5
|
export default defineAgentTool<{
|
|
6
|
-
endpoint_id: string;
|
|
7
6
|
user_id: string;
|
|
8
7
|
}>({
|
|
9
8
|
description: '查询 Slack 用户详细信息',
|
|
10
9
|
inputSchema: z.object({
|
|
11
|
-
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
12
10
|
user_id: z.string().describe('用户 ID'),
|
|
13
11
|
}),
|
|
14
|
-
|
|
12
|
+
adapter: 'slack',
|
|
15
13
|
tags: ['slack'],
|
|
16
|
-
async execute({
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const user = await endpoint.getUserInfo(user_id);
|
|
14
|
+
async execute({ user_id }, context) {
|
|
15
|
+
const client = context.$client;
|
|
16
|
+
const user = (await client.users.info({ user: user_id })).user as SlackUserInfo | undefined;
|
|
20
17
|
if (!user) throw new Error(`Slack 用户不存在: ${user_id}`);
|
|
21
18
|
return {
|
|
22
19
|
id: user.id,
|
package/lib/client.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { SlackWebClientLike } from './endpoint.js';
|
|
2
|
+
import type { SlackEvent } from './protocol.js';
|
|
3
|
+
/** Slack users.info response fields projected by the bundled tools. */
|
|
4
|
+
export interface SlackUserInfo {
|
|
5
|
+
id?: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
real_name?: string;
|
|
8
|
+
is_admin?: boolean;
|
|
9
|
+
is_bot?: boolean;
|
|
10
|
+
profile?: {
|
|
11
|
+
display_name?: string;
|
|
12
|
+
email?: string;
|
|
13
|
+
status_text?: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export type SlackClientEventMap = Record<string, SlackEvent>;
|
|
17
|
+
declare module '@zhin.js/feature-kit' {
|
|
18
|
+
interface AdapterClientRegistry {
|
|
19
|
+
readonly slack: {
|
|
20
|
+
readonly client: SlackWebClientLike;
|
|
21
|
+
readonly events: SlackClientEventMap;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export declare const slackClient: import("@zhin.js/adapter").EndpointClientToken<SlackWebClientLike, SlackClientEventMap>;
|
package/lib/client.js
ADDED
package/lib/endpoint.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
1
|
+
import { Endpoint } from 'zhin.js/adapter';
|
|
2
|
+
import type { EndpointControl, EndpointManagement, EndpointSendRequest } from 'zhin.js/adapter';
|
|
3
3
|
import type { HttpHost } from '@zhin.js/host-http';
|
|
4
4
|
import type { CapabilityId } from 'zhin.js';
|
|
5
5
|
import { type ResolvedSlackConfig, type SlackEvent, type SlackInteractionPayload, type SlackMessageEvent, type SlackSlashCommand } from './protocol.js';
|
|
6
|
-
import { type SlackUserInfo } from './slack-agent-deps.js';
|
|
7
6
|
import { type SlackChatClient } from './slack-outbound.js';
|
|
8
7
|
import { type SlackWebhookHandler } from './webhook.js';
|
|
9
8
|
export interface SlackSocketLike {
|
|
@@ -117,8 +116,6 @@ export interface SlackWebClientLike extends SlackChatClient {
|
|
|
117
116
|
}
|
|
118
117
|
export interface SlackEndpointOptions {
|
|
119
118
|
readonly id: CapabilityId;
|
|
120
|
-
readonly gateway: MessageGateway;
|
|
121
|
-
readonly sideEvents?: SideEventGateway;
|
|
122
119
|
readonly config: ResolvedSlackConfig;
|
|
123
120
|
readonly http?: HttpHost;
|
|
124
121
|
readonly createClient?: (token: string) => SlackWebClientLike;
|
|
@@ -127,14 +124,14 @@ export interface SlackEndpointOptions {
|
|
|
127
124
|
readonly clientPingTimeout: number;
|
|
128
125
|
}) => SlackSocketLike;
|
|
129
126
|
}
|
|
130
|
-
export declare class SlackEndpoint implements
|
|
127
|
+
export declare class SlackEndpoint extends Endpoint<SlackWebClientLike> implements SlackWebhookHandler {
|
|
131
128
|
#private;
|
|
132
129
|
readonly management: EndpointManagement;
|
|
133
130
|
readonly control: EndpointControl;
|
|
134
131
|
constructor(options: SlackEndpointOptions);
|
|
135
132
|
/** Console 展示 / AdapterIndex live name(多 endpoint 时与 entry name 一致)。 */
|
|
136
133
|
get name(): string;
|
|
137
|
-
get client(): SlackWebClientLike
|
|
134
|
+
get client(): SlackWebClientLike;
|
|
138
135
|
get platformUserId(): string | undefined;
|
|
139
136
|
get config(): ResolvedSlackConfig;
|
|
140
137
|
start(): Promise<void>;
|
|
@@ -153,19 +150,4 @@ export declare class SlackEndpoint implements EndpointInstance, SlackWebhookHand
|
|
|
153
150
|
ts: string;
|
|
154
151
|
} | null;
|
|
155
152
|
recallMessage(messageId: string): Promise<void>;
|
|
156
|
-
editMessage(channel: string, messageTs: string, content: unknown): Promise<void>;
|
|
157
|
-
inviteToChannel(channel: string, users: string[]): Promise<boolean>;
|
|
158
|
-
kickFromChannel(channel: string, user: string): Promise<boolean>;
|
|
159
|
-
setChannelTopic(channel: string, topic: string): Promise<boolean>;
|
|
160
|
-
setChannelPurpose(channel: string, purpose: string): Promise<boolean>;
|
|
161
|
-
archiveChannel(channel: string): Promise<boolean>;
|
|
162
|
-
unarchiveChannel(channel: string): Promise<boolean>;
|
|
163
|
-
renameChannel(channel: string, name: string): Promise<boolean>;
|
|
164
|
-
getChannelMembers(channel: string): Promise<string[]>;
|
|
165
|
-
getChannelInfo(channel: string): Promise<unknown>;
|
|
166
|
-
getUserInfo(user: string): Promise<SlackUserInfo | undefined>;
|
|
167
|
-
addReaction(channel: string, timestamp: string, name: string): Promise<boolean>;
|
|
168
|
-
removeReaction(channel: string, timestamp: string, name: string): Promise<boolean>;
|
|
169
|
-
pinMessage(channel: string, timestamp: string): Promise<boolean>;
|
|
170
|
-
unpinMessage(channel: string, timestamp: string): Promise<boolean>;
|
|
171
153
|
}
|