A OneSignal client that implement some of the endpoints from the OneSignal API
Note: The responses are the direct responses from the provider so you can see the examples on his documentation (See ref).
Creates a new OneSignal client.
const client = new OneSignal({
authKey: process.env.AUTH_KEY,
restApiKey: process.env.REST_API_KEY,
appId: process.env.APP_ID,
});
Validate that the app exist in the provider.
client.isValid()
View the details of a single OneSignal app.
Usage example:
client.getApp()
Sends notifications to your users.
If attribute included_segments
not provided will send to "Test" segment by default.
Usage example:
const message = {
heading: {
en: 'Example Explicit Segment',
es: 'Ejemplo Segmento Explicito',
},
content: {
en: 'This is an example for Test segment explicitly',
es: 'Este es un ejemplo para el segmento Test de forma explícita',
}
}
const opt = {
targets: {
to: {
type: 'external',
value: ['1130745'],
}
}
}
client.sendNotification(message, opt);
Stop a scheduled or currently outgoing notification.
Usage example:
client.cancelNotification('fd1723c6-bfaf-4f53-b4f4-0408ff43e18a');
View the details of multiple notifications.
Usage example:
client.viewNotifications({ limit: 5 });
View the details of a single notification and outcomes associated with it.
Usage example:
client.viewNotification('fd1723c6-bfaf-4f53-b4f4-0408ff43e18a');
View the details of multiple devices in your app.
Usage example:
client.viewDevices({ limit: 2 });
View the details of an existing device in your OneSignal apps.
Usage example:
client.viewDevice('fd1723c6-bfaf-4f53-b4f4-0408ff43e18a');