First things first
- To get started with 86%, you first need to create an account on the platform.
- Then, create your first bot, by clicking on “My first bot” button.
- You’re all set!
If you want to learn more on the Bot Editor, open the Bot Editor documentation
Basic integration concepts
- Bot: we refer as
bot
a scenario that is defined within theBot Editor
. - Conversation: we refer as
conversation
the content of the exchange between the user and86% SDK
. - Bot file: when you publish a
bot
in theBot Editor
, it generates abot file
. This file contains the entire definition of your bot scenario.
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
- First, initialize the SDK calling
EPManager
, the main class of86% SDK
. - 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:
- Internet permission : In most cases, your App will need to access internet to download the latest bot file or to load any picture / GIF / videos you’re using in your bot. To do so, add this line to your manifest:
<uses-permission android:name="android.permission.INTERNET" />
- Camera permission: If you intend to use the picture widget, to allow users to take picture, you should add this to your manifest:
<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
uuid
is the bot identifier. It can be found from theBot Editor
, in the bot’s settings.fetchingStrategy
can be of 3 kinds:onlineWithDefault
(recommended): you provide the SDK with a defaultbot file
to use in case of no internet. If you are connected though, the SDK will automatically update your bot to the latest version defined in theBot Editor
and compatible with your App (see the section onmajorVersion
).online
: the bot definition is loaded directly from the web and you don’t need to provide any defaultbot file
. It will raise an error if the user is not connected to internet.offline
: thebot file
is provided within the App build and will never change dynamically.
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.