Suggestions

close search

Getting started with Stringee Live Chat API

Step 1: Prepare

The Stringee Live Chat API requires the use of a widget key, which is used to identify your portal. You can obtain that key by following the steps below:

  1. Login to your StringeeX account as an admin
  2. In the Setting -> Chat Management -> Chat Widget -> Embed web widget and get the key in the URL

Step 2: Adding the Stringee SDK

  1. Copy the Stringee SDK JAR file to the libs folder

  2. Navigate to your build.gradle at the app level and include the following:

android {
    ...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}
dependencies {    
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'org.webrtc:google-webrtc:1.0.30039'
    implementation 'com.android.volley:volley:1.1.0'
}
  1. Sync your project

Step 3: Permissions and proguard

The Stringee Android SDK requires the following permissions from your app's AndroidManifest.xml file:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

If your project uses ProGuard, you may need to add the following settings to the ProGuard configuration file to make sure Stringee builds correctly:

-dontwarn org.apache.**
-keep class com.stringee.** { *; }
-keep class org.apache.** { *; }

Step 4: Get chat profile

Chat Profile is an object which will let you know:

Follow these steps to create a chat profile:

  1. Add a StringeeClient property to your Activity
    private StringeeClient stringeeClient;

    The StringeeClient class is defined in the Stringee SDK. It contains methods for communicating with the Stringee Server.

  2. Instantiate the StringeeClient object:
    stringeeClient = new StringeeClient(this);
  3. Call the method:

    stringeeClient.getChatProfile("YOUR_WIDGET_KEY", new CallbackListener<ChatProfile>() {
    @Override
    public void onSuccess(ChatProfile profile) {
    }
    
    @Override
    public void onError(StringeeError error) {
    }
    });

Step 5: Generate access token for customers

Customers must first connect to Stringee server in order to communicate with your agents. However, they are not system users and can be anyone, so you must generate a token for them. To accomplish this, use the following function:

stringeeClient.getLiveChatToken("YOUR_WIDGET_KEY", "YOUR_CUSTOMER_NAME", "YOUR_CUSTOMER_EMAIL", new CallbackListener<String>() {
    @Override
    public void onSuccess(String token) {
    }

    @Override
    public void onError(StringeeError error) {
    }
});

In which:

Step 6: Connect to Stringee Server

Next, we will connect to Stringee Server. Before beginning a live chat conversation, you must complete this step.

  1. Register a StringeeConnectionListener interface with StringeeClient object before connecting.

    client.setConnectionListener(new StringeeConnectionListener() {
    @Override
    public void onConnectionConnected(StringeeClient stringeeClient, boolean isReconnecting) {
    }
    
    @Override
    public void onConnectionDisconnected(StringeeClient stringeeClient, boolean isReconnecting) {
    
    }
    
    @Override
    public void onIncomingCall(StringeeCall stringeeCall) {
    
    }
    
    @Override
    public void onConnectionError(StringeeClient stringeeClient, StringeeError stringeeError) {
    
    }
    
    @Override
    public void onRequestNewToken(StringeeClient stringeeClient) {
    
    }
    
    @Override
    public void onCustomMessage(String from, JSONObject msg) {
    
    }
    
    @Override
    public void onTopicMessage(String from, JSONObject msg) {
    
    }
    });        
    • When the client connects to Stringee Server, the onConnectionConnected(StringeeClient stringeeClient, boolean isReconnecting) method is called.
    • When the client disconnects to Stringee Server, the onConnectionDisconnected(StringeeClient stringeeClient, boolean isReconnecting) method is called
    • When the client fails to connect to Stringee Server, the onConnectionError(StringeeClient stringeeClient, StringeeError stringeeError) method is called.
    • When the token is expired, the onRequestNewToken(StringeeClient stringeeClient) is called. You will need re-generate a new token and connect again.
  2. To listen for object (Conversation, Message) change events, you will need register a ChangeEventListenter interface:

    stringeeClient.setChangeEventListenter(new ChangeEventListenter() {
    @Override
    public void onChangeEvent(StringeeChange change) {
    }
    });
  3. Connect by calling:

    stringeeClient.connect(accessToken);

Step 7: Start a live chat conversation

Before beginning a live chat conversation, you can update the customer information on Stringee Server so that your agent has a better understanding of your customer; for example, where the customer is from or what type of cell phone he/she uses. To accomplish this, call the following function:

stringeeClient.updateUser("USER_NAME", "USER_EMAIL", "USER_AVATAR", new StatusListener() {
    @Override
    public void onSuccess() {
    }

    @Override
    public void onError(StringeeError error) {
    }
});

Then start a live chat conversation by calling:

stringeeClient.startLiveChat(queueId, new CallbackListener<Conversation>() {
    @Override
    public void onSuccess(Conversation conversation) {
    }

    @Override
    public void onError(StringeeError error) {
    }
});

In which:

Step 8: Messages

Follow this instruction Messages

Step 9: End a live chat conversation

To end a live chat conversation, call the following method:

stringeeClient.endChat(convId, new StatusListener() {
    @Override
    public void onSuccess() {

    }

    @Override
    public void onError(StringeeError error) {

    }
});

In which:

Step 10: Create a ticket for a miss chat

To create a ticket for a missed live chat conversation, call:

stringeeClient.createLiveChatTicket("YOUR_WIDGET_KEY", "CUSTOMER_NAME", "CUSTOMER_EMAIL", "TICKET_DESCRIPTION", new StatusListener() {
    @Override
    public void onSuccess() {

    }

    @Override
    public void onError(StringeeError error) {

    }
});