@notifi-network/notifi-node
Node SDK for Notifi APIs.
This SDK is intended for use with Servers who have obtained a SID / Secret pair from Notifi.
Please reach out to us for help on Discord!
Usage
Instantiating a NotifiClient
import {
NotifiClient,
createGraphQLClient,
createNotifiService,
} from '@notifi-network/notifi-node';
const gqlClient = createGraphQLClient();
const notifiService = createNotifiService(gqlClient);
const client = new NotifiClient(notifiService);
Creating a Tenant User
import { NotifiClient } from '@notifi-network/notifi-node';
const client: NotifiClient = getNotifiClient();
const { token, expiry } = await client.logIn({
sid: MY_SID,
secret: MY_SECRET,
});
const userId = await client.createTenantUser(token, {
walletBlockchain: 'NEAR',
walletPublicKey: 'juni-kim.near',
});
await persistUserIdSomehow(userId);
const alertObject = await client.createDirectPushAlert(token, {
userId,
emailAddresses: [...userEmails],
phoneNumbers: [...userPhoneNumbers],
});
await persistAlertIdSomehow(userId, alertObject.id);
Sending a Direct Push Alert to a user
import { NotifiClient } from '@notifi-network/notifi-node';
const client: NotifiClient = getNotifiClient();
const { token, expiry } = await client.logIn({
sid: MY_SID,
secret: MY_SECRET,
});
const result = await client.sendDirectPush(token, {
key: '<KEY_USED_FOR_IDEMPOTENCY>',
walletBlockchain: 'SOLANA',
walletPublicKey: '<ACCOUNT_ADDRESS>',
template: {
emailTemplate: '<UUID_OF_TEMPLATE_GROUP>',
smsTemplate: '<UUID_OF_TEMPLATE_GROUP>',
variables: {
someTemplateVariable: 'foo',
someOtherTemplateVariable: 'bar',
someOtherTemplateVariable1: 'bar1',
},
},
});
Sending a Broadcast Alert to a user
import * as dotenv from 'dotenv';
import { NotifiClient, NotifiEnvironment, createGraphQLClient, createNotifiService } from '@notifi-network/notifi-node';
const gqlClient = createGraphQLClient();
const notifiService = createNotifiService(gqlClient);
const client = new NotifiClient(notifiService);
dotenv.config();
class App {
private JWT = '';
public async start() {
const result = await client.logIn({
sid: process.env.MY_SID,
secret: process.env.MY_SECRET,
});
this.JWT = result.token;
}
public async sendMessage() {
await client.sendBroadcastMessage(this.JWT, {
topicName: 'yourdappid__announcements',
variables: [
{
key: 'message',
value: 'This is the body of the message I would like my users to receive!',
},
{
key: 'subject',
value: 'Some Special Announcement',
},
],
});
}
}
export default App;