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,
): CartesianChatControllerkotlinCreating 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
| Property | Type | Description |
|---|---|---|
chat | ChatState | Messages, isResponding, isLoading, error, feedback |
auth | AuthState | Restoring, SignedOut or SignedIn |
connection | ConnectionState | Idle, Connecting, Open or Closed |
cart / wishlist | Cart / Wishlist | Built-in cart state |
cartCount / savedCount | Int | Follows the feature mode (built-in or host) |
isDeviceOnline | Boolean | Device network |
isRetrying | Boolean | A manual reconnect is in progress |
canSend | Boolean | Online, connected and idle |
draft | String (var) | Composer text |
drawer | CartesianDrawer? (var) | Cart, Wishlist or null |
error | String? (var) | UI-level error message |
starters | List<String> | Welcome questions |
suggestions | List<String> | Current follow-ups. Empty while responding. |
assistantName / cartName | String | From the options and strings |
isWhiteLabel | Boolean | From the licence |
features / options / vertical | Config |
Actions
| Method | Description |
|---|---|
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 |