Slack 凭据#
¥Slack credentials
你可以使用以下凭据验证以下节点:
¥You can use these credentials to authenticate the following nodes:
支持的身份验证方法#
¥Supported authentication methods
- API 访问令牌:
¥API access token:
-
Slack 触发器 节点必需。
¥Required for the Slack Trigger node.
-
可与 Slack 节点一起使用,但不建议使用。
¥Works with the Slack node, but not recommended.
-
OAuth2:
-
推荐用于 Slack 节点的方法。
¥Recommended method for the Slack node.
-
不适用于 Slack 触发器 节点。
¥Doesn't work with the Slack Trigger node.
相关资源#
¥Related resources
有关服务的更多信息,请参阅 Slack API 文档。
¥Refer to Slack's API documentation for more information about the service.
使用 API 访问令牌#
¥Using API access token
要配置此凭据,你需要一个 Slack 账户以及:
¥To configure this credential, you'll need a Slack account and:
- 访问令牌
¥An Access Token
要生成访问令牌,请创建一个 Slack 应用:
¥To generate an access token, create a Slack app:
- 打开 Slack API 应用 页面。
¥Open your Slack API Apps page. 2. 选择“创建新应用”>“从头开始”。
¥Select Create New App > From scratch. 3. 输入应用名称。
¥Enter an App Name. 4. 选择你将开发应用的工作区。
¥Select the Workspace where you'll be developing your app. 5. 选择“创建应用”。打开应用详情。
¥Select Create App. The app details open. 6. 在左侧菜单的“功能”下,选择“OAuth 和权限”。
¥In the left menu under Features, select OAuth & Permissions. 7. 在“作用域”部分,为你的应用选择合适的作用域。请参阅 作用域 获取推荐的作用域列表。
¥In the Scopes section, select appropriate scopes for your app. Refer to Scopes for a list of recommended scopes. 8. 添加作用域后,请转到“OAuth 令牌”部分,然后选择“安装到工作区”。你必须是 Slack 工作区管理员才能完成此操作。
¥After you've added scopes, go up to the OAuth Tokens section and select Install to Workspace. You must be a Slack workspace admin to complete this action. 9. 选择允许。
¥Select Allow. 10. 复制客户端 ID,并将其输入到 n8n 中。
1 | |
-
如果你将此凭据用于 Slack 触发器,请按照 Slack 触发器配置 中的步骤完成应用的设置。
¥If you're using this credential for the Slack Trigger, follow the steps in Slack Trigger configuration to finish setting up your app.
请参阅 Slack API 快速开始 文档了解更多信息。
¥Refer to the Slack API Quickstart for more information.
Slack 触发器配置#
¥Slack Trigger configuration
要将你的 Slack 应用与 Slack 触发器 节点一起使用:
¥To use your Slack app with the Slack Trigger node:
- 在 Slack 中前往 你的应用 并选择要使用的应用。
¥Go to Your Apps in Slack and select the app you want to use.
- 前往“功能”>“事件订阅”。
¥Go to Features > Event Subscriptions.
- 启用“启用事件”控件。
¥Turn on the Enable Events control.
- 在 n8n 中,复制 Webhook URL,并将其作为请求 URL 输入到你的 Slack 应用中。
¥In n8n, copy the Webhook URL and enter it as the Request URL in your Slack app.
Request URL
1 2 3 4 | |
- 验证完成后,选择要订阅的机器人事件。使用 n8n 中的“触发字段”来过滤这些请求。
¥Once verified, select the bot events to subscribe to. Use the Trigger on field in n8n to filter these requests.
-
要使用列表中未列出的事件,请将其添加为机器人事件,并在 n8n 节点中选择“任意事件”。
¥To use an event not in the list, add it as a bot event and select Any Event in the n8n node.
有关更多信息,请参阅 快速入门 |配置应用以监听事件。
¥Refer to Quickstart | Configuring the app for event listening for more information.
n8n 建议你为 Slack 触发器启用请求签名验证,以增强安全性:
¥n8n recommends enabling request signature verification for your Slack Trigger for additional security:
- 在 Slack 中前往 你的应用 并选择要使用的应用。
¥Go to Your Apps in Slack and select the app you want to use. 2. 前往“设置”>“基本信息”。
¥Go to Settings > Basic Information. 3. 复制 Signing 的值。
¥Copy the value of Signing. 4. 在 n8n 中,将此值粘贴到凭证的“签名密钥”字段中。
¥In n8n, Paste this value into the Signature Secret field for the credential.
使用 OAuth2#
¥Using OAuth2
Note for n8n Cloud users
Cloud users don't need to provide connection details. Select Connect my account to connect through your browser.
如果你是 自托管 n8n 并且需要从头开始配置 OAuth2,你需要一个 Slack 账户以及:
¥If you're self-hosting n8n and need to configure OAuth2 from scratch, you'll need a Slack account and:
- 客户端 ID
¥A Client ID
- 客户端密钥:
¥A Client Secret
要同时获取 API 密钥和应用 ID,请创建一个 Slack 应用:
¥To get both, create a Slack app:
- 打开 Slack API 应用 页面。
¥Open your Slack API Apps page. 2. 选择“创建新应用”>“从头开始”。
¥Select Create New App > From scratch. 3. 输入应用名称。
¥Enter an App Name. 4. 选择你将开发应用的工作区。
¥Select the Workspace where you'll be developing your app. 5. 选择“创建应用”。打开应用详情。
¥Select Create App. The app details open. 6. 在“设置”>“基本信息”中,打开“应用凭据”部分。
¥In Settings > Basic Information, open the App Credentials section. 7. 复制客户端 ID 和客户端密钥。将以下内容粘贴到 n8n 中的相应字段中。
¥Copy the Client ID and Client Secret. Paste these into the corresponding fields in n8n. 8. 在左侧菜单的“功能”下,选择“OAuth 和权限”。
¥In the left menu under Features, select OAuth & Permissions. 9. 在“重定向 URL”部分,选择“添加新的重定向 URL”。
¥In the Redirect URLs section, select Add New Redirect URL. 10. 从 n8n 复制 OAuth 回调 URL,并将其作为新的重定向 URL 输入到 Slack 中。
1 | |
-
选择添加。
¥Select Add. 12. 选择“保存 URL”。
¥Select Save URLs. 13. 在“作用域”部分,为你的应用选择合适的作用域。有关作用域列表,请参阅 作用域。
¥In the Scopes section, select appropriate scopes for your app. Refer to Scopes for a list of scopes. 14. 添加作用域后,请转到“OAuth 令牌”部分,然后选择“安装到工作区”。你必须是 Slack 工作区管理员才能完成此操作。
¥After you've added scopes, go up to the OAuth Tokens section and select Install to Workspace. You must be a Slack workspace admin to complete this action. 15. 选择允许。
¥Select Allow. 16. 此时,你应该能够选择 n8n 凭据中的 OAuth 按钮进行连接。
¥At this point, you should be able to select the OAuth button in your n8n credential to connect.
请参阅 Slack API 快速开始 文档了解更多信息。请参阅 Slack 使用 OAuth 安装 文档,了解有关 OAuth 流程的更多详细信息。
¥Refer to the Slack API Quickstart for more information. Refer to the Slack Installing with OAuth documentation for more details on the OAuth flow itself.
作用域#
¥Scopes
作用域决定应用拥有的权限。
¥Scopes determine what permissions an app has.
- 如果你希望你的应用代表已授权的用户执行操作,请在“用户令牌范围”部分下添加所需的范围。
¥If you want your app to act on behalf of users who authorize the app, add the required scopes under the User Token Scopes section.
- 如果你正在构建机器人,请在“机器人令牌范围”部分下添加所需的范围。
¥If you're building a bot, add the required scopes under the Bot Token Scopes section.
以下是 OAuth 凭据所需的权限范围列表,这是一个很好的起点:
¥Here's the list of scopes the OAuth credential requires, which are a good starting point:
| 范围名称 | 备注 |
|---|---|
channels:read |
|
channels:write |
不适用于机器人令牌范围 |
channels:history |
|
chat:write |
|
files:read |
|
files:write |
|
groups:read |
|
groups:history |
|
im:read |
|
im:history |
|
mpim:read |
|
mpim:history |
|
reactions:read |
|
reactions:write |
|
stars:read |
不适用于机器人令牌范围 |
stars:write |
不适用于机器人令牌范围 |
usergroups:read |
|
usergroups:write |
|
users.profile:read |
|
users.profile:write |
不适用于机器人令牌范围 |
users:read |
|
search:read |
常见问题#
¥Common issues
Token 已过期#
¥Token expired
Slack offers token rotation that you can turn on for bot and user tokens. This makes every tokens expire after 12 hours. While this may be useful for testing, n8n credentials using tokens with this enabled will fail after expiry. If you want to use your Slack credentials in production, this feature must be off.
To check if your Slack app has token rotation turned on, refer to the Slack API Documentation | Token Rotation.
If your app uses token rotation
Please note, if your Slack app uses token rotation, you can't turn it off again. You need to create a new Slack app with token rotation disabled instead.