ขอสิทธิ์ใช้งานล่วงหน้า

กรอกชื่อพร้อมอีเมลหรือหมายเลขโทรศัพท์ แล้วเราจะติดต่อกลับพร้อมรายละเอียดการเข้าใช้งาน Tajo

คู่มืออ้างอิงประเภทอีเวนต์

คู่มืออ้างอิงฉบับสมบูรณ์นี้ครอบคลุม webhook event ทุกประเภทที่มีใน Brevo พร้อมตัวอย่างเฉพาะสำหรับการเชื่อมต่อกับแพลตฟอร์มสะสมคะแนน Tajo

อีเวนต์ของอีเมล

delivered

เกิดขึ้นเมื่อส่งอีเมลถึงกล่องจดหมายของผู้รับสำเร็จ

ตัวอย่าง payload:

{
"event": "delivered",
"email": "[email protected]",
"id": 123456,
"date": "2024-01-25 14:30:00",
"ts": 1640995200,
"message-id": "<[email protected]>",
"template_id": 101,
"tags": ["loyalty", "points-earned"],
"sending_ip": "185.107.232.1",
"event_id": "evt_abc123"
}

กรณีใช้งานร่วมกับ Tajo:

  • อัปเดตอัตราการส่งสำเร็จในโปรไฟล์ลูกค้า
  • เริ่มการดำเนินการต่อเนื่องสำหรับแคมเปญสะสมคะแนน
  • ติดตามประสิทธิภาพการส่งอีเมลแยกตามระดับสมาชิก
async function handleEmailDelivered(event) {
const customer = await loyaltyService.getCustomer(event.email);
// Update delivery stats
await loyaltyService.updateEngagement(event.email, {
emailsDelivered: customer.emailsDelivered + 1,
lastEmailDelivered: new Date(event.date),
deliveryRate: calculateDeliveryRate(customer)
});
// Track loyalty campaign delivery
if (event.tags.includes('loyalty')) {
await loyaltyService.trackCampaignMetric('loyalty_email_delivered', {
email: event.email,
template_id: event.template_id,
tier: customer.loyaltyTier
});
}
}

opened

เกิดขึ้นเมื่อผู้รับเปิดอีเมล (ตรวจจับจากการโหลดพิกเซล)

ตัวอย่าง payload:

{
"event": "opened",
"email": "[email protected]",
"date": "2024-01-25 15:45:00",
"ts": 1641000300,
"message-id": "<[email protected]>",
"template_id": 101,
"tags": ["loyalty", "tier-upgrade"],
"user-agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X)",
"geo": {
"country": "US",
"region": "CA",
"city": "San Francisco"
}
}

กรณีใช้งานร่วมกับ Tajo:

  • เพิ่มคะแนน engagement ของลูกค้า
  • ติดตามประสิทธิผลของแคมเปญสะสมคะแนน
  • มอบรางวัลตามพฤติกรรมของลูกค้า
  • ปรับการสื่อสารครั้งถัดไปให้เหมาะกับแต่ละบุคคล
async function handleEmailOpened(event) {
const customer = await loyaltyService.getCustomer(event.email);
// Significant engagement - boost score
await loyaltyService.updateEngagement(event.email, {
emailsOpened: customer.emailsOpened + 1,
lastEmailOpened: new Date(event.date),
engagementScore: customer.engagementScore + 5,
preferredDevice: getDeviceType(event['user-agent'])
});
// Reward engagement for loyalty members
if (event.tags.includes('loyalty') && customer.loyaltyTier) {
await loyaltyService.awardEngagementBonus(event.email, {
type: 'email_engagement',
points: getEngagementPoints(customer.loyaltyTier),
reason: 'Email opened'
});
}
// Track timing patterns for optimization
await loyaltyService.recordEngagementTime(event.email, {
campaign: event.template_id,
openTime: new Date(event.date),
timezone: getTimezone(event.geo)
});
}

clicked

เกิดขึ้นเมื่อผู้รับคลิกลิงก์ในอีเมล

ตัวอย่าง payload:

{
"event": "clicked",
"email": "[email protected]",
"date": "2024-01-25 16:20:00",
"ts": 1641002400,
"message-id": "<[email protected]>",
"template_id": 101,
"tags": ["loyalty", "rewards-reminder"],
"link": "https://yourdomain.com/rewards?utm_source=brevo&utm_campaign=loyalty",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
}

กรณีใช้งานร่วมกับ Tajo:

  • ติดตามประสิทธิภาพของกรวยการเปลี่ยนเป็นลูกค้า
  • มอบโบนัสจากการคลิก
  • ระบุเนื้อหาที่สร้างมูลค่าสูง
  • ปรับปรุงเส้นทางจากอีเมลไปยังเว็บไซต์
async function handleEmailClicked(event) {
const customer = await loyaltyService.getCustomer(event.email);
const clickedUrl = new URL(event.link);
// High-value engagement
await loyaltyService.updateEngagement(event.email, {
emailsClicked: customer.emailsClicked + 1,
lastEmailClicked: new Date(event.date),
engagementScore: customer.engagementScore + 15,
clickThroughRate: calculateCTR(customer)
});
// Track specific link types
if (clickedUrl.pathname.includes('/rewards')) {
await loyaltyService.trackEvent(event.email, 'Rewards Page Clicked', {
source: 'email',
campaign: event.template_id,
utm_campaign: clickedUrl.searchParams.get('utm_campaign')
});
// Award exploration bonus
await loyaltyService.awardEngagementBonus(event.email, {
type: 'rewards_exploration',
points: 10,
reason: 'Clicked rewards link'
});
}
// Track product interest
if (clickedUrl.pathname.includes('/products')) {
const productId = extractProductId(clickedUrl);
await loyaltyService.trackProductInterest(event.email, productId, {
source: 'email_click',
timestamp: new Date(event.date)
});
}
}

bounced / hard_bounced

เกิดขึ้นเมื่ออีเมลตีกลับ (ความล้มเหลวชั่วคราว) หรือตีกลับถาวร (ความล้มเหลวถาวร)

ตัวอย่าง payload:

{
"event": "hard_bounced",
"email": "[email protected]",
"date": "2024-01-25 14:35:00",
"ts": 1640995500,
"message-id": "<[email protected]>",
"template_id": 101,
"tags": ["loyalty"],
"reason": "550 5.1.1 User unknown",
"bounce_type": "hard"
}

กรณีใช้งานร่วมกับ Tajo:

  • อัปเดตสถานะความถูกต้องของอีเมล
  • เปลี่ยนไปใช้ช่องทางการสื่อสารอื่น
  • ทำความสะอาดฐานข้อมูลลูกค้า
  • ป้องกันการส่งซ้ำไปยังที่อยู่ที่ใช้งานไม่ได้
async function handleEmailBounced(event) {
const isHardBounce = event.event === 'hard_bounced' || event.bounce_type === 'hard';
if (isHardBounce) {
// Permanent failure - mark email as invalid
await loyaltyService.updateCustomerStatus(event.email, {
emailStatus: 'invalid',
emailBounced: true,
bounceReason: event.reason,
lastBounce: new Date(event.date),
communicationPreference: 'sms' // Switch to SMS if available
});
// Remove from email marketing lists
await loyaltyService.removeFromEmailMarketing(event.email);
// Suggest phone verification
const customer = await loyaltyService.getCustomer(event.email);
if (customer?.phone) {
await loyaltyService.suggestPhoneVerification(customer.phone);
}
} else {
// Soft bounce - temporary issue
await loyaltyService.updateEngagement(event.email, {
softBounceCount: customer.softBounceCount + 1,
lastSoftBounce: new Date(event.date)
});
// Retry logic for soft bounces
if (customer.softBounceCount < 5) {
await loyaltyService.scheduleEmailRetry(event.email, event.template_id);
}
}
}

spam

เกิดขึ้นเมื่อผู้รับทำเครื่องหมายว่าอีเมลเป็นสแปม

ตัวอย่าง payload:

{
"event": "spam",
"email": "[email protected]",
"date": "2024-01-25 17:10:00",
"ts": 1641005400,
"message-id": "<[email protected]>",
"template_id": 101,
"tags": ["loyalty", "promotional"]
}

กรณีใช้งานร่วมกับ Tajo:

  • หยุดการสื่อสารทางอีเมลทันที
  • ทบทวนและปรับปรุงเนื้อหาอีเมล
  • วิเคราะห์รูปแบบการรายงานสแปมแยกตามกลุ่มลูกค้า
  • ใช้กระบวนการขอความยินยอมที่เข้มงวดขึ้น
async function handleEmailSpam(event) {
// Immediately disable email marketing
await loyaltyService.updateCustomerPreferences(event.email, {
emailMarketing: false,
marketingEnabled: false,
spamReported: true,
spamReportDate: new Date(event.date)
});
// Alert marketing team for review
await loyaltyService.alertMarketing('spam_complaint', {
email: event.email,
template: event.template_id,
campaign_tags: event.tags,
severity: 'high'
});
// Analyze spam patterns
await loyaltyService.analyzeSpamPattern({
template_id: event.template_id,
tags: event.tags,
customer_segment: await loyaltyService.getCustomerSegment(event.email)
});
// Consider account review if multiple spam reports
const customer = await loyaltyService.getCustomer(event.email);
if (customer.spamReports > 2) {
await loyaltyService.flagForReview(event.email, 'multiple_spam_reports');
}
}

อีเวนต์ของ SMS

sms_delivered

เกิดขึ้นเมื่อส่ง SMS ถึงโทรศัพท์ของผู้รับสำเร็จ

ตัวอย่าง payload:

{
"event": "sms_delivered",
"phone": "+1234567890",
"date": "2024-01-25 14:45:00",
"ts": 1640996700,
"message-id": "sms_abc123",
"tags": ["loyalty", "points-alert"],
"sender": "TAJO",
"content": "🎉 Great news! You earned 150 points from your recent purchase. Total: 1,250 points."
}

กรณีใช้งานร่วมกับ Tajo:

  • ยืนยันว่าส่ง SMS สำเร็จ
  • ติดตามอัตรา engagement ของ SMS
  • ตรวจสอบความถูกต้องของหมายเลขโทรศัพท์
  • ติดตามประสิทธิภาพการส่งของผู้ให้บริการเครือข่าย
async function handleSMSDelivered(event) {
const customer = await loyaltyService.getCustomerByPhone(event.phone);
await loyaltyService.updateEngagement(customer.email, {
smsDelivered: customer.smsDelivered + 1,
lastSMSDelivered: new Date(event.date),
smsDeliveryRate: calculateSMSDeliveryRate(customer),
phoneStatus: 'valid'
});
// Track loyalty SMS performance
if (event.tags.includes('loyalty')) {
await loyaltyService.trackCampaignMetric('loyalty_sms_delivered', {
phone: event.phone,
content_type: getSMSContentType(event.content),
customer_tier: customer.loyaltyTier
});
}
}

sms_failed

เกิดขึ้นเมื่อการส่ง SMS ล้มเหลว

ตัวอย่าง payload:

{
"event": "sms_failed",
"phone": "+1234567890",
"date": "2024-01-25 14:32:00",
"ts": 1640996320,
"message-id": "sms_def456",
"tags": ["loyalty", "urgent"],
"sender": "TAJO",
"reason": "Invalid phone number format",
"error_code": "30006"
}

กรณีใช้งานร่วมกับ Tajo:

  • อัปเดตความถูกต้องของหมายเลขโทรศัพท์
  • เปลี่ยนไปแจ้งเตือนทางอีเมลแทน
  • ทำความสะอาดฐานข้อมูลหมายเลขโทรศัพท์
  • แจ้งฝ่ายบริการลูกค้าให้ตรวจสอบด้วยตนเอง
async function handleSMSFailed(event) {
const customer = await loyaltyService.getCustomerByPhone(event.phone);
await loyaltyService.updateCustomerStatus(customer.email, {
phoneStatus: 'invalid',
smsEnabled: false,
smsFailureReason: event.reason,
lastSMSFailure: new Date(event.date),
communicationPreference: 'email'
});
// For urgent loyalty notifications, fall back to email
if (event.tags.includes('urgent') || event.tags.includes('loyalty')) {
await loyaltyService.sendEmailFallback(customer.email, {
originalSMS: event.content,
reason: 'SMS delivery failed'
});
}
// Flag for phone number verification
await loyaltyService.flagForPhoneVerification(customer.email);
}

sms_reply

เกิดขึ้นเมื่อผู้รับตอบกลับ SMS

ตัวอย่าง payload:

{
"event": "sms_reply",
"phone": "+1234567890",
"date": "2024-01-25 15:20:00",
"ts": 1641000000,
"message-id": "sms_reply_123",
"text": "BALANCE",
"original_message_id": "sms_abc123"
}

กรณีใช้งานร่วมกับ Tajo:

  • ประมวลผลคำสั่งของโปรแกรมสะสมคะแนน
  • จัดการคำขอจากฝ่ายบริการลูกค้า
  • อัปเดตการตั้งค่าการสื่อสาร
  • เริ่มการตอบกลับอัตโนมัติ
async function handleSMSReply(event) {
const customer = await loyaltyService.getCustomerByPhone(event.phone);
const replyText = event.text.toUpperCase().trim();
// High engagement - customer actively participating
await loyaltyService.updateEngagement(customer.email, {
smsReplies: customer.smsReplies + 1,
lastSMSReply: new Date(event.date),
engagementScore: customer.engagementScore + 10
});
// Process loyalty commands
switch (replyText) {
case 'BALANCE':
await loyaltyService.sendPointsBalance(event.phone);
break;
case 'REWARDS':
await loyaltyService.sendAvailableRewards(event.phone, customer.loyaltyTier);
break;
case 'TIER':
await loyaltyService.sendTierInfo(event.phone, customer);
break;
case 'HELP':
await loyaltyService.sendSMSHelp(event.phone);
break;
case 'STOP':
case 'UNSUBSCRIBE':
await loyaltyService.unsubscribeFromSMS(event.phone);
break;
default:
// Forward to customer service
await loyaltyService.forwardToSupport(customer.email, {
channel: 'sms',
message: event.text,
timestamp: new Date(event.date)
});
}
}

อีเวนต์ของ contact

contact_created

เกิดขึ้นเมื่อมีการเพิ่ม contact ใหม่ลงใน Brevo

ตัวอย่าง payload:

{
"event": "contact_created",
"email": "[email protected]",
"date": "2024-01-25 13:15:00",
"ts": 1640992500,
"attributes": {
"FIRSTNAME": "John",
"LASTNAME": "Doe",
"LOYALTY_ID": "LYL-2024-001",
"LOYALTY_TIER": "Bronze",
"LOYALTY_POINTS": 0
},
"lists": [1, 5]
}

กรณีใช้งานร่วมกับ Tajo:

  • เริ่มแคมเปญต้อนรับ
  • ตั้งค่าการสมัครเข้าโปรแกรมสะสมคะแนน
  • เริ่มต้นเส้นทางของลูกค้า
  • มอบโบนัสการสมัครสมาชิก
async function handleContactCreated(event) {
const isLoyaltyMember = event.attributes?.LOYALTY_ID;
if (isLoyaltyMember) {
// New loyalty member - trigger welcome flow
await loyaltyService.triggerWelcomeFlow(event.email, {
loyaltyId: event.attributes.LOYALTY_ID,
tier: event.attributes.LOYALTY_TIER || 'Bronze',
signupBonus: 500
});
// Award signup bonus
await loyaltyService.awardPoints(event.email, {
amount: 500,
reason: 'Welcome bonus',
type: 'signup_bonus'
});
// Schedule onboarding emails
await loyaltyService.scheduleOnboardingSequence(event.email, {
tier: event.attributes.LOYALTY_TIER,
preferences: event.attributes
});
}
// Track signup source
await loyaltyService.trackSignupSource(event.email, {
lists: event.lists,
attributes: event.attributes,
timestamp: new Date(event.date)
});
}

contact_updated

เกิดขึ้นเมื่อข้อมูล contact ถูกอัปเดต

ตัวอย่าง payload:

{
"event": "contact_updated",
"email": "[email protected]",
"date": "2024-01-25 16:45:00",
"ts": 1641003900,
"updated_attributes": {
"LOYALTY_POINTS": 1250,
"LOYALTY_TIER": "Silver",
"TOTAL_SPENT": 899.99
},
"previous_attributes": {
"LOYALTY_POINTS": 750,
"LOYALTY_TIER": "Bronze",
"TOTAL_SPENT": 549.99
}
}

กรณีใช้งานร่วมกับ Tajo:

  • ตรวจจับการเลื่อนระดับสมาชิก
  • ติดตามการเปลี่ยนแปลงของยอดคะแนนสะสม
  • ตรวจสอบความครบถ้วนของโปรไฟล์
  • เริ่มแคมเปญเฉพาะสำหรับแต่ละระดับสมาชิก
async function handleContactUpdated(event) {
const updated = event.updated_attributes;
const previous = event.previous_attributes;
// Check for tier upgrade
if (updated.LOYALTY_TIER && updated.LOYALTY_TIER !== previous.LOYALTY_TIER) {
await loyaltyService.handleTierUpgrade(event.email, {
previousTier: previous.LOYALTY_TIER,
newTier: updated.LOYALTY_TIER,
pointsBalance: updated.LOYALTY_POINTS
});
// Send congratulations
await loyaltyService.sendTierUpgradeEmail(event.email, {
newTier: updated.LOYALTY_TIER,
benefits: loyaltyService.getTierBenefits(updated.LOYALTY_TIER)
});
}
// Track significant point increases
const pointIncrease = updated.LOYALTY_POINTS - previous.LOYALTY_POINTS;
if (pointIncrease > 0) {
await loyaltyService.trackPointsEarned(event.email, {
amount: pointIncrease,
newTotal: updated.LOYALTY_POINTS,
source: 'profile_update'
});
}
// Monitor spending milestones
if (updated.TOTAL_SPENT > previous.TOTAL_SPENT) {
await loyaltyService.checkSpendingMilestones(event.email, {
currentSpend: updated.TOTAL_SPENT,
previousSpend: previous.TOTAL_SPENT
});
}
}

แนวปฏิบัติที่ดีในการประมวลผลอีเวนต์

1. การจัดการ idempotency

class WebhookProcessor {
constructor() {
this.processedEvents = new Set();
}
async processEvent(event) {
const eventKey = `${event.event}_${event.email}_${event.ts}`;
if (this.processedEvents.has(eventKey)) {
console.log('Duplicate event ignored:', eventKey);
return;
}
this.processedEvents.add(eventKey);
try {
await this.handleEvent(event);
} catch (error) {
this.processedEvents.delete(eventKey); // Allow retry
throw error;
}
}
}

2. การจัดลำดับอีเวนต์

async function processEventInSequence(event) {
const customer = await loyaltyService.getCustomer(event.email);
const lastProcessedTime = customer.lastWebhookProcessed || 0;
// Ensure events are processed in chronological order
if (event.ts < lastProcessedTime) {
console.warn('Out-of-order event received, queuing for later processing');
await loyaltyService.queueEventForLaterProcessing(event);
return;
}
await handleWebhookEvent(event);
// Update last processed timestamp
await loyaltyService.updateCustomer(event.email, {
lastWebhookProcessed: event.ts
});
}

3. การประมวลผลแบบเป็นชุด

class BatchEventProcessor {
constructor() {
this.eventBatch = [];
this.batchSize = 100;
this.flushInterval = 5000; // 5 seconds
setInterval(() => this.flushBatch(), this.flushInterval);
}
addEvent(event) {
this.eventBatch.push(event);
if (this.eventBatch.length >= this.batchSize) {
this.flushBatch();
}
}
async flushBatch() {
if (this.eventBatch.length === 0) return;
const batch = this.eventBatch.splice(0);
try {
await loyaltyService.processBatchEvents(batch);
} catch (error) {
console.error('Batch processing failed:', error);
// Re-queue failed events
this.eventBatch.unshift(...batch);
}
}
}

ขั้นตอนถัดไป

  • คู่มือความปลอดภัยของ Webhook - แนวปฏิบัติที่ดีด้านความปลอดภัย
  • การทดสอบ Webhook - การทดสอบและการแก้จุดบกพร่อง
  • การวิเคราะห์ Webhook - การติดตามประสิทธิภาพ
  • การเชื่อมต่อแพลตฟอร์ม - คู่มือการเชื่อมต่อฉบับสมบูรณ์

ขอสิทธิ์ใช้งานล่วงหน้า

กรอกชื่อพร้อมอีเมลหรือหมายเลขโทรศัพท์ แล้วเราจะติดต่อกลับพร้อมรายละเอียดการเข้าใช้งาน Tajo

ตรวจจับอัตโนมัติ
ผู้ช่วย AI

สวัสดี! ถามฉันเกี่ยวกับเอกสารได้เลย