跳到正文
GrowSocmed文档Social media command center
Developers

Webhook

在账号连接、post 发布或失败、评论和 DM 到达以及 Automation 运行时发送的签名 HTTP 通知。

无需轮询,添加一个 webhook endpoint 即可:当 workspace 中发生事件时,GrowSocmed 会向您的 URL 发送 POST。webhook 由 workspace owner 和 admin 管理,可在 dashboard(Developer → Webhooks)中或通过 API 管理。

添加 endpoint

curl -X POST https://socmed.growpaces.com/api/v1/webhooks \
  -H "Authorization: Bearer gs_..." \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com/hooks/grow-socmed","events":["post.published","post.failed","comment.created"]}'

URL 必须是公开的 https:// 地址。响应中包含签名用的 secret(whsec_…),仅显示这一次。

事件

Event发送时机
account.connected已连接社交账号,或重新连接(reconnected: true)。
account.expired账号需要重新连接(其在平台上的访问权限已结束)。
account.disconnected账号已断开连接,在 GrowSocmed 中或由平台一方断开。
post.publishedpost 已在一个账号上发布(每个账号一个 event)。
post.failedpost 在一个账号上最终失败(重试之后)。
comment.created有人评论了其中一个账号的 post。
comment.replied账号回复了一条评论(来自 GrowSocmed、automation 或平台的应用)。
comment.hidden一条评论被隐藏。
comment.unhidden一条被隐藏的评论重新显示。
comment.deleted一条评论被删除。
message.received收到一条 DM。
message.sent账号发送了一条 DM(来自 GrowSocmed、automation 或平台的应用)。
automation.runAutomation 完成了一次运行:已发送、已跳过或失败,并附原因。

webhook.test 只由测试按钮和 POST /webhooks/{id}/test 发送。评论和消息事件只针对 24 小时内的内容发送(同步时发现的更早内容不会触发通知)。

请求

POST /hooks/grow-socmed HTTP/1.1
Content-Type: application/json
User-Agent: GrowSocmed-Webhook/1
Grow-Event: post.published
Grow-Delivery: 0193a7c2-…
Grow-Signature: t=1763600000,v1=5d41402abc4b2a76b9719d911017c592…

{
  "id": "0193a7c2-…",
  "type": "post.published",
  "created_at": "2026-11-20T02:00:00.000Z",
  "workspace_id": "3f1c…",
  "data": {
    "post_id": "…", "target_id": "…", "account_id": "…", "platform": "instagram",
    "platform_post_id": "…", "permalink": "https://www.instagram.com/p/…", "published_at": "2026-11-20T02:00:00.000Z"
  }
}

id 是事件的 id:同一事件再次发送(重试或重新发送)时保持相同的 id,因此可用它忽略重复。data 取决于事件;账号事件带有 account(id、platform、username、display_name、status),评论事件带有评论及其 post 和作者,automation.run 带有该次运行的 status 和 reason。

验证签名

Grow-Signature 的格式为 t=<unix seconds>,v1=<hex>,其中 v1 是以您 endpoint 的 secret 为密钥、对字符串 <t>.<raw body> 计算的 HMAC-SHA256。请基于收到的原始 body 原样计算,使用恒定时间比较,并拒绝过旧的时间戳(例如超过五分钟)。

import { createHmac, timingSafeEqual } from 'node:crypto';

export function verify(rawBody: string, header: string, secret: string, toleranceSec = 300) {
  const parts = Object.fromEntries(header.split(',').map((p) => p.split('=') as [string, string]));
  const t = Number(parts.t);
  if (!t || Math.abs(Date.now() / 1000 - t) > toleranceSec) return false;
  const expected = createHmac('sha256', secret).update(`${t}.${rawBody}`).digest('hex');
  const given = Buffer.from(parts.v1 ?? '', 'hex');
  const want = Buffer.from(expected, 'hex');
  return given.length === want.length && timingSafeEqual(given, want);
}

响应和重试

请在 5 秒内以任意 2xx 响应;耗时的工作在响应之后再做。不会跟随重定向。投递失败(超时、连接错误、非 2xx)时,会在 1、5、30、120、300、480 和 480 分钟后重试:约一天内共 8 次尝试。

连续 50 次投递失败后,endpoint 会被关闭,其创建者会收到一封邮件;关闭期间发生的事件不会保留。使用 PATCH /webhooks/{id}(active: true)重新开启。

GET /webhooks/{id}/deliveries 显示最近 30 天的投递记录,以及响应状态和 body;POST /webhooks/{id}/deliveries/{deliveryId}/resend 会立即重新发送一次。测试发送和重新发送每个 workspace 每小时最多 60 次。