Slack 触发器节点(Slack Trigger node)#
使用 Slack 触发节点来响应 Slack 中的事件,并将 Slack 与其他应用集成。n8n 内置支持多种 Slack 事件,包括新消息、表情反应和新通道。
🌐 Use the Slack Trigger node to respond to events in Slack and integrate Slack with other applications. n8n has built-in support for a wide range of Slack events, including new messages, reactions, and new channels.
在此页面,你可以找到 Slack 触发器节点可以响应的事件列表以及更多资源的链接。
🌐 On this page, you'll find a list of events the Slack Trigger node can respond to and links to more resources.
凭证
你可以在此处找到此节点的认证信息。
示例和模板
有关使用示例和模板以帮助你入门,请参阅 n8n 的 Slack 集成 页面。
事件(Events)#
- 任何事件:该节点会在 Slack 中的任何事件触发时启动。
- 机器人/应用被提及:当你的机器人或应用在它所在的通道中被提及时,该节点会触发。
- 文件公开:当文件被公开时,节点会触发。
- 文件已共享:当应用所在通道中有文件被共享时,此节点会触发。
- 新消息已发布到通道:当应用所在通道有新消息发布时,该节点将被触发。
- 已创建新公共通道:当创建新的公共通道时,节点会触发。
- 新用户:当有新用户加入 Slack 时,该节点会触发。
- 已添加反应:当向应用所加入的消息添加反应时,该节点会触发。
参数(Parameters)#
设置好触发事件后,使用剩余参数进一步定义节点的行为:
🌐 Once you've set the events to trigger on, use the remaining parameters to further define the node's behavior:
-
监控整个工作区:该节点是否应在工作区的所有通道中监控所选的事件(开启)或不监控(关闭,默认)。
小心
这将对你的机器人或应用所在的任何通道的每个事件使用一次执行。请谨慎使用!
-
监视通道:选择你的节点应监视所选事件的通道。仅当你未开启监视整个工作区时,此参数才会显示。你可以选择一个通道:
- 从列表中:该节点使用你的凭证查找工作区中的通道列表,以便你可以选择所需的通道。
- 按 ID:输入你想要观看的通道的 ID。Slack 会在通道详情底部显示通道 ID,并提供一键复制按钮。
- 通过 URL:输入你想观看的通道的 URL,格式为
https://app.slack.com/client/<channel-address>。
- 下载文件:是否下载文件并在节点输出中使用它们(开启)或不使用(关闭,默认)。将此参数与文件公开和文件共享事件一起使用。
选项(Options)#
当你添加选项时,你可以进一步优化节点的行为:
🌐 You can further refine the node's behavior when you Add Options:
- 解析ID:是否将ID解析为其对应的名称并返回(开启)或不解析(关闭,默认)。
- 要忽略的用户名或ID:选择用户名或输入用逗号分隔的编码用户ID字符串,以忽略其事件。可以从列表中选择,也可以使用表达式指定ID。
相关资源(Related resources)#
n8n 提供了一个用于 Slack 的应用节点。你可以在 这里 找到该节点的文档。
🌐 n8n provides an app node for Slack. You can find the node docs here.
在 n8n 网站上查看示例工作流及相关内容。
🌐 View example workflows and related content on n8n's website.
有关其 API 的详细信息,请参阅 Slack 的文档。
🌐 Refer to Slack's documentation for details about their API.
必填范围(Required scopes)#
要使用此节点,你需要在 Slack 中创建一个应用并启用事件订阅。有关更多信息,请参阅 Slack 凭据 | Slack 触发器配置。
🌐 To use this node, you need to create an application in Slack and enable event subscriptions. Refer to Slack credentials | Slack Trigger configuration for more information.
你必须向 Slack 应用添加相应的权限范围,此触发节点才能正常工作。
🌐 You must add the appropriate scopes to your Slack app for this trigger node to work.
该节点至少需要 conversations.list 和 users.list 方法的范围。查看 Scopes | Slack credentials 列表以获取更完整的范围列表。
🌐 The node requires scopes for the conversations.list and users.list methods at minimum. Check out the Scopes | Slack credentials list for a more complete list of scopes.
验证 Webhook(Verify the webhook)#
从版本 1.106.0 开始,在配置你的 Slack 凭证 时,你可以设置 Slack 签名密钥。设置后,Slack 触发节点会自动验证请求是否来自 Slack 并包含可信的签名。n8n 建议设置此项,以确保你只处理来自 Slack 的请求。
🌐 From version 1.106.0, you can set a Slack Signing Secret when configuring your Slack credentials. When set, the Slack trigger node automatically verifies that requests are from Slack and include a trusted signature. n8n recommends setting this to ensure you only process requests sent from Slack.
常见问题(Common issues)#
以下是 Slack 触发器节点的一些常见错误和问题,以及解决或故障排除步骤。
🌐 Here are some common errors and issues with the Slack Trigger node and steps to resolve or troubleshoot them.
工作流仅在测试或生产环境中运行(Workflow only works in testing or production)#
Slack 只允许你为每个应用注册一个 Webhook。这意味着你不能在测试 URL 和生产 URL 之间切换(反之亦然),除非重新配置已注册的 Webhook URL。
🌐 Slack only allows you to register a single webhook per app. This means that you can't switch from using the testing URL to the production URL (and vice versa) without reconfiguring the registered webhook URL.
如果你尝试测试同时在生产环境中活跃的工作流,可能会遇到问题。Slack 只会向其中一个 webhook URL 发送事件,另一个将永远不会收到事件通知。
🌐 You may have trouble with this if you try to test a workflow that's also active in production. Slack will only send events to one of the two webhook URLs, so the other will never receive event notifications.
要解决此问题,你可以在测试时禁用工作流:
🌐 To work around this, you can disable your workflow when testing:
停止生产流量
这会暂时禁用你的生产工作流以进行测试。在此期间,你的工作流将不再接收生产流量。
- 前往你的工作流页面。
- 在顶部面板切换 激活 开关以暂时禁用工作流程。
- 在你的 Slack 触发器配置 中编辑 请求 URL,使用测试 Webhook URL 而不是生产 Webhook URL。
- 使用测试 Webhook URL 测试你的工作流。
- 测试完成后,在你的 Slack 触发器配置 中编辑 请求 URL,将其改为使用生产环境的 webhook URL,而不是测试环境的 webhook URL。
- 切换 未激活 开关以重新启用工作流程。生产环境的 webhook URL 应该会恢复正常工作。
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.