tufu
免费开始
文档菜单

转人工

Webhook

每有新的潜在客户就实时发送到 Zapier、Make 或你自己的服务器,并带签名,方便你验证请求来自 tufu。

本页内容

Webhook会在每个新潜在客户出现、以及其发生任何变化的那一刻,把它发送到你指定的地址。你可以借助 Zapier、Make 或你自己的代码,把潜在客户存入你的 CRM、电子表格或邮件列表。Webhook 包含在 Team 套餐中。

管理员在设置 → Webhook 下添加它们。

事件#

  • lead.created:访客第一次留下联系方式。
  • lead.updated:潜在客户发生变化:访客再次留下联系方式、团队成员编辑了它们,或者状态改变(新建或已跟进)。

每个事件都是一个带 JSON 正文的 POST 请求,格式如下(绝不会发送会话中的内容):

json
{
  "id": "evt_1f0c…",
  "type": "lead.created",
  "created": "2026-10-26T16:56:02+00:00",
  "test": false,
  "data": {
    "lead": {
      "id": 42,
      "email": "riley@example.com",
      "name": "Riley Chen",
      "phone": "+1 555 0142",
      "custom": {"planned_trip": "A week"},
      "custom_labels": {"planned_trip": "Planned trip"},
      "consent": {"asked": true, "given": true, "text": "Send me news and offers by email.", "answered_at": "2026-10-26T16:56:00+00:00"},
      "status": "new",
      "status_changed_at": null,
      "page_url": "https://example.com/pricing",
      "attribution": {"utm_source": "google", "utm_medium": "cpc", "utm_campaign": "fall-sale", "ref": "www.google.com"},
      "created_at": "2026-10-26T16:56:00+00:00",
      "updated_at": "2026-10-26T16:56:00+00:00"
    },
    "bot": {"id": 7, "name": "Help"},
    "conversation_url": "https://tufu.ai/a/your-team/inbox/c/…/",
    "team": {"slug": "your-team", "name": "Your team"}
  }
}

配合 Zapier#

  1. 在 Zapier 中创建一个 Zap,触发器选择 Webhooks by Zapier → Catch Hook,并复制它的地址。
  2. 在 tufu 中,进入设置 → Webhook → 添加 Webhook:粘贴该地址,并保留访客留下联系方式。
  3. 点击发送测试。Zapier 会收到一个示例潜在客户,这样你就可以在下一步映射它的字段(lead.email、lead.name 等):HubSpot、Mailchimp、Google Sheets,或 Zapier 能连接的任何其他应用。

配合 Make#

  1. 在 Make 中,用 Webhooks → Custom webhook 开始一个场景,并复制它的地址。
  2. 用同样的方式把它添加到 tufu,然后点击发送测试:Make 会从示例中识别各个字段。
  3. 添加后续处理它的模块。

验证请求来自 tufu#

每个 Webhook 的签名密钥会在你添加它时(或点击新密钥时)显示一次。每个请求都带有一个 Tufu-Signature 请求头:t=<unix time>,v1=<signature>,其中签名是对 <unix time>.<the raw body> 以该密钥计算的 HMAC-SHA256。请在解析之前对原始正文进行验证,并拒绝与你的时钟相差超过五分钟的时间:

python
import hashlib, hmac, time


def from_tufu(secret: str, header: str, body: bytes) -> bool:
    parts = dict(item.split("=", 1) for item in header.split(","))
    timestamp = int(parts["t"])
    if abs(time.time() - timestamp) > 300:
        return False
    expected = hmac.new(secret.encode(), f"{timestamp}.".encode() + body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, parts["v1"])
javascript
const crypto = require("crypto");

function fromTufu(secret, header, rawBody) {
  const parts = Object.fromEntries(header.split(",").map((item) => item.split("=")));
  const timestamp = Number(parts.t);
  if (Math.abs(Date.now() / 1000 - timestamp) > 300) return false;
  const expected = crypto.createHmac("sha256", secret).update(`${timestamp}.${rawBody}`).digest("hex");
  return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1 || ""));
}

同一事件的每次重试,id 都相同,所以你可以跳过已经处理过的事件。

地址没有响应时#

tufu 期望在十秒内收到 2xx 响应。否则它会重试:一共尝试 5 次,历时大约两个半小时。每次尝试都会显示在该 Webhook 的卡片上,附带响应或错误信息。连续失败 15 次后,tufu 会暂停这个 Webhook,并给团队管理员发邮件;地址恢复正常后,请点击恢复。只接受公共互联网上的 https 地址。