JavaScript / TypeScript

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:

await client.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.

Returns:

{
  messagesHardLimit,
  maxAIRequestsPerMonth,
  maxAIWordsPerMonth,
  knowledgeBaseMaxWords,
  aiEnabled,
  maxUsers,
  maxRowsPerUser
}

Usage:


send({ senderId, receiverId, receiverIds, data })

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:


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)

Last updated