---
title: "Slack 连接器"
description: "完整的 Slack 集成指南，通过 Tajo 发送通知、同步频道数据，并从 Slack 事件触发 Brevo 自动化。"
url: https://tajo.io/zh-cn/docs/connectors/custom/slack/
markdown: https://tajo.io/zh-cn/docs/connectors/custom/slack.md
lang: zh-CN
robots: noindex
---

申请抢先体验

请输入您的名字和公司电子邮箱地址。我们会发送确认 Tajo 访问申请的链接。

# Slack 连接器

连接器状态: 计划中 尚未构建。Tajo 目前不运行此连接器。

| 来源字段 | 目标字段 | 示例值 |
| --- | --- | --- |
| `record.id` | `source_id` | `record_1042` |
| `record.updated_at` | `updated_at` | `2026-10-18T08:00:00Z` |
| `record.value` | `value` | `sample_value` |

通过 Tajo 将您的 Slack 工作区连接到 Brevo，实现实时营销通知、客户事件的团队提醒，以及由 Slack 互动触发的工作流自动化。

## 概览

| 属性 | 值 |
| --- | --- |
| **平台** | Slack |
| **类别** | 自定义集成 |
| **设置复杂度** | 简单 |
| **官方集成** | 否 |
| **同步数据** | 用户、频道、消息、事件 |
| **API 基础 URL** | `https://slack.com/api` |

## 功能

- **营销提醒** - 为活动事件、新订阅者和收入里程碑发送实时通知
- **客户事件通知** - 就 Brevo 中的高价值客户行为提醒团队
- **工作流触发** - 使用 Slack 互动（按钮点击、表单提交）触发 Brevo 自动化
- **基于频道的路由** - 根据事件类型或客户细分将通知路由到特定频道
- **用户同步** - 将 Slack 工作区用户映射到 Brevo 联系人，用于内部通信
- **交互式消息** - 发送带按钮和操作的富文本消息，用于团队工作流
- **定时消息** - 为每日/每周营销摘要安排通知
- **线程支持** - 在线程中组织相关通知，便于管理

## 前提条件

开始之前，请确保您已具备：

1. 具有管理员权限的 Slack 工作区
2. 在 [api.slack.com/apps](https://api.slack.com/apps) 创建的 Slack 应用
3. 具有所需范围的机器人令牌
4. 具有 API 访问权限的 Brevo 账户
5. Tajo 账户

## 认证

### 机器人令牌（推荐）

将 Slack 应用安装到您的工作区，并使用机器人令牌进行 API 访问。

1. 在 [api.slack.com/apps](https://api.slack.com/apps) 创建应用
2. 在”OAuth & Permissions”下添加所需的 OAuth 范围
3. 将应用安装到工作区
4. 复制 Bot User OAuth 令牌（`xoxb-...`）

```bash
curl -X POST "https://slack.com/api/chat.postMessage" \
  -H "Authorization: Bearer xoxb-YOUR-BOT-TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel": "C01234567", "text": "Hello from Tajo!"}'
```

### OAuth 2.0

用于向多个工作区分发 Slack 集成：

```bash
# Authorization URL
https://slack.com/oauth/v2/authorize?
  client_id={client_id}&
  scope=chat:write,channels:read,users:read&
  redirect_uri={redirect_uri}

# Token exchange
curl -X POST "https://slack.com/api/oauth.v2.access" \
  -d "client_id={client_id}" \
  -d "client_secret={client_secret}" \
  -d "code={auth_code}"
```

#### 所需机器人范围

```
chat:write           # Send messages
channels:read        # List channels
channels:history     # Read channel messages
users:read           # List workspace users
users:read.email     # Read user email addresses
reactions:write      # Add reactions to messages
files:write          # Upload files
```

用户邮箱访问

需要 `users:read.email` 范围才能将 Slack 用户与 Brevo 联系人匹配。没有该范围，用户映射将仅限于显示名称。

## 配置

### 基础设置

```yaml
connectors:
  slack:
    enabled: true
    bot_token: "${SLACK_BOT_TOKEN}"
    signing_secret: "${SLACK_SIGNING_SECRET}"

    # Notification channels
    channels:
      marketing: "C01234567"
      sales: "C01234568"
      support: "C01234569"
      alerts: "C01234570"

    # Event routing
    notifications:
      new_subscriber:
        channel: marketing
        template: subscriber_alert
      high_value_order:
        channel: sales
        template: order_alert
      support_ticket:
        channel: support
        template: ticket_alert
```

### 字段映射

将 Slack 用户数据映射到 Brevo 联系人属性：

#### 默认映射

| Parameter | Type | Description |
| --- | --- | --- |
| `profile.email` required | string | 用户邮箱（Brevo 匹配的唯一标识符） |
| `real_name` optional | string | 全名，分割为 FIRSTNAME/LASTNAME |
| `profile.phone` optional | string | 映射到 SMS 属性 |
| `profile.title` optional | string | 职位名称 |
| `tz` optional | string | 用户时区 |
| `is_admin` optional | boolean | 工作区管理员状态 |
| `team_id` optional | string | 工作区团队 ID |
| `status_text` optional | string | 用户自定义状态 |

## API 方法

### 消息

| 方法 | 端点 | 描述 |
| --- | --- | --- |
| `POST` | `chat.postMessage` | 向频道发送消息 |
| `POST` | `chat.update` | 更新现有消息 |
| `POST` | `chat.delete` | 删除消息 |
| `POST` | `chat.scheduleMessage` | 定时发送消息 |
| `POST` | `chat.postEphemeral` | 向用户发送临时消息 |

### 频道

| 方法 | 端点 | 描述 |
| --- | --- | --- |
| `GET` | `conversations.list` | 列出频道 |
| `GET` | `conversations.info` | 获取频道信息 |
| `GET` | `conversations.members` | 列出频道成员 |
| `GET` | `conversations.history` | 获取频道消息 |

### 用户

| 方法 | 端点 | 描述 |
| --- | --- | --- |
| `GET` | `users.list` | 列出工作区用户 |
| `GET` | `users.info` | 获取用户信息 |
| `GET` | `users.lookupByEmail` | 按邮箱查找用户 |
| `GET` | `users.conversations` | 列出用户频道 |

### 互动

| 方法 | 端点 | 描述 |
| --- | --- | --- |
| `POST` | `views.open` | 打开模态视图 |
| `POST` | `views.update` | 更新模态视图 |
| `POST` | `reactions.add` | 添加表情反应 |

## 事件

### Brevo 到 Slack 的通知

| 事件 | 触发条件 | Slack 操作 |
| --- | --- | --- |
| `new_subscriber` | 在 Brevo 中创建联系人 | 发布到 #marketing |
| `campaign_sent` | 邮件活动已发送 | 将摘要发布到 #marketing |
| `order_placed` | 检测到高价值订单 | 将详情发布到 #sales |
| `cart_abandoned` | 购物车遗弃超过 30 分钟 | 发布到 #sales 跟进 |
| `ticket_created` | 支持工单开启 | 发布到 #support |
| `unsubscribed` | 联系人取消订阅 | 向 #marketing 发送提醒 |

### Slack 到 Brevo 的触发

| Slack 事件 | 触发条件 | Brevo 操作 |
| --- | --- | --- |
| `message_action` | 自定义消息快捷键 | 将联系人添加到列表或触发自动化 |
| `block_actions` | 消息中的按钮点击 | 更新联系人属性或发送邮件 |
| `view_submission` | 模态表单提交 | 创建联系人或触发工作流 |

## 代码示例

### 初始化连接器

```javascript
import { TajoClient } from '@tajo/sdk';

const tajo = new TajoClient({
  apiKey: process.env.TAJO_API_KEY,
  brevoApiKey: process.env.BREVO_API_KEY
});

// Connect Slack
await tajo.connectors.connect('slack', {
  botToken: process.env.SLACK_BOT_TOKEN,
  signingSecret: process.env.SLACK_SIGNING_SECRET
});
```

### 发送营销通知

```javascript
// Send a notification when a high-value order is placed
await tajo.slack.notify({
  channel: 'sales',
  event: 'order_placed',
  data: {
    customerEmail: 'customer@example.com',
    orderValue: '$1,250.00',
    products: ['Premium Widget', 'Pro Service'],
    isFirstOrder: true
  },
  template: {
    blocks: [
      {
        type: 'header',
        text: { type: 'plain_text', text: 'New High-Value Order' }
      },
      {
        type: 'section',
        fields: [
          { type: 'mrkdwn', text: '*Customer:*\ncustomer@example.com' },
          { type: 'mrkdwn', text: '*Amount:*\n$1,250.00' }
        ]
      },
      {
        type: 'actions',
        elements: [
          {
            type: 'button',
            text: { type: 'plain_text', text: 'View in Brevo' },
            url: 'https://app.brevo.com/contacts'
          }
        ]
      }
    ]
  }
});
```

### 处理 Slack 互动

```javascript
import crypto from 'crypto';

app.post('/slack/interactions', async (req, res) => {
  // Verify Slack request signature
  const timestamp = req.headers['x-slack-request-timestamp'];
  const signature = req.headers['x-slack-signature'];
  const sigBasestring = `v0:${timestamp}:${req.rawBody}`;
  const mySignature = 'v0=' + crypto
    .createHmac('sha256', process.env.SLACK_SIGNING_SECRET)
    .update(sigBasestring)
    .digest('hex');

  if (signature !== mySignature) {
    return res.status(401).send('Unauthorized');
  }

  const payload = JSON.parse(req.body.payload);

  // Handle button actions
  if (payload.type === 'block_actions') {
    await tajo.connectors.handleWebhook('slack', {
      type: 'interaction',
      action: payload.actions[0].action_id,
      userId: payload.user.id,
      payload
    });
  }

  res.status(200).send();
});
```

## 速率限制

Slack API 速率限制使用分级系统：

| 等级 | 限制 | 常见方法 |
| --- | --- | --- |
| Tier 1 | 1 请求/分钟 | `chat.delete`、`conversations.kick` |
| Tier 2 | 20 请求/分钟 | `conversations.history`、`users.info` |
| Tier 3 | 50 请求/分钟 | `conversations.list`、`users.list` |
| Tier 4 | 100 请求/分钟 | `chat.postMessage` |
| 特殊 | 不定 | 向同一频道发送 `chat.postMessage`：1/秒 |

附加限制：

- **Web API**：带短期限流的突发限制
- **Events API**：3 次重试投递
- **Incoming Webhooks**：每个 Webhook URL 每秒 1 条消息
- **Block Kit**：每条消息最多 50 个块

频道发布速率

向同一频道发布消息限制为约每秒 1 条。批量通知或使用线程以避免速率限制。

## 故障排除

### 常见问题

| 问题 | 原因 | 解决方案 |
| --- | --- | --- |
| `not_authed` | 机器人令牌无效 | 重新安装应用并复制新的机器人令牌 |
| `channel_not_found` | 机器人不在频道中 | 将机器人邀请到目标频道 |
| `missing_scope` | 所需范围未授予 | 添加范围并重新安装应用 |
| 未收到事件 | 未设置事件订阅 | 配置事件订阅 URL |
| 互动超时 | 响应超过 3 秒 | 立即回复 200，异步处理 |

### 调试模式

启用详细日志：

```yaml
connectors:
  slack:
    debug: true
    log_level: verbose
    log_events: true
```

### 测试连接

```bash
tajo connectors test slack
# ✓ Bot token valid
# ✓ Workspace accessible
# ✓ Channels readable
# ✓ Message posting enabled
# ✓ Event subscriptions active
```

## 最佳实践

1. **使用 Block Kit** - 使用 Slack 的 Block Kit 框架构建富文本交互消息
2. **快速响应** - 3 秒内确认互动，异步处理
3. **将相关消息放入线程** - 将相关通知放入线程以减少噪音
4. **按频道路由** - 将不同事件类型发送到相应的团队频道
5. **添加操作按钮** - 添加”在 Brevo 中查看”按钮以快速访问客户数据
6. **实施链接预览** - 为 Slack 中分享的 Brevo 链接显示富文本预览

## 安全

- **机器人令牌** - 带精细权限的 OAuth 范围访问令牌
- **请求签名** - 传入请求的 HMAC SHA-256 签名验证
- **OAuth 2.0** - 多工作区分发的行业标准授权
- **TLS 加密** - 所有 API 通信通过 HTTPS 加密
- **令牌轮换** - 自动令牌轮换增强安全性

## 相关资源

- [Slack API 文档](https://api.slack.com/methods)
- [Slack Block Kit 构建器](https://app.slack.com/block-kit-builder)
- [Slack Events API](https://api.slack.com/events-api)
- [Brevo 连接器](https://tajo.io/zh-cn/docs/connectors/marketing/brevo)
- [客户同步技能](https://tajo.io/zh-cn/docs/skills/data-sync/customer-sync)
