Giao diện
@digiforce-nc/plugin-firebase-notification
Plugin thông báo đẩy Firebase — gửi push notification đến thiết bị mobile và web browser qua Firebase Cloud Messaging (FCM), quản lý device token và đăng ký kênh thông báo.
Plugin này làm gì?
Khi hệ thống cần gửi thông báo đẩy đến user (đơn hàng mới, task được gán, tin nhắn mới...), plugin tích hợp Firebase Cloud Messaging (FCM) — dịch vụ push notification miễn phí của Google. Plugin đăng ký một notification channel type tên firebase vào hệ thống, quản lý device token của từng user, và gửi push đến đúng thiết bị.
Ba nhiệm vụ chính
| # | Nhiệm vụ | Chi tiết |
|---|---|---|
| 1 | Đăng ký channel | Đăng ký notification channel type firebase vào hệ thống |
| 2 | Device token management | Lưu/cập nhật/xóa device token cho mỗi user-device |
| 3 | Push delivery | Gửi notification qua FCM API đến đúng thiết bị |
Kiến trúc
Luồng gửi push notification
Luồng đăng ký device token
API endpoints
| Endpoint | Mô tả |
|---|---|
deviceTokens:register | Đăng ký device token mới (token, platform) |
deviceTokens:unregister | Hủy đăng ký token (khi logout hoặc gỡ app) |
deviceTokens:list | Danh sách device tokens của user hiện tại |
firebaseConfig:get | Lấy cấu hình Firebase (projectId, vapidKey) |
firebaseConfig:update | Cập nhật cấu hình Firebase (admin only) |
Database
| Bảng | Chứa gì | Ví dụ |
|---|---|---|
deviceTokens | Device token của user (userId, token, platform) | { userId: 1, token: 'fcm_xxx', platform: 'android' } |
firebaseConfig | Cấu hình Firebase (projectId, serviceAccount) | { projectId: 'my-app', vapidKey: '...' } |
Cấu hình
| Tham số | Mô tả |
|---|---|
serviceAccount | Firebase service account JSON (private key) |
projectId | Firebase project ID |
vapidKey | VAPID key cho web push (Web Push Certificate) |
Thành phần client
| Thành phần | Mô tả |
|---|---|
FCMConfigForm | Form cấu hình Firebase credentials (Settings → Notifications → Firebase) |
DeviceTokenList | Danh sách thiết bị đã đăng ký của user |
PushPermissionPrompt | Prompt yêu cầu user cho phép nhận push notification |
Dependencies
| Package | Vai trò |
|---|---|
@digiforce-nc/server | Server framework (peer) |
@digiforce-nc/database | Database ORM (peer) |
@digiforce-nc/client | Client UI framework (peer) |
firebase-admin | Firebase Admin SDK — gửi push qua FCM API |