SDK

@kili/vue

Vue SDK

Add Kili's chat widget to a Vue 3 or Nuxt app with @kili/vue. Conversations go to your team's Kili inbox in real time.

Requirements

Vue 3.3 or later. vue is a peer dependency, so your app supplies it. The package ships its own compiled stylesheet, so you don't need Tailwind in your app.

Install

npm install @kili/vue

Quick start

Support.vue
<script setup lang="ts">
import { KiliChat } from "@kili/vue";
import "@kili/vue/styles.css";

const config = {
  apiBaseUrl: "https://api.kili.africa",
  apiKey: "YOUR_API_KEY",
  apiSecret: "YOUR_API_SECRET",
};
</script>

<template>
  <KiliChat :config="config" />
</template>

Both imports are required

Keep the styles.css import. Without it the widget renders unstyled.

Configuration

KiliChat takes one prop, config, typed as KiliConfig. It's the same config object as the React SDK:

OptionTypeRequiredDescription
apiBaseUrlstringrequiredBase URL of the Kili REST API, for example https://api.kili.africa.
socketBaseUrlstringoptionalBase URL of the realtime server. Defaults to apiBaseUrl.
apiKeystringrequiredYour organisation's API key.
apiSecretstringrequiredYour organisation's API secret.

The component watches config deeply. When you pass a new config object, the SDK applies it again, so later requests use the new values. The socket and the session are not rebuilt.

Keep the values in environment variables. In Vite, variables must start with VITE_ to reach the browser:

.env
# .env
VITE_KILI_API_BASE_URL=https://api.kili.africa
VITE_KILI_API_KEY=YOUR_API_KEY
VITE_KILI_API_SECRET=YOUR_API_SECRET
Support.vue
<script setup lang="ts">
import { KiliChat } from "@kili/vue";
import "@kili/vue/styles.css";

const config = {
  apiBaseUrl: import.meta.env.VITE_KILI_API_BASE_URL,
  apiKey: import.meta.env.VITE_KILI_API_KEY,
  apiSecret: import.meta.env.VITE_KILI_API_SECRET,
};
</script>

<template>
  <KiliChat :config="config" />
</template>

Keep the key and secret private

Never commit the key or secret. A client-side SDK runs in the browser, so these values are included in your app bundle. The widget also sends them with every request and socket connection, so anyone who loads your page can read them.

Not configurable yet

There are no props for a brand name, greeting text, colours or launcher position. The SDK also can't take a signed-in user's name or email yet.

Placing the widget

Like the React widget, the root element is h-dvh w-full, so it fills the full viewport height and ignores its container's height. Use a full-page route or a full-screen overlay:

A full-page support route

SupportPage.vue
<script setup lang="ts">
import { KiliChat } from "@kili/vue";
import "@kili/vue/styles.css";

const config = {
  apiBaseUrl: "https://api.kili.africa",
  apiKey: "YOUR_API_KEY",
  apiSecret: "YOUR_API_SECRET",
};
</script>

<template>
  <!-- A route that renders only the widget, for example /support -->
  <KiliChat :config="config" />
</template>

A full-screen overlay

SupportOverlay.vue
<script setup lang="ts">
import { ref } from "vue";
import { KiliChat } from "@kili/vue";

const open = ref(false);
const config = {
  apiBaseUrl: "https://api.kili.africa",
  apiKey: "YOUR_API_KEY",
  apiSecret: "YOUR_API_SECRET",
};
</script>

<template>
  <button @click="open = true">Chat with us</button>
  <div v-if="open" class="fixed inset-0 z-50 bg-background">
    <KiliChat :config="config" />
    <!-- The widget has no close button. Add one that doesn't cover its header. -->
    <button @click="open = false">Close</button>
  </div>
</template>

A fixed-size panel won't work cleanly

A fixed-height panel or a small drawer clips the widget. The root stays at full viewport height, and overflow-hidden cuts off its bottom, which can hide the message composer.

Nuxt

The widget reads localStorage, sessionStorage and window, so it must render on the client. Wrap it in <ClientOnly>, as this page does:

nuxt.config.ts
// nuxt.config.ts
export default defineNuxtConfig({
  runtimeConfig: {
    public: {
      kiliApiKey: "", // set with NUXT_PUBLIC_KILI_API_KEY
      kiliApiSecret: "", // set with NUXT_PUBLIC_KILI_API_SECRET
    },
  },
});
pages/support.vue
<!-- pages/support.vue -->
<script setup lang="ts">
import { KiliChat } from "@kili/vue";
import "@kili/vue/styles.css";

const runtime = useRuntimeConfig();
const config = {
  apiBaseUrl: "https://api.kili.africa",
  apiKey: runtime.public.kiliApiKey,
  apiSecret: runtime.public.kiliApiSecret,
};
</script>

<template>
  <ClientOnly>
    <KiliChat :config="config" />
  </ClientOnly>
</template>

Dark mode

Add a dark class to any ancestor element. The stylesheet includes both light and dark themes.

vue
<div class="dark">
  <KiliChat :config="config" />
</div>

Styling notes

The stylesheet changes global styles

@kili/vue/styles.css is the same stylesheet as the React SDK's. It includes Tailwind's base styles (preflight), which reset margins, heading sizes, lists and buttons across the whole page, and it loads Space Grotesk and DM Sans from Google Fonts. Import it only on the route that renders the widget.

Building your own UI

To compose the widget yourself, call configureKili(config) first. Then use the building blocks:

  • AppStateProvider (component), provideAppState() / createAppState(), and useApp().
  • SocketProvider (component) and useSocket(). The socket connects once the app state has a user and an access token.
  • ChatWidget, ChatHome, ChatThread, InitialsAvatar, Button, Textarea, chatService, coreService, SocketEvent, and the Chat, Message and Customer types.

ChatWidget, ChatThread and any component that calls useApp() must be rendered inside AppStateProvider. As in the React SDK, KiliChat also runs the bootstrap, so a custom composition has to make the four calls itself:

CustomSupport.vue
<script setup lang="ts">
import { AppStateProvider, ChatWidget, configureKili } from "@kili/vue";
import Bootstrap from "./Bootstrap.vue";

configureKili({
  apiBaseUrl: "https://api.kili.africa",
  apiKey: "YOUR_API_KEY",
  apiSecret: "YOUR_API_SECRET",
});
</script>

<template>
  <AppStateProvider>
    <Bootstrap />
    <ChatWidget />
  </AppStateProvider>
</template>
Bootstrap.vue
<!-- Bootstrap.vue: the same steps KiliChat runs on mount -->
<script setup lang="ts">
import { onMounted } from "vue";
import { chatService, coreService, useApp } from "@kili/vue";

const state = useApp();

onMounted(async () => {
  const customer = await coreService.createCustomer();
  await coreService.setCustomerHmac();
  const auth = await coreService.registerCustomer();

  state.setUser(customer);
  state.setAccessToken(auth.accessToken);

  const chats = await chatService.getAllChats(customer.id);
  state.setChats(chats.data);
});
</script>

<template>
  <span hidden />
</template>

Coming from React?

The Vue SDK is a port of the React SDK. This table maps the React API to the Vue one.

@kili/react@kili/vue
<KiliChat config={...} /><KiliChat :config="..." />
AppStateContext (React context)AppStateContext (Vue InjectionKey)
SocketContext (React context)SocketContext (InjectionKey<ShallowRef<Socket>>)
useIsMobile() → booleanuseIsMobile() → ComputedRef<boolean>
ChatHome onOpen / onStartNew@open / @start-new
ChatThread draft + onDraftChangev-model:draft
ChatThread onSend / onBack@send / @back
ChatThread onTextfieldFocus / onTextFieldBlur@textfield-focus / @textfield-blur
Textarea value + onChangev-model
Button asChild (Radix Slot)Button as-child (built-in Slot)

Troubleshooting