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.
Description:
Send a realtime message to one or multiple receivers.
Parameters:
senderId β required
receiverId β single recipient (optional if receiverIds provided)
receiverIds β array of recipient IDs (optional if receiverId provided)
data β message payload
Usage:
If a message exceeds the size limit defined in your subscription plan, it will be counted as multiple messages. You can review the usage breakdown in the Dashboard graphs for better visibility.
sendAI({ senderId, message })
Description:
Send a message to the AI pipeline. Use this instead of sendWithOpenAI.
Parameters:
senderId β required
message β object
Usage:
fetchAIHistory({ senderId })
Description:
Fetch past AI messages sent by a user.
Parameters:
senderId β required
Usage:
sendBinary({ senderId, receiverIds, buffer, type })
Description:
Send binary data (files, images, audio, etc.) to one or more receivers.
Parameters:
senderId β required
receiverIds β array of recipients
buffer β binary data buffer (required)
type β optional, default "binary"
Usage:
Full Workflow Example β NPM SDK (Safe Post-Connection)
// Use it for string / textual messages
message : {
text : "hey ai, what you can do for me?"
useKnowledgeBase: false // or true, if you want to use Knowledge base for the agent.
}
// Use for context and multiple messages
message : {
messages : [
{ role: "user" , content : "hey ai...!" } ,
{ role: "user" , content : "what can do you for me?" }
],
useKnowledgeBase: false // or true, if you want to use Knowledge base for the agent.
}
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);