Skip to main content

Kurulum ve Yapılandırma

OneSignal TypeScript SDK’sını yükleyin ve uygulamanız için yapılandırın.
npm install @onesignal/node-onesignal
import Onesignal from '@onesignal/node-onesignal';

const configuration = Onesignal.createConfiguration({
    restApiKey: '<YOUR_REST_API_KEY>'
    organizationApiKey: '<YOUR_ORGANIZATION_API_KEY>',
});

const apiInstance = new Onesignal.DefaultApi(configuration);

Mesaj gönderme

OneSignal API aracılığıyla kullanıcılarınıza push, e-posta ve SMS mesajları gönderin. Mesajların nasıl yapılandırılacağına dair daha fazla ayrıntı için OneSignal API ile mesaj gönderme kılavuzuna bakın.

Push bildirimleri gönderme

Web ve mobil Abonelikler’e push bildirimleri gönderin.
const notification = new OneSignal.Notification();
notification.app_id = 'YOUR_APP_ID';
notification.contents = {
  en: 'Hello from your app!'
};
notification.headings = {
  en: 'Push Notification'
};
notification.included_segments = ['All'];

const { id } = await client.createNotification(notification);
console.log('Notification sent with ID:', id);

E-posta gönderme

E-posta Abonelikler’inize e-posta gönderin.
const notification = new OneSignal.Notification();
notification.app_id = 'YOUR_APP_ID';
notification.contents = {
  en: 'This is your email message content'
};
notification.headings = {
  en: 'Email Subject Line'
};
notification.email_subject = 'Important Update';
notification.email_body = '<h1>Hello!</h1><p>This is an HTML email.</p>';
notification.included_segments = ['All'];
notification.channel_for_external_user_ids = 'email';

const { id } = await client.createNotification(notification);
console.log('Email notification sent with ID:', id);

SMS gönderme

SMS Abonelikler’e SMS “metin” mesajları gönderin.
const notification = new OneSignal.Notification();
notification.app_id = 'YOUR_APP_ID';
notification.contents = {
  en: 'Your SMS message content here'
};
notification.included_segments = ['All'];
notification.channel_for_external_user_ids = 'sms';
notification.sms_from = '+1234567890'; // Your SMS sender number

const { id } = await client.createNotification(notification);
console.log('SMS notification sent with ID:', id);
Diğer Server SDK endpoint’leri hakkında bilgi edinmek için lütfen tam API referansını kontrol edin.