SDK & Frameworks

Chat Widget — React

Add the FutureBase AI chat widget to any React application using the @futurebase/chat package.

Installation

npm install @futurebase/chat

Quick start

Wrap your app with ChatProvider

Import ChatProvider from @futurebase/chat/react and wrap your application. Pass your website ID as the wid prop — you can find it in your FutureBase dashboard under Settings.

import { ChatProvider } from "@futurebase/chat/react";

function App() {
  return (
    <ChatProvider wid="YOUR_WEBSITE_ID">
      {/* your app */}
    </ChatProvider>
  );
}

Add the ChatBubble component

Place ChatBubble anywhere inside the provider. It renders a floating chat button in the corner of the screen.

import { ChatProvider, ChatBubble } from "@futurebase/chat/react";

function App() {
  return (
    <ChatProvider wid="YOUR_WEBSITE_ID">
      <Main />
      <ChatBubble />
    </ChatProvider>
  );
}

Replace YOUR_WEBSITE_ID with the website ID from your FutureBase dashboard.

ChatProvider props

ChatProvider accepts the following props:

PropTypeRequiredDescription
widstringYesYour FutureBase website ID.
childrenReactNodeYesChild components to render inside the provider.
embedUrlstringNoOverride the embed app base URL (defaults to https://embed.futurebase.io).
serverUrlstringNoOverride the server API base URL (defaults to https://api.futurebase.io).
externalUserIdstringNoAssociate conversations with a user ID from your system.
ignorePathsstring[]NoPathname patterns where the chat bubble should be hidden. Supports trailing * wildcards (e.g. "/admin/*").

ChatBubble props

PropTypeDefaultDescription
position"bottom-right" | "bottom-left""bottom-right"Screen corner where the bubble appears.
theme"light" | "dark""light"Light or dark mode for the chat embed.
iconReactNodeCustom icon to render inside the bubble button.
defaultTab"home" | "chat" | "help"Which tab to show when the chat opens.
autoStartConversationbooleanAutomatically start a new conversation on mount.

useChat() hook

Access the chat state programmatically from any component inside ChatProvider:

import { useChat } from "@futurebase/chat/react";

function MyComponent() {
  const { isOpen, open, close, toggle, isEnabled, isLoading, status, wid } = useChat();

  return (
    <button onClick={toggle}>
      {isOpen ? "Close chat" : "Open chat"}
    </button>
  );
}

Return value

PropertyTypeDescription
widstringThe website ID.
isOpenbooleanWhether the chat panel is currently open.
open() => voidOpen the chat panel.
close() => voidClose the chat panel.
toggle() => voidToggle the chat panel.
isEnabledbooleanWhether the chat widget is enabled (status check passed).
isLoadingbooleanWhether the initial status check is still loading.
statusChatStatusResponse | nullRaw status response from the server.

Types

ChatTheme

type ChatTheme = "light" | "dark";

ChatBubblePosition

type ChatBubblePosition = "bottom-right" | "bottom-left";

ChatConfig

type ChatConfig = {
  wid: string;
  embedUrl?: string;
  serverUrl?: string;
  externalUserId?: string;
  ignorePaths?: string[];
};

ChatStatusResponse

type ChatStatusResponse = {
  status: "ok" | "ai-credits-exceeded" | "not-ok";
  enabled: boolean;
  brandingRemoved?: boolean;
  chatBubbleColor?: string;
  chatBubbleIcon?: string;
  chatBubblePosition?: "left" | "right";
};

On this page