Bỏ qua, đến nội dung

@digiforce-nc/plugin-notification-in-app-message

Plugin cung cấp kênh thông báo in-app real-time — hiển thị thông báo trực tiếp trong ứng dụng qua SSE (Server-Sent Events), hỗ trợ inbox UI và mobile.

Plugin này làm gì?

Plugin đăng ký kênh in-app-message vào notification-manager. Khi gửi thông báo in-app, server lưu message vào DB rồi đẩy real-time đến client qua SSE. Người dùng thấy thông báo ngay lập tức — không cần refresh.

Ba nhiệm vụ chính

#Nhiệm vụChi tiết
1Lưu và gửi real-timeLưu message vào DB, đẩy qua SSE đến client đang online
2Inbox UIDanh sách thông báo với trạng thái đọc/chưa đọc, badge count
3Hỗ trợ mobileRoutes và tab bar riêng cho mobile, badge thông báo mới

Kiến trúc

Luồng gửi thông báo in-app

SSE - Real-time delivery

Plugin dùng Server-Sent Events thay vì WebSocket — đơn giản hơn, tương thích tốt với proxy/load balancer:

Đặc điểmGiá trị
Giao thứcHTTP SSE (text/event-stream)
HướngServer → Client (one-way)
Kết nốiMỗi user một stream, auto-reconnect
FilteringChỉ push đến đúng userId

Database - collection messages

FieldMô tả
titleTiêu đề thông báo
contentNội dung chi tiết (JSON cho rich content)
userIdNgười nhận
readTrạng thái đã đọc (mặc định false)

Vòng đời plugin

Desktop vs Mobile

Tính năngDesktopMobile
Inbox UIPopup dropdown từ header bell iconTrang inbox toàn màn hình
Badge countSố trên bell iconBadge trên tab bar
ComponentsAntdantd-mobile

Ví dụ sử dụng API

Gửi thông báo in-app

typescript
await agent.resource('messages').send({
  values: {
    channelName: 'in-app-channel',
    to: [userId],
    title: 'Don hang moi',
    content: { text: 'Don hang #1234', link: '/orders/1234' },
  },
});

Lấy thông báo chưa đọc

typescript
const response = await agent.resource('messages').list({
  filter: { userId: currentUserId, read: false },
  sort: ['-createdAt'],
});

Đánh dấu đã đọc

typescript
await agent.resource('messages').update({
  filterByTargetKey: messageId,
  values: { read: true },
});

Thành phần client

Thành phầnMô tả
MessageManagerProviderContext provider quản lý state thông báo (dùng immer)
InboxPopupPopup danh sách thông báo (desktop)
InboxPageTrang inbox toàn màn hình (mobile)
NotificationBadgeBadge hiển thị số thông báo chưa đọc

Dependencies

PackageVai trò
immerImmutable state management cho message list
antd-mobileUI components cho mobile inbox
@digiforce-nc/plugin-notification-managerHub thông báo trung tâm (bắt buộc)
@digiforce-nc/serverServer framework — SSE endpoint
@digiforce-nc/clientClient framework — UI components

Mục lục chi tiết