Android SDK quickstart

Add the Askocto Android SDK to your app, create an OctoClient and send your first message to an agent in a few minutes.

Working draft. These docs are illustrative: names, endpoints and examples describe the intended behaviour and can change before launch.

This page takes you from an empty Android project to a working reply from your agent. You need the agent id of a published agent and an app that targets minSdk 24 or higher.

Add the SDK

  1. Open your module's build.gradle.kts and add the dependency. Use the latest version listed in the changelog.

    dependencies {
        implementation("co.askocto:sdk:1.0.0")
    }
    
  2. Allow network access in AndroidManifest.xml.

    <uses-permission android:name="android.permission.INTERNET" />
    
  3. Sync the project.

Create the client

Create one OctoClient for the whole app, for example in your Application class, and reuse it.

class SupportApp : Application() {
    lateinit var octo: OctoClient

    override fun onCreate() {
        super.onCreate()
        octo = OctoClient(context = this, agentId = "agt_123")
    }
}

To find the agent id, open the agent in the dashboard and go to Settings > General.

Send a message

  1. Call chat from a coroutine. It is a suspend function, so use viewModelScope or lifecycleScope.

    viewModelScope.launch {
        try {
            val response = octo.chat(text = "Where is my order?")
            println(response.message.content)
        } catch (e: OctoError) {
            println("Request failed: ${e.message}")
        }
    }
    
  2. Run the app and trigger the call.

You should see the agent's answer printed in Logcat. The response.conversationId value identifies the new conversation. Pass it to the next call to continue the same thread.

Try streaming

To show the answer as it is written, collect streamChat instead.

octo.streamChat(text = "What is your return policy?").collect { event ->
    if (event is StreamEvent.MessageDelta) print(event.text)
}

Next steps

  • Read Client for every setting of OctoClient.
  • Handle the whole stream in Streaming.
  • Connect customers to their own history with User identity.
  • Check answers before your users see them with the Playground.

Something unclear or missing? Tell us and we will fix the page.