Bỏ qua để đến nội dung

Webhooks

Webhook cung cấp thông báo HTTP POST theo thời gian thực khi các tác vụ nền không đồng bộ hoàn tất, chẳng hạn như đăng bài thành công, thất bại hoặc gửi phản hồi.


Phương thứcĐường dẫnMô tảScope yêu cầu
POST/v1/brand/webhooks/subscriptionsĐăng ký một điểm cuối webhook mớiwebhooks:write hoặc *
GET/v1/brand/webhooks/subscriptionsLiệt kê các đăng ký webhook đã đăng kýwebhooks:read hoặc *
DELETE/v1/brand/webhooks/subscriptions/{id}Xóa một đăng ký webhookwebhooks:write hoặc *

Tên sự kiệnĐiều kiện kích hoạt
sns.publish.succeededBài viết đã được xuất bản thành công lên mạng xã hội mục tiêu
sns.publish.failedXuất bản bài viết thất bại (bao gồm mã lỗi và khả năng thử lại)
sns.publish.blocked_entitlementViệc xuất bản bị chặn do giới hạn hạn ngạch hoặc gói đã hết hạn
sns.reply.succeededBình luận phản hồi đã được đăng thành công
sns.reply.failedViệc gửi bình luận phản hồi thất bại
sns.provider.notification_receivedNhận được webhook theo thời gian thực từ nhà cung cấp SNS bên ngoài

📦 Ví dụ Payload Webhook (sns.publish.succeeded)

Phần tiêu đề “📦 Ví dụ Payload Webhook (sns.publish.succeeded)”
{
"event_id": "evt_01jm8za2example",
"event_type": "sns.publish.succeeded",
"schema_version": 1,
"occurred_at": "2026-08-16T03:30:00Z",
"producer": "ankk.sns",
"brand_ref": "brand_01jm8v4k9example",
"idempotency_key": "launch-2026-001",
"trace_id": "trc_9a8b7c6d",
"data": {
"content_id": "content_01jm8za2example",
"publish_job_id": "job_01jm8za2jobexample",
"sns_type": "instagram",
"connection_id": "conn_01jm8x9k2example",
"provider_post_id": "18029384756102938",
"permalink": "https://www.instagram.com/p/C-example/"
}
}

Các yêu cầu Webhook bao gồm các tiêu đề xác minh tùy chỉnh:

  • Social-Webhook-Signature: Payload chữ ký (t=1723780000,v1=hex_signature)
  • Social-Webhook-Timestamp: Dấu thời gian Unix tính bằng giây
  • Social-Webhook-Id: Mã định danh sự kiện
import crypto from 'node:crypto';
export function verifyWebhookSignature(
rawBody: string,
signatureHeader: string,
timestampHeader: string,
secret: string
): boolean {
const signedPayload = `${timestampHeader}.${rawBody}`;
const expectedSignature = crypto
.createHmac('sha256', secret)
.update(signedPayload)
.digest('hex');
return crypto.timingSafeEqual(
Buffer.from(signatureHeader),
Buffer.from(expectedSignature)
);
}
import hmac
import hashlib
def verify_webhook_signature(raw_body: bytes, signature: str, timestamp: str, secret: str) -> bool:
signed_payload = f"{timestamp}.".encode('utf-8') + raw_body
expected = hmac.new(secret.encode('utf-8'), signed_payload, hashlib.sha256).hexdigest()
return hmac.compare_digest(signature, expected)

[!CAUTION] Việc xác minh chữ ký phải sử dụng thân yêu cầu thô chưa được phân tích (unparsed raw request body).