First things first

  1. To get started with 86%, you first need to create an account on the platform.
  2. Then, create your first bot, by clicking on “My first bot” button.
  3. You’re all set!

If you want to learn more on the Bot Editor, open the Bot Editor documentation

Basic integration concepts

Basic integration in your iOS App

To run a bot within your App, you first need to add 86% SDK as a pod to your project. Then, there are 2 simple steps to register it and create a conversation.

Add 86% SDK to your project

Simply add the following to your Podfile.

    pod 'EightySixPercent'

For more information about pod integration, please refer to the Cocoapod web site.

Step 1: Register your bot

  1. First, initialize the SDK calling EPManager, the main class of 86% SDK.
  2. Then, register any bot that you want to use in your App.

Typically, you would define a function that you call from the application didFinishLaunchingWithOptions in your AppDelegate.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    EPManager.shared.initialize()
    EPManager.shared.registerBot(uuid: "YOU_BOT_UUID_GOES_HERE", fetchingStrategy: .online(majorVersion: nil))
    return true
}

Step 2: Play your bot

To play your bot, you need to create a conversation, starting it with your bot and then you can present the 86% SDK main controller with your conversation played within.

// Create a new conversation: 
let conversation = EPChatConversation(botUuid: "YOU_BOT_UUID_GOES_HERE")

// Get the controller that displays this conversation:
EPManager.shared.controller(for: conversation) { controller, error in
    if let controller = controller {
        //depending on the fetching strategy you have chosen you may need to handle error and a HUD
        self.presentController(UINavigationController(rootViewController: controller))
    } else {
        self.showAlert(message: error?.localizedDescription ?? "N/A")
    }
}

Basic integration in your Android App

To run a bot within your App, you first need to add 86% SDK as a pod to your project. Then, there are 2 simple steps to register it and create a conversation.

Requirements for your project

1. Your project must use AndroidX:

Your project must use the AndroidX libraries. This guide assumes that you included androidx.appcompat library in your gradle dependencies:

dependencies {
    ...

    // AndroidX
    implementation "androidx.constraintlayout:constraintlayout:1.1.3"
    implementation "androidx.appcompat:appcompat:1.0.2"

    ...
}

In the gradle.properties file, add the following :

    android.useAndroidX=true
    android.enableJetifier=true

As described in the Migration to AndroidX guide

2. Your project should be using Java 8:

Finally, you need to add the following in the android section of the App gradle script:

 android {
     ...
     compileOptions {
         targetCompatibility = "8"
         sourceCompatibility = "8"
     }
     ...
 }

3. Your project need permissions for 86% SDK:

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

Add 86% SDK to your project

In the project build.gradle add the 86% SDK repository in the repositories section:

allprojects {
    repositories {
        ...
        maven {
            url "http://artifactory.86percent.co/artifactory/bot-release-local"
        }
        maven { 
            url "https://jitpack.io" 
        }
        ...
    }
}

Then in your app build.gradle file, add the following, in the dependencies section:

dependencies {
    ...
    implementation 'co.86percent:bot:1.1.0’
    ... 
}

Step 1: Register your bot

Initialize the 86% SDK, typically in your Application onCreate , call a initEightySixPercent() method that does the following:

private fun initEightySixPercent() {
    EPManager.init(this)
    EPManager.registerBot("YOU_BOT_UUID_GOES_HERE", EPBotFetchingStrategy.OnlineWithDefault(1,"SimpleDemo.json"))
}

Where SimpleDemo.json is the path of your bot JSON export file, relative to your project assets folder.

Note : you need to create the assets folder under the main folder of your Android project.

Step 2: play your bot

In the activity your want to run the chatbot, add the following:

val conversation = EPChatConversation(Constants.BotUuid.simpleDemo)
EPManager.fragment(this, conversation) { chatConversationFragment, exception ->
    if (chatConversationFragment != null) {
        val transaction = supportFragmentManager.beginTransaction()
        transaction.replace(R.id.container, chatConversationFragment)
        transaction.commit()
    } else {
        exception?.printStackTrace()
    }
}

More informations

RegisterBot’s parameters

What is the majorVersion?

The major version helps enforcing the compatibility between your App and your bot file.

In case the fetchingStrategy is not offline, the 86% SDK automatically fetches new bot files once they are published in the Bot Editor. But only bot files with the same majorVersion.

What’s next?

Next, you can take a look at the SDK API reference for Android and iOS.