PubNub JavaScript Chat API & SDK Docs 0.14.2
The JavaScript Chat SDK helps you build feature-rich chat apps or add chat to existing applications. Written in TypeScript, the SDK builds on the JavaScript SDK and PubNub APIs to provide a streamlined developer experience.
Why use the Chat SDK?
The Chat SDK simplifies chat development with these benefits:
- Chat-focused methods - Call intuitive methods like
startTyping()andjoin()instead of working with low-level APIs. - Built-in features - Use ready-made features like quotes, mentions, channel references, threads, rate limiting, and read receipts.
- Framework flexibility - Build web, mobile, or desktop apps with React, React Native, Vue.js, Angular, Electron, Svelte, Nest, Express, or any JavaScript-based framework.
- UI freedom - Design your own interface or use open-source UI libraries like Chat UI Kit (React) or Gifted Chat (React Native).
Learn more
Explore the Learn section for deeper understanding:
- Chat SDK architecture - Design principles and structure
- Access control - Authentication and authorization
- Chat SDK entities - Core objects, properties, and methods
- Glossary - Key terms and concepts
Installation
The JavaScript Chat SDK is available as the @pubnub/chat package. You can install it using a package manager or load it directly from the PubNub CDN.
Environment setup
For detailed guidance on Node.js versions, TypeScript configuration, and modern build tools, refer to the JavaScript Environment Setup guide.
Package manager
Install the @pubnub/chat package using npm, yarn, pnpm, or bun:
npm install @pubnub/chat
yarn add @pubnub/chat
pnpm add @pubnub/chat
bun add @pubnub/chat
CDN
Alternatively, include the SDK directly in your HTML by referencing the PubNub CDN:
<script src="https://cdn.pubnub.com/sdk/js-chat/pubnub-chat.0.14.2.js"></script>
Once installed, initialize the Chat SDK to configure it for the features you want to implement.
The JavaScript Chat SDK is also available on GitHub.
Get started
Follow these steps to build your first chat app:
-
Create a PubNub account - Sign up at the Admin Portal and create an app. You need the publish and subscribe keys from your keyset.
Sign up
Don't feel like leaving this page to sign up?
Required keyset configuration
To use the getChannels(), getChannelSuggestions(), getUsers(), and getUserSuggestions() methods in the Chat SDKs with Access Manager, you must uncheck the Disallow Get All Channel Metadata and Disallow Get All User Metadata checkboxes in the App Context section of your keyset configuration in the Admin Portal. -
Run the sample app - Follow the Sample chat guide to see a working example.
-
Build your app:
- Initialize the Chat SDK with your keys and settings.
- Add channels, users, messages, and other features.
Sample apps
Explore working examples:
| App | Description |
|---|---|
| Interactive chat demo | Full-featured TypeScript demo (mobile version) |
| Direct chat (React) | 1:1 chat app with Getting Started guide |
| Group chat (React Native) | Multi-user chat sample |