Gửi push notification từ backend (REST API)
Backend của bạn gọi REST API để gửi thông báo và cuộc gọi tới app.
🖥️ Backend
Backend của bạn gọi REST API để gửi thông báo và cuộc gọi tới app.
Gửi thông báo
Backend gọi
POST /notificationsvới headerAuthorization: Key <API_KEY>. Cấu trúc giống API của OneSignal.curlcurl -X POST "https://tingpush.com/notifications" \ -H "Authorization: Key <API_KEY>" \ -H "Content-Type: application/json" \ -d '{ "app_id": "YOUR_APP_ID", "include_aliases": { "external_id": ["user-123"] }, "headings": { "en": "Đơn hàng đã giao" }, "contents": { "en": "Đơn #42 đã giao thành công" }, "data": { "screen": "order", "id": "42" } }'Gửi cuộc gọi
Thêm trường
call. App nhận sự kiện accepted kèmcall_idvàdatađể kết nối cuộc gọi thật (WebRTC/SIP/Agora…). Khi người gọi huỷ hoặc một máy khác đã nghe, gửi"action": "ended"cùngidđể các máy còn lại tắt chuông.JSON// Cuộc gọi đến — id phải là UUID, backend tự sinh và lưu lại { "app_id": "YOUR_APP_ID", "include_aliases": { "external_id": ["user-123"] }, "call": { "action": "incoming", "id": "6f1c2a3e-8a7b-4c5d-9e0f-1a2b3c4d5e6f", "caller_name": "Nguyễn Văn A", "handle": "0901234567", "is_video": false, "timeout": 45 }, "data": { "room": "abc" } } // Kết thúc cuộc gọi (người gọi huỷ / máy khác đã nghe / hết giờ) { "app_id": "YOUR_APP_ID", "include_aliases": { "external_id": ["user-123"] }, "headings": { "en": "Cuộc gọi nhỡ" }, "contents": { "en": "Nguyễn Văn A đã gọi cho bạn" }, "call": { "action": "ended", "id": "6f1c2a3e-8a7b-4c5d-9e0f-1a2b3c4d5e6f" } }Ví dụ theo ngôn ngữ
C#using var http = new HttpClient { BaseAddress = new Uri("https://tingpush.com") }; http.DefaultRequestHeaders.Add("Authorization", "Key <API_KEY>"); var callId = Guid.NewGuid(); await http.PostAsJsonAsync("/notifications", new { app_id = "YOUR_APP_ID", include_aliases = new { external_id = new[] { "user-123" } }, call = new { action = "incoming", id = callId, caller_name = "Nguyễn Văn A", is_video = false }, data = new { room = "abc" } });Node.jsconst callId = crypto.randomUUID(); await fetch('https://tingpush.com/notifications', { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: 'Key <API_KEY>' }, body: JSON.stringify({ app_id: 'YOUR_APP_ID', include_aliases: { external_id: ['user-123'] }, call: { action: 'incoming', id: callId, caller_name: 'Nguyễn Văn A', is_video: false }, data: { room: 'abc' }, }), });Xem thêm mọi trường hỗ trợ ở Tài liệu API.
✅ Kiểm tra sau khi tích hợp
- Chạy app trên máy thật, bật log: thấy
[PushConsole] Đã đăng ký thiết bị …. - Tab Thiết bị của dự án: thiết bị xuất hiện; máy iOS có badge VoIP nếu dùng cuộc gọi.
- Tab Gửi thông báo: gửi thử tới thiết bị đó.
- Chọn 📞 Cuộc gọi, gửi thử khi app đang mở, khi đã tắt app và khi màn hình đang khoá.