Skip to main content
< All Topics
Print

With Android Mobile app in Kotlin

Overview

In order to include CuVo chatbot, you need to integrate your Android mobile app with the CuVo  chat library.  This guide shows how to successfully complete the necessary steps involved in the integration. 

It helps you understand all the essential parts of the integration such as downloading the CuVo chat agent library, adding it as a dependency, and integrating the necessary code.

The last section lists all the API methods exposed by the library for additional customisation handle on the agent.

The following is the list of version compatibility for the feedback agent:

Android Version Support: Android version 7 and above

Minimum SDK Version: Android SDK 21

Target and compile SDK Version: Android SDK 34

Java Version: Java 8 and above

Android Gradle Plugin (AGP) Version: 1.6.10 and above

Gradle Distribution URL: 7.2.0 and above

Adding CuVo Library as a Dependency in Your App

After creating an account and configuring the chat agent, you will see the Integration steps section. Generate an API key, select Mobile for Platform and Android Kotlin for Technology. Now you have the code snippet, chat library and integration instructions for integration with your kotlin app for android mobile.

Click the Download SDK button to download and save the CuVo agent library file. The file would be most likely be named cuvo-chat-agent.aar.

Once you have the CuVo agent library file, you need to add it as a dependency in your app to facilitate the integration. 

1. Navigate to File > Project Structure.

The Project Structure dialog is displayed.

2. Navigate to Dependencies > Declared Dependencies tab.

3. Click the Add icon.

4. Select JAR/AAR Dependency from the dropdown list.  

The Add JAR/AAR Dependency dialog is displayed.

5. Enter the folder path of the downloaded library file, cuvo-chat-agent.aar. 

6. Assign your dependency to a configuration by selecting the configuration as Implementation from the dropdown list.

7. Click OK.

8. Click Apply, then OK.

Note: Once you apply the dependency file, you can see its path in the app’s build.gradle file.

implementation (files(“libs/cuvo-chat-agent.aar”))

Integrating Code

To integrate the code, follow the steps below.

1. Add the following library dependencies in the app’s build.gradle file.

// SDP support

implementation "com.intuit.sdp:sdp-android:1.1.0"
// Gson

implementation 'com.google.code.gson:gson:2.8.5'
// Retrofit networking

implementation "com.squareup.retrofit2:retrofit:2.9.0"

implementation "com.github.akarnokd:rxjava3-retrofit-adapter:3.0.0"

implementation "com.squareup.okhttp3:logging-interceptor:4.7.2"

implementation "com.squareup.retrofit2:converter-gson:2.9.0"
// Image Loader

implementation 'com.squareup.picasso:picasso:2.8'

implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
// Ensure the Material Design library is included

implementation 'com.google.android.material:material:1.2.0'

2. Add the list of queries and activities from the CuVo library to the main application’s AndroidManifest.xml file.

<!-- Add permissions -->

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-permission android:name="android.permission.INTERNET" />


<!-- Add CuVo library activity -->

<activity

   android:name="com.cuvo.mylibrary.ui.activity.MessageActivity"

   android:configChanges="orientation|screenSize"

   android:exported="false">

</activity>

Please note that our library has disabled CleartextTraffic for security purposes. In case applications need to enable it, they need to

tools:replace="android:usesCleartextTraffic"

add to <applicaton> element at AndroidManifest.xml

3.  Initialize CuVo Library

Copy the code snippet you see in the Code Snippet box of the Integration steps  section on the CuVo portal and add it to the onCreate() function in the main activity to initialize the CuVo Library. The code snippet will look like the below code with appropriate values for the APIKEY_VALUE, ORG_ID_VALUE, PROD_ID_VALUE, PRODUCT_VERSION_VALUE and CHATBOT_IMAGE_URL filled in. You will need to replace the text ‘DEFAULT_FONT_FILE’ with your appropriate font resource or the value 0 in order to use the system default font.

CuvoInitConfigs.init(

   context, //activityContext where you want to add the chatbot

   isCustomButton, //set this parameter to true to use CuVo's button, set to false to use app's own button

   APIKEY_VALUE,

   ORG_ID_VALUE,

   PROD_ID_VALUE,

   PRODUCT_VERSION_VALUE,

   DEFAULT_FONT_FILE, //set this parameter to your font resource value, example(R.font.Robotto), or 0 to use system default font

   CHATBOT_IMAGE_URL,

   object : CuvoInitCallback { //callback to handle init complete success and error

       override fun onSuccess() {

           // Handle success

       }

       override fun onError(message: String) {

           // Handle Error

           Log.e(ApiUtils.LogTag, "${message}")

       }

   }

)

Note: Set the value of isCustomButton as false if you want to use your own chat button.

Use the CuvoInitCallback.onSuccess() to handle any action the needs to happen when init completes.

Use the CuvoInitCallback.onError() to handle any errors during init call.

Additional Methods

You can use the following methods to control the chat agent UI programatically.

// This method is used to display the chatbot button on the relevant screens.
// context: the activity context in which to show the button

CuvoInitConfigs.showChatbotButton(context)
// This method is used to hide or delete the chatbot button from recommended screens.

CuvoInitConfigs.hideChatbotButton()
// This method is used to open the chat window from your custom event

CuvoInitConfigs.openChatView()
Table of Contents