Dokümantasyon

Bildirimler ve E-posta

Expo / FCM / APNs / Web Push ile push ve Resend ile e-posta — gönderimi Liap yapar.

Genel bakış

Liap tek bir API ile uygulama içi bildirim, mobil push (Expo, FCM, APNs), Web Push ve e-posta (Resend) gönderir. Gönderimi Liap yapar: sunucunuzda Expo SDK'sı veya Resend SDK'sı gerekmez.

Akış üç adımdır: (1) Dashboard → Proje → API Bilgileri'ne sağlayıcı anahtarlarını girin, (2) uygulamanız kullanıcının cihazını kaydeder, (3) sunucunuz Liap'e "gönder" der.

Anahtarlar yalnızca projenin edge node'unda saklanır ve dashboard'da maskelenir; control plane'e gitmez.

İki ayrı API anahtarı kullanın: istemci anahtarı (data:read + data:write) uygulamaya gömülür ve cihaz kaydı yapar; sunucu anahtarı (data:write + notifications:send) yalnızca sunucunuzda durur ve push / e-posta gönderir. notifications:send yetkili anahtarı asla mobil veya web uygulamasına koymayın.

MethodPathAçıklama
POST/notifications/devicesCihaz kaydı (expo | fcm | apns | webpush)
GET/notifications/devicesCihaz özeti — platform başına sayı (sunucu)
POST/notifications/pushPush gönder (sunucu)
POST/notifications/emailE-posta gönder — notifications:send (sunucu)
POST/notificationsUygulama içi bildirim oluştur (sunucu)
GET/notificationsKullanıcının bildirimleri (oturum)
POST/notifications/{id}/readOkundu işaretle (oturum)

1. API Bilgileri'ni ayarlayın

Dashboard → Projeler → projeniz → API Bilgileri sayfasını açın.

Expo Push: Expo hesabınızda "Enhanced push security" açıksa expo.dev → Access tokens'tan bir token oluşturup "Expo Access Token" alanına girin. Kapalıysa boş bırakabilirsiniz; Liap yine gönderir.

Resend: resend.com'da alan adınızı doğrulayın (DNS kayıtları), API Keys'ten "Sending access" yetkili bir anahtar oluşturun ve "Resend API anahtarı" alanına girin. "Varsayılan gönderen" (ör. Uygulamam <[email protected]>) istekte from verilmediğinde kullanılır.

Her kartta "Test" butonu vardır: Expo için bir ExponentPushToken, Resend için bir alıcı adresi girip bağlantıyı hemen deneyin.

Sunucu anahtarı: API Anahtarları → Yeni anahtar → data:write ve notifications:send kapsamlarını seçin.

2. Expo: cihazı kaydedin (uygulama)

Uygulamanızda expo-notifications ile alınan Expo push token'ını kullanıcı giriş yaptıktan sonra Liap'e kaydedin. Cihaz, oturumdaki kullanıcıya bağlanır; böylece sunucudan userId ile yalnızca o kullanıcıya gönderebilirsiniz.

Token ExponentPushToken[…] biçimindeyse platform otomatik "expo" sayılır. Aynı token tekrar kaydedilirse çoğaltılmaz. Expo "DeviceNotRegistered" dediğinde (uygulama silindi vb.) token kayıttan kendiliğinden düşer.

MethodPathAçıklama
POST/notifications/devices{ platform?, token } — oturumdaki kullanıcıya bağlanır
Node.js
import * as Notifications from 'expo-notifications'
import { createClient } from '@liap-cloud/sdk'

// İstemci anahtarı: data:read + data:write
const liap = createClient(EDGE_URL, { apiKey: LIAP_CLIENT_KEY })
await liap.auth.login({ email, password })

const { status } = await Notifications.requestPermissionsAsync()
if (status === 'granted') {
  const { data: expoPushToken } = await Notifications.getExpoPushTokenAsync({ projectId: EAS_PROJECT_ID })
  await liap.notifications.registerExpoToken(expoPushToken)
}

3. Push gönderin (sunucu)

Sunucunuzdan tek çağrı: Liap kayıtlı cihazlara platformlarına göre (Expo, FCM, APNs, Web Push) iletir. userId verirseniz yalnızca o kullanıcının cihazlarına, vermezseniz tüm kayıtlı cihazlara gider.

Seçenekler: title (zorunlu), body, userId, data (uygulamaya iletilen nesne), sound (varsayılan "default"), badge, channelId (Android bildirim kanalı).

Kayıt olmadan belirli cihazlara göndermek için tokens: ['ExponentPushToken[…]'] verin (tek istekte en fazla 1000). Bu modda uygulama içi kayıt oluşturulmaz.

Yanıt: expo_targets, expo_delivered, expo_failed, expo_errors (ilk 5 hata mesajı) ve expo_removed (kayıttan düşen cihaz sayısı). FCM / APNs / Web Push sayıları da aynı yanıtta döner.

MethodPathAçıklama
POST/notifications/push{ title, body?, user_id?, tokens?, data?, sound?, badge?, channel_id? }
Node.js
import { createClient } from '@liap-cloud/sdk'

// Sunucu anahtarı — yalnızca sunucuda
const admin = createClient(EDGE_URL, { apiKey: process.env.LIAP_SERVER_KEY })

// Bir kullanıcının tüm cihazlarına
const r = await admin.notifications.push({
  title: 'Siparişin yolda',
  body: '#1042 kargoya verildi',
  userId: order.userId,
  data: { orderId: 1042, screen: 'orders' },
  channelId: 'orders',
})
console.log(r.expo_delivered, r.expo_failed, r.expo_errors)

// Kayıt olmadan doğrudan token'lara
await admin.notifications.push({
  title: 'Merhaba',
  tokens: ['ExponentPushToken[xxxxxxxxxxxxxxxxxxxxxx]'],
})

FCM, APNs ve Web Push

Expo dışı cihazlar aynı uçla kaydedilir: platform "fcm" (Firebase token), "apns" (iOS device token) veya "webpush" (tarayıcının PushSubscription JSON'u, string olarak).

Bu kanalların sağlayıcı anahtarları edge sunucusunda ortam değişkeniyle tanımlanır: LIAP_FCM_SERVER_KEY, LIAP_VAPID_PUBLIC_KEY / LIAP_VAPID_PRIVATE_KEY / LIAP_VAPID_SUBJECT, LIAP_APNS_KEY_ID / LIAP_APNS_TEAM_ID / LIAP_APNS_TOPIC + LIAP_APNS_KEY_PATH veya LIAP_APNS_P8.

Web Push için tarayıcıda abonelik açarken GET /notifications/vapid-public-key ile public anahtarı alın.

MethodPathAçıklama
GET/notifications/vapid-public-keyWeb Push VAPID public anahtarı
Node.js
// Tarayıcı: Web Push aboneliği
const { public_key } = await liap.notifications.vapidPublicKey()
const reg = await navigator.serviceWorker.ready
const sub = await reg.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: public_key })
await liap.notifications.registerDevice({ platform: 'webpush', token: JSON.stringify(sub) })

// React Native (FCM / APNs)
await liap.notifications.registerDevice({ platform: 'fcm', token: fcmToken })

E-posta gönderin (Resend)

Liap, isteği projenizin Resend anahtarıyla Resend'e iletir; e-posta sizin alan adınızdan çıkar. from olarak Resend'de doğrulanmış alan adınızdaki herhangi bir adresi verebilirsiniz (ör. [email protected] veya "Ekip <[email protected]>"). from verilmezse API Bilgileri'ndeki varsayılan gönderen kullanılır.

Alanlar: to (zorunlu, tek adres veya dizi), subject (zorunlu), html ve/veya text (en az biri), from, cc, bcc, replyTo. to + cc + bcc toplam en fazla 50 alıcı.

Bu uç notifications:send kapsamı ister: yalnızca sunucu anahtarıyla çağırın. Dashboard'daki Test butonu proje sahibinin oturumuyla çalışır.

Hatalar: 412 Resend bağlı değil (API Bilgileri'nde anahtar yok) · 400 eksik/geçersiz alan veya Resend reddi (geçersiz anahtar, doğrulanmamış alan adı — mesajda Resend'in açıklaması yer alır) · 429 Resend hız sınırı · 502 Resend'e ulaşılamadı.

MethodPathAçıklama
POST/notifications/email{ to, subject, html?, text?, from?, cc?, bcc?, reply_to? } → { id, provider, from, to }
Node.js
import { createClient } from '@liap-cloud/sdk'

// Sunucu anahtarı: data:write + notifications:send
const admin = createClient(EDGE_URL, { apiKey: process.env.LIAP_SERVER_KEY })

const { id } = await admin.notifications.email({
  from: 'Destek <[email protected]>', // boşsa varsayılan gönderen
  to: ['[email protected]'],
  subject: 'Siparişiniz alındı',
  html: '<h1>Teşekkürler!</h1><p>Siparişiniz #1042 hazırlanıyor.</p>',
  text: 'Teşekkürler! Siparişiniz #1042 hazırlanıyor.',
  replyTo: '[email protected]',
})
console.log('Resend id:', id)

Uygulama içi bildirimler

Sunucunuz bir bildirim oluşturur (userId verilmezse tüm kullanıcılara yayın); uygulama, oturumdaki kullanıcının bildirimlerini listeler ve okundu işaretler. Push gönderimi de aynı kaydı oluşturur, böylece uygulama içi gelen kutusu push ile tutarlı kalır.

Node.js
// Sunucu
await admin.notifications.send({ title: 'Yeni özellik', body: 'Karanlık mod geldi', userId })

// Uygulama (oturum açık)
const items = await liap.notifications.list()
await liap.notifications.markRead(items[0].id)

REST ile (SDK'sız)

Her dilde aynı istekler: kök adres projenin data_plane_url'i (edge), proje X-Liap-Key başlığıyla seçilir.

Node.js
// Push
await fetch(`${EDGE_URL}/notifications/push`, {
  method: 'POST',
  headers: { 'X-Liap-Key': process.env.LIAP_SERVER_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({ title: 'Merhaba', body: 'Liap push', user_id: userId }),
})

// E-posta
const res = await fetch(`${EDGE_URL}/notifications/email`, {
  method: 'POST',
  headers: { 'X-Liap-Key': process.env.LIAP_SERVER_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({ to: '[email protected]', subject: 'Merhaba', text: 'Liap üzerinden gönderildi' }),
})
if (!res.ok) console.error((await res.json()).error)

Gönderimleri izleme

Dashboard → Proje → Live sekmesinde her push ve e-posta isteği anlık görünür ("Push bildirimi gönderildi", "E-posta gönderildi"); hatalı istekler Hatalar filtresinde listelenir. API Bilgileri'ndeki Expo kartı kayıtlı Expo cihaz sayısını gösterir.

Docs · API