Skip to content

Slack 凭据(Slack credentials)#

你可以使用以下凭据验证以下节点:

🌐 You can use these credentials to authenticate the following nodes:

支持的身份验证方法(Supported authentication methods)#

  • API 访问令牌:
  • OAuth2:

有关该服务的更多信息,请参考 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:

  • 一个 访问令牌

要生成访问令牌,请创建一个 Slack 应用:

🌐 To generate an access token, create a Slack app:

  1. 打开你的 Slack API 应用 页面。
  2. 选择 创建新应用 > 从头开始
  3. 请输入应用名称
  4. 选择你将开发应用的工作区
  5. 选择 创建应用。应用详情将打开。
  6. 在左侧菜单的 功能 下,选择 OAuth 与权限
  7. Scopes 部分,为你的应用选择合适的权限范围。请参考 Scopes 获取推荐权限范围的列表。
  8. 在添加了权限范围之后,前往 OAuth 令牌 部分并选择 安装到工作区。你必须是 Slack 工作区管理员才能完成此操作。10. 选择 允许。12. 复制 机器人用户 OAuth 令牌 并在你的 n8n 凭证中将其作为 访问令牌 输入。13. 如果你打算使用此凭证用于 Slack 触发器,请按照 Slack 触发器配置 中的步骤完成应用设置。

有关更多信息,请参阅 Slack API 快速入门

🌐 Refer to the Slack API Quickstart for more information.

Slack 触发器配置(Slack Trigger configuration)#

要在 Slack Trigger 节点中使用你的 Slack 应用:

🌐 To use your Slack app with the Slack Trigger node:

  1. 在 Slack 中前往 你的应用,然后选择你想使用的应用。
  2. 转到 功能 > 事件订阅
  3. 打开 启用事件 控件。
  4. 在 n8n 中,复制 Webhook URL 并将其作为 Request URL 输入到你的 Slack 应用中。

    请求网址

    Slack 每个应用只允许一个请求 URL。如果你想测试你的工作流程,你需要执行以下其中一项操作:

    • 首先使用你的测试 URL进行测试,然后在确认一切正常后,将你的 Slack 应用切换为使用生产 URL
    • 使用生产 URL并启用执行日志记录。
  5. 验证后,选择要订阅的机器人事件。在 n8n 中使用 触发条件 字段来筛选这些请求。

    • 要使用列表中没有的事件,请将其添加为机器人事件,并在 n8n 节点中选择 任意事件

有关更多信息,请参阅 快速入门 | 配置应用以监听事件

🌐 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:

  1. 在 Slack 中前往 你的应用,然后选择你想使用的应用。
  2. 前往 设置 > 基本信息
  3. 复制 Signing 的值。
  4. 在 n8n 中,将此值粘贴到凭证的 Signature Secret 字段中。

使用 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
  • 客户端密钥

要同时获取 API 密钥和应用 ID,请创建一个 Slack 应用:

🌐 To get both, create a Slack app:

  1. 打开你的 Slack API 应用 页面。
  2. 选择 创建新应用 > 从头开始
  3. 请输入应用名称
  4. 选择你将开发应用的工作区
  5. 选择 创建应用。应用详情将打开。
  6. 设置 > 基本信息 中,打开 应用凭证 部分。
  7. 复制 客户端 ID客户端密钥。将它们粘贴到 n8n 中对应的字段中。
  8. 在左侧菜单的 功能 下,选择 OAuth 与权限
  9. 重定向 URL 部分,选择 添加新的重定向 URL
  10. 从 n8n 复制 OAuth 回调 URL,并将其作为新的重定向 URL 输入到 Slack 中。
  11. 选择 添加。10. 选择 保存 URL。11. 在 作用域 部分,为你的应用选择适当的作用域。有关作用域的列表,请参阅 Scopes。13. 添加作用域后,向上滚动到 OAuth 令牌 部分,选择 安装到工作区。你必须是 Slack 工作区管理员才能完成此操作。14. 选择 允许。15. 此时,你应该能够在 n8n 凭证中选择 OAuth 按钮进行连接。

有关更多信息,请参阅 Slack API 快速入门。有关 OAuth 流程本身的更多详细信息,请参阅 Slack 使用 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.

  • 如果你希望你的应用代表授权该应用的用户执行操作,请在 用户令牌权限 部分添加所需的权限范围。
  • 如果你正在创建一个机器人,请在 Bot Token Scopes 部分添加所需的权限范围。

以下是 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.