Sendbird Chat SDK v3 for JavaScript

3.1.33 · deprecated · verified Sun Apr 19

The Sendbird Chat SDK v3 for JavaScript (current stable v3.1.33) facilitates the integration of real-time chat functionalities into client applications, abstracting the complexities of backend infrastructure. It enables core chat features such as user authentication, channel management (open and group channels), message sending and receiving, and event handling. This version is officially deprecated, with v3.1.33 being its final release in August 2023. Sendbird is actively transitioning users to its v4 SDK, which was first released in April 2022 and offers an extended feature set including enhanced WebSocket handling, improved local caching, polls, scheduled messages, and pinned messages. Developers are strongly encouraged to migrate to v4 due to the end of support and future bug fixes for v3.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates initializing the Sendbird SDK, connecting a user, entering an open channel, and sending a basic user message, including handling environment variables for credentials.

import SendBird from 'sendbird';

const APP_ID = process.env.SENDBIRD_APP_ID ?? 'YOUR_SENDBIRD_APP_ID';
const USER_ID = process.env.SENDBIRD_USER_ID ?? 'testuser123';
const NICKNAME = process.env.SENDBIRD_USER_NICKNAME ?? 'Test User';

const sb = new SendBird({
  appId: APP_ID,
  modules: [new SendBird.ChannelModule(), new SendBird.MessageModule()]
});

async function initializeAndConnect() {
  try {
    console.log('Connecting to Sendbird...');
    const user = await sb.connect(USER_ID);
    console.log(`Connected as ${user.nickname} (${user.userId})`);

    // Create or get a channel
    const channelUrl = process.env.SENDBIRD_CHANNEL_URL ?? 'sendbird_open_channel_28653_373c38c116d90a78627e7f77a880949216065548';
    const channel = await sb.OpenChannel.getChannel(channelUrl);
    await channel.enter();
    console.log(`Entered channel: ${channel.name}`);

    // Send a message
    const messageText = `Hello from SDK v3! Current time: ${new Date().toLocaleTimeString()}`;
    const params = new sb.UserMessageParams();
    params.message = messageText;
    const message = await channel.sendUserMessage(params);
    console.log('Message sent:', message.message);

    // Disconnect (optional, for cleanup)
    // await sb.disconnect();
    // console.log('Disconnected from Sendbird.');
  } catch (error) {
    console.error('Sendbird operation failed:', error);
  }
}

initializeAndConnect();

view raw JSON →