@flowengage/react-chatbot

中文文档
8.0.173发布于 2026/11/10MITESM + CJS近 30 天下载 4571

Embeddable AI chat widget for React — powered by FlowEngage. Drop it in with a single siteId.

原始使用文档
文档目录30 节
  1. Choose how to integrate
  2. A. npm package (React / Next.js / Vite)
  3. Prerequisites
  4. 1. Install
  5. 2. Import the stylesheet once
  6. 3. Wrap your app and mount the widget
  7. Next.js App Router
  8. Yarn / monorepo
  9. Dashboard styling vs code ( widgetSettings )
  10. B. CDN / script tag (no React project required)
  11. B1. FlowEngage CDN (recommended)
  12. B2. npm registry CDN (pin a version)
  13. Auto-init attributes ( data-* )
  14. Manual initialization
  15. CDN API ( window.FlowEngage )
  16. Optional: customization (npm)
  17. Props
  18. <FlowEngageProvider>
  19. <FlowEngageWidget>
  20. Using the useFlowEngage Hook
  21. Available context values
  22. SPA Route Tracking
  23. Voice Mode
  24. Session lifecycle
  25. Voice resume across page reloads
  26. Requirements
  27. How It Works
  28. Getting Your Site ID
  29. Building the embed
  30. License

@flowengage/react-chatbot

Embeddable AI-powered customer support chat widget — built by FlowEngage.
Add live chat, AI assistant, and agent handoff to any site in minutes. All you need is your Site ID.


Choose how to integrate

ApproachBest forWhat you add
npm packageReact, Next.js, Vite, Remix, etc.Install the package, wrap your app with FlowEngageProvider, render FlowEngageWidget.
CDN (script tag)Plain HTML, PHP, any CMS, non-React SPAsOne <script> tag; styles are bundled into the embed — no separate CSS file.

You need a Site ID from the FlowEngage dashboard (Integration Guide or site settings).


A. npm package (React / Next.js / Vite)

Prerequisites

  • React 18+ and react-dom 18+ in your project (peer dependencies).
  • Node 18+ recommended for local development.

1. Install

npm install @flowengage/react-chatbot
# or
yarn add @flowengage/react-chatbot
pnpm add @flowengage/react-chatbot

Pin a version in production if you prefer reproducible builds:

npm install @flowengage/react-chatbot@^1.0.0

2. Import the stylesheet once

The widget ships its own CSS. Import it at your app entry (or a layout file):

import '@flowengage/react-chatbot/styles.css';

3. Wrap your app and mount the widget

FlowEngageProvider must wrap any component that uses FlowEngageWidget or useFlowEngage.

// e.g. App.jsx, main.jsx, or a root layout wrapper
import { FlowEngageProvider, FlowEngageWidget } from '@flowengage/react-chatbot';
import '@flowengage/react-chatbot/styles.css';

export default function App() {
  return (
    <FlowEngageProvider siteId="YOUR_SITE_ID">
      <YourExistingApp />
      <FlowEngageWidget />
    </FlowEngageProvider>
  );
}

Next.js App Router

  • Put the provider + widget in a Client Component (file with "use client" at the top), or a client wrapper imported from layout.tsx.
  • Keep a single provider tree so chat state is shared.

Yarn / monorepo

Ensure the package resolves once at app level so you do not mount duplicate providers.

Dashboard styling vs code (widgetSettings)

Use only siteId (and optional apiBaseUrl for local dev) on FlowEngageProvider so the widget loads branding, theme, greetings, and recommendations from the FlowEngage dashboard on every page load—same as the CDN embed.

If you also pass config={{ widgetSettings: { ... } }}, those fields act as defaults only; saved dashboard settings override them. Avoid pasting a full widget JSON into your app unless you intentionally want offline defaults; otherwise you would have to update code after each dashboard change.


B. CDN / script tag (no React project required)

The embed build includes React and injects styles automatically. You do not import styles.css when using the script.

Use the hosted script (kept in sync with FlowEngage infrastructure):

<script
  src="https://cdn.flowengage.com/flowengage-embed.js"
  data-site-id="YOUR_SITE_ID"
  defer>
</script>

Place this before </body> on every page where the widget should appear, or in your global theme template.

B2. npm registry CDN (pin a version)

If you prefer to load the same artifact published to npm (useful for pinning or offline mirrors):

<!-- Replace 1.0.0 with the version you want -->
<script
  src="https://cdn.jsdelivr.net/npm/@flowengage/[email protected]/dist/flowengage-embed.js"
  data-site-id="YOUR_SITE_ID"
  defer>
</script>

Equivalent path on unpkg:

https://unpkg.com/@flowengage/[email protected]/dist/flowengage-embed.js

Auto-init attributes (data-*)

On the <script> tag:

AttributeRequiredDescription
data-site-id✅ for auto-initYour Site ID from the dashboard.
data-api-url❌Override API base URL (advanced; usually omit).
data-widget-settings❌JSON string of runtime widget overrides (theme, branding). Example: '{"theme":{"primaryColor":"#2563EB"}}'

Manual initialization

If you cannot use data-site-id on the script tag:

<script src="https://cdn.flowengage.com/flowengage-embed.js" defer></script>
<script>
  window.addEventListener('load', function () {
    window.FlowEngage.init({
      siteId: 'YOUR_SITE_ID',
      widgetSettings: {
        theme: { primaryColor: '#2563EB', position: 'bottom-right' },
        branding: { headerName: 'Support', chatButtonText: 'Chat' },
      },
    });
  });
</script>

CDN API (window.FlowEngage)

MethodDescription
FlowEngage.init({ siteId, widgetSettings?, apiBaseUrl? })Mounts the widget. Safe to call after DOMContentLoaded.
FlowEngage.destroy()Unmounts the widget and removes injected styles/container. Call before init again if you need to reconfigure.

To open/close the panel from custom UI inside a React app, use the npm package and useFlowEngage() (openWidget, closeWidget, etc.). The standalone embed exposes init / destroy only.


Optional: customization (npm)

Pass runtime overrides via config on the provider (merged with dashboard defaults):

<FlowEngageProvider
  siteId="YOUR_SITE_ID"
  config={{
    widgetSettings: {
      theme: {
        primaryColor: '#FF5733',
        position: 'bottom-left',
      },
      branding: {
        headerName: 'Cool Support Assistant',
        chatButtonText: 'Talk to us',
      },
    },
  }}
>
  <FlowEngageWidget />
</FlowEngageProvider>

Props

<FlowEngageProvider>

PropTypeRequiredDescription
siteIdstring✅Your Site ID from the FlowEngage dashboard
configobject❌{ widgetSettings?: … } merged with server config

<FlowEngageWidget>

No props required. It reads state from the nearest FlowEngageProvider.


Using the useFlowEngage Hook

Access the full widget context in any child component:

import { useFlowEngage } from '@flowengage/react-chatbot';

function MyCustomButton() {
  const { openWidget, isOpen, chatHistory } = useFlowEngage();

  return (
    <button type="button" onClick={() => openWidget()}>
      Chat ({chatHistory.length} messages)
    </button>
  );
}

Available context values

ValueTypeDescription
status"booting" | "ready" | "error"Widget boot status
isOpenbooleanWhether the chat panel is open
chatHistoryMessage[]Full chat history array
isHumanHandledbooleanWhether a live agent has taken over
agentNamestring | nullActive agent's name
agentHeadshotstring | nullActive agent's avatar URL
isAgentTypingbooleanAgent typing indicator
isLoadingbooleanWaiting for AI response
isVoiceModebooleanVoice mode active
isRateLimitedbooleanRate limit hit
openWidget()functionOpen the chat panel
closeWidget()functionClose the chat panel
toggleWidget()functionToggle the panel
sendMessage(msg, category?)functionSend a message
setVoiceMode(bool)functionToggle voice mode
notifyRouteChange()functionNotify tracker of SPA route change

SPA Route Tracking

For client-side routing (React Router, Next.js App Router, etc.):

import { useFlowEngage } from '@flowengage/react-chatbot';
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';

function RouteTracker() {
  const { notifyRouteChange } = useFlowEngage();
  const location = useLocation();

  useEffect(() => {
    notifyRouteChange();
  }, [location.pathname]);

  return null;
}

Voice Mode

The widget includes an ElevenLabs-powered voice agent that visitors can interact with hands-free.

Session lifecycle

  1. Visitor clicks "Start Voice" (or auto-starts on voice-enabled sites)
  2. Widget fetches a signed URL from the backend (GET /api/voice/signed-url)
  3. ElevenLabs WebSocket session starts with page-context greeting override
  4. Agent can call client tools: flowengage_navigate, flowengage_highlight, flowengage_list_forms, flowengage_fill_form, flowengage_click_button, end_voice_session
  5. On SPA navigation the session persists — a URL-change tracker sends contextual updates so the agent knows the current page
  6. On hard navigation (page reload), the transcript is saved to sessionStorage and the session auto-resumes on the next page

Voice resume across page reloads

When the agent navigates the visitor to a new page (flowengage_navigate), the widget:

  • Saves the current transcript and a resume flag to sessionStorage
  • Triggers a hard reload or SPA route change
  • On the new page, useLayoutEffect detects the pending resume and re-enters voice_mode
  • The new session loads with a "continue the tour" preamble so the agent picks up where it left off

Requirements

  • ElevenLabs agent must have first_message override enabled in platform settings
  • Backend must have ELEVENLABS_API_KEY configured
  • Visitor must grant microphone permission

How It Works

Your App
   └── <FlowEngageProvider siteId="...">
          │
          ├── Boot:  GET /api/widget/bootstrap  → validates siteId, returns config
          ├── Start: POST /api/ai/chat           → loads chat history
          ├── Chat:  Socket.IO                   → real-time messages & agent handoff
          ├── Voice: GET /api/voice/signed-url   → ElevenLabs WebSocket voice session
          └── Track: Socket.IO events            → visitor session, page views

Backend URLs are resolved by FlowEngage; you normally do not set them unless using apiBaseUrl (advanced).


Getting Your Site ID

  1. Log in to the FlowEngage Dashboard
  2. Open Integration Guide or your site / workspace settings
  3. Copy the Site ID for your website

Building the embed

The CDN embed is an IIFE bundle that includes React, all widget code, and inlined CSS. Build it with:

FLOWENGAGE_API_URL=https://your-api-url npx vite build --config vite.embed.config.js

Output lands in dist/flowengage-embed.js. Copy this file to the CDN or the backend public/ folder for serving.

The FLOWENGAGE_API_URL env var is baked into the bundle at build time — the widget uses it as the default API base URL when no data-api-url attribute is present on the script tag.


License

MIT © FlowEngage

版本与发布记录

@flowengage/react-chatbot 共发布 485 个版本,首次发布于 2026/04/08;过去 12 个月发布了 485 个版本。

版本发布日期距今
8.0.173latest2026/11/105 天前
8.0.1722026/11/105 天前
8.0.1712026/11/0411 天前
8.0.1702026/10/2323 天前
8.0.1692026/10/2225 天前
8.0.1682026/10/2225 天前

其他发布通道:beta → 1.6.1-test。

关于 @flowengage/react-chatbot 的常见问题

@flowengage/react-chatbot 是什么?

Embeddable AI chat widget for React — powered by FlowEngage. Drop it in with a single siteId.

如何安装 @flowengage/react-chatbot?

在项目目录运行 npm install @flowengage/react-chatbot,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=18.0.0)、react-dom(>=18.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@flowengage/react-chatbot 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/flowengage__react-chatbot 是否存在。

@flowengage/react-chatbot 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@flowengage/react-chatbot 可以商用吗?

@flowengage/react-chatbot 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@flowengage/react-chatbot 的下载量有多少?

根据 npm 官方下载统计,@flowengage/react-chatbot 在 2026/10/15 – 2026/11/13 这 30 天内被下载 4,571 次,日均约 152 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@flowengage/react-chatbot 还在维护吗?

最新版本 8.0.173 发布于 2026/11/10(5 天前);至今共发布 485 个版本,其中过去 12 个月发布了 485 个;首次发布于 2026/04/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。