Chat object

Once you initialize the Chat SDK and create its instance, you'll get immediate access to the Chat entity from which you can call the PubNub server.

To communicate with PubNub, you can use various methods. For example, you can use deleteChannel() to remove a given channel (Chat.deleteChannel("support")) or wherePresent() to check which channels a given user is subscribed to (Chat.wherePresent("support_agent_15")).

By calling methods on the Chat entity, you create chat objects like Channel, User, Message, Membership, ThreadChannel, ThreadMessage, and MessageDraft. These objects also expose Chat API under various methods, letting you perform CRUD operations on messages, channels, users, the related user-channel membership, and many more.

Each of these entities comes with a set of readonly parameters you define when creating, modifying, and deleting specific channels, users, messages, or memberships in your chat app.


The Chat object has the following properties:

class Chat {
sdk: PubNub,
config: ChatConfig
sdkPubNubsdk lets you access any JavaScript SDK method. For example, if you want to call a method available in the App Context API, you'd use chat.sdk.objects.getAllUUIDMetadata().
configChatConfigChatConfig contains chat app configuration settings, such as saveDebugLog or typingTimeout that you provide when initializing your chat app with the init() method. You can later directly access these properties, like: chat.storeUserActivityInterval.

ChatConfig includes these properties:

type ChatConfig = {
// For logging errors
saveDebugLog: boolean;
// For typing indicator
typingTimeout: number;
// Two properties for enabling user's global presence & for tracking the user's last online activity
storeUserActivityInterval: number;
storeUserActivityTimestamps: boolean;
// For push notifications
pushNotifications: {
sendPushes: boolean;
deviceToken?: string;
deviceGateway: "apns2" | "gcm";
apnsTopic?: string;
apnsEnvironment: "development" | "production";
show all 22 lines

To initialize the Chat SDK, you must provide three parameters: publishKey, subscribeKey, and userId, while all other settings (mentioned above) are optional. Read the Configuration page for details.


You can call the following methods on the Chat object.

Click on each method for more details.

Use case

For example, you can use the Chat object methods to:

Last updated on