Quickstart Guide
Hướng dẫn bắt đầu với NotiBoost trong 5 phút. Từ setup đến gửi notification đầu tiên.
Bước 1: Tạo Account và API Key
Đăng ký tài khoản NotiBoost và lấy API key:
- Đăng ký tại notiboost.com
- Vào Dashboard và tạo API key
- Lưu API key vào biến môi trường
Bước 2: Cài đặt SDK
Cài đặt SDK cho ngôn ngữ của bạn:
Node.js
npm install @notiboost/sdk
const { NotiBoost } = require('@notiboost/sdk');
const client = new NotiBoost({
apiKey: process.env.NOTIBOOST_API_KEY
});
PHP
composer require notiboost/php-sdk
use NotiBoost\NotiBoostClient;
$client = new NotiBoostClient([
'api_key' => getenv('NOTIBOOST_API_KEY')
]);
Bước 3: Tạo User và Channel Data
Tạo user và cấu hình channel data (email, phone, etc.):
Tạo User
// Node.js
await client.users.create({
user_id: 'u_123',
name: 'Nguyễn Văn A',
phone: '+84901234567'
});
// Set channel data for all channels
await client.users.setChannelData('u_123', {
email: 'user@example.com',
phone: '+84901234567',
push_token: 'fcm_token_abc123',
push_platform: 'android',
zns_oa_id: '123456789'
});
Bước 4: Tạo Flow
Tạo notification flow với rules và channels:
Tạo Flow
// Create a flow for order confirmation
await client.flows.create({
name: 'order_confirmation',
description: 'Send ZNS when order is created',
rules: [
{
condition: 'event_name == "order_created"',
action: 'send_zns'
}
],
channels: ['zns'],
template_id: 'tpl_order_confirm'
});
Bước 5: Gửi Event
Gửi event để trigger notification:
Gửi Event
// Send an event
const result = await client.events.ingest({
event_name: 'order_created',
event_id: 'evt_001',
occurred_at: new Date().toISOString(),
user_id: 'u_123',
properties: {
order_id: 'A001',
amount: 350000
}
});
console.log('Trace ID:', result.trace_id);
Bước 6: Kiểm tra Status
Kiểm tra delivery status của message:
Kiểm tra Status
// Check message status
const status = await client.messages.getStatus(result.trace_id);
console.log('Status:', status.delivery_status);
console.log('Channel:', status.channel);
Next Steps
Common Issues
API Key không hợp lệ
Kiểm tra API key trong Dashboard và đảm bảo đã set đúng.
User không nhận được notification
Kiểm tra channel data (email, phone) đã được set đúng chưa. Xem Observability để debug.
Flow không trigger
Kiểm tra event_name và rules trong flow có match với event đang gửi không.
