Skip to main content
OsviChatClient is the chat without an interface: it opens the session, keeps the connection alive, and gives you the transcript as state. The SDK’s own widgets are built on it, so anything they do, your interface can do too.
Creating a client opens no connection. start(), or the first send(), does. OsviChatView calls start() itself, so with the SDK’s widgets you only call it to connect before the visitor opens the chat, for example so the launcher’s unread badge counts replies to a returning visitor’s conversation.

Creating a client

OsviChatClient.create(agentId:, baseUrl:, auth:) is the one to use in an app. It stores the visitor ID and current session with shared_preferences, and reconnects when the app returns to the foreground. baseUrl defaults to https://api.osvi.ai. auth defaults to ChatAuth.anonymous(); for signed-in customers see Logged-in users. For tests or custom environments, construct the client directly with OsviChatClient(ChatClientOptions(…)). Its hooks are httpClient (an http.Client), socketFactory, store (a KeyValueStore, such as MemoryStore), page (PageSignals, which tell the client when the app is visible and online), and random. Without a store the client keeps nothing between runs.

State

The client is a ValueListenable<ChatState>, so it works with ValueListenableBuilder, addListener and client.value. client.stream emits the same states as a broadcast Stream. A Message has an id, a role (user, assistant or human for a team member), content in markdown, createdAt, a status of sending, sent or failed, and any reactions.

Methods

send resolves to ok: true with the messageId once the message is queued, or ok: false with a reason: empty, destroyed, awaiting_interaction (answer the card first) or unavailable. ok: true does not mean the server has it: the message’s status turns sent when the server confirms it. The client resends unconfirmed messages after a reconnect, and retries busy and rate-limited sends by itself.

Errors

state.error has a stable code, a message, a retryable flag and, for waits, retryAfterSeconds. The codes are constants on ChatErrorCode and are the same as the website SDK’s; each one is explained in Error codes.