Skip to content

Notification System

@nx/helpdesk ship hệ thống con thông báo riêng với gom batch digest, quiet hours, gửi đa kênh, và theo dõi đầy đủ trạng thái gửi.

Kiến trúc

Data Model

Notification

CộtTypeMô tả
idbigintSnowflake ID
eventCodevarcharMã loại event (ví dụ TICKET_ASSIGNED)
recipientIdbigintID người nhận
recipientTypeenumUSER / AGENT / SYSTEM
merchantIdbigintPhạm vi tenant
contextTypevarcharLoại thực thể context (ví dụ Ticket)
contextIdbigintID thực thể context
titlejsonbTiêu đề thông báo (i18n)
contentjsonbNội dung thông báo (i18n)
templateDatajsonbDữ liệu dùng để render template
channelsvarchar[]Kênh gửi đã chọn
statusenumPENDING / PROCESSING / DELIVERED / PARTIALLY_DELIVERED / FAILED
isReadbooleanNgười nhận đã đọc chưa
readAttimestampMốc thời gian đọc
batchIdbigintFK → NotificationBatch (nếu digest)
actionUrlvarcharURL hành động khi người nhận click thông báo

NotificationTemplate

Template theo từng loại event và kênh:

CộtTypeMô tả
eventCodevarcharMã event
channelenumKênh template này áp dụng
subjectjsonbSubject email (i18n)
bodyHtmljsonbBody HTML (i18n)
bodyTextjsonbBody plain-text (i18n)
isActivebooleanTemplate có đang dùng không

NotificationPreference

Preference thông báo theo từng user/agent:

CộtTypeMô tả
userIdbigintID User hoặc Agent
eventCodevarcharLoại event
channelsvarchar[]Kênh gửi ưu tiên
quietHoursStarttimeBắt đầu quiet hours (không thông báo)
quietHoursEndtimeKết thúc quiet hours
digestEnabledbooleanGom thông báo vào một digest
digestIntervalMinutesintKhoảng giữa các lần gửi digest

NotificationDeliveryLog

Lịch sử gửi theo từng kênh:

CộtTypeMô tả
notificationIdbigintFK → Notification
channelvarcharKênh gửi
statusenumSUCCESS / FAILED
errorMessagetextChi tiết lỗi khi fail
sentAttimestampMốc thời gian gửi

NotificationBatch

Gom batch digest — tổng hợp nhiều thông báo thành một lần gửi:

CộtTypeMô tả
idbigintSnowflake ID
recipientIdbigintNgười nhận
statusenumPENDING / PROCESSING / SENT
scheduledAttimestampKhi digest sẽ được gửi
sentAttimestampMốc thời gian gửi thực tế
itemCountintSố thông báo trong batch

Kênh Gửi

KênhTriển khaiMô tả
EMAILNodemailerComponentSMTP với template HTML/text
WEBSOCKETApplicationWebSocketComponentThời gian thực qua dịch vụ Signal
PUSHPush adapterThông báo push mobile
SMSSMS adapterGửi tin nhắn text

Quiet Hours

ProcessNotificationService kiểm tra NotificationPreference.quietHoursStart/End trước khi gửi. Nếu thời gian hiện tại rơi vào quiet hours của người nhận, thông báo bị hoãn cho đến khi quiet hours kết thúc.

Gom Batch Digest

NotificationBatchService tổng hợp thông báo thành một digest:

Workers

WorkerHàng đợiChức năng
notification.workerhelpdesk.notificationXử lý mỗi thông báo, gọi ProcessNotificationService (jobs: notification, notification-batch, notification-digest)

Event Trigger Thông báo

EventNgười nhậnMô tả
TICKET_CREATEDAgent được phân côngTicket mới đang chờ
TICKET_ASSIGNEDAgentTicket đã được phân công
STATUS_CHANGEDNgười báo cáoStatus ticket được cập nhật
MESSAGE_ADDEDAgent / Người báo cáoMessage mới trong ticket
SLA_WARNINGAgentDeadline SLA sắp tới (75%)
SLA_BREACHEDAgent + ManagerSLA bị vi phạm (100%)
SLA_CRITICALManager + LeadershipVi phạm SLA critical (150%)
TICKET_RESOLVEDNgười báo cáoTicket đã được giải quyết
TICKET_CLOSEDAgentKhách hàng xác nhận đóng

WebSocket Rooms & Topics

ApplicationWebSocketComponent (với socket-event.service.ts) phát trên một topic helpdesk duy nhất, vào các room giới hạn theo ticket + message. Build từ helper @nx/core:

BuilderGiá trịMô tả
HelpdeskWebSocketTopics.HELP_DESKobservation/helpdeskTopic observation helpdesk
HelpdeskWebSocketRooms.getHelpdeskRooms({ ticketId, messageId })helpdesk/:ticketId/:messageIdRoom theo từng ticket, từng message

Nguồn: src/components/websocket/topics.ts, src/components/websocket/rooms.ts.

Trang liên quan

Proprietary and Confidential. Unauthorized copying, distribution, or use of this software is strictly prohibited.