Chat Widget
React / Next.js Integration
Embed @aelio/chat in React, Next.js, or Vite applications.
npm import
npm install @aelio/chatimport { mountAelioChat, unmountAelioChat } from '@aelio/chat';React component
'use client';
import { useEffect, useRef } from 'react';
import { mountAelioChat, unmountAelioChat } from '@aelio/chat';
export function AelioChatWidget({ user }: { user: { id: string; email: string; chatToken?: string } }) {
const handleRef = useRef<ReturnType<typeof mountAelioChat>>(null);
useEffect(() => {
handleRef.current = mountAelioChat({
serverUrl: process.env.NEXT_PUBLIC_AELIO_SERVER_URL!,
customerId: user.id,
authToken: user.chatToken,
email: user.email,
title: 'Chat with us',
launcherLabel: 'Help',
});
return () => {
if (handleRef.current) unmountAelioChat(handleRef.current);
};
}, [user.id, user.email, user.chatToken]);
return null; // Widget renders as a floating overlay
}Next.js App Router
Add the component to your layout or a dedicated page:
// app/layout.tsx or app/support/page.tsx
import { AelioChatWidget } from '@/components/aelio-chat';
export default function Layout({ children }) {
return (
<>
{children}
<AelioChatWidget user={currentUser} />
</>
);
}Environment variables
# .env.local
NEXT_PUBLIC_AELIO_SERVER_URL=https://your-aelio-server.comOnly expose the server HTTP URL to the frontend. Never expose
AELIO_SDK_SECRET.
Options reference
type AelioChatOptions = {
serverUrl: string; // Required — Aelio server HTTP URL
customerId: string; // Required — your user ID
authToken?: string; // Short-lived session token (production)
email?: string; // Customer email
target?: HTMLElement | string; // Mount target (default: auto-created div)
title?: string; // Panel header (default: "Chat with us")
launcherLabel?: string; // Button label (default: "Chat")
initialMessage?: string; // Empty-state hint
};Confirmation UI
When the LLM calls a write safety tool (checkout, cancel, etc.), the widget automatically shows Confirm / Cancel buttons. No extra configuration needed.
Troubleshooting
| Issue | Fix |
|---|---|
| "Origin not allowed" | Add your app origin to channels.web.allowed_origins |
| "Connecting..." forever | Check serverUrl, server /health, and channels.web.enabled |
| Widget not appearing | Ensure channels.web.enabled: true in server config |
| History not loading | Requires Aelio server v0.1.2+ with matching widget build |