This is a wrapper for Kustomer v2 Sdk for react native. This implements the kustomer v2 for android and ios. Functions available for android and ios are available on react native.
$ npm install react-native-kustomer-sdk-v2 --save
or
$ yarn add react-native-kustomer-sdk-v2
- Android minSdkVersion 21
- iOS level 11
For android to register the api key
Add the following dependancies in build.gradle (App)
dependencies {
...
implementation 'com.kustomer.chat:ui:2.9.2'
...
}
Add the code at last inside onCreate() in MainApplication.java
//MainApplication.java
//Add these import files
import kotlin.jvm.functions.Function1;
import com.kustomer.ui.KustomerOptions;
import com.reactnativekustomersdk.KustomerSdkPackage;
import com.kustomer.ui.Kustomer; // Added for customer
import android.widget.Toast;
import com.kustomer.core.models.KusResult;
import kotlin.Unit;
...
public void onCreate() {
...
try {
Kustomer.Companion.init(this, "Enter-api-key-here", (KustomerOptions) null, (result) -> {
return Unit.INSTANCE;
});
}
catch (AssertionError e) {
Toast toast= Toast.makeText(getApplicationContext(),"API KEY IS INVALID",Toast.LENGTH_SHORT);
toast.show();
}
}// onCreate closing bracket
The above code will show the toast if the API key is invalid.
Either make following changes in AndroidManifest.xml
//This is preffered because it overrides all sub androidManifest files with allowBackup true.
<manifest
...
xmlns:tools="http://schemas.android.com/tools"
>
...
<application
...
tools:replace="android:allowBackup"
>
or
following changes in the AndroidManifest.xml file
...
<application
...
android:allowBackup="true" //Change from false to true
>
To read more about allowBackup.
Import the library to use its methods:
import * as KustomerSDK from "react-native-kustomer-sdk-v2";
or
import { open, login, logout } from "react-native-kustomer-sdk-v2";
Call initialize function at start in react native with the api key to register the Api key for iOS.
import { initialize } from "react-native-kustomer-sdk-v2";
...
initialize('Enter-API-Key'); // Add this when the app will mount
import * as KustomerSDK from "react-native-kustomer-sdk-v2";
...
KustomerSDK.initialize('Enter-API-Key'); // Add this when the app will mount
After installing the react-native-kustomer-sdk-v2 do pod install inside the ios folder.
pod install
Initializes the apiKey to customer sdk. It is only required for ios and would cause no side effects on android.
KustomerSDK.initialize('Enter-API-Key').then(...);
Calls the isLoggedIn function in the kustomer sdk. It checks whether the use is logged in.
KustomerSDK.isLoggedIn('email').then(...);
Calls the logIn function in the kustomer sdk. It checks whether the use is logged in. To generate the jwt token use this code
KustomerSDK.logIn('Enter-JWT-token here').then(...);
Calls the logOut function in the kustomer sdk. It checks whether the user is logged in.
KustomerSDK.logOut().then(...);
Calls the open function in the kustomer sdk. Open the chat with one of the following types.
KustomerSDK.open('default').then(...);
type openTypes = 'default' | 'chat_kb' | 'chat_only' | 'kb_only';
Calls the openNewConversation function in the kustomer sdk. Open the conversation with initial Message. Animated param is only available for iOS.
KustomerSDK.openNewConversation('intial_message').then(...); //Android
KustomerSDK.openNewConversation('intial_message',true).then(...); //iOS
Calls the openConversationByID function in the kustomer sdk. Open the conversaton by id.
KustomerSDK.openConversationByID('id').then(...);
Calls the getUnreadCount function in the kustomer sdk. Returns the number unreadMessages.
KustomerSDK.getUnreadCount().then(...);
Calls the openKBbyID function in the kustomer sdk. Opens the knowledge base by id.
KustomerSDK.openKBbyID('kbid').then(...);
Calls the setActiveAssistant function in the kustomer sdk. Sets the active assistant to the assistantID.
KustomerSDK.setActiveAssistant('assistantID').then(...);
Calls the getOpenConversationCountfunction in the kustomer sdk. Check the kustomer documentation for more description.
KustomerSDK.getOpenConversationCount().then(...);
Calls the closeChat function in the kustomer sdk. Closes the chat. Only available for iOS.
KustomerSDK.closeChat().then(...);
Calls the chatVisiblefunction in the kustomer sdk. Returns if the chat is visible. Only available for iOS.
KustomerSDK.chatVisible().then(...);
Include the library in your android/app/build.gradle
:
implementation 'com.kustomer.chat:ui:2.9.+'
The preferred installation method is with CocoaPods. Add the following to your Podfile
:
pod 'KustomerChat'
To contribute fork repository and make the nessecary changes. Raise a PR for the same. Mention iOS/Android/RN in the PR. Mention fix/feature/refactor in the PR.
In case of error please raise a issue.
While development do following if error occurs.
- Set android:allowBackup="true" in the AndroidManifest.xml file (Android)
- comment flipper in the Podfile (iOS)
- add use_framework! in the Podfile (iOS)