Android
The Android SDK can be used to add Teneo bot functionality to Android apps. It handles communication with the Teneo Engine and makes it fast and easy to add Teneo chat functionality to your Android app. See Android Chat for an example of an Android project that uses this SDK.
The source code of this SDK can be found on GitHub.
Requirements
- Android Lollipop 5.0+
- Android Studio 3.4+
- JRE 1.8+
Example usage
Messages are sent to the engine by calling sendInput on the TieApiService singleton:
java
1TieApiService.getSharedInstance().sendInput(text, parameters)
2 .subscribeOn(Schedulers.io())
3 .observeOn(AndroidSchedulers.mainThread())
4 .subscribeWith(new DisposableSingleObserver<TieResponse>() {
5 @Override
6 public void onSuccess(TieResponse result) {
7 // Do something with the result
8 }
9 @Override
10 public void onError(Throwable e) {
11 // Do something with the exception
12 }
13 });
14
Installation
You can add the library to your project through jCenter. Make sure to reference the jCenter repository, and then add the dependency com.artificalsolutions.tiesdk:library:1.0.2. Using the library also requires rxjava2.
build.gradle example:
groovy
1buildscript {
2 repositories {
3 google()
4 jcenter()
5 }
6}
7
8dependencies {
9 implementation 'com.artificalsolutions.tiesdk:library:1.0.2'
10 implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
11}
12
API Documentation
TieApiService.setup
Before usage, setup needs to be called once with context, base URL, and endpoint.
java
1TieApiService.getSharedInstance().setup(getApplicationContext(), teneoEngineBaseUrl, endpoint);
2
TieApiService.input
Communication with Teneo Interaction Engine is done with sendInput function, that returns an observable that produces either a TieResponse object with onSuccess or a Throwable on onError.
java
1TieApiService.getSharedInstance().sendInput(userInput, parameters)
2
Parameter | Type | Description |
---|---|---|
userInput | String | The input string that is sent to the engine. |
parameters | HashMap | Any engine instance specific parameters. The following keywords are reserved: viewtype, viewname, and userinput. |
Response: On success, a TieResponse object is returned.
- input: TieInput
- text: String
- parameters: HashMap<String, String>
- output: TieOutput
- text: String
- parameters: HashMap<String, String>
- link: String
- emotion: String
- status: String
On fail, the call returns a Throwable. The exception can be JsonParseException, IOException, or NotInitializedException when setup has not been called, or TieApiException when the engine responds with an error. TieApiException:
- error: TieErrorResponse
- status: String
- input: TieInput
- text: String
- parameters: HashMap<String, String>
- message: String
TieApiService.close
The SDK maintains the session until it is expired by the server, in which case the session is renewed automatically, or until it is closed by calling the close function.
java
1TieApiService.getSharedInstance().close();
2
Error handling
Server-sent error messages are returned with sendInput ja close functions as TieApiException objects.