• Stars
    star
    101
  • Rank 338,166 (Top 7 %)
  • Language
  • License
    Other
  • Created almost 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Sendbird Chat SDK for JavaScript for enablement of a rich, engaging, scalable, and real-time chat service.

Sendbird Chat SDK v3 for JavaScript

Platform Languages npm

Deprecation Note (v3)

โš ๏ธ Please note that Sendbirdโ€™s SDK v3 will be deprecated by July 2023. You may still use the older SDKs at your choice, but no new updates or bug fixes will be made to SDK v3.

We recommend clients to plan their migration to SDK v4 as early as possible as there are breaking changes. We also provide prioritized support for migration and any issues related to v4. SDK v4 provides far richer and robust features in Websocket, Local caching, Polls, Scheduled Messages, Pinned Message, and many more. So try it out now! (Chat SDK v4)


Table of contents

  1. Introduction
  2. Before getting started
  3. Getting started
  4. Sending your first message
  5. Appendix
  6. Notice
  7. Changelogs

Introduction

Through Sendbird Chat SDK for Javascript, you can efficiently integrate real-time chat into your client app. On the client-side implementation, you can initialize, configure and build the chat with minimal effort. On the server-side, Sendbird ensures reliable infra-management services for your chat within the app. This read.me provides the Chat SDKโ€™s structure, supplementary features, and the installation steps.

How it works

It is simple to implement chat in your client app with the Chat SDK: a user logs in, sees a list of channels, selects or creates an open channel or a group channel, and, through the use of the channel event handlers, sends messages to the channel, while also receiving them from other users within the channel.

More about Sendbird Chat SDK for JavaScript

Find out more about Sendbird Chat for JavaScript on Chat SDK for JavaScript doc.


Before getting started

This section shows you the prerequisites you need to check for using Sendbird Chat SDK for JavaScript. If you have any comments or questions regarding bugs and feature requests, visit Sendbird community.

Supported browsers

Browser Supported versions
Internet Explorer 10 or higher
Edge 13 or higher
Chrome 16 or higher
Firefox 11 or higher
Safari 7 or higher
Opera 12.1 or higher
iOS Safari 7 or higher
Android Browswer 4.4 (Kitkat) or higher

More about additional features of Sendbird the the Chat SDK

Try building your Sendbird application with these two add-ons:

  • Sendbird UIKit for JavaScript: a development kit with a user interface that enables an easy and fast integration of standard chat features into new or existing client apps.
  • Sendbird SyncManager for JavaScript: the Chat SDK add-on that optimizes the user caching experience by interlinking the synchronization of the local data storage with the chat data in Sendbird server through an event-driven structure.

Getting started

This section gives you information you need to get started with Sendbird Chat SDK for JavaScript.

Try the sample app

The fastest way to test the Chat SDK is to build your chat app on top of our sample app. To create a project for the sample app, download the app from our GitHub repository. The link is down below.

You can also download the sample using a git command:

$ git clone https://github.com/sendbird/SendBird-JavaScript

Note: Find out more about Sendbird SDK for JavaScript samples on https://sample.sendbird.com

Different sample projects

For JavaScript, Sendbird supports a variety of sample projects. Their installation procedures are detailed as below:

Run the web sample projects

There are three web sample projects: basic sample, live chat sample, and widget sample. To run the sample projects, do the following to use NodeJS for your local server:

  1. Download and install NodeJS if your system doesn't have it yet.
  2. Open a terminal and move to the project path.
$ cd web-basic-sample
  1. Install packages that are used in the sample project.
$ npm install
  1. Run the sample project.
$ npm start

Run the React Native sample project

Our React Native sample project is built on the Redux pattern of React Native. To run the sample, do the following:

  1. Download and install NodeJS if your system doesn't have it yet.
  2. Setup the React Native environment in your system.
  3. Open a terminal and enter the commands below in your project path.
$ cd react-native-redux-sample/ReactNativeWithSendBird
$ npm install
  1. Run the sample app by entering the commands below.
$ react-native run-ios
$ react-native run-android

Before entering the two commands above, you should run the simulator from the Android Studio in advance. The command for iOS works without further action.

Here are the steps to install Chat SDK

Follow the simple steps below to build the Chat SDK into your client app.

Step 1: Create a Sendbird application from your dashboard

A Sendbird application comprises everything required in a chat service including users, message, and channels. To create an application:

  1. Go to the Sendbird Dashboard and enter your email and password, and create a new account. You can also sign up with a Google account.
  2. When prompted by the setup wizard, enter your organization information to manage Sendbird applications.
  3. Lastly, when your dashboard home appears after completing setup, click Create + at the top-right corner.

Regardless of the platform, only one Sendbird application can be integrated per app; however, the application supports communication across allSendbirdโ€™s provided platforms without any additional setup. Sendbird currently supports iOS, Android, web, .NET, and Unity client apps.

Note: All the data is limited to the scope of a single application, thus the users in different Sendbird applications are unable to chat with each other.

Step 2: Install the Chat SDK

If youโ€™re familiar with using external libraries or SDKs, installing the Chat SDK is simple.You can install the Chat SDK with package manager npm or yarn by entering the command below on the command line.

  • Npm

Note: To use npm to install the Chat SDK, Node.js must be first installed on your system.

$ npm install sendbird (request to npm server)

Install via Npm and import like below in your TypeScript file.

import * as SendBird from "sendbird";
var sb = new SendBird({ appId: "APP_ID" });
// do something...

If you have trouble importing Sendbird, please check your tsconfig.json file and change the value of allowSyntheticDefaultImports to true in compilerOptions.

  • Yarn
$ yarn add sendbird

Or download the latest Chat SDK for JavaScript from the following link if you do not want to use package manager

Note: You should also add axios library into the <script> tag before the Sendbird library inclusion since v3.0.127. You can host the library or utilize the CDN as the library refers to it. The following serves as examples.

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="/your-own-path-to-sendbird/Sendbird.min.js"></script>

Sending your first message

Follow the step-by-step instructions below to authenticate and send your first message.

Authentication

To use the features of the Chat SDK in your client app, a sb instance must be initiated in each client app before user authentication with Sendbird server. These instances communicate and interact with the server based on an authenticated user account, allowing for the client app to use the Chat SDK features.

Step 1: Initialize the Chat SDK

You need to initialize a sb instance before authentication. Initialization binds the Chat SDK to Javascriptโ€™s context which allows the Chat SDK to respond to connection and state changes and also enables client apps to use the Chat SDK features.

To initialize a Sendbird instance, pass the App_ID of your Sendbird application in the dashboard as an argument to a parameter in the new Sendbird() method. As the new SendBird() can only be a single instance, call it only a single time across your Javascript client app. Typically, initialization is implemented in the user login screen.

Note: It is recommended to initialize the Chat SDK at the top of your Javascript file.

var sb = new SendBird({appId: APP_ID});

Step 2: Connect to Sendbird server

After initialization by use of new SendBird(), your client app must always be connected to Sendbird server before calling any methods. If you attempt to call a method without connecting, an ERR_CONNECTION_REQUIRED (800101) error would return.

Connect a user to Sendbird server either through a unique user ID or in combination with an access token. Sendbird prefers the latter method, as it ensures privacy with the user. The former is useful during the developmental phase or if your service doesn't require additional security.

A. User ID

Connect a user to Sendbird server using their unique user ID. By default, Sendbird server can authenticate a user by a unique user ID. Upon request for a connection, the server queries the database to check for a match. Any untaken user ID is automatically registered as a new user to the Sendbird system, while an existing ID is allowed to log indirectly. The ID must be unique within a Sendbird application, such as a hashed email address or phone number in your service.

sb.connect(USER_ID, function(user, error) {
    if (error) {
        return;
    }
});

B. A combination of user ID and access token ID

Sendbird prefers that you pass the APP ID through the use of a token, as it ensures privacy for the users. Create a user along with their access token, or issue an access token for an existing user. Once an access token is issued, a user is required to provide the access token in the sb.connect() method which is used for logging in.

  1. Using the Chat Platform API, create a Sendbird user account with the information submitted when a user signs up your service.
  2. Save the user ID along with the issued access token to your persistent storage which is securely managed.
  3. When the user attempts to log in to the Sendbird application, load the user ID and access token from the storage, and then pass them to the sb.connect() method.
  4. Periodically replacing the user's access token is recommended to protect the account.
sb.connect(USER_ID, ACCESS_TOKEN, function(user, error) {});

- Tips for user account security

From Settings > Application > Security > Access token permission setting in your dashboard, you can prevent users without an access token from logging in to your Sendbird application or restrict their access to read and write messages.

For security reasons, you can also use a session token when a user logs in to Sendbird server instead of an access token. Go to the Access token vs. Session token section from the Chat Platform API guide to learn more.

Step 3: Create a new open channel

Create an open channel. Once created, all users in your Sendbird application can easily participate in the channel. You also can create a group channel by inviting users as new members to the channel.

Note: All the methods in the following steps are asynchronous, excluding the new SendBird(). As a result, your client app must receive success callbacks from Sendbird server to proceed to the next step. A good way to do this is the nesting of methods: Go to Step 4: Enter the channel to learn more about how you can nest the openChannel.enter() in the OpenChannel.getChannel() method.

sb.OpenChannel.createChannel(function(openChannel, error) {
    if (error) {
        return;
    }
});

Step 4: Enter the channel

Enter the channel to send and receive messages.

sb.OpenChannel.getChannel(CHANNEL_URL, function(openChannel, error) {
    if (error) {
        return;
    }

    openChannel.enter(function(response, error) {
        if (error) {
            return;
        }
    })
});

Step 5: Send a message to the channel

Finally, send a message to the channel. There are three types: a user message, which is a plain text, a file message, which is a binary file, such as an image or PDF, and an admin message, which is a plain text sent through the dashboard or Chat Platform API.

openChannel.sendUserMessage(MESSAGE, DATA, CUSTOM_TYPE, function(message, error) {
    if (error) {
        return;
    }
});

Appendix

Sendbird wants customers to be confident that Chat SDK will be useful, work well, and fit within their needs. Thus, we have compiled a couple of optional guidelines. Take a few minutes to read and apply them at your convenience.

XSS prevention

XSS (Cross-site scripting) is a type of computer security vulnerability. XSS helps attackers inject client-side scripts into web pages viewed by other users. Users can send any type of string data without restriction through Chat SDKs. Make sure that you check the safety of received data from other users before rendering it into your DOM.

Note: For more about the XSS prevention, visit the OWASP's XSS Prevention Cheat Sheet page.

Use functions of Sendbird objects with Immutable-js

If you are using the Immutable-js in your web app, instead of the Immutable.Map(), call the Immutable.fromJS() which converts deeply nested objects to an Immutable Map. So you can call the functions of Sendbird objects because the fromJS() method returns internal objects. But if you use a Map function, you can't call any functions of a Sendbird object.

var userIds = ['John', 'Harry'];

sb.GroupChannel.createChannelWithUserIds(userIds, false, NAME, COVER_URL, DATA, function(groupChannel, error) {
    if (error) {
        return;
    }

    var immutableObject = Immutable.fromJS(groupChannel);
    console.log(immutableObject);
});

Parameter ordering in callbacks

In a callback, the error parameter is passed last in order by default. For example, the connect() method below returns parameters in (user, error) order.

sb.connect(USER_ID, function(user, error) {});

You can configure your Sendbird application to change the order by calling the sb.setErrorFirstCallback(true). Once true is set, all callbacks pass the error as the first parameter.

sb.setErrorFirstCallback(true);
sb.connect(USER_ID, function(error, user) {});

The sb.setErrorFirstCallback(false) returns callbacks to their original parameter ordering, with errors last.

Note: Go to the Event handler page to learn more about the usages of the Chat SDK's handlers and callbacks.


Notice

v.3.1.0 Release (Local Caching)

Local caching has been introduced to the Chat SDK in this v3.1.0 release. The newly embedded local caching functionalities can be enabled through an optional parameter localCacheEnabled in the Sendbird constructor, whose default is false. When local caching is turned off, the SDK is backward compatible with v3.0. This means it will work exactly the same as v3.0 and therefore is compatible with SyncManager. However, we strongly recommend you to use the Chat SDK with local caching instead of SyncManager for the following reasons:

  • Sendbird Chat SDK with local caching supports new functionalities such as group channel collection, message collection, and message auto-resend.
  • SyncManager will be deprecated eventually as the embedded local caching serves as the new and better version of it.

For further information, please see our Docs.

Additionally, migration guide for clients currently using SyncManager will be available soon.


Changelogs

v3.1.33 (Aug 24, 2023)

Thank you everyone for using our SDK v3. This is our final release as we transition to our latest SDK v4 (first released in Apr 2022). Please reach out to our support if you have any questions.

Improvements

  • Fixed a bug where called ChangeLogAPI infinitely

If you want to check the record of other versions, go to Change Log.

More Repositories

1

sendbird-javascript-samples

A guide of the installation and functions of Sendbird Chat, UIKit, and SyncManager for JavaScript samples.
JavaScript
345
star
2

quickstart-calls-reactjs

TypeScript
240
star
3

SendBird-Android

A guide of the installation and functions of Sendbird Chat, and SyncManager for Android samples.
Java
206
star
4

sendbird-uikit-react

Build chat in minutes with Sendbird UIKit open source code.
TypeScript
195
star
5

SendBird-iOS

A guide of the installation and functions of Sendbird Chat, UIKit, and SyncManager for iOS in Objective-C samples.
127
star
6

sendbird-uikit-ios

Sendbird UIKit for iOS is a development kit with a user interface, offering a simplified integration into chat.
Swift
98
star
7

sendbird-uikit-react-native

Build chat in minutes with Sendbird UIKit open source code.
TypeScript
70
star
8

sendbird-ios-framework

[Deprecated] Sendbird Chat SDK for iOS in Objectivce-C for enablement of a rich, engaging, scalable, and real-time chat service.
Objective-C
61
star
9

sendbird-chat-sample-flutter

Dart
59
star
10

sendbird-chat-sdk-flutter

Sendbird Chat SDK for Flutter
Dart
52
star
11

sendbird-chat-sample-react

SendBird Chat SDK sample for React.
JavaScript
46
star
12

sb-osc

Sendbird's Online Schema Change Tool for Aurora MySQL
Python
42
star
13

sendbird-uikit-android

Build chat in minutes with Sendbird UIKit open source code and samples.
Java
39
star
14

sendbird-chat-sample-ios

This repository provides feature-level Chat samples with Swift.
Swift
33
star
15

SendBird-SDK-Android

Sendbird Chat SDK for Android for enablement of a rich, engaging, scalable, and real-time chat service.
32
star
16

chat-ai-widget

Build AI Chatbot in minutes with Sendbird Chatbot Widget.
TypeScript
28
star
17

sendbird-chat-sdk-javascript

Sendbird Chat SDK for JavaScript.
JavaScript
25
star
18

quickstart-calls-directcall-ios

iOS sample for Direct Call of Sendbird Calls, guiding you to build a real-time voice and video calls quickly and easily.
Swift
25
star
19

sendbird-chat-sdk-ios

Sendbird Chat SDK for iOS for enablement of a rich, engaging, scalable, and real-time chat service.
Shell
20
star
20

sendbird-sample

SendBird - Messaging and Chat API for Mobile Apps and Websites
18
star
21

SendBird-iOS-Swift

A guide of the installation and functions of Sendbird Chat for iOS in Swift sample.
Swift
17
star
22

quickstart-calls-directcall-android

Sendbird Calls for Android sample, guiding you to build a real-time voice and video calls quickly and easily.
Java
15
star
23

SendBird-UIKIT-JavaScript

Sendbird UIKit for JavaScript is a development kit with a user interface, offering a simplified integration into chat.
JavaScript
15
star
24

sendbird-webrtc-ios

This is WebRTC framework for iOS that SendBird builds on top of Google WebRTC
Ruby
13
star
25

sendbird-calls-javascript

A guide of Sendbird Calls SDK for JavaScript for an engaging voice and video call experience.
Shell
13
star
26

quickstart-calls-javascript

Sendbird Calls for JavaScript sample, guiding you to bulid a real-time voice and video calls quickly and easily.
JavaScript
12
star
27

sendbird-calls-sdk-react-native-legacy

Sendbird Calls SDK for React-Native
TypeScript
12
star
28

sendbird-calls-android

A guide of Sendbird Calls SDK for Android for an engaging voice and video call experience.
11
star
29

sendbird-platform-sdk-python

Sendbird Platform API SDK for server languages
Python
11
star
30

sendbird-chat-sample-android

Kotlin
11
star
31

sendbird-calls-ios

A guide of Sendbird Calls SDK for iOS for an engaging voice and video call experience.
Objective-C
11
star
32

AndroidChatTutorial

Chat tutorial source code
Java
10
star
33

mymessenger_tutorial

Objective-C
10
star
34

sendbird-platform-sdk-typescript

Sendbird Typescript SDK for the server to server API
TypeScript
10
star
35

sendbird-chat-sample-unity

A guide of the installation and functions of Sendbird Chat for Unity sample.
C#
9
star
36

sendbird-chat-sdk-android

Sendbird Chat SDK for Android
Shell
9
star
37

sendbird-chat-sdk-dotnet

Sendbird Chat SDK for .NET for enablement of a rich, engaging, scalable, and real-time chat service.
9
star
38

sendbird-platform-sdk-java

Sendbird Platform SDK for Java
Java
8
star
39

sendbird-syncmanager-javascript

Sendbird SyncManager for JavaScript is an add-on for reliable chat data caching with Chat SDK features.
8
star
40

sendbird-syncmanager-ios

Sendbird SyncManager for iOS is an add-on for reliable chat data caching with Chat SDK features.
Objective-C
7
star
41

sendbird-calls-directcall-quickstart-react-native

quickstart-calls-directcall-react-native
TypeScript
6
star
42

sendbird-swiftui-ios

https://sendbird.com/docs/chat/uikit/v3/swiftui/overview
Swift
6
star
43

sendbird-chatube

Objective-C
5
star
44

examples-calls-javascript

This repository provides feature-level Calls samples with JavaScript and lets you know how to implement Sendbird Call's various features.
JavaScript
5
star
45

AndroidChannelListTutorial

Complete Source Code for Channel List Tutorial
Java
5
star
46

sendbird-uikit-nextjs-sample

A sample app the uses Next.js 13 and Sendbird UIKit V3
CSS
5
star
47

sendbird-uikit-sample-react-native-expo

[Sample] uikit-react-native with expo
JavaScript
5
star
48

sendbird-calls-quickstart-react-native

Download quickstart apps to try the core features for Sendbird Calls SDK.
5
star
49

healthcare-ai-chatbot

healthcare-ai-chatbot
Swift
5
star
50

sendbird-platform-sdk-javascript

Sendbird Platform API JavaScript SDK
JavaScript
4
star
51

SyncManager-iOS-Swift

[Deprecated] Sendbird SyncManager for iOS sample: installation and functions.
Swift
4
star
52

guidelines-ios

Sendbird guidelines for iOS development.
4
star
53

examples-calls-android

Kotlin
4
star
54

sendbird-discord-javascript-sample

An example of how UIKit can be customized to fit different look and feels
JavaScript
4
star
55

react-native-scrollview-enhancer

A utility package enabling onStartReached & maintainVisibleContentPosition in pre-0.72 react-native ScrollView.
TypeScript
4
star
56

sendbird-videochat-ios

Objective-C
4
star
57

ecommerce-ai-chatbot

ecommerce-ai-chatbot
Swift
4
star
58

examples-calls-ios

This repository provides feature-level Calls samples with Swift and lets you know how to implement Sendbird Call's various features.
Swift
4
star
59

sendbird-syncmanager-android

Sendbird SyncManager for Android is an add-on for reliable chat data caching with Chat SDK features.
4
star
60

sendbird-uikit-ios-spm

Sendbird UIKit for iOS is a development kit with a user interface, offering a simplified integration into chat.
Objective-C
3
star
61

tutorial-react-native

tutorial-react-native
3
star
62

sendbird-react-uikit-vue-sample

Adding UIKit to a Vue 3 application
Vue
3
star
63

python-daemon

Python
3
star
64

sendbird-chat-sample-unreal

C++
3
star
65

quickstart-calls-groupcall-android

Kotlin
3
star
66

quickstart-desk-javascript

Sendbird Desk for JavaScript sample for fast and easy implementation of a customizable live chat customer support system on Sendbird Chat platform.
JavaScript
3
star
67

SendBird-Desk-SDK-Android

Sendbird Desk SDK for Android: customizable live chat customer support system on Sendbird Chat platform.
3
star
68

sendbird-uikit-sample-android-jetpack-compose

Build chat in minutes with Sendbird UIKit for Android Jetpack Compose.
Kotlin
3
star
69

SendBird-Desk-SDK-JavaScript

Sendbird Desk SDK for JavaScript: customizable live chat customer support system on Sendbird Chat platform.
3
star
70

sendbird-live-sample-react

TypeScript
2
star
71

sendbird-calls-sdk-unity

A guide of Sendbird Calls SDK for Unity for an engaging voice and video call experience.
C#
2
star
72

sendbird-calls-groupcall-quickstart-react-native

quickstart-calls-groupcall-react-native
TypeScript
2
star
73

sendbird-platform-sdk-csharp

Sendbird Platform SDK for C#
C#
2
star
74

sendbird-chat-sdk-unreal

C++
2
star
75

simple_pong_chatbot

Describes how to setup a basic chat bot on SendBird, including launching the infrastructure necessary on AWS.
Python
2
star
76

release-automation-action

Release automation comment bot
TypeScript
2
star
77

sendbird_mymessenger_tutorial

Objective-C
2
star
78

sendbird-webrtc-ios-dev

C++
2
star
79

sendbird-chat-ios-spm

[v3] Sendbird Chat SDK for SPM
Shell
2
star
80

quickstart-calls-chat-integration-javascript

Calls integration to Chat for JavaScript Quickstart
JavaScript
2
star
81

react-native-touch-reload

reload helper for react-native
TypeScript
2
star
82

sendbird-videochat-android

2
star
83

sendbird-chatgpt-sample-android

Kotlin
2
star
84

SendBird-iOS-ObjectiveC

[Deprecated] A guide of the installation and functions of Sendbird Chat for iOS sample.
Objective-C
2
star
85

sendbird-calls-sdk-react-native

Sendbird Calls SDK for React-Native
Kotlin
2
star
86

SendBirdCallKitSampleApp

Swift
2
star
87

sendbird-chat-sdk-windows

Sendbird Chat SDK for Windows for enablement of a rich, engaging, scalable, and real-time chat service.
C++
1
star
88

quickstart-calls-ios

Download quickstart apps to try the core features for Sendbird Calls SDK.
1
star
89

sendbird-chat-sample-windows

A guide of the installation and functions of Sendbird Chat for Window sample.
C++
1
star
90

sendbird-live-sample-android

Kotlin
1
star
91

sendbird-videochat-javascript

SendBird VideoChat for JavaScript
1
star
92

sendbird-live-sample-ios

iOS general sample for Sendbird Live, guiding you to build a real-time massive steaming event quickly and easily.
Swift
1
star
93

SendBird-Desk-iOS-Framework

Sendbird Desk SDK for iOS: customizable live chat customer support system on Sendbird Chat platform.
Objective-C
1
star
94

sendbird-chat-sample-react-native

Sendbird Chat SDK sample for React-Native.
TypeScript
1
star
95

sendbird-chatgpt-sample-ios

GPT Sample in iOS
Swift
1
star
96

sendbird-ai-chatbot-sample-android

Kotlin
1
star
97

LocalCaching-iOS-Swift

Sendbird Chat iOS sample app that supports Local Caching
Swift
1
star
98

quickstart-desk-android

Sendbird Desk for Android sample for fast and easy implementation of a customizable live chat customer support system on Sendbird Chat platform.
Java
1
star