ข้ามไปยังเนื้อหา

Webhook

Webhook จะส่งการแจ้งเตือน HTTP POST แบบเรียลไทม์เมื่องานเบื้องหลังแบบอะซิงโครนัสเสร็จสิ้น เช่น การเผยแพร่สำเร็จ การเผยแพร่ล้มเหลว หรือการส่งคำตอบกลับ


เมธอดพาธคำอธิบายขอบเขตสิทธิ์ที่จำเป็น
POST/v1/brand/webhooksลงทะเบียน Endpoint ของ Webhook ใหม่webhooks:write หรือ *
GET/v1/brand/webhooksแสดงรายการ Webhook ที่ลงทะเบียนไว้webhooks:read หรือ *
DELETE/v1/brand/webhooks/{webhook_id}ลบ Webhook ที่ลงทะเบียนไว้webhooks:write หรือ *

ชื่อเหตุการณ์เงื่อนไขการเกิด
sns.publish.succeededเผยแพร่โพสต์ไปยังเครือข่ายสังคมเป้าหมายสำเร็จ
sns.publish.failedการเผยแพร่โพสต์ล้มเหลว (รวมรหัสข้อผิดพลาดและสิทธิ์การลองใหม่)
sns.publish.blocked_entitlementการเผยแพร่ถูกบล็อกเนื่องจากเกินขีดจำกัดโควตาหรือแผนบริการหมดอายุ
sns.reply.succeededโพสต์คอมเมนต์ตอบกลับสำเร็จ
sns.reply.failedการส่งคอมเมนต์ตอบกลับล้มเหลว
sns.provider.notification_receivedได้รับ Webhook แบบเรียลไทม์จากผู้ให้บริการ SNS ภายนอก

{
"event_id": "evt_01jm8za2example",
"event_type": "sns.publish.succeeded",
"schema_version": 1,
"occurred_at": "2026-08-16T03:30:00Z",
"brand_ref": "brand_01jm8v4k9example",
"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",
"status": "succeeded"
}
}

คำขอ Webhook มีส่วนหัวสำหรับการตรวจสอบดังนี้:

  • Social-Webhook-Signature: ข้อมูลลายเซ็น (v1=hex_signature)
  • Social-Webhook-Timestamp: Unix timestamp ในหน่วยวินาที
  • Social-Webhook-Id: รหัสการส่ง
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');
const actual = Buffer.from(signatureHeader);
const expected = Buffer.from(`v1=${expectedSignature}`);
return actual.length === expected.length && crypto.timingSafeEqual(actual, expected);
}
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, f"v1={expected}")

[!CAUTION] การตรวจสอบลายเซ็นต้องใช้ เนื้อหาคำขอดิบที่ยังไม่ได้แยกวิเคราะห์