Blockscan Chat SDK
A Blockscan Chat API wrapper written in NodeJS
Prerequisites
- NodeJS
To verify installation
node -v
To install
winget install OpenJS.NodeJS
- Blockscan Chat API Key and URL (Apply at https://chat.blockscan.com/apis)
Set Up
- Install this package in your project directory
npm i blockscanchat-sdk
Usage
- Import the package to your project
const BlockscanChat = require('blockscanchat-sdk');
let blockscanchat = new BlockscanChat();
- Initalize the SDK by passing in the Blockscan API_KEY and API_URL parameters specified as your environment variables
blockscanchat.init('YOUR_API_KEY');
- Generally, for all methods, the calling convention is
blockscanchat.<METHOD_NAME>(PARAMETERS)
Example (if method does not require parameters):
blockscanchat.<METHOD_NAME>()
Example (if method requires parameters):
blockscanchat.getExternalMsgCount('EXTERNAL_WALLET_ADDRESS')
MESSAGE ENDPOINT
getLocalMsgCount
Retrieves the unread message count associated with your API key address.
Parameters: None
Usage:
blockscanchat.getLocalMsgCount().then((response) => {
console.log(response);
});
getExternalMsgCount
Retrieves the unread message count of an external address. (you must have additional apikey permissions)
Parameters:
- address (REQUIRED) - The external wallet address.
Usage:
blockscanchat.getExternalMsgCount('WALLET_ADDRESS').then((response) => {
console.log(response);
});
getFirstMsgId
Fetches the ID of the first message.
Parameters: None
Usage:
blockscanchat.getFirstMsgId().then((response) => {
console.log(response);
});
getLastMsgId
Fetches the ID of the last message.
Parameters: None
Usage:
blockscanchat.getLastMsgId().then((response) => {
console.log(response);
});
getAllMsg
Gets unread message count of your apikey address
Parameters:
- startID (OPTIONAL) -> Integer message ID to start searching for chats
- offset (OPTIONAL) -> Number of chats displayed per page, maximum is 100
- cType (OPTIONAL) -> Chat Type, 0 = All, 1 = Incoming Messages, 2 = Outgoing Messages
Usage:
No parameters
blockscanchat.getAllMsg().then((response) => {
console.log(response);
});
With parameters
blockscanchat.getAllMsg({startID: 539070, offset: 99, cType: 2}).then((response) => {
console.log(response);
});
sendMsg
Sends a message to a wallet address
Parameters:
- address (REQUIRED) -> Address you want to send the message to
- message (REQUIRED) -> Message you want to sent to that address
Usage:
blockscanchat.sendMsg('TARGET_ADDRESS', 'YOUR_MESSAGE').then((response) => {
console.log(response);
});
markAllMsgAsRead
All messages with a particular address will be marked as read
Parameters:
- address (REQUIRED) -> The address with which you want to mark the messages as read
Usage:
blockscanchat.markAllMsgAsRead('WALLET_ADDRESS').then((response) => {
console.log(response);
});