Skip to content

Instantly share code, notes, and snippets.

@elraphty
Created March 23, 2022 00:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elraphty/185250443a36d0495839d782364bef3b to your computer and use it in GitHub Desktop.
Save elraphty/185250443a36d0495839d782364bef3b to your computer and use it in GitHub Desktop.
// const EpnsSDK = require('@epnsproject/backend-sdk-staging');
import EpnsSDK from '@epnsproject/backend-sdk-staging';
// for testing or development.
// The private key of the address which you used to create a channel// Initialise the SDK
const CHANNEL_PK = '0x0000000000000000000000000000000000000000000000000000000000000fff';
const epnsSdk = new EpnsSDK(CHANNEL_PK);
// Send single notification to a recipient
epnsSdk.sendNotification(
recipientAddress,
pushNotificationtitle,
pushNotificationMessage,
notificationTitle,
notificationMessage,
3, //this is the notificationType 3 is for single notification
cta, // a url for users to be redirected to
image ,// an image url, or an empty string
null, //this can be left as null
).then(res => {
console.log('Result ===', res)
}).catch(err => {
console.log('Error ===', err);
});
// Broadcast notification to all subscribers
epnsSdk.sendNotification(
channelAddress, // Paste ur channel address here
pushNotificationtitle,
pushNotificationMessage,
notificationTitle,
notificationMessage,
1, //this is the notificationType, 1 is for broadcast notification
cta, // a url for users to be redirected to
image ,// an image url, or an empty string
null, //this can be left as null
).then(res => {
console.log('Result ===', res)
}).catch(err => {
console.log('Error ===', err);
});
// Send notifications to multiple recipients
epnsSdk.sendNotification(
['0xaddress1', '0xaddress2', '0xaddress3'], // Paste ur channel addresses here
pushNotificationtitle,
pushNotificationMessage,
notificationTitle,
notificationMessage,
4, //this is the notificationType, 4 is for notification to multiple recipients
cta, // a url for users to be redirected to
image ,// an image url, or an empty string
null, //this can be left as null
).then(res => {
console.log('Result ===', res)
}).catch(err => {
console.log('Error ===', err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment