Notification
Base URL: https://notification-api.pcampus.co
Overview
Notification คือ centralized notification hub สำหรับทุก service ใน Pcampus ecosystem แทนที่แต่ละ service จะส่ง notification เอง ทุกอย่างผ่าน Notification service เดียว ทำให้จัดการ template, delivery, และ analytics ได้จากที่เดียว
รองรับช่องทาง: Email, Push notification, SMS, LINE
Who uses this
| Persona | ใช้ทำอะไร |
|---|---|
| Developer (internal service) | เรียก API ส่ง notification จาก Cockpit / Content OS |
| Developer (ลูกค้า) | ส่ง notification ถึง user ของตัวเองผ่าน API |
| Admin | จัดการ templates, ดู delivery analytics |
| End user | รับ notification, จัดการ notification preferences |
Key features
- Multi-channel delivery — Email, Push, SMS, LINE จาก API เดียว
- Template management — สร้าง template พร้อม variable substitution (
{{user.name}},{{booking.date}}) - Notification preferences — User เลือกได้ว่าอยากรับ notification ช่องทางไหน
- Delivery tracking — ติดตาม sent / delivered / opened / failed ต่อ notification
- Retry & fallback — ถ้าส่ง SMS ไม่ได้ fallback ไป Email อัตโนมัติ
- Rate limiting — ป้องกันส่ง notification มากเกินไปถึง user คนเดียว
User stories
Internal service:
"เมื่อ payment สำเร็จ ต้องการแจ้ง org admin ทันทีผ่าน Email"
→ POST /notifications/send ระบุ channel: email, templateId: payment-success, userId → ส่งทันที
Developer (ลูกค้า):
"ผมต้องการส่ง push notification ถึง user ที่ app ของผมเมื่อมี order ใหม่"
→ Register application → สร้าง template → เรียก API ส่ง push พร้อม payload
End user:
"ผมอยากรับแจ้งเตือนผ่าน LINE แทน SMS"
→ Console → Notification Settings → เลือก LINE → เชื่อม LINE account
How it works
Data model
Integration
- PIP — ดึง user preferences และ contact info (email, phone, LINE ID)
- Mail — ใช้ Mail service สำหรับ email delivery (ไม่ส่ง email ตรงเอง)
- Other services — รับ event แล้วส่ง notification ตาม template
API overview
| Method | Endpoint | Description |
|---|---|---|
POST | /notifications/send | Send notification to user |
POST | /notifications/broadcast | Send to multiple users |
GET | /notifications | List notification history |
GET | /notifications/:id | Get delivery status |
GET | /templates | List templates |
POST | /templates | Create template |
PATCH | /templates/:id | Update template |
DELETE | /templates/:id | Delete template |
GET | /preferences/:userId | Get user notification preferences |
PATCH | /preferences/:userId | Update preferences |
Send notification payload
{
"userId": "usr_xxxx",
"templateId": "tmpl_xxxx",
"channel": "email",
"data": {
"user": { "name": "Somchai" },
"booking": { "id": "BK-001", "date": "2026-08-01" }
}
}LINE Flex Message Templates
LINE Flex Message คือ rich message format ของ LINE ที่กำหนด layout ด้วย JSON — รองรับ card, carousel, image hero, button, และ separator ได้อย่างอิสระ
Notification รองรับ template type flex_message เพิ่มเติมจาก text ธรรมดา ใส่ variable slots ด้วย syntax {{variableName}} เหมือนกัน — ระบบจะ substitute ค่าลงใน JSON ก่อนส่งออก LINE
Template types
| Type | รูปแบบ | ใช้กับ |
|---|---|---|
text | ข้อความธรรมดา | แจ้งเตือนทั่วไป, OTP |
flex_message | JSON Flex layout | Product card, order summary, appointment reminder |
image_map | รูปพร้อม tap zones | Banner โปรโมชั่น |
carousel | Flex แบบ swipe | หลาย product, หลาย branch |
ตัวอย่าง Flex Message template — Order Card
{
"type": "flex",
"altText": "ยืนยันคำสั่งซื้อ {{orderId}}",
"contents": {
"type": "bubble",
"hero": {
"type": "image",
"url": "{{productImageUrl}}",
"size": "full",
"aspectRatio": "20:13",
"aspectMode": "cover"
},
"body": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "text",
"text": "สวัสดีครับ {{customerName}}",
"weight": "bold",
"size": "xl"
},
{
"type": "text",
"text": "คำสั่งซื้อ #{{orderId}} ได้รับแล้ว",
"color": "#aaaaaa",
"size": "sm"
},
{
"type": "separator",
"margin": "md"
},
{
"type": "box",
"layout": "vertical",
"margin": "md",
"contents": [
{
"type": "box",
"layout": "horizontal",
"contents": [
{ "type": "text", "text": "{{productName}}", "size": "sm", "flex": 3 },
{ "type": "text", "text": "{{total}}", "size": "sm", "align": "end" }
]
}
]
}
]
},
"footer": {
"type": "box",
"layout": "vertical",
"contents": [
{
"type": "button",
"style": "primary",
"action": {
"type": "uri",
"label": "ดูรายละเอียด",
"uri": "{{orderDetailUrl}}"
}
}
]
}
}
}Variable slots ในตัวอย่างนี้: customerName, orderId, productImageUrl, productName, total, orderDetailUrl
Flex Message Builder (Console)
ใน Pcampus Console → Notification → Templates → New Template → เลือก Flex Message:
ขั้นตอน:
- เลือก layout เริ่มต้น — Bubble, Carousel, Image Hero, Receipt
- แก้ไข block — คลิก block เพื่อแก้ text, สี, ขนาด, URL ปุ่ม
- ใส่ variable — พิมพ์
{{เพื่อ autocomplete variable ที่ระบบ suggest จาก Customer Story - Preview — ดู preview บน LINE emulator ทั้ง Android / iOS
- Save และ Test send — ส่ง test ไป LINE account จริงก่อน publish
ตัว builder ใน Console ใช้ LINE Flex Message Simulator เดียวกันกับ LINE Official — JSON ที่ได้สามารถ copy ไปทดสอบใน Flex Message Simulator (opens in a new tab) ได้โดยตรง
Carousel template
Carousel คือ collection ของ bubble ที่ swipe ได้ เหมาะกับ multi-product, multi-branch:
{
"type": "flex",
"altText": "สินค้าแนะนำสำหรับคุณ {{customerName}}",
"contents": {
"type": "carousel",
"contents": [
"{{#each recommendations}}",
{
"type": "bubble",
"body": {
"type": "box",
"layout": "vertical",
"contents": [
{ "type": "text", "text": "{{this.name}}", "weight": "bold" },
{ "type": "text", "text": "{{this.price}}", "color": "#1DB446" }
]
}
},
"{{/each}}"
]
}
}
{{#each recommendations}}/{{/each}}คือ loop syntax สำหรับ array variables — รองรับใน Flex Message template เท่านั้น
Broadcast Scheduler
Scheduler ใน Notification จัดการ scheduled broadcasts ของทุกช่องทาง (LINE, Push, SMS) — เห็นและสร้างได้จาก calendar view เดียว
Console → Notification → Scheduler
Calendar view
แสดง scheduled broadcasts ทุกช่องทางในปฏิทินเดียวกัน กรองตาม channel / segment / status ได้:
┌─────────────────────────────────────────────────────────────┐
│ 📅 Notification Scheduler — กรกฎาคม 2026 │
│ [+ New Broadcast] [All Channels ▼] [List] [Calendar] │
├──────────┬──────────┬──────────┬──────────┬────────────────┤
│ จ 14 │ อ 15 │ พ 16 │ พฤ 17 │ ศ 18 │
├──────────┼──────────┼──────────┼──────────┼────────────────┤
│ │ 09:00 │ 14:00 │ 10:00 │ │
│ │ 📱 LINE │ 🔔 Push │ 📱 LINE │ │
│ │ Winback │ Flash │ Loyalty │ │
│ │ 3,241 คน │ 8,002 คน │ 1,532 คน │ │
│ │ │ Sale │ Tier Up │ │
└──────────┴──────────┴──────────┴──────────┴────────────────┘สร้าง Scheduled Broadcast
- + New Broadcast → เลือก channel: LINE | Push | SMS
- เลือก template — text หรือ Flex Message
- กำหนด recipients — segment, subscriber list, หรือ customer ID list
- ตั้งเวลา — วันที่ + เวลา หรือ recurrence (daily / weekly / monthly)
- ตั้งค่า rate limit — กี่ message ต่อนาที ป้องกัน burst
- Confirm → ปรากฎบน calendar ทันที สามารถ edit / cancel ได้จนถึง 5 นาทีก่อนส่ง
Recurrence patterns
| Pattern | Cron | ตัวอย่างใช้งาน |
|---|---|---|
| ทุกวัน 08:00 | 0 8 * * * | Daily order reminder |
| ทุกวันจันทร์ | 0 9 * * 1 | Weekly loyalty summary |
| วันที่ 1 ทุกเดือน | 0 10 1 * * | Monthly points digest |
| ทุกวันศุกร์บ่าย | 0 14 * * 5 | Flash sale LINE |
Delivery window
ตั้ง delivery window เพื่อไม่รบกวนลูกค้านอกเวลา:
{
"deliveryWindow": {
"start": "08:00",
"end": "21:00",
"timezone": "Asia/Bangkok",
"skipWeekends": false
}
}ถ้า broadcast trigger นอก window ระบบจะ hold และส่งเมื่อเริ่ม window ถัดไป
ดู Notification API → Scheduler สำหรับ REST endpoints