React Native SDK

This guide demonstrates how to easily implement our SDK for chat.

Installation

The React Native SDK is available using npm.

To install it, run the following command in a terminal or command prompt:

Copy
Copied
npm install sinch-chat-react-native-sdk

Configuring the application

To set up your application to start sending and receiving messages, you need to perform the following steps:

  1. Initialize the SDK as soon as the application starts.
  2. Set the identity of the user.
  3. Enable the chat functionality.

Initialize the SDK

To initialize the SDK, use the initialize method:

Copy
Copied
async initialize(): Promise<void>

Set Identity

We need to authorize the user next. To do that, call this method as early as possible to authorize the user:

javascriptjavascript
Copy
Copied
async setIdentity(options: IdentityOptions): Promise<void>
Copy
Copied
interface IdentityOptions {
  region: string;
  clientID: string;
  projectID: string;
  configID: string;
  userID?: string;
  secret?: string;
}

After correct authorization, the token will be saved in local storage.

Set the configuration parameters

To connect your Sinch Chat client to your Sinch account, you need to set the following parameters:

Parameter Description
projectId Get your project ID from your Sinch Dashboard.
clientId Get your client ID from your Sinch Dashboard.
region Use either EU for Europe or US for the United States.

Enabling and controlling the chat

You can enable and control the chat widget using the following method:

open

To display the widget.

Copy
Copied
async startChat(): Promise<void>

Next steps

After your client is set up, now you can configure the Sinch Chat channel in the Conversation API and start sending and receiving messages.

We'd love to hear from you!
Rate this content:
Still have a question?
 
Ask the community.