Skip to main content

osvi_chat 0.3.1 copy "osvi_chat: ^0.3.1" to clipboard
osvi_chat: ^0.3.1 copied to clipboard

Embed an Osvi AI chat agent in a Flutter app: a headless chat client and drop-in chat widgets.

osvi_chat #

Embed an Osvi AI chat agent in a Flutter app. You get a ready-made chat screen and launcher button, plus a headless client if you want to build your own UI.

It talks to the same agent, dashboard settings and conversations as the web SDK (@osvi-ai/chat). It runs on iOS, Android, web and desktop, with no native code.

Install #

flutter pub add osvi_chat

Quick start #

import 'package:osvi_chat/osvi_chat.dart';

final client = await OsviChatClient.create(agentId: 'AGENT_ID');

// A floating button that opens the chat full screen, with an unread badge:
Scaffold(floatingActionButton: OsviChatLauncher(client: client));

// Or the chat panel anywhere in your layout:
OsviChatView(client: client);

OsviChatClient.create stores the visitor id and current session with shared_preferences, so a returning visitor sees their conversation. It closes the chat connection while the app is in the background and reconnects when the app returns to the foreground.

Dispose the client when you no longer need it: client.dispose().

Signed-in users (server mode) #

Without auth, each device is an anonymous visitor. For signed-in users, your backend creates the session with your Osvi API token and hands the app a short-lived stream token:

final client = await OsviChatClient.create(
  agentId: 'AGENT_ID',
  auth: ChatAuth.server(getToken: ({bool newSession = false}) async {
    final res = await myApi.get('/osvi-token', query: {'new': '$newSession'});
    return ServerToken.fromJson(res); // {sessionId, token, wsUrl, expiresAt}
  }),
);

Your backend calls:

  • GET /v1/chat/session/active?customer_id=…&agent_uuid=…, or POST /v1/chat/session with {agent_uuid, customer_id}
  • then POST /v1/chat/session/:id/ws_token with {"stream": "user"}

Send the API-Token header on these calls. Never put the API token in the app.

Notifications while the app is closed #

The SDK closes the chat connection when the app goes to the background, and reconnects when it comes back. Replies are not lost: anything sent meanwhile loads when the chat reopens. To keep the connection open instead, pass disconnectInBackground: false to OsviChatClient.create.

To tell users about a reply while the app is closed:

  1. In the Osvi dashboard or API, add a message_created notify hook to the agent. It fires to your webhook for each AI or team member message, but only while the user has no chat open.
  2. Use server mode with your own identifiers: the user's phone number as customer_id, and your app's user id in input_fields, so the webhook tells you who to notify.
  3. Send the push notification from your backend.
  4. When the user taps it, open the chat with OsviChatView or OsviChatLauncher.open. To check whether the notification is for the conversation already open, compare its session_id with client.sessionId().

Customising #

OsviChatView(
  client: client,
  title: 'Help',
  subtitle: 'We reply in minutes',
  theme: const OsviChatTheme(
    colors: OsviChatColorOverrides(primary: Color(0xFF0B6A87)),
    mode: OsviThemeMode.auto, // light, dark or auto (follows the device)
    radius: 16,
    buttons: OsviButtonsVariant.list,
    carousel: OsviCarouselVariant.slider,
  ),
  strings: const OsviChatStrings(placeholder: 'Ask us anything…'),
  newChatKeepsHistory: true,
  onPrechat: (info) => print('pre-chat saved: ${info.toJson()}'),
  headerActions: [
    OsviChatHeaderAction(
      icon: const Icon(Icons.call_outlined),
      tooltip: 'Call us',
      onPressed: () => launchUrl(Uri.parse('tel:+18005550100')),
    ),
  ],
);

Header buttons: headerActions (also on OsviChatLauncher and OsviChatLauncher.open) adds up to two of your own buttons to the chat header. They sit before the chat's own buttons (Continue on WhatsApp, New chat, Close), which keep their places, and get the same size and colour. When two app buttons would leave the title too little room (a narrow phone with WhatsApp, New chat and Close showing), they fold into one More menu that lists each by its icon and tooltip. tooltip is required: it names the button for screen readers. The menu button's label is the moreActions string.

What the dashboard controls: the colour, light/dark mode, title, pre-chat form and WhatsApp hand-off configured there apply automatically. Values you set in the app win over them.

Strings: every visible string is overridable. The keys match the web SDK, plus a few extra (for example team, select and confirmDate) for text the web panel hard-codes.

Attachments (photos and PDFs) #

When the agent accepts attachments (switched on in the dashboard's chat widget settings), a paperclip appears in the composer. Visitors can send a photo from the library or the camera, or a PDF, with an optional caption. The agent reads it like a WhatsApp photo or document: images through vision, PDFs as a text excerpt. Your team sees it in the Inbox.

  • Limits come from the server (by default photos up to 5 MB as JPEG, PNG or WebP, and PDFs up to 10 MB). Files are checked on the device first, and again on the server by their bytes.
  • Photos are resized on the device to at most 2048 px.
  • Photos leave the device without metadata. Before uploading, the client removes EXIF (including GPS position and camera details), XMP, IPTC and text metadata from JPEG, PNG and WebP photos, including those from a custom attachmentPicker. Only the orientation is kept, so photos still show the right way up.
  • Your own picker: pass attachmentPicker: (an OsviAttachmentPicker) to OsviChatView or OsviChatLauncher to use your app's picker instead of the built-in one (image_picker and file_selector, both flutter.dev plugins).
  • Headless: client.sendAttachment(OsviChatFile(bytes: bytes, name: 'quote.pdf'), caption: 'My quote'). client.attachmentRefusal(file) tells you before sending why a file would be refused.

Platform setup for the built-in picker:

  • iOS: add NSCameraUsageDescription to Info.plist (and NSPhotoLibraryUsageDescription if you support iOS 13 or older). The photo library itself needs no permission from iOS 14.
  • Android: nothing to add.
  • macOS: add the com.apple.security.files.user-selected.read-only entitlement.

Call reception #

A guest can call their property's front desk from the chat. When the server says the chat may call, a phone button appears in the header. Tapping it rings the guest's own phone, then the front desk, and connects the two. It is an ordinary phone call: no audio runs through the app, so there is no native code and no microphone permission.

The button shows only when all of these hold (the server checks them again when the guest taps):

  • the chat was created in server mode for the guest's phone number;
  • the guest's status is one that may call (for example, checked in);
  • the property's front desk number is on the chat.

Nothing is needed in the app for the ready-made screen. To hide the button, pass showCallReception: false to OsviChatView. With your own UI:

if (client.value.callReception != null) {
  final outcome = await client.callReception(); // outcome.ok, or outcome.reason
}
final call = client.value.call; // state: calling_you, connecting, in_progress, completed, …
await client.endCall();         // cancel while ringing, or hang up
client.dismissCall();           // clear a call that is over

Features #

  • Messages: markdown replies, links in visitor messages, reactions, and typing indicators for both the AI and a team member.
  • Interactive cards: buttons (chips or list, including an "other" free-text answer), carousels (slider or list), and a date picker (single date or range).
  • Human takeover: a "team member joined" notice, with card answers paused while a person is connected.
  • Resilient connection: pings, token rotation, reconnect with backoff, resending unconfirmed messages, and recovery of history after a reconnect.
  • Limits: handling for rate limits, daily caps and the per-conversation cap, with countdowns.
  • Pre-chat and hand-off: the pre-chat form (name and phone) and Continue on WhatsApp.
  • Accessibility: status changes and new replies are announced, focus moves to new cards, and animations respect reduced-motion settings.

Headless use #

Build your own UI on the client:

ValueListenableBuilder<ChatState>(
  valueListenable: client,
  builder: (context, state, _) => Text('${state.items.length} messages'),
);
await client.start();
await client.send('Hello');
await client.respond(interactionId, const InteractionResponse.selection('billing'));
await client.newSession();

Relationship to the web SDK #

The core is a one-to-one port of @osvi-ai/chat's TypeScript core. Its test suite is ported test for test, and it replays the same recorded server fixtures. See PARITY.md for how the two are kept in step.

1
likes
160
points
1.2k
downloads

Documentation

API reference

Publisher

verified publisherosvi.ai

Weekly Downloads

Embed an Osvi AI chat agent in a Flutter app: a headless chat client and drop-in chat widgets.

Homepage
Repository (GitHub)
View/report issues

Topics

#chat #ai #customer-support #chatbot

License

MIT (license)

Dependencies

clock, file_selector, flutter, http, image_picker, shared_preferences, url_launcher, web_socket_channel

More

Packages that depend on osvi_chat