DefinitelyTyped/types/node-pushnotifications/node-pushnotifications-tests.ts
Julian Hundeloh e6e2c8349d fix(node-pushnotifications): add web support (#34444)
* fix: add web support

* fix: lint

* fix: add web in settings

* fix: remove package.json

* fix: upgrade Typescript version

* fix: lint
2019-05-07 11:15:12 -07:00

71 lines
1.7 KiB
TypeScript

import PushNotifications = require('node-pushnotifications');
import { supportedContentEncodings } from 'web-push';
const settings = {
gcm: {
id: "null"
},
apn: {
token: {
key: './certs/key.p8',
keyId: 'ABCD',
teamId: 'EFGH',
}
},
adm: {
client_id: "null",
client_secret: "null"
},
wns: {
client_id: "null",
client_secret: "null",
notificationMethod: 'sendTileSquareBlock',
},
web: {
vapidDetails: {
subject: '< \'mailto\' Address or URL >',
publicKey: '< URL Safe Base64 Encoded Public Key >',
privateKey: '< URL Safe Base64 Encoded Private Key >',
},
gcmAPIKey: 'gcmkey',
TTL: 2419200,
contentEncoding: supportedContentEncodings.AES_128_GCM,
headers: {},
}
};
const push = new PushNotifications(settings);
const registrationIds = [];
registrationIds.push('INSERT_YOUR_DEVICE_ID');
registrationIds.push('INSERT_OTHER_DEVICE_ID');
registrationIds.push({
endpoint: 'https://fcm.googleapis.com/fcm/send/...',
keys: {
auth: '...',
p256dh: '...'
}
});
const data = {
title: 'New push notification',
body: 'Powered by AppFeel'
};
// You can use it in node callback style
push.send(registrationIds, data, (err, result) => {
if (err) {
console.log(err);
} else {
console.log(result);
}
});
// Or you could use it as a promise and send only a single notifications:
push.send(registrationIds[0], data)
.then((results) => {
console.log(results);
})
.catch((err) => {
console.log(err);
});