Sendbird.Chat
4.1.0
dotnet add package Sendbird.Chat --version 4.1.0
NuGet\Install-Package Sendbird.Chat -Version 4.1.0
<PackageReference Include="Sendbird.Chat" Version="4.1.0" />
paket add Sendbird.Chat --version 4.1.0
#r "nuget: Sendbird.Chat, 4.1.0"
// Install Sendbird.Chat as a Cake Addin #addin nuget:?package=Sendbird.Chat&version=4.1.0 // Install Sendbird.Chat as a Cake Tool #tool nuget:?package=Sendbird.Chat&version=4.1.0
Sendbird Chat SDK for .NET
Table of contents
Introduction
The Sendbird Chat SDK for .NET allows you to add real-time chat into your client app with minimal effort. Sendbird offers a feature rich, scalable, and proven chat solution depended on by companies like Reddit, Hinge, PubG and Paytm. <br />
How it works
The Chat SDK provides the full functionality to provide a rich chat experience, implementing it begins by adding a user login, listing the available channels, selecting or creating an open channel or group channel, and receive messages and other events through channel event delegates and the ability to send a message. Once this basic functionality is in place, congratulations, you now have a chat app!
Once this is in place, take a look at all the other features that Sendbird supports and add what works best for your users. <br />
Getting started
Step 1: Create a Sendbird application from your dashboard
Before installing Sendbird Chat SDK, you need to create a Sendbird application on the Sendbird Dashboard. You will need the App ID
of your Sendbird application when initializing the Chat SDK.
Note: Each Sendbird application can be integrated with a single client app. Within the same application, users can communicate with each other across all platforms, whether they are on mobile devices or on the web.
<br />
Step 2: Install the Chat SDK
To install the Sendbird Chat SDK for .NET, you need to add the Sendbird.Chat
package from NuGet. Follow the steps below:
- Open your project in Visual Studio.
- Go to Tools > NuGet Package Manager > Package Manager Console.
- Search for
Sendbird.Chat
in the Browse tab. - Select the package and click Install.
Alternatively, you can install the package using the NuGet Package Manager Console with the following command:
dotnet add package Sendbird.Chat
Once the package is installed, you can start integrating Sendbird Chat into your application.
<br />
Sending your first message
Now that the Chat SDK has been imported, we're ready to start sending a message.
Authentication
In order to use the features of the Chat SDK, a SendbirdChat
instance must be initiated through user authentication with Sendbird server. This instance communicates and interacts with the server based on an authenticated user account, and then the user’s client app can use the Chat SDK's features.
Here are the steps to sending your first message using Chat SDK:
<br />
Step 3: Using the Sendbird.Chat namespace
Once the SDK have been installed, create a new source code file and add the following code at the top to start using Sendbird Chat SDK.
using Sendbird.Chat;
Step 4: Initialize the Chat SDK
Now, initialize the Chat SDK in the app to allow the Chat SDK to respond to changes in the connection status in Android client apps.
To initialize the SendbirdChat
instance, pass the APP_ID
of your Sendbird application in the Sendbird Dashboard as an argument to a parameter in the SendbirdChat.Init()
method.
SendbirdChat.Init(new SbInitParams(APP_ID));
Step 5: Connect to Sendbird server
After initialization by use of the Init()
method, your client app must always be connected to Sendbird server before calling any methods. If you attempt to call a method without connecting, an ConnectionRequired(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. Using a unique 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.
This allows you to get up and running without having to go deep into the details of the token registration process, however make sure to enable enforcing tokens before launching as it is a security risk to launch without.
SendbirdChat.Connect(USER_ID, (inUser, inError) => { });
B. Using a combination of unique user ID and token
Sendbird prefers that you pass the APP ID through the use of a token, as it ensures privacy and security for the users. Create a user along with their access token, or issue an session token to pass during connection. A comparison between an access token and session token can be found here. Once a token is issued, a user is required to provide the issued token in the SendbirdChat.connect()
method which is used for logging in.
- Using the Chat Platform API, create a Sendbird user account with the information submitted when a user signs up your service.
- Save the user ID along with the issued token to your persistent storage which is securely managed.
- When the user attempts to log in to the Sendbird application, load the user ID and token from the storage, and then pass them to the
SendbirdChat.Connect()
method. - Periodically replacing the user's token is recommended to protect the account.
SendbirdChat.Connect(USER_ID, AUTH_TOKEN, (inUser, inError) => { });
<br />
Step 6: Create a new open channel
Create an open channel using the following codes. Open channels are where all users in your Sendbird application can easily participate without an invitation.
SendbirdChat.OpenChannel.CreateChannel(new SbOpenChannelCreateParams(), (inChannel, inError) => { });
Step 7: Enter the channel
Enter the open channel to send and receive messages.
SbOpenChannel openChannel = null;
SendbirdChat.OpenChannel.GetChannel(CHANNEL_URL, (inChannel, inCache, inGetChannelError) =>
{
if (inGetChannelError != null)
return; //Error
openChannel = inChannel;
openChannel.Enter((inEnterChannelError) =>
{
if (inEnterChannelError != null)
return; //Error
});
});
<br />
Step 8: 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 also sent through the dashboard or Chat Platform API.
openChannel.SendUserMessage(MESSAGE, (inMessage, inError) =>
{
if (inError != null)
return; //Error
});
<br />
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Newtonsoft.Json (>= 13.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.