The DNotifier NPM SDK allows developers to integrate Realtime Chat, Pub/Sub messaging, and AI features into any JavaScript environment (Node.js, React, Angular, Next.js, NestJS, Vue, etc.).
Below are the main functions available and examples for each.
connect()
Description:
Authenticates with DNotifier and establishes a WebSocket connection. Sets up message listeners and handshake.
Usage:
awaitclient.connect();
Callbacks (optional):
onConnected β called after successful connection
onMessage β called for every incoming message
onDisconnected β called if the connection closes or errors
getPlanLimits()
Description:
Returns the current subscription limits after authentication, including AI and messaging limits.
import { DNotifier } from "@dnotifier-realtime/dnotifier";
const client = new DNotifier({
appId: "YOUR_APP_ID", // Replace with your App ID
secret: "YOUR_SECRET", // Replace with your App Secret
userId: "user123", // Your user ID
transport: "ws", // Use WebSocket transport
onConnected: () => {
console.log("Connected to DNotifier!");
// Send a simple text message after connection
client.send({
senderId: "user123",
receiverId: "user456",
data: { text: "Hello!" }
});
// Send a message to AI pipeline after connection
client.sendAI({
senderId: "user123",
message: { text : "Explain DNotifier in simple terms." }
//message : { messages : [] }
});
console.log("Messages sent!");
},
onMessage: (msg) => console.log("Received:", msg),
onDisconnected: (info) => console.log("Disconnected:", info)
});
// Connect to DNotifier
client.connect().catch(console.error);