React live chat widget
@replyze/react is a React live chat widget for Next.js and any React 18 or 19 app. One <ReplyzeChat /> component puts the Replyze chat on your site: a floating launcher, an AI chatbot that answers from your knowledge base and hands over to your team, and live chat with your team. The useReplyze() hook lets your own buttons open the chat and show the unread count. Events are typed, and identity verification for signed-in users is built in. It works with the Next.js App Router (Next.js 13.4 and newer) and Pages Router, Vite and other React setups, and it is safe to render on the server.
Create a free account · Live demo · Docs
Replyze brings web chat, email, WhatsApp and Telegram into one inbox for your team (Messenger and Instagram are in beta). This package adds the web chat to a React app. The live demo is replyze.chat itself: the chat bubble in the bottom-right corner is the same widget.
Quickstart
- Get your widget token. Create a free account, then copy the token (
wgt_...) from Settings → Integrations → Install widget.
- Install the package from GitHub:
npm install github:Replyze/react-live-chat
- Render
<ReplyzeChat /> once, near the root of your app:import { ReplyzeChat } from '@replyze/react';
export default function App() {
return (
<>
<YourApp />
<ReplyzeChat token="wgt_YOUR_TOKEN" />
</>
);
}
Once the page has loaded, the chat launcher appears in the bottom corner. For Next.js, see App Router and Pages Router.
Contents
Install · Your own chat button · Next.js App Router · Next.js Pages Router · Vite · Your widget token · Props · useReplyze() · Events · Identity verification · Cookie consent · Performance · TypeScript · How it works · FAQ · Development
Install
@replyze/react is not on the npm registry yet. Install it from GitHub:
npm install github:Replyze/react-live-chat
You import it as @replyze/react. npm builds the package while it installs (its prepare script runs tsup), so the install needs git and takes a few seconds longer than a package from the registry. Pin a commit or tag with github:Replyze/react-live-chat#<ref>.
After the first npm release (not yet), the registry install will be:
npm install @replyze/react
Requirements: React 18 or 19 (peer dependency). For the Next.js App Router, Next.js 13.4 or newer. You also need a Replyze account (sign up).
Render <ReplyzeChat /> once, near the root, so it stays mounted while people move between pages. The widget notices client-side route changes by itself.
Your own chat button
An "Open chat" button with the unread count:
import { useReplyze } from '@replyze/react';
export function HelpButton() {
const { toggle, unreadCount } = useReplyze();
return (
<button type="button" onClick={toggle}>
Help{unreadCount > 0 ? ` (${unreadCount})` : ''}
</button>
);
}
useReplyze() needs no provider. Calls made before the widget has loaded wait and run as soon as it starts.
Next.js App Router
app/layout.tsx can stay a server component. <ReplyzeChat /> is already a client component: the package's entry starts with "use client".
import type { ReactNode } from 'react';
import { ReplyzeChat } from '@replyze/react';
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html lang="en">
<body>
{children}
<ReplyzeChat token={process.env.NEXT_PUBLIC_REPLYZE_TOKEN!} />
</body>
</html>
);
}
# .env.local
NEXT_PUBLIC_REPLYZE_TOKEN=wgt_YOUR_TOKEN
Components that use useReplyze() need 'use client' at the top, like any component with hooks. A full example app is in examples/nextjs.
Next.js Pages Router
pages/_app.tsx:
import type { AppProps } from 'next/app';
import { ReplyzeChat } from '@replyze/react';
export default function App({ Component, pageProps }: AppProps) {
return (
<>
<Component {...pageProps} />
<ReplyzeChat token={process.env.NEXT_PUBLIC_REPLYZE_TOKEN!} />
</>
);
}
Vite
src/main.tsx:
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import { ReplyzeChat } from '@replyze/react';
import App from './App';
createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
<ReplyzeChat token={import.meta.env.VITE_REPLYZE_TOKEN} />
</StrictMode>,
);
# .env.local
VITE_REPLYZE_TOKEN=wgt_YOUR_TOKEN
Create React App, React Router and other setups work the same way: render it once near the root.
Your widget token and allowed domains
- Token. The widget token (
wgt_...) is in the dashboard under Settings → Integrations → Install widget. It is not a secret: it is in your page for anyone to see and only lets the chat talk to your workspace. API keys (rpz_live_...) are secrets; <ReplyzeChat /> refuses to load with one and says so in the console.
- Allowed domains. Settings → Chat Widget has the list of sites that may show the widget. An empty list allows every site. With entries, the host must match:
example.com doesn't cover www.example.com; *.example.com covers both. While you develop, add localhost. On a domain that isn't allowed, the console says [Replyze] Widget blocked: this domain (...) is not in the widget's allowed-domains list.
Props
| Prop |
Type |
Default |
What it does |
token |
string |
required |
The widget token, wgt_... |
user |
ReplyzeIdentity | null |
undefined |
The signed-in user: see Identity verification |
language |
string |
the browser's, or the widget's setting |
The chat's interface language: "de", "pt-BR", "ar"... The widget speaks English, Serbian, German, Spanish, French, Italian, Portuguese, Dutch, Polish, Turkish, Russian, Ukrainian, Arabic, Chinese, Japanese, Hebrew and Persian. Changes apply live |
tracking |
boolean |
true |
false turns off visitor tracking: no visitor cookie, page views or presence on the Visitors page. The chat works either way. Changes apply live |
color |
string |
the dashboard's |
Brand colour, "#1eabd2" or "rgb(...)" |
position |
"bottom_left" | "bottom_right" |
the dashboard's |
The launcher's corner |
theme |
"light" | "dark" |
the dashboard's |
|
botName |
string |
the dashboard's |
The assistant's name |
botAvatar |
string |
the dashboard's |
The assistant's picture, an https URL |
welcomeMessage |
string |
the dashboard's |
The welcome message |
showGreetingTeaser |
boolean |
the dashboard's |
The welcome card next to the launcher |
autoOpenDelay |
number |
the dashboard's |
Seconds (0 to 300) before the welcome card shows |
strategy |
"lazyOnload" | "afterInteractive" |
"lazyOnload" |
When widget.js is requested: after the page's load event when the browser is idle, or right after React has mounted the component |
apiUrl |
string |
https://client.replyze.chat |
The Replyze API. Only for a staging or local backend |
scriptUrl |
string |
https://cdn.replyze.chat/widget.js |
Where widget.js comes from |
nonce |
string |
|
A Content-Security-Policy nonce for the script tag |
The look props (color to autoOpenDelay) win over the dashboard's widget settings; a value that doesn't fit (a colour that isn't one, an http: picture) is ignored by the widget. token, apiUrl, scriptUrl and the look props are read once, when the widget loads; if they change later, the console says the change applies on the next page load. language and tracking follow the props through setLanguage() and setTracking().
useReplyze()
const { status, isOpen, unreadCount, open, close, toggle, identify, reset, on } = useReplyze();
State (the component re-renders when it changes):
|
Type |
|
status |
"idle" | "loading" | "ready" | "error" |
idle: no <ReplyzeChat /> has asked for the widget yet. loading: scheduled or downloading. ready: running. error: widget.js failed to load (network, ad blocker, Content-Security-Policy) or the widget didn't start; the console says why |
isOpen |
boolean |
The chat window is open |
unreadCount |
number |
Replies the visitor hasn't seen: the number on the launcher's badge |
Methods (stable between renders). They are the widget's own JavaScript API, with the same arguments:
| Method |
What it does |
open() / close() / toggle() |
Open, close or toggle the chat window |
show() / hide() |
Show or hide the launcher and the chat. The widget keeps running while hidden. After show(), the widget shows on every page, whatever its page rules in the dashboard say |
identify(email, name?) |
Who the visitor is |
identify({ user_id, email, name, user_hash }) |
A signed-in user, verified with user_hash: see Identity verification |
reset() |
The visitor signed out: forget them (chat, contact, visitor cookie). The next chat starts as a new visitor |
setLanguage(language) |
The chat's interface language, over the browser's and the widget settings |
setUser({ email, name, data }) |
Name and email, plus custom data in data |
setData({ plan: 'pro', seats: 3 }) |
Custom data on the visitor's contact: text, numbers, true/false, or null to remove a key. Keys that match a contact field fill it; others are kept as extra data. Up to 50 keys |
pushEvent('Upgraded', { plan: 'pro' }) |
An event on the visitor's timeline in the inbox, with the page it happened on. Names are 1 to 64 characters |
sendMessage(text) |
Send a message as the visitor |
setTracking(allowed) |
Turn visitor tracking on or off |
openArticle(id) |
Open the widget on a help article (the widget needs its Home or Help tab) |
on(event, handler) |
Listen to an event. Returns a function that stops listening |
off(event, handler) |
Stop listening |
Outside React (an auth callback, a store, a router event), the same methods are on the Replyze object: