Skip to content

Initialization

Initialize the SDK

The first step to use the Kindly SDK is to initialize it with your bot key:

KindlySDK.start(
    application = application, 
    botKey = "YOUR_BOT_KEY", 
    languageCode = "en"
)

You can also provide an authentication callback if your bot requires authentication:

KindlySDK.start(
    application = application,
    botKey = "YOUR_BOT_KEY",
    languageCode = "en",
    authTokenCallback = { chatId, promise ->
        // Generate JWT token
        // On success, call
        promise.fulfill("JWT_TOKEN")
        // On error
        promise.reject(error)
    }
)

For more details on authentication, see Using Authentication.

Change Language at Runtime

You can change the language after initialization using:

KindlySDK.setLanguage("lt")  // Change to Lithuanian

This method will: - Call the language switch API - Update the cached settings - Refresh UI translations - Notify all UI components of the language change

The language setting will persist across chat sessions until explicitly changed.

Bot Switching and Reinitialization

The SDK intelligently handles bot switching and reinitialization scenarios when you call start() multiple times with different parameters.

Automatic Bot Key Switching

When you call start() with a different bot key, the SDK automatically:

  1. Detects the change: Compares the new bot key with the current one
  2. Performs cleanup: Calls endChat() internally to end the current session
  3. Resets state: Clears SDK initialization flags and session data
  4. Reinitializes: Connects to the new bot seamlessly
// First initialization
KindlySDK.start(application = this, botKey = "bot-key-1")
KindlySDK.launchChat(context = this)

// Later, switch to different bot - automatic cleanup happens
KindlySDK.start(application = this, botKey = "bot-key-2")  // SDK handles cleanup internally
KindlySDK.launchChat(context = this)

Connection State Handling

When the SDK is disconnected (e.g., after calling endChat()), calling start() with the same bot key will reconnect:

KindlySDK.start(application = this, botKey = "YOUR_BOT_KEY")
KindlySDK.launchChat(context = this)

// Later, end the chat
KindlySDK.endChat()

// Reconnect with same bot key - allowed reconnection  
KindlySDK.start(application = this, botKey = "YOUR_BOT_KEY")  // Reconnects instead of skipping
KindlySDK.launchChat(context = this)

Skipping Duplicate Initialization

The SDK skips initialization only when all conditions are met: - Same bot key - Still connected (not disconnected)

KindlySDK.start(application = this, botKey = "YOUR_BOT_KEY")
// This second call will be skipped - no changes needed
KindlySDK.start(application = this, botKey = "YOUR_BOT_KEY")

Best Practices for Bot Switching

// SDK handles cleanup automatically
KindlySDK.start(application = this, botKey = "new-bot-key")
KindlySDK.launchChat(context = this)

Option 2: Explicit End-then-Start

// Explicit control over the lifecycle
KindlySDK.endChat()
// endChat() completes synchronously, so you can immediately call start()
KindlySDK.start(application = this, botKey = "new-bot-key")
KindlySDK.launchChat(context = this)

Both approaches work identically - choose based on your preference for explicit vs automatic lifecycle management.