2.0.3 • Published 2 years ago

@epnsproject/backend-sdk-staging v2.0.3

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

Frontend 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-staging

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-staging");
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,
	} = {}
)
ParameterDescriptionDefault Value
channelKeyThe private key of the account used to create a channel on EPNSN/A (This is the only parameter not required)
communicatorContractAddressan override parameter if you intend to use a different communicator contract from the staging oneFor Kovan Network:0x87da9Af1899ad477C67FeA31ce89c1d2435c77DC and for Polygon Network: 0xD2ee1e96e3592d5945dDc1808834d7EE67400823
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 42 which is for the kovan network, other option is 80001 which is for the kovan network

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(
	chainId: string,
	address: string,
	abi: string
) {}
ParameterDescriptionDefault Value
chainIdSpecify the id of the chain on which the contract ye seek existsN/A - required parameter
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
KOVAN42EPNS CORE CONTRACT STAGING0x97D7c5f14B8fe94Ef2b4bA589379f5Ec992197dA
KOVAN42EPNS COMMUNICATOR CONTRACT STAGING0x97D7c5f14B8fe94Ef2b4bA589379f5Ec992197dA
POLYGON80001EPNS COMMUNICATOR CONTRACT STAGING0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa
1.3.6

2 years ago

1.3.5

2 years ago

1.3.2

2 years ago

2.0.3

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

3 years ago

1.0.0

3 years ago