Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
djorka committed May 6, 2024
1 parent ed13231 commit a2b556e
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 104 deletions.
213 changes: 110 additions & 103 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A valid API key is needed in order to use the Forethought Solve SDK. In additon

### Groovy

```groovy
```groovy
// add the jitpack maven repository to the project repositories, this can exist
// inside project's build.gradle, or settings.gradle.
repositories {
Expand All @@ -21,13 +21,13 @@ repositories {
// add the dependency to the app's build.gradle
dependencies {
// Solve Android SDK
implementation "ai.forethought:solve-android-source:1.2.0"
implementation "ai.forethought:solve-android-source:1.3.0"
}
```
```

### Kotlin

```kotlin
```kotlin
// add the jitpack maven repository to the project repositories, this can exist
// inside project's build.gradle, or settings.gradle.
repositories {
Expand All @@ -40,147 +40,154 @@ repositories {
// add the dependency to the app's build.gradle
dependencies {
// Solve Android SDK
implementation("ai.forethought:solve-android-source:1.2.0")
implementation("ai.forethought:solve-android-source:1.3.0")
}
```
```

## Basic Usage

1. Inside the Android Application class, add the following lines to the onCreate() method:

```java
Forethought.INSTANCE.setup("FORETHOUGHT_API_KEY")
```
```java
Forethought.INSTANCE.setup("FORETHOUGHT_API_KEY")
```

2. Replace `FORETHOUGHT_API_KEY` with a valid Forethought API key

3. To show / hide the Forethought Solve SDK, add the following in the `Activity/Fragment`:

```java
Forethought.INSTANCE.show();
Forethought.INSTANCE.hide();
```
```java
Forethought.INSTANCE.show();
Forethought.INSTANCE.hide();
```


## Additional Usage

### Data Parameters

To send data parameters, add the following before calling `.show()`:
A comprehensive list of non workflow context variable parameters can be found [here.](https://support.forethought.ai/hc/en-us/articles/1500002917301-Installation-Guide-for-Solve-Widget#:~:text=Additional%20Attributes) To pass widget parameters, add any or all the following before calling `.show()`:

```java
// Java
Map<String, String> dataParameters = new HashMap<>();
dataParameters.put("language", "EN");
dataParameters.put("tracking-email", "[email protected]");
Forethought.INSTANCE.setDataParameters(dataParameters);
- `dataParameters` will be prefixed with `data-ft-`
- `configParameters` will be prefixed with `config-ft-`
- `additionalParameters` will NOT be prefixed

// Kotlin
val dataParameters = mapOf(
"language" to "EN",
"tracking-email" to "[email protected]"
)
Forethought.INSTANCE.dataParameters = dataParameters
```
```java
// Java
Map<String, String> dataParameters = new HashMap<>();
dataParameters.put("language", "EN");
dataParameters.put("tracking-email", "[email protected]");
Forethought.INSTANCE.setDataParameters(dataParameters);

// Kotlin
val dataParameters = mapOf(
"language" to "EN",
"tracking-email" to "[email protected]"
)
Forethought.INSTANCE.dataParameters = dataParameters
```

### Handoffs

To handoff from Forethought to another helpdesk / provider, implement the following:

1. Make sure the `Activity/Fragment` implements the ForethoughtListener interface, and override it's methods. The methods
do have default implementations so they are optional.
```java
// Java
public class MainActivity extends AppCompatActivity implements ForethoughtListener {

```java
// Java
public class MainActivity extends AppCompatActivity implements ForethoughtListener {
// ...
@Override
public void forethoughtHandoffRequested(@NonNull ForethoughtHandoffData forethoughtHandoffData) {
// Custom handoff action
// ...
@Override
public void forethoughtHandoffRequested(@NonNull ForethoughtHandoffData forethoughtHandoffData) {
// Custom handoff action
// ...

// if handoff was successful
Forethought.INSTANCE.sendHandoffResponse(true);

// if handoff was unsuccessful
Forethought.INSTANCE.sendHandoffResponse(false);

// hide Forethought after sendHandoffResponse
Forethought.INSTANCE.hide();
}

@Override
public void onWidgetClosed() {
// Custom close action
}

@Override
public void onWidgetError() {
// handle when the webview doesn't render the widget
}

// if handoff was successful
Forethought.INSTANCE.sendHandoffResponse(true);

// if handoff was unsuccessful
Forethought.INSTANCE.sendHandoffResponse(false);

// hide Forethought after sendHandoffResponse
Forethought.INSTANCE.hide();
}

// Kotlin
class MainActivity : AppCompatActivity(), ForethoughtListener {
// ...
override fun forethoughtHandoffRequested(handoffData: ForethoughtHandoffData) {
// Custom handoff action
// ...
@Override
public void onWidgetClosed() {
// Custom close action
// Called when customer closes the widget or when onBackPressed is triggered
}

// if handoff was successful
Forethought.INSTANCE.sendHandoffResponse(true)
@Override
public void onWidgetError() {
// handle when the webview doesn't render the widget
}
}

// if handoff was unsuccessful
Forethought.INSTANCE.sendHandoffResponse(false)
// Kotlin
class MainActivity : AppCompatActivity(), ForethoughtListener {
// ...
override fun forethoughtHandoffRequested(handoffData: ForethoughtHandoffData) {
// Custom handoff action
// ...

// hide Forethought after sendHandoffResponse
Forethought.INSTANCE.hide()
}
// if handoff was successful
Forethought.INSTANCE.sendHandoffResponse(true)

override fun onWidgetClosed() {
// Custom close action
}
// if handoff was unsuccessful
Forethought.INSTANCE.sendHandoffResponse(false)

override fun onWidgetError() {
// handle when the webview doesn't render the widget
}
// hide Forethought after sendHandoffResponse
Forethought.INSTANCE.hide()
}
```

2. In the onCreate method, add the `Activity/Fragment` as a listener to the Forethought Solve SDk:
```java
// Java
@Override
protected void onCreate(...) {
super.onCreate(savedInstanceState);
// ...
Forethought.INSTANCE.addListener(this);
override fun onWidgetClosed() {
// Custom close action
// Called when customer closes the widget or when onBackPressed is triggered
}

// Kotlin
override fun onCreate(...) {
super.onCreate(savedInstanceState)
// ...
Forethought.INSTANCE.addListener(this)
override fun onWidgetError() {
// handle when the webview doesn't render the widget
}
```
}
```

2. In the onCreate method, add the `Activity/Fragment` as a listener to the Forethought Solve SDk:
```java
// Java
@Override
protected void onCreate(...) {
super.onCreate(savedInstanceState);
// ...
Forethought.INSTANCE.addListener(this);
}

// Kotlin
override fun onCreate(...) {
super.onCreate(savedInstanceState)
// ...
Forethought.INSTANCE.addListener(this)
}
```

3. Don't forget to remove the listener on the `onDestory` of the `Activity/Fragment` to prevent memory leaks.
```java
// Java
@Override
protected void onDestroy() {
super.onDestroy();
// Remove the listener once the activity is destroyed.
Forethought.INSTANCE.removeListener(this);
}
```java
// Java
@Override
protected void onDestroy() {
super.onDestroy();
// Remove the listener once the activity is destroyed.
Forethought.INSTANCE.removeListener(this);
}

// Kotlin
override fun onDestroy() {
super.onDestroy()
// Remove the listener once the activity is destroyed.
Forethought.INSTANCE.removeListener(this)
}
```
// Kotlin
override fun onDestroy() {
super.onDestroy()
// Remove the listener once the activity is destroyed.
Forethought.INSTANCE.removeListener(this)
}
```


### Plugins
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/java/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object Versions {
const val constraintLayout = "2.1.3"
}

const val solve = "1.2.0"
const val solve = "1.3.0"

const val material = "1.5.0"

Expand Down

0 comments on commit a2b556e

Please sign in to comment.