Cartesiandocs

Android · cartesian-ui

CartesianChatController

The state and actions behind every assistant surface. Your custom slots get the same controller.

@Composable
fun rememberCartesianChatController(
    client: CartesianClient = Cartesian.client,
    options: CartesianOptions = Cartesian.options,
    listener: CartesianListener? = Cartesian.listener,
): CartesianChatController
kotlin

Creating a controller also starts these behaviours: restoring the session with backoff while online, connecting when the network returns, sending ChatEvents to the listener, and checking your licence.

State

PropertyTypeDescription
chatChatStateMessages, isResponding, isLoading, error, feedback
authAuthStateRestoring, SignedOut or SignedIn
connectionConnectionStateIdle, Connecting, Open or Closed
cart / wishlistCart / WishlistBuilt-in cart state
cartCount / savedCountIntFollows the feature mode (built-in or host)
isDeviceOnlineBooleanDevice network
isRetryingBooleanA manual reconnect is in progress
canSendBooleanOnline, connected and idle
draftString (var)Composer text
drawerCartesianDrawer? (var)Cart, Wishlist or null
errorString? (var)UI-level error message
startersList<String>Welcome questions
suggestionsList<String>Current follow-ups. Empty while responding.
assistantName / cartNameStringFrom the options and strings
isWhiteLabelBooleanFrom the licence
features / options / verticalConfig

Actions

MethodDescription
send(text = draft)Ask a question. Clears the draft if text was the draft.
stop()Interrupt the running answer
newChat()Start a new thread
retry()Re-run the last failed question
rate(messageId, Rating.Up / Down)Feedback
addToCart(product, quantity = 1)Built-in: backend cart. Host: onAddToCart. Off: nothing.
setQuantity(productId, quantity)Built-in cart only. 0 removes the item.
toggleSaved(product)Built-in or onToggleSaved
openProduct(product)onProductSelected if productTap is on
openCart() / openWishlist()Opens the drawer, or calls the host callback
showDrawer(CartesianDrawer?)Opens or closes the built-in drawer
checkout()Calls onCheckout(cart)
retryConnection()Reconnect now
quantityInCart(productId) / isSaved(productId) / isBusy(productId)Card state helpers