JavaScript SDK
JavaScript SDK for integrating Notiboy
NPM
npm install notiboy-js-sdk
ESM
CJS
import algosdk from "algosdk";
import Notiboy from "notiboy-js-sdk";
const algosdk = require('algosdk');
const Notiboy = require('notiboy-js-sdk').default;
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);
const channelCreationTransaction = await notiboy.createChannel(
Creator Address
);
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.
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.
const txns = await notiboy.channelContractOptin(
Creator Address,
Channel Smart Contract AppID,
Channel Name
);
Returns an array of six transactions.
const txns = await notiboy.channelContractOptin(
"3KOQUDTQAYKMXFL66Q5DS27FJJS6O3E2J3YMOC3WJRWNWJW3J4Q65POKPI",
151406743,
"MINT"
);
The maximum length of channel name limited to 10 characters.
const appIndex = await notiboy.getAddressAppIndex(
Creator Address
)
Returns the channel smart contract app index, if the address is a creator else returns zero.
const appIndex = await notiboy.getAddressAppIndex(
"AAVUPELO5ZCBDA3DD3G7ZDZ64BSEOOE3G7ZBOMR7DKI3YIBXLYEC3EATQA"
)
const channelList = await notiboy.getChannelList();
const txns = await notiboy.channelContractOptout(
Creator Address,
Channel Smart Contract AppID,
Channel Name,
Channel Index
);
const txns = await notiboy.channelContractOptout(
"3KOQUDTQAYKMXFL66Q5DS27FJJS6O3E2J3YMOC3WJRWNWJW3J4Q65POKPI",
151406743,
"MINT",
5
);
const txns = await notiboy.userContractOptin(
End User Address,
);
const txns = await notiboy.userContractOptin(
"SVCYFMQM6QER62RMPSVUHHIZXUIYHBXEZVGUPL6OVBRBNK7LNVGIRYMP3Y",
);
This creates the global box space for the end-user where personal notifications are stored.
const txns = await notiboy.userChannelOptin(
End User Address,
Channel Smart Contract AppID
);
const txns = await notiboy.userChannelOptin(
"SVCYFMQM6QER62RMPSVUHHIZXUIYHBXEZVGUPL6OVBRBNK7LNVGIRYMP3Y",
151406743
);
const txns = await notiboy.userChannelOptout(
Creator Address,
Channel Smart Contract AppID
);
const txns = await notiboy.userChannelOptout(
"SVCYFMQM6QER62RMPSVUHHIZXUIYHBXEZVGUPL6OVBRBNK7LNVGIRYMP3Y",
151406743
);
const txns = await notiboy
.notification()
.sendPublicNotification(
Creator Address,
Channel Smart Contract AppID,
Public Notification
);
const txns = await notiboy
.notification()
.sendPublicNotification(
"3KOQUDTQAYKMXFL66Q5DS27FJJS6O3E2J3YMOC3WJRWNWJW3J4Q65POKPI",
151406743,
"Public notification testing."
);
Each public notification limited to 120 characters.
const publicNotifications = await notiboy
.notification()
.getPublicNotification(
Channel Smart Contract AppID
);
const notifications = await notiboy
.notification()
.getPublicNotification(
151406743
);
const txns = await notiboy
.notification()
.sendPersonalNotification(
Creator Address,
End User Address,
Channel Smart Contract AppID,
Channel Name,
Personal Notification
);
const txns = await notiboy
.notification()
.sendPersonalNotification(
"3KOQUDTQAYKMXFL66Q5DS27FJJS6O3E2J3YMOC3WJRWNWJW3J4Q65POKPI",
"SVCYFMQM6QER62RMPSVUHHIZXUIYHBXEZVGUPL6OVBRBNK7LNVGIRYMP3Y",
151406743,
"MINT",
"Personal Notification number4 from MINT "
);
Each personal notification limited to 280 characters.
const notifications = await notiboy
.notification()
.getPersonalNotification(
End User Address
);
Example:
const notifications = await notiboy
.notification()
.getPersonalNotification(
"SVCYFMQM6QER62RMPSVUHHIZXUIYHBXEZVGUPL6OVBRBNK7LNVGIRYMP3Y"
);
const counter = await notiboy.getCounter(
Creator/End User Address
);
const counter = await notiboy.getCounter(
"3KOQUDTQAYKMXFL66Q5DS27FJJS6O3E2J3YMOC3WJRWNWJW3J4Q65POKPI"
);
const optinState = await notiboy.getNotiboyOptinState(
End User/Creator Address
);
const optinState = await notiboy.getNotiboyOptinState(
"SVCYFMQM6QER62RMPSVUHHIZXUIYHBXEZVGUPL6OVBRBNK7LNVGIRYMP3Y"
);
Checks if the address has opted-in to notiboy smart contract.
const optinState = await notiboy.getChannelScOptinState(
End User Address,
Channel Smart Contract AppID
);
const optinState = await notiboy.getChannelScOptinState(
"SVCYFMQM6QER62RMPSVUHHIZXUIYHBXEZVGUPL6OVBRBNK7LNVGIRYMP3Y",
151406743
);
Checks if the address has opted-in to channel smart contract.
const addressList = await notiboy.getOptinAddressList(
Smart Contract AppID
);
const addressList = await notiboy.getOptinAddressList(
144113274
)
Returns array of addresses (if any) that have opted-in to smart-contract.
const appIndex = await notiboy.getAddressAppIndex(
Creator Address
)
const appIndex = await notiboy.getAddressAppIndex(
"3KOQUDTQAYKMXFL66Q5DS27FJJS6O3E2J3YMOC3WJRWNWJW3J4Q65POKPI"
)
Last modified 28d ago