@onesignal/node-onesignal 5.4.0 → 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -535
- package/dist/apis/DefaultApi.js +44 -44
- package/dist/models/BasicNotification.d.ts +1 -0
- package/dist/models/BasicNotification.js +6 -0
- package/dist/models/BasicNotificationAllOf.d.ts +1 -0
- package/dist/models/BasicNotificationAllOf.js +6 -0
- package/dist/models/CreateTemplateRequest.d.ts +3 -0
- package/dist/models/CreateTemplateRequest.js +18 -0
- package/dist/models/Notification.d.ts +1 -0
- package/dist/models/Notification.js +6 -0
- package/dist/models/NotificationWithMeta.d.ts +2 -0
- package/dist/models/NotificationWithMeta.js +12 -0
- package/dist/models/NotificationWithMetaAllOf.d.ts +2 -0
- package/dist/models/NotificationWithMetaAllOf.js +12 -0
- package/dist/models/UpdateTemplateRequest.d.ts +3 -0
- package/dist/models/UpdateTemplateRequest.js +18 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<h1 align="center">Welcome to @onesignal/node-onesignal
|
|
1
|
+
<h1 align="center">Welcome to @onesignal/node-onesignal</h1>
|
|
2
2
|
<p>
|
|
3
3
|
<a href="https://www.npmjs.com/package/@onesignal/node-onesignal" target="_blank">
|
|
4
4
|
<img alt="Version" src="https://img.shields.io/npm/v/@onesignal/node-onesignal.svg">
|
|
@@ -9,581 +9,112 @@
|
|
|
9
9
|
<a href="https://github.com/OneSignal/node-onesignal/graphs/commit-activity" target="_blank">
|
|
10
10
|
<img alt="Maintenance" src="https://img.shields.io/badge/Maintained%3F-yes-green.svg" />
|
|
11
11
|
</a>
|
|
12
|
-
<a href="https://twitter.com/onesignal" target="_blank">
|
|
13
|
-
<img alt="Twitter: onesignal" src="https://img.shields.io/twitter/follow/onesignal.svg?style=social" />
|
|
14
|
-
</a>
|
|
15
12
|
</p>
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
### 🏠 [Homepage](https://github.com/OneSignal/node-onesignal#readme)
|
|
20
|
-
### 🖤 [npm](https://www.npmjs.com/package/@onesignal/node-onesignal)
|
|
21
|
-
|
|
22
|
-
# Node Client SDK
|
|
23
|
-
The OneSignal Node client is a server OneSignal SDK for NodeJS. Integrate OneSignal with your backend events, data, and
|
|
24
|
-
more.
|
|
14
|
+
The OneSignal Node client is a server SDK for NodeJS. A powerful way to send personalized messages at scale and build effective customer engagement strategies. Learn more at [onesignal.com](https://onesignal.com).
|
|
25
15
|
|
|
26
|
-
|
|
27
|
-
# Install
|
|
16
|
+
## Installation
|
|
28
17
|
|
|
29
18
|
```sh
|
|
30
|
-
# yarn
|
|
31
|
-
yarn add @onesignal/node-onesignal
|
|
32
|
-
|
|
33
19
|
# npm
|
|
34
|
-
npm install @onesignal/node-onesignal
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
# Usage
|
|
38
|
-
```js
|
|
39
|
-
const OneSignal = require('@onesignal/node-onesignal');
|
|
40
|
-
```
|
|
41
|
-
```js
|
|
42
|
-
import * as OneSignal from '@onesignal/node-onesignal';
|
|
43
|
-
```
|
|
20
|
+
npm install @onesignal/node-onesignal
|
|
44
21
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
We can configure the client using the `createConfiguration` function. You can find more info on each configuration
|
|
48
|
-
parameter [here](https://github.com/OpenAPITools/openapi-generator/pull/10283/files).
|
|
22
|
+
# pnpm
|
|
23
|
+
pnpm add @onesignal/node-onesignal
|
|
49
24
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
```
|
|
25
|
+
# bun
|
|
26
|
+
bun add @onesignal/node-onesignal
|
|
53
27
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const client = new OneSignal.DefaultApi(configuration);
|
|
28
|
+
# yarn
|
|
29
|
+
yarn add @onesignal/node-onesignal
|
|
57
30
|
```
|
|
58
31
|
|
|
59
|
-
|
|
60
|
-
You can configure auth parameters passing them like this:
|
|
32
|
+
## Configuration
|
|
61
33
|
|
|
62
|
-
|
|
63
|
-
const configuration = OneSignal.createConfiguration({
|
|
64
|
-
organizationApiKey: '<YOUR_ORGANIZATION_API_KEY>', // Organization key is only required for creating new apps and other top-level endpoints
|
|
65
|
-
restApiKey: '<YOUR_REST_API_KEY>', // App REST API key required for most endpoints
|
|
66
|
-
});
|
|
34
|
+
Every SDK requires authentication via API keys. Two key types are available:
|
|
67
35
|
|
|
68
|
-
|
|
69
|
-
|
|
36
|
+
- **REST API Key** — required for most endpoints (sending notifications, managing users, etc.). Found in your app's **Settings > Keys & IDs**.
|
|
37
|
+
- **Organization API Key** — only required for organization-level endpoints like creating or listing apps. Found in **Organization Settings**.
|
|
70
38
|
|
|
71
|
-
|
|
72
|
-
If creating a new app via the client, the response will return the app's API key via the `basic_auth_key` response
|
|
73
|
-
parameter. You can then use this to modify your configuration object and create a new client that will have both user-level and app-level authentication set up.
|
|
39
|
+
> **Warning:** Store your API keys in environment variables or a secrets manager. Never commit them to source control.
|
|
74
40
|
|
|
75
|
-
```
|
|
76
|
-
const
|
|
41
|
+
```javascript
|
|
42
|
+
const OneSignal = require('@onesignal/node-onesignal');
|
|
77
43
|
|
|
78
44
|
const configuration = OneSignal.createConfiguration({
|
|
79
|
-
|
|
80
|
-
|
|
45
|
+
restApiKey: 'YOUR_REST_API_KEY',
|
|
46
|
+
organizationApiKey: 'YOUR_ORGANIZATION_API_KEY',
|
|
81
47
|
});
|
|
82
48
|
|
|
83
49
|
const client = new OneSignal.DefaultApi(configuration);
|
|
84
50
|
```
|
|
85
51
|
|
|
86
|
-
|
|
87
|
-
## API Reference
|
|
88
|
-
|
|
89
|
-
> See the full list of [API Endpoints](DefaultApi.MD).
|
|
90
|
-
|
|
91
|
-
To make stateful changes requests should take on the following pattern:
|
|
92
|
-
1. create or get an object
|
|
93
|
-
2. make changes to that object
|
|
94
|
-
3. pass the object to the request function to make the changes
|
|
95
|
-
|
|
96
|
-
Examples of important OneSignal objects include `App`, `Notification`, `Player`, and `Segment`.
|
|
97
|
-
|
|
98
|
-
For example, see the section below on creating an app. First an app object is created via the instantiation of the `App`
|
|
99
|
-
class. Then, the app instance is modified directly. Finally, we use the `client` to create the app via a remote request.
|
|
100
|
-
|
|
101
|
-
### Creating an app
|
|
102
|
-
Creates a new OneSignal app.
|
|
103
|
-
|
|
104
|
-
**Example**
|
|
105
|
-
```js
|
|
106
|
-
const app = new OneSignal.App();
|
|
107
|
-
|
|
108
|
-
// configure your application
|
|
109
|
-
app.name = 'app_name';
|
|
110
|
-
app.gcm_key = '<your key here>';
|
|
111
|
-
app.android_gcm_sender_id = '<your id here>';
|
|
112
|
-
|
|
113
|
-
const response = await client.createApp(app);
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
### Getting an app
|
|
117
|
-
View the details of a single OneSignal app.
|
|
118
|
-
|
|
119
|
-
**Example**
|
|
120
|
-
```js
|
|
121
|
-
const app = await client.getApp('<app id>');
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
### Getting multiple apps
|
|
125
|
-
View apps.
|
|
126
|
-
|
|
127
|
-
**Example**
|
|
128
|
-
```js
|
|
129
|
-
const apps = await client.getApps();
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### Updating an app
|
|
133
|
-
Updates the name or configuration settings of an existing OneSignal app.
|
|
134
|
-
|
|
135
|
-
**Example**
|
|
136
|
-
```js
|
|
137
|
-
const app = new OneSignal.App();
|
|
138
|
-
app.name = 'modified_app_name';
|
|
139
|
-
|
|
140
|
-
const udpateAppResponse = await client.updateApp('<existing_app_id>', app);
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
### Creating a notification
|
|
144
|
-
Sends a notification to your users.
|
|
145
|
-
|
|
146
|
-
**Example**
|
|
147
|
-
```js
|
|
148
|
-
const notification = new OneSignal.Notification();
|
|
149
|
-
notification.app_id = app.id;
|
|
150
|
-
// Name property may be required in some case, for instance when sending an SMS.
|
|
151
|
-
notification.name = "test_notification_name";
|
|
152
|
-
notification.contents = {
|
|
153
|
-
en: "Gig'em Ags"
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// required for Huawei
|
|
157
|
-
notification.headings = {
|
|
158
|
-
en: "Gig'em Ags"
|
|
159
|
-
}
|
|
160
|
-
const notification = await client.createNotification(notification);
|
|
161
|
-
```
|
|
162
|
-
### Creating a notification using Filters
|
|
163
|
-
Sends a notification to your users filtered by specific criteria.
|
|
52
|
+
## Send a push notification
|
|
164
53
|
|
|
165
|
-
|
|
166
|
-
```js
|
|
54
|
+
```javascript
|
|
167
55
|
const notification = new OneSignal.Notification();
|
|
168
|
-
notification.app_id =
|
|
169
|
-
|
|
170
|
-
notification.
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// required for Huawei
|
|
175
|
-
notification.headings = {
|
|
176
|
-
en: "Gig'em Ags"
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Find all the users that have not spent any amount in USD on IAP.
|
|
180
|
-
// https://documentation.onesignal.com/reference/create-notification#send-to-users-based-on-filters
|
|
181
|
-
notification.filters = [
|
|
182
|
-
{
|
|
183
|
-
field: 'amount_spent',
|
|
184
|
-
relation: '=',
|
|
185
|
-
value: "0"
|
|
186
|
-
},
|
|
187
|
-
];
|
|
188
|
-
|
|
189
|
-
const notification = await client.createNotification(notification);
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
### Canceling a notification
|
|
193
|
-
Stop a scheduled or currently outgoing notification.
|
|
194
|
-
|
|
195
|
-
**Example**
|
|
196
|
-
|
|
197
|
-
```js
|
|
198
|
-
const cancelNotificationResponse = await client.cancelNotification('<app id>', '<notification id>');
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
### Getting a notification
|
|
203
|
-
View the details of a single notification and outcomes associated with it.
|
|
204
|
-
|
|
205
|
-
**Example**
|
|
206
|
-
```js
|
|
207
|
-
await client.getNotification('<app id>', '<notification id>');
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
### Getting notifications
|
|
211
|
-
View the details of multiple notifications.
|
|
212
|
-
|
|
213
|
-
| Param | Type | Description |
|
|
214
|
-
|--------|--------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
215
|
-
| app_id | string | The OneSignal App ID for your app. Available in Keys & IDs. |
|
|
216
|
-
| limit | string | How many notifications to return. Max is 50. Default is 50. |
|
|
217
|
-
| offset | number | Page offset. Default is 0. Results are sorted by queued_at in descending order. `queued_at` is a representation of the time that the notification was queued at. |
|
|
218
|
-
| kind | number | Kind of notifications returned: * unset - All notification types (default) * `0` - Dashboard only * `1` - API only * `3` - Automated only |
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
**Example**
|
|
222
|
-
```js
|
|
223
|
-
const notifications = await client.getNotifications('<app id>', '50', 0, 1);
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
### Getting notification history
|
|
227
|
-
View the devices sent a message - **OneSignal Paid Plan Required**
|
|
228
|
-
This method will return all devices that were sent the given `notification_id` of an Email or Push Notification if used
|
|
229
|
-
within 7 days of the date sent.
|
|
230
|
-
|
|
231
|
-
**Example**
|
|
232
|
-
```js
|
|
233
|
-
const notificationHistory = await client.getNotificationHistory('<notification id>');
|
|
234
|
-
```
|
|
235
|
-
|
|
236
|
-
### Creating a segment
|
|
237
|
-
Create segments visible and usable in the dashboard and API - **Required: OneSignal Paid Plan**
|
|
238
|
-
|
|
239
|
-
**Example**
|
|
240
|
-
```js
|
|
241
|
-
const segment = new OneSignal.Segment();
|
|
242
|
-
|
|
243
|
-
segment.filters = [
|
|
244
|
-
{ field: 'session_count', relation: '>', value: '1' },
|
|
245
|
-
{ field: 'tag', key: 'my_tag', relation: 'exists' }
|
|
246
|
-
]
|
|
247
|
-
|
|
248
|
-
const segment = await client.createSegments(app.id, segment);
|
|
249
|
-
```
|
|
250
|
-
|
|
251
|
-
### Deleting a segment
|
|
252
|
-
Delete segments (not user devices) - **Required: OneSignal Paid Plan**
|
|
253
|
-
You can delete a segment under your app by calling this API. You must provide an API key in the Authorization header
|
|
254
|
-
that has admin access on the app.
|
|
255
|
-
The `segment_id` can be found in the URL of the segment when viewing it in the dashboard.
|
|
256
|
-
|
|
257
|
-
**Example**
|
|
258
|
-
```js
|
|
259
|
-
const deleteSegmentsResponse = await client.deleteSegments('<app id>', '<segment id>');
|
|
260
|
-
```
|
|
56
|
+
notification.app_id = 'YOUR_APP_ID';
|
|
57
|
+
notification.contents = { en: 'Hello from OneSignal!' };
|
|
58
|
+
notification.headings = { en: 'Push Notification' };
|
|
59
|
+
notification.included_segments = ['Subscribed Users'];
|
|
261
60
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
**Example**
|
|
266
|
-
```js
|
|
267
|
-
const player = new OneSignal.Player();
|
|
268
|
-
player.device_type = 1;
|
|
269
|
-
player.app_id = app_id;
|
|
270
|
-
player.identifier = '<identifier>';
|
|
271
|
-
const player = await client.createPlayer(player);
|
|
272
|
-
```
|
|
273
|
-
|
|
274
|
-
### Getting a player
|
|
275
|
-
View the details of an existing device in one of your OneSignal apps.
|
|
276
|
-
The email and the hash is **only required if you have enabled Identity Verification and `device_type` is email**.
|
|
277
|
-
|
|
278
|
-
**Example**
|
|
279
|
-
```js
|
|
280
|
-
const player = await client.getPlayer('<app id>', '<player id>', '<email auth hash>');
|
|
281
|
-
```
|
|
282
|
-
|
|
283
|
-
### Getting players
|
|
284
|
-
View the details of multiple devices in one of your OneSignal apps.
|
|
285
|
-
|
|
286
|
-
⚠️ Unavailable for Apps Over 80,000 Users.
|
|
287
|
-
|
|
288
|
-
| Param | Type | Description |
|
|
289
|
-
|--------|--------|------------------------------------------------------------------|
|
|
290
|
-
| app_id | string | The OneSignal App ID for your app. Available in Keys & IDs. |
|
|
291
|
-
| limit | string | How many devices to return. Max is 300. Default is 300 |
|
|
292
|
-
| offset | number | Result offset. Default is 0. Results are sorted by id; |
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
**Example**
|
|
296
|
-
```js
|
|
297
|
-
const players = await client.getPlayers('<app id>', '300', 0);
|
|
61
|
+
const response = await client.createNotification(notification);
|
|
62
|
+
console.log('Notification ID:', response.id);
|
|
298
63
|
```
|
|
299
64
|
|
|
300
|
-
|
|
301
|
-
Generate a compressed CSV export of all of your current user data. This method can be used to generate a compressed CSV
|
|
302
|
-
export of all of your existing user data and is a better alternative to retrieving this data using the /players API endpoint.
|
|
65
|
+
## Send a push notification by External ID
|
|
303
66
|
|
|
304
|
-
|
|
67
|
+
Target specific users with the alias label `external_id` (snake_case). This is different from the notification-level `external_id` field, which is only for [idempotent requests](https://documentation.onesignal.com/docs/idempotent-notification-requests).
|
|
305
68
|
|
|
306
|
-
|
|
307
|
-
```js
|
|
308
|
-
const exportPlayerResponse = await client.exportPlayer('<app id>', {
|
|
309
|
-
extra_fields: ['location', 'external_user_id'],
|
|
310
|
-
last_active_since: 1469392779,
|
|
311
|
-
segment_name: "Subscribed Users"
|
|
312
|
-
});
|
|
313
|
-
```
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
### Updating a player
|
|
317
|
-
Update an existing device in one of your OneSignal apps.
|
|
318
|
-
|
|
319
|
-
**Example**
|
|
320
|
-
```js
|
|
321
|
-
const updatePlayerResponse = await client.updatePlayer('<player id>', player);
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
### Updating player tags
|
|
325
|
-
Update an existing device's tags in one of your OneSignal apps using the External User ID.
|
|
326
|
-
|
|
327
|
-
```js
|
|
328
|
-
const playerToUpdate = new OneSignal.Player();
|
|
69
|
+
You must set `target_channel` when sending push (or email/SMS) to alias targets.
|
|
329
70
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
**Example**
|
|
345
|
-
```json
|
|
346
|
-
"tags": {
|
|
347
|
-
"rank": "",
|
|
348
|
-
"category": "",
|
|
349
|
-
"class": "my_new_value"
|
|
71
|
+
```javascript
|
|
72
|
+
const notification = new OneSignal.Notification();
|
|
73
|
+
notification.app_id = 'YOUR_APP_ID';
|
|
74
|
+
notification.contents = { en: 'Hello from OneSignal!' };
|
|
75
|
+
notification.headings = { en: 'Push Notification' };
|
|
76
|
+
// Keys under include_aliases must match API alias labels exactly (e.g. external_id, not externalId).
|
|
77
|
+
notification.include_aliases = { external_id: ['YOUR_USER_EXTERNAL_ID'] };
|
|
78
|
+
notification.target_channel = 'push';
|
|
79
|
+
|
|
80
|
+
const response = await client.createNotification(notification);
|
|
81
|
+
if (!response.id) {
|
|
82
|
+
console.error('Notification was not created:', response.errors);
|
|
83
|
+
} else {
|
|
84
|
+
console.log('Notification ID:', response.id);
|
|
350
85
|
}
|
|
351
86
|
```
|
|
352
87
|
|
|
353
|
-
|
|
354
|
-
Deletes a user record.
|
|
355
|
-
|
|
356
|
-
**Example**
|
|
357
|
-
```js
|
|
358
|
-
const deletePlayerResponse = await client.deletePlayer(app.id, '<player id>')
|
|
359
|
-
```
|
|
360
|
-
|
|
361
|
-
### Getting outcomes
|
|
362
|
-
View the details of all the outcomes associated with your app.
|
|
363
|
-
|
|
364
|
-
🚧 **Requires your OneSignal App's REST API Key, available in Keys & IDs** 🚧
|
|
365
|
-
|
|
366
|
-
Outcome data are accessible for 30 days before being deleted from our servers. You can export this data monthly if you need it for a more extended period.
|
|
367
|
-
|
|
368
|
-
| Param | Type | Description |
|
|
369
|
-
|---------------------|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
370
|
-
| app_id | string | The OneSignal App ID for your app. Available in Keys & IDs. |
|
|
371
|
-
| outcome_names | string | Required Comma-separated list of names and the value (sum/count) for the returned outcome data. Note: Clicks only support count aggregation. For out-of-the-box OneSignal outcomes such as click and session duration, please use the “os” prefix with two underscores. For other outcomes, please use the name specified by the user. Example:os__session_duration.count,os__click.count,CustomOutcomeName.sum |
|
|
372
|
-
| outcome_names2 | string | If outcome names contain any commas, then please specify only one value at a time. Example: `outcome_names[]=os__click.count&outcome_names[]=Sales, Purchase.count` where “Sales, Purchase” is the custom outcomes with a comma in the name. |
|
|
373
|
-
| outcome_time_range | string | Optional Time range for the returned data. The values can be `1h` (for the last 1 hour data), `1d` (for the last 1 day data), or `1mo` (for the last 1 month data). Default is 1h if the parameter is omitted. |
|
|
374
|
-
| outcome_platforms | string | Optional Platform id. Refer device's platform ids for values. **Example:** `outcome_platform=0` for iOS `outcome_platform=7`, `8` for Safari and Firefox Default is data from all platforms if the parameter is omitted. |
|
|
375
|
-
| outcome_attribution | string | Optional Attribution type for the outcomes. The values can be direct or influenced or unattributed. Example: outcome_attribution=direct Default is total (returns direct+influenced+unattributed) if the parameter is omitted. |
|
|
376
|
-
|
|
377
|
-
**Example**
|
|
378
|
-
```js
|
|
379
|
-
const outcomes = await client.getOutcomes(app.id, 'os__click.count,os_session_duration.count,my_outcome.sum');
|
|
380
|
-
```
|
|
381
|
-
|
|
382
|
-
### Begin Live Activity
|
|
383
|
-
Starts a Live Activity event
|
|
384
|
-
```js
|
|
385
|
-
// Create a player first
|
|
386
|
-
const player = new OneSignal.Player();
|
|
387
|
-
player.device_type = 0;
|
|
388
|
-
player.app_id = '<app id>';
|
|
389
|
-
const playerResponse = await api.createPlayer(player);
|
|
390
|
-
|
|
391
|
-
// Prepare a request
|
|
392
|
-
const beginLiveActivityRequest: BeginLiveActivityRequest = {
|
|
393
|
-
push_token: '<push_token>',
|
|
394
|
-
subscription_id: playerResponse.id!,
|
|
395
|
-
};
|
|
396
|
-
const activityId = '<activity_id>'; // any string
|
|
397
|
-
|
|
398
|
-
// Begin activity
|
|
399
|
-
await api.beginLiveActivity('<app_id>', activityId, beginLiveActivityRequest);
|
|
400
|
-
```
|
|
401
|
-
|
|
402
|
-
### Update Live Activity
|
|
403
|
-
Updates a Live Activity event
|
|
404
|
-
```js
|
|
405
|
-
const updateLiveActivityRequest: UpdateLiveActivityRequest = {
|
|
406
|
-
event_updates: {
|
|
407
|
-
data: 'test'
|
|
408
|
-
},
|
|
409
|
-
event: "update",
|
|
410
|
-
name: "contents"
|
|
411
|
-
};
|
|
412
|
-
|
|
413
|
-
await api.updateLiveActivity('<app_id>', '<activity_id>', updateLiveActivityRequest);
|
|
414
|
-
```
|
|
415
|
-
|
|
416
|
-
### End Live Activity
|
|
417
|
-
Stops a Live Activity event
|
|
418
|
-
```js
|
|
419
|
-
const subscriptionId = '<subscription_id>'; // player id
|
|
420
|
-
await api.endLiveActivity('<app_id>', '<activity_id>', subscriptionId);
|
|
421
|
-
```
|
|
422
|
-
|
|
423
|
-
### Subscription types
|
|
424
|
-
* iOSPush
|
|
425
|
-
* AndroidPush
|
|
426
|
-
* FireOSPush
|
|
427
|
-
* ChromeExtensionPush
|
|
428
|
-
* ChromePush
|
|
429
|
-
* WindowsPush
|
|
430
|
-
* SafariLegacyPush
|
|
431
|
-
* FirefoxPush
|
|
432
|
-
* macOSPush
|
|
433
|
-
* HuaweiPush
|
|
434
|
-
* SafariPush
|
|
435
|
-
* Email
|
|
436
|
-
* SMS
|
|
437
|
-
|
|
438
|
-
## Users
|
|
439
|
-
### Creating a OneSignal User
|
|
440
|
-
```js
|
|
441
|
-
const user = new OneSignal.User();
|
|
442
|
-
|
|
443
|
-
const aliasLabel = '<alias_label>';
|
|
444
|
-
const aliasId = '<alias_id>';
|
|
445
|
-
const subscriptionToken = '<subscription_token>';
|
|
446
|
-
|
|
447
|
-
user.identity = {
|
|
448
|
-
[aliasLabel]: aliasId,
|
|
449
|
-
};
|
|
450
|
-
|
|
451
|
-
user.subscriptions = [
|
|
452
|
-
{
|
|
453
|
-
type: "iOSPush",
|
|
454
|
-
token: subscriptionToken,
|
|
455
|
-
}
|
|
456
|
-
];
|
|
457
|
-
|
|
458
|
-
const createdUser = await api.createUser('<app_id>', user);
|
|
459
|
-
assert(createdUser.identity!['onesignal_id'] != null);
|
|
460
|
-
```
|
|
461
|
-
|
|
462
|
-
### Getting a user by `onesignal_id`
|
|
463
|
-
```js
|
|
464
|
-
const oneisgnalAliasLabel = "onesignal_id";
|
|
465
|
-
const onesignalAliasId = createdUser.identity!['onesignal_id'];
|
|
466
|
-
|
|
467
|
-
const fetchedUser = await api.fetchUser('<app_id>', oneisgnalAliasLabel, onesignalAliasId);
|
|
468
|
-
```
|
|
469
|
-
|
|
470
|
-
### Getting a user by an alias
|
|
471
|
-
```js
|
|
472
|
-
const fetchedUser = await api.fetchUser('<app_id>', alias_label, alias_id);
|
|
473
|
-
```
|
|
474
|
-
|
|
475
|
-
### Updating a user
|
|
476
|
-
```js
|
|
477
|
-
const updateUserRequest: UpdateUserRequest = {
|
|
478
|
-
properties: {
|
|
479
|
-
language: 'fr'
|
|
480
|
-
}
|
|
481
|
-
};
|
|
482
|
-
|
|
483
|
-
const updatedUser = await api.updateUser('<app_id>', aliasLabel, aliasId, updateUserRequest);
|
|
484
|
-
```
|
|
485
|
-
|
|
486
|
-
### Deleting a user
|
|
487
|
-
```js
|
|
488
|
-
await api.deleteUser('<app_id>', aliasLabel, aliasId);
|
|
489
|
-
```
|
|
88
|
+
The API may return HTTP 200 with an empty `id` when no matching subscribed recipients are found; always check `response.id` and `response.errors`.
|
|
490
89
|
|
|
491
|
-
##
|
|
492
|
-
### Creating a subscription for existing user
|
|
493
|
-
```js
|
|
494
|
-
const createSubscriptionRequestBody: CreateSubscriptionRequestBody = {
|
|
495
|
-
subscription: {
|
|
496
|
-
type: "AndroidPush",
|
|
497
|
-
token: '<subscription_token>',
|
|
498
|
-
}
|
|
499
|
-
};
|
|
500
|
-
|
|
501
|
-
const response = await api.createSubscription('<app_id>', '<alias_label>', '<alias_id>', createSubscriptionRequestBody);
|
|
502
|
-
```
|
|
90
|
+
## Send an email
|
|
503
91
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
};
|
|
512
|
-
|
|
513
|
-
await api.updateSubscription('<app_id>', '<existing_subscription_id>', updateSubscriptionRequestBody);
|
|
514
|
-
```
|
|
515
|
-
|
|
516
|
-
### Deleting a subscription
|
|
517
|
-
```js
|
|
518
|
-
await api.deleteSubscription('<app_id>', '<subscription_id>');
|
|
519
|
-
```
|
|
520
|
-
|
|
521
|
-
### Transfer subscription ownership
|
|
522
|
-
Transfers the subscription from one user to another.
|
|
523
|
-
```js
|
|
524
|
-
// Setting the user for transfering the subscription to. User is identyfied by an IdentityObject.
|
|
525
|
-
const transferSubscriptionRequestBody: TransferSubscriptionRequestBody = {
|
|
526
|
-
identity: otherUserIdentityObject
|
|
527
|
-
};
|
|
528
|
-
|
|
529
|
-
const transferResponse = await api.transferSubscription('<app_id>', '<subscription_id>', transferSubscriptionRequestBody);
|
|
530
|
-
```
|
|
531
|
-
|
|
532
|
-
## Aliases
|
|
533
|
-
### Fetching aliases for a user
|
|
534
|
-
```js
|
|
535
|
-
const fetchResponse = await api.fetchAliases('<app_id>', '<subscription_id>');
|
|
536
|
-
```
|
|
537
|
-
|
|
538
|
-
### Fetching user identity
|
|
539
|
-
```js
|
|
540
|
-
const fetchResponse = await api.fetchUserIdentity('<app_id>', '<alias_label>', '<alias_id>');
|
|
541
|
-
```
|
|
542
|
-
### Identifying user by alias
|
|
543
|
-
```js
|
|
544
|
-
const userIdentityRequestBody: UserIdentityRequestBody = {
|
|
545
|
-
identity: {
|
|
546
|
-
['<new_alias_label>']: '<new_alias_id>'
|
|
547
|
-
}
|
|
548
|
-
};
|
|
92
|
+
```javascript
|
|
93
|
+
const notification = new OneSignal.Notification();
|
|
94
|
+
notification.app_id = 'YOUR_APP_ID';
|
|
95
|
+
notification.email_subject = 'Important Update';
|
|
96
|
+
notification.email_body = '<h1>Hello!</h1><p>This is an HTML email.</p>';
|
|
97
|
+
notification.included_segments = ['Subscribed Users'];
|
|
98
|
+
notification.channel_for_external_user_ids = 'email';
|
|
549
99
|
|
|
550
|
-
const
|
|
551
|
-
'<existing_alias_label>',
|
|
552
|
-
'<existing_alias_id>',
|
|
553
|
-
userIdentityRequestBody);
|
|
100
|
+
const response = await client.createNotification(notification);
|
|
554
101
|
```
|
|
555
102
|
|
|
556
|
-
|
|
557
|
-
```js
|
|
558
|
-
const userIdentityRequestBody: UserIdentityRequestBody = {
|
|
559
|
-
identity: {
|
|
560
|
-
['<new_alias_label>']: '<new_alias_id>'
|
|
561
|
-
}
|
|
562
|
-
};
|
|
103
|
+
## Send an SMS
|
|
563
104
|
|
|
564
|
-
|
|
565
|
-
|
|
105
|
+
```javascript
|
|
106
|
+
const notification = new OneSignal.Notification();
|
|
107
|
+
notification.app_id = 'YOUR_APP_ID';
|
|
108
|
+
notification.contents = { en: 'Your SMS message content here' };
|
|
109
|
+
notification.included_segments = ['Subscribed Users'];
|
|
110
|
+
notification.channel_for_external_user_ids = 'sms';
|
|
111
|
+
notification.sms_from = '+15551234567';
|
|
566
112
|
|
|
567
|
-
|
|
568
|
-
```js
|
|
569
|
-
await api.deleteAlias('<app_id>', '<alias_label>', '<alias_id>', '<alias_label_to_delete>');
|
|
113
|
+
const response = await client.createNotification(notification);
|
|
570
114
|
```
|
|
571
|
-
## Author
|
|
572
|
-
|
|
573
|
-
* Website: https://onesignal.com
|
|
574
|
-
* Twitter: [@onesignal](https://twitter.com/onesignal)
|
|
575
|
-
* Github: [@OneSignal](https://github.com/OneSignal)
|
|
576
|
-
|
|
577
|
-
## 🤝 Contributing
|
|
578
|
-
|
|
579
|
-
Contributions, issues and feature requests are welcome!<br />Feel free to check [issues page](https://github.com/OneSignal/node-onesignal/issues).
|
|
580
|
-
|
|
581
|
-
## Show your support
|
|
582
|
-
|
|
583
|
-
Give a ⭐️ if this project helped you!
|
|
584
115
|
|
|
585
|
-
##
|
|
116
|
+
## Full API reference
|
|
586
117
|
|
|
587
|
-
|
|
118
|
+
The complete list of API endpoints and their parameters is available in the [DefaultApi documentation](https://github.com/OneSignal/node-onesignal/blob/main/DefaultApi.md).
|
|
588
119
|
|
|
589
|
-
|
|
120
|
+
For the underlying REST API, see the [OneSignal API reference](https://documentation.onesignal.com/reference).
|