Widget SDK Reference
Embed the ChatDrift agent widget in any web app using the JavaScript SDK or React components.
Widget SDK Reference
@nexvio-ai/widget-js is the official client library for embedding the ChatDrift agent. It ships two custom elements and matching React components, and runs entirely in the browser — no server-side setup needed beyond identity verification.
Installation
npm install @nexvio-ai/widget-js
# or
pnpm add @nexvio-ai/widget-js
# or
yarn add @nexvio-ai/widget-js
Two embed modes
| Element | React component | Description |
|---|---|---|
<nexvio-agent> | <NexvioWidget> | Inline widget — renders in place, no launcher button |
<nexvio-chat-bot> | <NexvioChatbot> | Floating launcher — fixed-position button that opens a chat panel |
Use <nexvio-agent> when you want the chat embedded in a page section. Use <nexvio-chat-bot> when you want the familiar floating button in the corner of every page.
Quickstart
Inline widget (React)
import { NexvioWidget } from "@nexvio-ai/widget-js/react"
export function SupportPanel() {
return (
<NexvioWidget
options={{
publicKey: "pk_...",
context: {
locale: "en",
},
}}
/>
)
}
Floating launcher (React)
import { NexvioChatbot } from "@nexvio-ai/widget-js/react"
export function SupportChat() {
return (
<NexvioChatbot
options={{
publicKey: "pk_...",
position: "bottom-right",
defaultOpen: false,
}}
/>
)
}
Script tag (floating launcher)
<script>
window.nexvioConfig = {
publicKey: "pk_..."
}
</script>
<script src="https://app.nexvio.ai/api/agent.js" async></script>
<nexvio-chat-bot></nexvio-chat-bot>
NexvioWidgetOptions
These options apply to both <nexvio-agent> and <nexvio-chat-bot>.
| Option | Type | Required | Description |
|---|---|---|---|
publicKey | string | Yes | Agent public key from your dashboard embed snippet. |
appearance | NexvioWidgetAppearance | No | Visual options — see Appearance. |
context | VisitorContext | No | Context about the current visitor — see Visitor context. |
identity | NexvioWidgetIdentity | No | Verified user identity for logged-in users — see Identity verification. |
metadata | Record<string, unknown> | No | Arbitrary metadata passed to the agent on every conversation. |
client | { tools?: ClientTool[] } | No | Client-side tools the agent can call — see Client tools. |
startScreen | StartScreenConfig | No | Configure the pre-chat greeting and prompt suggestions. |
messageActions | unknown | No | Custom actions shown on messages. |
host | string | No | Override the widget frame host. Defaults to chatwidget.app. |
onEvent | (event: WidgetEvent) => void | No | Callback for widget events — see Events. |
fetch | typeof fetch | No | Override the fetch implementation used by the SDK. |
Appearance
interface NexvioWidgetAppearance {
colorScheme?: "light" | "dark"
}
Visitor context
Passes unverified visitor metadata to the agent. For verified identity (logged-in users), use identity instead.
interface VisitorContext {
name?: string
email?: string
phone?: string
locale?: string
timezone?: string
externalId?: string
props?: Record<string, unknown>
}
Start screen
interface StartScreenConfig {
greeting?: string
prompts?: Array<{
label: string
prompt: string
}>
}
NexvioChatbotOptions
<nexvio-chat-bot> / <NexvioChatbot> accepts all NexvioWidgetOptions plus:
| Option | Type | Default | Description |
|---|---|---|---|
position | "bottom-right" | "bottom-left" | "top-right" | "top-left" | "bottom-right" | Position of the launcher button. |
defaultOpen | boolean | false | Open the chat panel on load. |
buttonColor | string | CSS var | Background color of the launcher button. |
buttonIcon | string | Default SVG | Custom SVG path string for the button icon. |
badge | number | boolean | — | Unread count badge. Pass true for a dot, a number for a count. |
gap | number | 20 | Distance in pixels from the viewport edge. |
showFloatingInitialMessages | boolean | false | Show agent initial messages above the launcher. See Floating Initial Messages. |
floatingInitialMessagesDelay | number | 2 | Seconds to wait before showing floating messages. |
floatingMessagesOncePerSession | boolean | true | Show floating messages only once per browser session. |
Public methods
Obtain a reference to the element before calling methods.
React
import { useRef } from "react"
import { NexvioChatbot, type NexvioChatbotElement } from "@nexvio-ai/widget-js/react"
export function Chat() {
const ref = useRef<NexvioChatbotElement>(null)
return (
<>
<NexvioChatbot ref={ref} options={{ publicKey: "pk_..." }} />
<button onClick={() => ref.current?.open()}>Open chat</button>
</>
)
}
Custom element
const widget = document.querySelector("nexvio-chat-bot")
widget.open()
Method reference
| Method | Available on | Signature | Description |
|---|---|---|---|
setOptions | both | (options: NexvioWidgetOptions): void | Initialize or reconfigure the widget. Must be called with publicKey before the widget loads. |
identify | both | (identity: NexvioWidgetIdentity): Promise<void> | Set verified user identity. Call after login. See Identity verification. |
resetUser | both | (): Promise<void> | Clear the current verified identity. Call on logout. |
setVisitor | both | (visitor: Record<string, unknown>): Promise<void> | Update visitor context at runtime. |
refresh | both | (): Promise<void> | Reload the widget frame content without full reinitialization. |
reload | both | (): Promise<void> | Force a full frame reinitialization. |
focusInput | both | (): Promise<void> | Move keyboard focus to the chat input field. |
open | chatbot only | (): void | Open the chat panel. |
close | chatbot only | (): void | Close the chat panel. |
toggle | chatbot only | (): void | Toggle the chat panel open/closed. |
isOpen | chatbot only | boolean (getter) | true if the chat panel is currently open. |
React hooks
useNexvioWidget
import { useNexvioWidget } from "@nexvio-ai/widget-js/react"
function MyWidget() {
const { ref, identify, resetUser } = useNexvioWidget()
return <nexvio-agent ref={ref} />
}
Returns { ref, setElement, identify, resetUser }.
useNexvioChatbot
import { useNexvioChatbot } from "@nexvio-ai/widget-js/react"
function MyChat() {
const { ref } = useNexvioChatbot()
return <nexvio-chat-bot ref={ref} />
}
Returns { ref, setElement }.
Client tools
Client tools let your server-side agent call JavaScript functions running in the user's browser — for example, to navigate to a page, open a modal, or read local state.
import { NexvioWidget } from "@nexvio-ai/widget-js/react"
import { z } from "zod"
<NexvioWidget
options={{
publicKey: "pk_...",
client: {
tools: [
{
name: "navigate",
description: "Navigate the user to a URL in the current app",
parameters: z.object({ url: z.string().url() }),
execute: async ({ url }) => {
window.location.href = url
return { navigated: true }
},
},
],
},
}}
/>
Tool schemas are sent to the agent as part of the conversation context. When the agent calls a tool, the SDK executes execute() in the browser and returns the result to the agent automatically.
Events
Pass an onEvent callback to receive lifecycle and interaction events from the widget.
<NexvioWidget
options={{
publicKey: "pk_...",
onEvent: (event) => {
console.log(event.type, event)
},
}}
/>
| Event type | Description |
|---|---|
widget.ready | Widget frame loaded and ready. |
widget.error | Widget failed to load. |
widget.event | User interaction event from inside the widget (message sent, conversation started, etc.). |
widget.resize | Widget frame changed dimensions. |
widget.appearance | Color scheme changed (light/dark). |
Identity verification
See the dedicated Identity Verification guide for server-side JWT and HMAC token generation, and how to call identify() from the SDK.