@adaptive-chatbot/widget
v0.1.3
Published
Embeddable website chatbot widget for the Adaptive Chatbot Platform.
Maintainers
Readme
@adaptive-chatbot/widget
Add the Adaptive Chatbot to a website with npm, React, or a script tag. The widget is a Web Component with Shadow DOM styles, lazy-loads its chat window, and is safe to import during server-side rendering.
Install
npm install @adaptive-chatbot/widgetPublish (maintainers)
From the repository root, target the widget workspace so npm packs the package in this directory rather than the private monorepo root:
pnpm --filter @adaptive-chatbot/widget exec npm publish --access public --otp=YOUR_6_DIGIT_CODEReplace YOUR_6_DIGIT_CODE with the current six-digit code from the npm authenticator. An npm_... access token is not an OTP and must not be passed as --otp.
Create a site in the dashboard, add the site's allowed domains, and use its public pk_live_... site key. Never put a secret key or model provider key in browser code.
Plain JavaScript or TypeScript
import { initChatbot } from "@adaptive-chatbot/widget";
const chatbot = initChatbot({ siteKey: "pk_live_..." });
chatbot.open();
chatbot.close();
chatbot.destroy();
chatbot.on("message", (event) => console.log(event));The launcher is added to the document body and the chat panel is loaded the first time it opens. The public API includes open, close, destroy, and on.
React
import { useChatbot } from "@adaptive-chatbot/widget/react";
export function SupportWidget() {
const chatbot = useChatbot({ siteKey: "pk_live_..." });
return <button type="button" onClick={chatbot.open}>Open support chat</button>;
}React 18 or 19 is an optional peer dependency. The framework-neutral entry point does not load React.
CDN
<script
src="https://cdn.jsdelivr.net/npm/@adaptive-chatbot/widget/dist/cdn/cdn.iife.global.js"
data-site-key="pk_live_..."
></script>The IIFE initializes itself from data-site-key and exposes window.AdaptiveChatbot.initChatbot() for manual setup. The ESM CDN entry remains available at dist/cdn/cdn.js; the package's unpkg/jsDelivr defaults point to the self-initializing IIFE.
Options and events
initChatbot requires siteKey. Optional settings include position (bottom-right or bottom-left), a partial theme, string context, and apiBaseUrl for local testing. The widget fetches appearance and bot name from /v1/config; bot names are rendered as plain text and shown with an “AI assistant” label.
The on method accepts open, close, and message events. Use the public key only. Requests are restricted by the allowed domains configured for the site.
Assistant replies support safe Markdown paragraphs, emphasis, inline code, ordered and unordered lists, and tables. Uploaded knowledge-base filenames are not shown in the visitor chat; deduplicated citations are shown only for sources with a public HTTP(S) URL.
Package contents
The package includes ESM, CommonJS, TypeScript declarations, a React entry point, and self-initializing CDN IIFE plus ESM builds. The initial-load bundles are checked against the 40 KB gzipped limit as part of packaging.
npm install @adaptive-chatbot/widget