Desk SDKs Android v1
Desk SDKs Android
Desk SDKs
Android
Version 1

Create your first ticket

Copy link

Sendbird Desk SDK for Android lets you easily initialize, configure, and build the customer-support related functionalities to a client app. When a customer asks for help through live, in-app support built with the Desk SDK, agents receive those messages as tickets and can start a conversation on the Sendbird Dashboard. This page walks you through the quick steps to create your first ticket by installing and initializing the Desk SDK.

Note: As Sendbird Desk works based on Sendbird Chat, the interaction between users is built and provided by Sendbird Chat.


Requirements

Copy link

The requirements of the Desk SDK for Android are as below:

  • Android 5.0 (API level 21) or later
  • Java 8 or later
  • Support androidx only
  • Android Gradle plugin 4.0.1 or later
  • Sendbird Chat SDK for Android 4.0.3 and later

Prerequisite

Copy link

Before installing Sendbird Desk SDK, you will need an account on Sendbird Dashboard. Sign up to create a Sendbird application first.

Note: A Sendbird application gets paired up with one client app. Agents can support customers across all platforms, but customers from different Sendbird applications are excluded because all data is limited to the scope of a single application.


Get started

Copy link

Step 1 Create a project

Copy link

To get started, open Android Studio and create a new project for Desk in the Project window as follows.

  1. Click Start a new Android Studio project in the Welcome to Android Studio window.
  2. Select Empty Activity in the Select a Project Template window and click Next.
  3. Enter your project name in the Name field in the Configure your project window.
  4. Select your language as either Java or Kotlin from the Language drop-down menu.
  5. Make sure Use legacy android.support.libraries is unchecked.
  6. Select minimum API level as 21 or higher.

Step 2 Install using Gradle

Copy link

You can install the Desk SDK for Android using Gradle. First, you need to add the Sendbird repository to your project. In this step, use different approaches as instructed below depending on the Gradle version. Then, add dependency to your module build.gradle file, regardless of the version.

  1. Add a repository.

If you are using Gradle 6.7 or lower, add the following code to your root build.gradle file. Make sure the above code block isn't added to your module build.gradle file.

allprojects {
    repositories {
        maven { url "https://repo.sendbird.com/public/maven" }
    }
}

For Gradle 6.8 or higher, add the following to your settings.gradle file:

dependencyResolutionManagement {
    repositories {
        maven { url "https://repo.sendbird.com/public/maven" }
    }
}

Note: To learn more about updates to Gradle, see this release note.

  1. Add dependency.

Once the repository is set, for all Gradle versions, add the dependency to your module build.gradle file:

dependencies {
    implementation 'com.sendbird.sdk:sendbird-desk-android-sdk:1.1.4'
}

Step 3 Initialize the Desk SDK

Copy link

Initialization of Sendbird Desk SDK requires your Sendbird application's Application ID, which can be found on Sendbird Dashboard. As Sendbird Desk SDK uses the features provided by Sendbird Chat SDK, you need to initialize a SendbirdChat instance as well.

  1. Initialize a SendBirdDesk instance when launching a client app.
  2. Copy Application ID of your Sendbird application from the dashboard, which should be passed to APP_ID of InitParams. The same Application ID must be used for both Chat and Desk SDKs.
  3. Call the SendbirdChat.init(InitParams) method using the copied APP_ID within Application.onCreate().
  4. Call the SendBirdDesk.init() method within Application.onCreate().
// Initialize a SendBirdDesk instance to use APIs in your app.
public class BaseApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        final InitParams initParams = new InitParams("APP_ID", this, false);
        SendbirdChat.init(initParams, new InitResultHandler() {
            @Override
            public void onMigrationStarted() {
            }

            @Override
            public void onInitFailed(SendbirdException e) {
                // If initialization fails, this method is called.
            }

            @Override
            public void onInitSucceed() {
                // If initialization is successful, this method is called
                // and you can proceed to the next step.
                // You can use all Sendbird APIs, including connect()
                // after init is completed in your app.
                SendBirdDesk.init();
            }
        });
    }
}

Note: If you call SendBirdDesk.init() again after calling SendbirdChat.init(InitParams) with a different APP_ID, all existing Desk-related data in the client app will be deleted.

Step 4 Add BaseApplication

Copy link

Add INTERNET permission and BaseApplication you created in the earlier step to AndroidManifest.xml.

<!--  To connect to the Sendbird server, you should to add INTERNET permission  -->
<uses-permission android:name="android.permission.INTERNET" />

<!--  Add android:name=".BaseApplication"  -->
<application
    android:name=".BaseApplication"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Step 5 Authenticate a customer from Sendbird Chat

Copy link

As explained earlier, Sendbird Desk SDK handles converstaion between customers and agents within a ticket using the features provided by Sendbird Chat. Because of its dependency on Sendbird Chat, every ticket in Sendbird Desk is mapped to a group channel in Sendbird Chat and every message sent by customers comes and goes through Sendbird Chat. To receive their messages, you need to authenticate the user using the SendbirdChat.connect() and the SendBirdDesk.authenticate() methods with their USER_ID used in Sendbird Chat.

// Use a user ID that is unique to your Sendbird application.
SendbirdChat.connect("USERID", "ACCESS_TOKEN", new ConnectHandler() {
    @Override
    public void onConnected(User user, SendbirdException e) {
        if (e != null) {    // error.
            return;
        }
        // Use the same userId and accessToken used in SendbirdChat.connect().
        SendBirdDesk.authenticate("USERID", "ACCESS_TOKEN", new SendBirdDesk.AuthenticateHandler() {
            @Override
            public void onResult(SendbirdException e) {
                if (e != null) {    //error.
                    return;
                }

                // SendBirdDesk is now initialized,
                // and the customer is authenticated.
            }
        });
    }
});

Step 6 Create your first ticket

Copy link

Implement the Ticket.create() method to create a ticket either before or after the customer’s initial message. Once a ticket is successfully created on the Desk server, use ticket.getChannel() to retrieve the information of the ticket and its channel as a callback from the server.

Until a customer sends the first message, agents can’t see the ticket on the dashboard. When the customer initiates conversation by sending a message, the ticket is assigned to an available agent by the Desk server while messages are sent and received through the Chat SDK.

Ticket.create(TICKET_TITLE, USER_NAME, new Ticket.CreateHandler() {
    @Override
    public void onResult(Ticket ticket, SendbirdException e) {
        if (e != null) {
            // Handle error.
        }

        // The ticket is created.
        // The customer and agent can chat with each other
        // by sending a message through the ticket.channel.sendUserMessage()
        // or sendFileMessage().
    }
});

Note: Because the SendbirdChat instance in a client app is connected to the Sendbird server, Desk-related events are delivered to the Chat SDK's event handlers. The event handlers receive callbacks from the server through event callback methods such as onMessageReceived(), onUserJoined(), and more.