Nostalgic Punchcard Missing

    @epnsproject/backend-sdk
    TypeScript icon, indicating that this package has built-in type declarations

    2.0.0 • Public • Published

    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
    
    	} = {}
    )
    Parameter Description Default Value
    channelKey The private key of the account used to create a channel on EPNS N/A (This is the only parameter that is required)
    communicatorContractAddress an override parameter if you intend to use a different communicator contract from the production one For Main Network:0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa and for Polygon Network: 0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa
    communicatorContractABI The ABI of the communicator contract specified Defaults to the latest communicator contract published by EPNS
    channelAddress The ethereum address used to create the channel defaults to ethers.utils.computeAddress(channelKey) which is the public key of the specified private key
    networkKeys These are important if you want to perform any on chain activities, you will have to provide infura keys The type of the object containing the keys are as follows interface NetWorkSettings {alchemy?: string;infura?: {projectID: string;projectSecret:string;};etherscan?: string;}
    notificationChainId The chain on which you want to send notifications defaults to 1 which is for the main network, other option is 137 which is for the polygon network
    networkToMonitor The SDK has a method to get a contract, this parameter specifies the chain to fetch contracts for when initialising a contract using the SDK, it defaults 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
    ) {}
    Parameter Description Value
    recipient The recipient of the notification it 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
    pushNotificationtitle This is the title of the notification which would be displayed on the push notification shorter form of the notification title, it could also be the same as the actual notification title
    pushNotificationMessage This is the message which is going to be displayed on the push notification for this notification usually a shorter version of the message, but could also be the actual message
    notificationTitle The title/heading of the notification about to be sent any string which is the title of your notification
    notificationMesssage The content of the notification to be sent could be any string which contains some text
    notificationType The type of notification being sent 1 ->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
    cta The url which you want user's to be redirected to upon clicking of the notifications URL or Undefined
    img A url which links to an image you want to be displayed along with your notification
    simulate An object which contains information used for testing purposes or simulating notification can safely be set to null
    { offChain = true } an optional parameter which is used to specify choosing to use off chain notifications defaults to use off chain notifications.

    Getting a deployed contract from the sdk

    async  getContract(
    	address: string,
    	abi: string
    ) {}
    Parameter Description Default Value
    address Specify the address of which the contract you seek exists N/A - required parameter
    abi Specify the abi of which the contract you seek N/A - required parameter

    CONTRACTS

    NETWORK CHAIN ID CONTRACT NAME CONTRACT ADDRESS
    MAINNET 1 EPNS CORE CONTRACT 0x66329Fdd4042928BfCAB60b179e1538D56eeeeeE
    MAINNET 1 EPNS COMMUNICATOR CONTRACT 0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa
    POLYGON 137 EPNS COMMUNICATOR CONTRACT 0xb3971BCef2D791bc4027BbfedFb47319A4AAaaAa

    Keywords

    none

    Install

    npm i @epnsproject/backend-sdk

    DownloadsWeekly Downloads

    22

    Version

    2.0.0

    License

    ISC

    Unpacked Size

    92.9 kB

    Total Files

    14

    Last publish

    Collaborators

    • epnsproject