Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
03d4c82
apn use rawPayload
banshiAnton Jun 5, 2022
1c70880
add fcm_notification field to sendGCM
banshiAnton Jul 11, 2022
7c09a10
2.0.3-banshiAnton.1
banshiAnton Jul 11, 2022
a3d8005
senderGCM: timeToLive calculated from expiry must not be negative
banshiAnton Oct 13, 2022
70c86d4
2.0.4
banshiAnton Oct 13, 2022
85ea960
Merge branch 'apn-raw-payload' into development-banshiAnton
banshiAnton Oct 13, 2022
3316ef2
2.0.4-banshiAnton
banshiAnton Oct 13, 2022
07db58c
add fcm method
banshiAnton Sep 13, 2023
3e45ea5
update build fcm message
banshiAnton Sep 18, 2023
3e3a59c
2.1.4
banshiAnton Sep 18, 2023
ee47518
2.1.0
banshiAnton Sep 18, 2023
255d7bf
Merge branch 'master' into banshiAnton-fcm-method
banshiAnton Sep 18, 2023
3b84a77
fix build android fcm message
banshiAnton Sep 18, 2023
224ece5
fix fcm buildApnsMessage
banshiAnton Sep 18, 2023
0fbaa24
remove pack
banshiAnton Sep 18, 2023
b129728
update toJSONorUndefined
banshiAnton Sep 20, 2023
d331836
add FCM method spec
banshiAnton Sep 20, 2023
a1f2b04
add fcm providersExclude option
banshiAnton Oct 4, 2023
f3730e1
update README.md
banshiAnton Jan 10, 2024
8d8fff3
update README.md
banshiAnton Jan 10, 2024
cfe17c8
update README.md
banshiAnton Jan 10, 2024
d2b0134
update README.md
banshiAnton Jan 10, 2024
ba9bce1
add rawPayload and fcm_notification to README.md
banshiAnton Jan 10, 2024
75bc97b
rename: buildGsmMessage -> buildGcmMessage
banshiAnton Jan 11, 2024
adebd63
add isLegacyGCM setting
banshiAnton Jan 12, 2024
0a2787c
remove .bind from toJSONorUndefined func
banshiAnton Jan 12, 2024
89a2c09
back 'no-param-reassign' eslint rule
banshiAnton Jan 12, 2024
9550623
back formatting / whitespace README.md
banshiAnton Jan 12, 2024
8c661f4
back whitespaces
banshiAnton Jan 12, 2024
0256e2b
remove )
banshiAnton Jan 12, 2024
f160f4d
Merge branch 'master' into update-fcm-method
ehaynes99 May 10, 2024
02e6c7c
Fix typo in readme
ehaynes99 May 10, 2024
f1cef63
Add export for FCM
ehaynes99 May 10, 2024
b008400
Fix ttl casing and units
ehaynes99 May 10, 2024
2f6c268
Fix linter error
ehaynes99 May 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ coverage
.sonar
lib
release.sh
.nyc_output
.nyc_output
114 changes: 111 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ A node.js module for interfacing with Apple Push Notification, Google Cloud Mess
- [Usage](#usage)
- [GCM](#gcm)
- [APN](#apn)
- [FCM](#fcm)
- [WNS](#wns)
- [ADM](#adm)
- [Web-Push](#web-push)
Expand Down Expand Up @@ -64,6 +65,11 @@ const settings = {
production: false // true for APN production environment, false for APN sandbox environment,
...
},
fcm: {
appName: 'localFcmAppName',
serviceAccountKey: require('../firebase-project-service-account-key.json'), // firebase service-account-file.json,
credential: null // 'firebase-admin' Credential interface
},
adm: {
client_id: null,
client_secret: null,
Expand All @@ -86,13 +92,16 @@ const settings = {
contentEncoding: 'aes128gcm',
headers: {}
},
isAlwaysUseFCM: false, // true all messages will be sent through node-gcm (which actually uses FCM)
isAlwaysUseFCM: false, // true all messages will be sent through gcm/fcm api
isLegacyGCM: false // if true gcm messages will be sent through node-gcm (deprecated api), if false gcm messages will be sent through 'firebase-admin' lib
};

const push = new PushNotifications(settings);
```

- GCM options: see [node-gcm](https://github.com/ToothlessGear/node-gcm#custom-gcm-request-options)
- APN options: see [node-apn](https://github.com/node-apn/node-apn/blob/master/doc/provider.markdown)
- FCM options: see [firebase-admin](https://firebase.google.com/docs/admin/setup) (read [FCM](#fcm) section below!)
- ADM options: see [node-adm](https://github.com/umano/node-adm)
- WNS options: see [wns](https://github.com/tjanczuk/wns)
- Web-push options: see [web-push](https://github.com/web-push-libs/web-push)
Expand Down Expand Up @@ -356,7 +365,7 @@ The following parameters are used to create a GCM message. See https://developer
body_loc_args: data.locArgs, // Android, iOS
title_loc_key: data.titleLocKey, // Android, iOS
title_loc_args: data.titleLocArgs, // Android, iOS
android_channel_id: data.android_channel_id, // Android
android_channel_id: data.android_channel_id, // Android
},
}
```
Expand Down Expand Up @@ -486,7 +495,8 @@ The following parameters are used to create an APN message:
collapseId: data.collapseKey,
mutableContent: data.mutableContent || 0,
threadId: data.threadId,
pushType: data.pushType
pushType: data.pushType,
rawPayload: data.rawPayload
}
```

Expand All @@ -496,6 +506,7 @@ _data is the parameter in `push.send(registrationIds, data)`_
- **Please note** that `topic` is required ([see node-apn docs](https://github.com/node-apn/node-apn/blob/master/doc/notification.markdown#notificationtopic)). When using token-based authentication, specify the bundle ID of the app.
When using certificate-based authentication, the topic is usually your app's bundle ID.
More details can be found under https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns
- `rawPayload` (hidden 'node-apn' lib notification param) [source code](https://github.com/node-apn/node-apn/blob/master/lib/notification/index.js#L99) this param will replace all payload

### Silent push notifications

Expand All @@ -519,6 +530,103 @@ const silentPushData = {
}
```

## FCM

The following parameters are used to create an FCM message (Android/APN):
[node-gcm](https://github.com/ToothlessGear/node-gcm) lib for `GCM` method use old firebase api (will be [deprecated ](https://firebase.google.com/docs/cloud-messaging/migrate-v1?hl=en&authuser=0))

Settings:

- `settings.fcm.appName` [firebase app name](https://firebase.google.com/docs/reference/admin/node/firebase-admin.app.app#appname) (required)
- `settings.fcm.serviceAccountKey` [firebase service account file](https://firebase.google.com/docs/admin/setup#initialize_the_sdk_in_non-google_environments) use downloaded 'service-account-file.json'
- `settings.fcm.credential` [firebase credential](https://firebase.google.com/docs/reference/admin/node/firebase-admin.app.credential)

Note: one of `serviceAccountKey`, `credential` fcm options is required

```js
const tokens = [
'e..Gwso:APA91.......7r910HljzGUVS_f...kbyIFk2sK6......D2s6XZWn2E21x',
];

const notifications = {
collapseKey: Math.random().toString().replace('0.', ''),
priority: 'high',
sound: 'default',
title: 'Title 1',
body: 'Body 2',
// titleLocKey: 'GREETING',
// titleLocArgs: ['Smith', 'M'],
// fcm_notification: {
// title: 'Title 1',
// body: 'Body 2',
// sound: 'default',
// default_vibrate_timings: true,
// },
// alert: {
// title: 'Title 2',
// body: 'Body 2'
// },
custom: {
friend_id: 54657,
list_id: 'N7jSif1INyZkA7r910HljzGUVS',
},
};

pushNotifications.send(tokens, notifications, (error, result) => {
if (error) {
console.log('[error]', error);
throw error;
} else {
console.log('[result]', result, result.at(0));
}
});
```

`fcm_notification` - object that will be passed to

```js
new gcm.Message({ ..., notification: data.fcm_notification })
```

Fcm object that will be sent to provider ([Fcm message format](https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0#Message)) :

```json
{
"data": {
"frined_id": "54657",
"list_id": "N7jSif1INyZkA7r910HljzGUVS"
},
"android": {
"collapse_key": "5658586678087056",
"priority": "high",
"notification": {
"title": "Title 1",
"body": "Body 2",
"sound": "default"
},
"ttl": 2419200000
},
"apns": {
"headers": {
"apns-expiration": "1697456586",
"apns-collapse-id": "5658586678087056"
},
"payload": {
"aps": {
"sound": "default",
"alert": {
"title": "Title 1",
"body": "Body 2"
}
}
}
},
"tokens": [
"e..Gwso:APA91.......7r910HljzGUVS_f...kbyIFk2sK6......D2s6XZWn2E21x"
]
}
```

## WNS

The following fields are used to create a WNS message:
Expand Down
Loading