Skip to content

Commit

Permalink
slack adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Sep 26, 2023
1 parent 479bf92 commit 709ca10
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 16 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
dist/
ecosystem/
.data
.temp
temp/
.vitepress/cache

node_modules/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"build": "yarn mixin && cross-env NODE_OPTIONS=--max-old-space-size=8192 vitepress build ."
},
"devDependencies": {
"@koishijs/components": "^1.4.4",
"@koishijs/components": "^1.4.5",
"@koishijs/core": "^4.14.6",
"@koishijs/market": "^4.1.6",
"@koishijs/registry": "^6.0.4",
Expand Down
Binary file added public/adapter/slack/app-1.webp
Binary file not shown.
Binary file added public/adapter/slack/app-2.webp
Binary file not shown.
Binary file added public/adapter/slack/events.webp
Binary file not shown.
Binary file added public/adapter/slack/scopes.webp
Binary file not shown.
Binary file added public/adapter/slack/secret-1.webp
Binary file not shown.
Binary file added public/adapter/slack/secret-2.webp
Binary file not shown.
Binary file added public/adapter/slack/webhook.webp
Binary file not shown.
Binary file added public/adapter/slack/websocket.webp
Binary file not shown.
Binary file added public/adapter/slack/workspace.webp
Binary file not shown.
59 changes: 46 additions & 13 deletions zh-CN/plugins/adapter/slack.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,51 @@

## 接入方式

1.[应用后台](https://api.slack.com/apps) 点击「Create New App」,选择「From Scratch」,填入应用名称和所添加的工作区 (目前适配器只支持一个应用处理一个工作区的事件),点击「Create App」
2. 在跳转至的应用信息页面,在底部复制 `Signing Secret` 备用 (将用作 [`signing`](#config-signing) 配置项)
3. 在「App-Level Tokens」一栏,点击带有 Generate 字样的按钮,填写 Token 名称,在下方下拉框中选择 `connections:write`,点击绿色 Generate 按钮,在弹出的对话框中点击 Copy 按钮,填入插件的 [`token`](#config-token) 字段
4. 按照使用需求,决定由 Slack 服务器推送 Webhook 至 Koishi 的公网地址(`Webhook` 模式)或是连接至 Slack 服务器接收推送的消息(`Socket Mode` 模式),参照下方说明配置
5. Socket Mode:在左侧打开「Socket Mode」页面,勾选页面内的单选框
6. Webhook:在左侧打开 Event Subscriptions 页面,勾选单选框。将机器人的 `selfUrl` 值后连接 `/slack`(如 `https://example.com/slack`),在 Request URL 中填写
7. 在 Event Subscriptions 页面勾选事件 (参见下方的推荐列表),填写完整后点击右下角绿色 Save Changes 保存
8. 在左侧 OAuth & Permissions 页面,在下方 Bot Token Scopes 中,点击 Add 添加权限 (参见下方的推荐列表)
9. 返回页面上方,点击 Install to Workspace,点击 Allow 授权,复制 Bot User OAuth Token 填入插件的 [`botToken`](#config-bottoken) 字段
10. 在相应工作区 @ 机器人名称或右键频道详情,选择 集成-添加应用 添加机器人到频道中

### 推荐勾选的事件
1. 准备一个 [Slack](https://slack.com/signin) 账号和工作区。

2. 前往 [应用后台](https://api.slack.com/apps),点击「Create New App」>「From Scratch」,填入应用名称和所添加的工作区 (目前适配器只支持一个应用处理一个工作区的事件),点击「Create App」。

![app-1](/adapter/slack/app-1.webp)

<!-- ![app-2](/adapter/slack/app-2.webp) -->

1. 在跳转至的应用信息页面,在底部复制 `Signing Secret`,填入插件的 [`signing`](#config-signing) 字段。

![secret-1](/adapter/slack/secret-1.webp)

4. 在「App-Level Tokens」一栏,点击带有 Generate 字样的按钮,填写 Token 名称,在下方下拉框中选择 `connections:write`,点击绿色 Generate 按钮,在弹出的对话框中点击 Copy 按钮,填入插件的 [`token`](#config-token) 字段。

![secret-2](/adapter/slack/secret-2.webp)

5. 按照使用需求,决定连接方式是 `http``ws` (推荐),填入插件的 [`protocol`](#config-protocol) 字段,并根据你的选择进行后续操作。

::: tip
`http` 连接方式需要一个公网可访问的地址。
:::

6. 如果你选择 `http` 连接方式:在左侧打开「Event Subscriptions」页面,勾选「Enable Events」。将机器人的 `selfUrl` 值后连接 `/slack` (如 `https://example.com/slack`),填入「Request URL」中。

![webhook](/adapter/slack/webhook.webp)

7. 如果你选择 `ws` 连接方式:在左侧打开「Socket Mode」页面,勾选「Enable Socket Mode」;再打开「Event Subscriptions」页面,勾选「Enable Events」。

![websocket](/adapter/slack/websocket.webp)

8. 前往「Event Subscriptions」页面,在「Subscribe to bot events」下方勾选事件 (参见 [推荐的事件列表](#推荐的事件列表)),填写完整后点击右下角的绿色「Save Changes」按钮保存。

![events](/adapter/slack/events.webp)

9. 前往「OAuth & Permissions」页面,在「Bot Token Scopes」下方添加权限 (参见 [推荐的权限列表](#推荐的权限列表))。

![scopes](/adapter/slack/scopes.webp)

10. 返回页面上方,点击「Install to Workspace」,点击 Allow 授权,复制「Bot User OAuth Token」,填入插件的 [`botToken`](#config-bottoken) 字段。

![workspace](/adapter/slack/workspace.webp)

11. 在相应工作区 @ 机器人名称或右键频道详情,选择 集成-添加应用 添加机器人到频道中。

### 推荐的事件列表

- channel_archive
- channel_created
Expand All @@ -29,7 +62,7 @@
- reaction_removed
- team_join

### 推荐添加的权限
### 推荐的权限列表

- channels:history
- channels:read
Expand Down

0 comments on commit 709ca10

Please sign in to comment.