APTalkmoji React SDK
Docs›Libraries

React SDK

Integrate the Talkmoji talking agent into any React application with a single component. Works with Next.js, Vite, Remix, and Create React App.

Installation

npm install @avatar-platform/react
# or
yarn add @avatar-platform/react
# or
pnpm add @avatar-platform/react
ℹ️

The React SDK mounts the real embed-loader.js script — the same one behind the plain <script data-bot> snippet on your dashboard's Install code step. No bundler configuration is needed. React 17+ and React 18 are both supported.

AvatarWidget

The primary component. Drop it anywhere in your component tree — typically near the root layout so it persists across route changes. It renders nothing visible itself.

import { AvatarWidget } from '@avatar-platform/react';

export default function App() {
  return (
    <>
      <YourApp />
      <AvatarWidget
        serverUrl="https://your-deployment.com"
        botId="YOUR_BOT_ID"
      />
    </>
  );
}

Props

PropTypeDefaultDescription
serverUrl string — Required. Base URL of your Talkmoji deployment, no trailing slash.
botId string — Required. The public ID of your project. Find it in the dashboard → Install code step.
⚠️

There's no position/theme/open()/close() — those are configured per-project in your Talkmoji dashboard's Widget settings, not overridable per-mount.

Async Q&A (no widget UI)

For headless integrations — asking questions without showing the animated character — use askAvatar directly:

import { askAvatar } from '@avatar-platform/react';

function SupportButton() {
  const handleSearch = async (query: string) => {
    const result = await askAvatar({
      serverUrl: 'https://your-deployment.com',
      botId: 'YOUR_BOT_ID',
      question: query,
    });
    console.log(result.answer);   // AI answer string
    console.log(result.sources);  // source files used
  };

  return (
    <button onClick={() => handleSearch('How do I reset my password?')}>
      Ask the AI
    </button>
  );
}

This calls POST /embed/:publicId/ask over HTTPS — no widget, no voice, no Rive. Pass the returned sessionId back in on the next call to continue the same conversation.

TypeScript types

interface AvatarWidgetProps {
  serverUrl: string;
  botId: string;
}

interface AskAvatarOptions {
  serverUrl: string;
  botId: string;
  question: string;
  sessionId?: string;
}

interface AskAvatarResult {
  answer: string;
  sources: {
    title: string;
    url: string | null;
    snippet: string;
  }[];
  sessionId: string;
}

Next.js example

For Next.js App Router, mark the component as a client component and add the widget to your root layout:

// app/layout.tsx
'use client';
import { AvatarWidget } from '@avatar-platform/react';

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html lang="en">
      <body>
        {children}
        <AvatarWidget
          serverUrl={process.env.NEXT_PUBLIC_AVATARPLATFORM_URL!}
          botId={process.env.NEXT_PUBLIC_BOT_ID!}
        />
      </body>
    </html>
  );
}
⚠️

SSR note: The widget renders on the client only. It is safe to use inside 'use client' components. The component tree above it can remain a Server Component.