2.0.0 • Published 2 years ago

@epnsproject/backend-sdk v2.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Backend SDK

About

This module is used to send notifications to EPNS channels easy. It Provides an abstraction layer above advanced internal EPNS notification functions.

It is written in typescript and requires node v10.0.0 or higher. Most features will work with nodejs v6.0.0 and higher but using older versions than v10.0.0 is not recommended.

About

Installation

npm install @epnsproject/backend-sdk

Usage

In order to use this package, you must first have created a channel at EPNS. Then note the private key of the account you used to create the channel, because we would be using it in this tutorial

// Import the required packages
EpnsSDK, { InfuraSettings, NetWorkSettings, EPNSSettings } = require("'@epnsproject/backend-sdk");
const ethers = require('ethers');

// Define the parameters we would need in order to initialize the SDK
const  CHANNEL_PK = '0x0000000000000000000000000000000000000000000000000000000000000fff'; // the private key of the channel


// Initialise the SDK
const  epnsSdk = new EpnsSDK(CHANNEL_PK);

// get the subscribers to your channel
const allSubscribers = await epnsSdk.getSubscribers()

// send a notification to your subscribers
const response = await epnsSdk.sendNotification(
      recipients, //the recipients of the notification
      pushNotificationTitle, // push notification title
      pushNotificationBody, //push notification body
      notificationTitle, //the title of the notification
      notificationBody, //the body of the notification
      notificationType, //1 - for broadcast, 3 - for direct message, 4 - for subset.
      link, //the CTA of the notification, the link which should be redirected to when they click on the notification
    );
    console.log(response)

API

Initialising the SDK

new EpnsSDK(
	channelKey: string,
	{
		communicatorContractAddress = config.communicatorContractAddress,
		communicatorContractABI = config.communicatorContractABI,
		channelAddress = null,
		networkKeys = DEFAULT_NETWORK_SETTINGS,
		notificationChainId = DEFAULT_NOTIFICATION_CHAIN,
    networkToMonitor =  this.cSettings.networkToMonitor

	} = {}
)
ParameterDescriptionDefault Value
channelKeyThe private key of the account used to create a channel on EPNSN/A (This is the only parameter that is required)
communicatorContractAddressan override parameter if you intend to use a different communicator contract from the production oneFor Main Network:0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa and for Polygon Network: 0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa
communicatorContractABIThe ABI of the communicator contract specifiedDefaults to the latest communicator contract published by EPNS
channelAddressThe ethereum address used to create the channeldefaults to ethers.utils.computeAddress(channelKey) which is the public key of the specified private key
networkKeysThese are important if you want to perform any on chain activities, you will have to provide infura keysThe type of the object containing the keys are as follows interface NetWorkSettings {alchemy?: string;infura?: {projectID: string;projectSecret:string;};etherscan?: string;}
notificationChainIdThe chain on which you want to send notificationsdefaults to 1 which is for the main network, other option is 137 which is for the polygon network
networkToMonitorThe SDK has a method to get a contract, this parameter specifies the chain to fetch contracts for when initialising a contract using the SDK, itdefaults to 1 which is for the main network, but it could potentially be any evm compatible chain.

Getting the subscribers of a particular channel

const  subscribers = await  epnsSdk.getSubscribedUsers();

This returns an array of addresses, which would be those already subscribed to your channel

Sending notifications using the SDK

/**
* Send Notification
* @description Sends notification to a particular user
* @param user User Address
* @param title push notification title of Notification
* @param message push notification Message of Notification
* @param payloadTitle Full notification Title
* @param payloadMsg Full notification Content
*/
public  async  sendNotification(
    recipient: string,
    pushNotificationTitle: string,
    pushNotificationMessage: string,
    notificationTitle: string,
    notificationMesssage: string,
    notificationType: number,
    cta: string | undefined,
    img: string | undefined,
    simulate: any,
  { offChain = true } = {}, //add optional parameter for offchain sending of notification
) {}
ParameterDescriptionValue
recipientThe recipient of the notificationit would be equal to the channelAddress for a broadcast notification(type=1), it would be equal to the recipient address for a direct(targetted notification)(type=3), it would be equal to the comma seperated string of addresses for subset notifications(type=4) e.g0xaddress1, 0xaddress2, 0xaddress3
pushNotificationtitleThis is the title of the notification which would be displayed on the push notificationshorter form of the notification title, it could also be the same as the actual notification title
pushNotificationMessageThis is the message which is going to be displayed on the push notification for this notificationusually a shorter version of the message, but could also be the actual message
notificationTitleThe title/heading of the notification about to be sentany string which is the title of your notification
notificationMesssageThe content of the notification to be sentcould be any string which contains some text
notificationTypeThe type of notification being sent1 ->Broadcast notification to every member of the channel. 3 -> Direct/targetted notification to a particular member of the channel 4 -> subset notifications to a group of subscribers of the channel
ctaThe url which you want user's to be redirected to upon clicking of the notificationsURL or Undefined
imgA url which links to an image you want to be displayed along with your notification
simulateAn object which contains information used for testing purposes or simulating notificationcan safely be set to null
{ offChain = true }an optional parameter which is used to specify choosing to use off chain notificationsdefaults to use off chain notifications.

Getting a deployed contract from the sdk

async  getContract(
	address: string,
	abi: string
) {}
ParameterDescriptionDefault Value
addressSpecify the address of which the contract you seek existsN/A - required parameter
abiSpecify the abi of which the contract you seekN/A - required parameter

CONTRACTS

NETWORKCHAIN IDCONTRACT NAMECONTRACT ADDRESS
MAINNET1EPNS CORE CONTRACT0x66329Fdd4042928BfCAB60b179e1538D56eeeeeE
MAINNET1EPNS COMMUNICATOR CONTRACT0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa
POLYGON137EPNS COMMUNICATOR CONTRACT0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa
2.0.0

2 years ago

1.3.5

2 years ago

1.3.4

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.2.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.0

3 years ago