Notiboy Project
Search…
⌃K

JavaScript SDK

JavaScript SDK for integrating Notiboy

Documentation

Install Package

NPM
npm install notiboy-js-sdk

Import Package

ESM
CJS
import algosdk from "algosdk";
import Notiboy from "notiboy-js-sdk";
const algosdk = require('algosdk');
const Notiboy = require('notiboy-js-sdk').default;

Setup

const client = new algosdk.Algodv2("", "https://mainnet-api.algonode.cloud", "");
const indexer = new algosdk.Indexer("", "https://mainnet-idx.algonode.cloud", "");
const notiboy = new Notiboy(client, indexer);

Creating Channel Smart Contract

const channelCreationTransaction = await notiboy.createChannel(
Creator Address
);

Example:

const channelCreationTransaction = await notiboy.createChannel(
"3KOQUDTQAYKMXFL66Q5DS27FJJS6O3E2J3YMOC3WJRWNWJW3J4Q65POKPI"
);
A dApp can pass their smart contract App ID instead of creating a new app id. This will allow them to send personal notification to all the addresses opted-in to the smart contract provided the addresses have opted-in to notiboy smart contract (end user global Opt-in). The address that create the channel should be the owner of channel smart contract. Note: We will provide a channel opt-out method in our UI which if the end user trigger will opt-out them from the channel smart contract.

Channel Smart Contract App ID

const txnInfo = await indexer.lookupTransactionByID(txId).do();
const appId = txnInfo['transaction']['created-application-index'];
In case you choose to use the channel creation process, app id of the channel smart contract has to be passed on to Notiboy smart contract to register the channel. Use this method to get app id after channel creation. Here txId is the transaction id of the channel creation transaction.

Creator Global Opt-In (Registering the channel with Notiboy)

const txns = await notiboy.channelContractOptin(
Creator Address,
Channel Smart Contract AppID,
Channel Name
);
Returns an array of six transactions.

Example:

const txns = await notiboy.channelContractOptin(
"3KOQUDTQAYKMXFL66Q5DS27FJJS6O3E2J3YMOC3WJRWNWJW3J4Q65POKPI",
151406743,
"MINT"
);
The maximum length of channel name limited to 10 characters.

App Index from Address

const appIndex = await notiboy.getAddressAppIndex(
Creator Address
)
Returns the channel smart contract app index, if the address is a creator else returns zero.

Example:

const appIndex = await notiboy.getAddressAppIndex(
"AAVUPELO5ZCBDA3DD3G7ZDZ64BSEOOE3G7ZBOMR7DKI3YIBXLYEC3EATQA"
)

List Channels

const channelList = await notiboy.getChannelList();
Returns array of objects. Each object representing the details of a channel.

Creator Global Opt-Out

const txns = await notiboy.channelContractOptout(
Creator Address,
Channel Smart Contract AppID,
Channel Name,
Channel Index
);

Example:

const txns = await notiboy.channelContractOptout(
"3KOQUDTQAYKMXFL66Q5DS27FJJS6O3E2J3YMOC3WJRWNWJW3J4Q65POKPI",
151406743,
"MINT",
5
);
Channel index will be available from channel list.

End User Global Opt-in

const txns = await notiboy.userContractOptin(
End User Address,
);

Example:

const txns = await notiboy.userContractOptin(
"SVCYFMQM6QER62RMPSVUHHIZXUIYHBXEZVGUPL6OVBRBNK7LNVGIRYMP3Y",
);
This creates the global box space for the end-user where personal notifications are stored.

End User Channel Opt-in

const txns = await notiboy.userChannelOptin(
End User Address,
Channel Smart Contract AppID
);

Example:

const txns = await notiboy.userChannelOptin(
"SVCYFMQM6QER62RMPSVUHHIZXUIYHBXEZVGUPL6OVBRBNK7LNVGIRYMP3Y",
151406743
);

End User Channel Opt-out

const txns = await notiboy.userChannelOptout(
Creator Address,
Channel Smart Contract AppID
);

Example:

const txns = await notiboy.userChannelOptout(
"SVCYFMQM6QER62RMPSVUHHIZXUIYHBXEZVGUPL6OVBRBNK7LNVGIRYMP3Y",
151406743
);

Send Public Notification

const txns = await notiboy
.notification()
.sendPublicNotification(
Creator Address,
Channel Smart Contract AppID,
Public Notification
);

Example:

const txns = await notiboy
.notification()
.sendPublicNotification(
"3KOQUDTQAYKMXFL66Q5DS27FJJS6O3E2J3YMOC3WJRWNWJW3J4Q65POKPI",
151406743,
"Public notification testing."
);
Each public notification limited to 120 characters.

Read Public Notification

const publicNotifications = await notiboy
.notification()
.getPublicNotification(
Channel Smart Contract AppID
);

Example:

const notifications = await notiboy
.notification()
.getPublicNotification(
151406743
);
Returns an array of objects.

Send Personal Notification

const txns = await notiboy
.notification()
.sendPersonalNotification(
Creator Address,
End User Address,
Channel Smart Contract AppID,
Channel Name,
Personal Notification
);

Example:

const txns = await notiboy
.notification()
.sendPersonalNotification(
"3KOQUDTQAYKMXFL66Q5DS27FJJS6O3E2J3YMOC3WJRWNWJW3J4Q65POKPI",
"SVCYFMQM6QER62RMPSVUHHIZXUIYHBXEZVGUPL6OVBRBNK7LNVGIRYMP3Y",
151406743,
"MINT",
"Personal Notification number4 from MINT "
);
Each personal notification limited to 280 characters.

Read Personal Notification

const notifications = await notiboy
.notification()
.getPersonalNotification(
End User Address
);

Example:

Example:
const notifications = await notiboy
.notification()
.getPersonalNotification(
"SVCYFMQM6QER62RMPSVUHHIZXUIYHBXEZVGUPL6OVBRBNK7LNVGIRYMP3Y"
);
Returns an array of objects.

Get Counter

const counter = await notiboy.getCounter(
Creator/End User Address
);

Example:

const counter = await notiboy.getCounter(
"3KOQUDTQAYKMXFL66Q5DS27FJJS6O3E2J3YMOC3WJRWNWJW3J4Q65POKPI"
);
Returns an object. For end-user address the public notification counter will be always zero.

Get Global Opt-in State

const optinState = await notiboy.getNotiboyOptinState(
End User/Creator Address
);

Example:

const optinState = await notiboy.getNotiboyOptinState(
"SVCYFMQM6QER62RMPSVUHHIZXUIYHBXEZVGUPL6OVBRBNK7LNVGIRYMP3Y"
);
Checks if the address has opted-in to notiboy smart contract.

Get Channel SC Opt-in State

const optinState = await notiboy.getChannelScOptinState(
End User Address,
Channel Smart Contract AppID
);

Example:

const optinState = await notiboy.getChannelScOptinState(
"SVCYFMQM6QER62RMPSVUHHIZXUIYHBXEZVGUPL6OVBRBNK7LNVGIRYMP3Y",
151406743
);
Checks if the address has opted-in to channel smart contract.

Get Opted-in List of Addresses

const addressList = await notiboy.getOptinAddressList(
Smart Contract AppID
);

Example:

const addressList = await notiboy.getOptinAddressList(
144113274
)
Returns array of addresses (if any) that have opted-in to smart-contract.

Get Channel App Index

const appIndex = await notiboy.getAddressAppIndex(
Creator Address
)

Example:

const appIndex = await notiboy.getAddressAppIndex(
"3KOQUDTQAYKMXFL66Q5DS27FJJS6O3E2J3YMOC3WJRWNWJW3J4Q65POKPI"
)
Returns an object. If the address has not created a channel the channelAppIndex will be 0.