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

Webhook

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


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

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

  • Social-Webhook-Signature: ข้อมูลลายเซ็น (t=1723780000,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');
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] การตรวจสอบลายเซ็นต้องใช้ เนื้อหาคำขอดิบที่ยังไม่ได้แยกวิเคราะห์