Skip to content

Repository files navigation

@rapidaai/web-widget

Embeddable voice + text AI agent widget. Drop a single script tag into any website to add an intelligent chat assistant powered by Rapida.

CInpmLicense: MIT

Quick Start

Add the widget to any HTML page with two lines:

<script>window.chatbotConfig={assistant_id: "YOUR_ASSISTANT_ID",token: "YOUR_API_KEY",};</script><scriptsrc="https://cdn-01.rapida.ai/public/scripts/app.min.js"></script>

That's it. A floating chat button appears in the bottom-right corner of your page.

Installation

CDN (recommended)

Use the latest version:

<scriptsrc="https://cdn-01.rapida.ai/public/scripts/app.min.js"></script>

Pin to a specific version:

<scriptsrc="https://cdn-01.rapida.ai/public/scripts/v1.2.0/app.min.js"></script>

npm

npm install @rapidaai/web-widget

Then import the built file from dist/app.min.js in your bundler or serve it statically.

Configuration

Set window.chatbotConfigbefore loading the script:

<script>window.chatbotConfig={// Requiredassistant_id: "your-assistant-id",token: "your-api-key",// Optional - API endpoint (defaults to Rapida cloud)api_base: "https://assistant-01.in.rapida.ai",// Optional - user identityuser: {name: "Jane Doe",user_id: "user-123",meta: {plan: "pro"},},// Optional - identityname: "Support Bot",logo_url: "https://example.com/avatar.png",// Optional - layout sectionlayout: {mode: "floating",// "floating" | "docked-right" | "docked-left" | "inline"position: "bottom-right",// "bottom-right" | "bottom-left" | "top-right" | "top-left"corners: "square",showFrame: true,},// Optional - theme sectiontheme: {mode: "light",// "light" | "dark" | "system"injectTheme: "g10",// "white" | "g10" | "g90" | "g100"},// Optional - AI Chat sectionsaiEnabled: false,header: {title: "Support Bot",showAiLabel: false,minimizeButtonIconType: "side-panel-right",},launcher: {isOn: true,},history: {isOn: false,},messaging: {messageTimeoutSecs: 150,messageLoadingIndicatorTimeoutSecs: 1,},// Optional - misclanguage: "en",assistant_version: "latest",debug: false,};</script>

Configuration Model

The widget has two configuration layers:

  • Rapida layer: connection, authentication, user identity, message bridge, and audio controls.
  • UI layer: native IBM AI Chat configuration exposed directly on window.chatbotConfig.

Rapida always owns messaging.customSendMessage because text messages must go through @rapidaai/react. Rapida also appends its audio controls through renderWriteableElements.afterInputElement; if you provide your own afterInputElement, it is preserved and Rapida audio is appended after it.

Use the sectioned config shape below. Do not use a carbon config key.

Required Rapida Options

PropertyTypeDefaultDescription
assistant_idstringrequiredRapida assistant/deployment ID.
tokenstringrequiredPublic web plugin token used to authenticate the widget.

Rapida Options

PropertyTypeDefaultDescription
api_basestringhttps://assistant-01.in.rapida.aiRapida API base URL. Use this for local or environment-specific backends.
assistant_versionstringlatestAssistant version to load when the backend supports versioned deployments.
user.namestringGuestDisplay name for the current user.
user.user_idstringgenerated and stored locallyStable user ID. Provide one if your host app already has an authenticated user ID.
user.metaRecord<string, string>{ source: "web plugin" }Extra metadata sent to Rapida with the user session.
languagestringhost page language or enLocale/language passed to the UI. The widget also watches <html lang>.
debugbooleanfalseEnables additional client logging. Also passed to the UI layer.
namestringdeployment nameFriendly assistant name. Used as the default assistantName and header.title.
logo_urlstringdefault assistant avatarAssistant avatar URL. Used as the default assistantAvatarUrl.

Theme Options

Use theme for all theme-level options.

PropertyTypeDefaultDescription
theme.mode"light" | "dark" | "system""light"Widget color mode. dark defaults the UI token injection to g100; light defaults it to g10; system lets the host/system decide unless theme.injectTheme is set.
theme.injectTheme"white" | "g10" | "g90" | "g100"derived from theme.modeUI theme token injected into the chat shadow DOM. Set this when the host page does not already provide compatible theme tokens.
theme.colorstringnoneLegacy primary brand color. Prefer layout.customProperties for current UI customization.

Layout Options

layout can be a string for old embeds or an object for the current sectioned config.

window.chatbotConfig={layout: {mode: "floating",position: "bottom-right",corners: "square",showFrame: true,customProperties: {width: "420px",height: "640px",},},};
PropertyTypeDefaultDescription
layoutstring | object"floating"Widget layout. String values are still supported: "floating", "docked-right", "docked-left", "inline".
layout.mode"floating" | "docked-right" | "docked-left" | "inline""floating"Rapida placement mode.
layout.position"bottom-right" | "bottom-left" | "top-right" | "top-left""bottom-right"Floating launcher and panel position.
layout.showLauncherbooleantrue for floatingLegacy launcher shortcut inside layout. Prefer launcher.isOn.
layout.showFramebooleantrueKeeps the native border and shadow frame.
layout.hasContentMaxWidthbooleanUI defaultConstrains message content to the UI max-width.
layout.corners"round" | "square" | object"square"Corner style. Use a string for all corners or an object for per-corner control.
layout.customPropertiesRecord<string, string>generated for floatingCSS variable overrides for the chat UI. Values are raw CSS strings.

Per-corner layout.corners object:

PropertyTypeDescription
startStart"round" | "square"Top-left in LTR, top-right in RTL.
startEnd"round" | "square"Top-right in LTR, top-left in RTL.
endStart"round" | "square"Bottom-left in LTR, bottom-right in RTL.
endEnd"round" | "square"Bottom-right in LTR, bottom-left in RTL.

Supported layout.customProperties keys:

KeyDescription
heightFloating chat height.
max-heightFloating chat maximum height.
widthFloating chat width.
min-heightFloating chat minimum height.
max-widthFloating chat maximum width.
z-indexFloating chat z-index.
bottom-positionFloating panel distance from viewport bottom.
right-positionFloating panel distance from viewport right.
top-positionFloating panel distance from viewport top.
left-positionFloating panel distance from viewport left.
launcher-default-sizeLauncher button size.
launcher-position-bottomLauncher distance from viewport bottom.
launcher-position-rightLauncher distance from viewport right.
launcher-extended-widthExpanded launcher width.
messages-max-widthMaximum width for message content.
messages-min-widthMinimum width for message content.
workspace-min-widthMinimum width for workspace panels.
card-max-widthMaximum width for card responses.
launcher-color-backgroundLauncher background color.
launcher-color-avatarLauncher icon/avatar color.
launcher-color-background-hoverLauncher hover background.
launcher-color-background-activeLauncher active background.
launcher-color-focus-borderLauncher focus border color.
launcher-mobile-color-textMobile launcher text color.
launcher-expanded-message-color-textExpanded launcher text color.
launcher-expanded-message-color-backgroundExpanded launcher background.
launcher-expanded-message-color-background-hoverExpanded launcher hover background.
launcher-expanded-message-color-background-activeExpanded launcher active background.
launcher-expanded-message-color-focus-borderExpanded launcher focus border color.
unread-indicator-color-backgroundUnread indicator background color.
unread-indicator-color-textUnread indicator text color.

Header Options

PropertyTypeDefaultDescription
header.isOnbooleantrueEnables the native chat header. Set false for a fully embedded/fullscreen experience with your own app header.
header.titlestringname or deployment nameHeader title. Set "" to remove the visible title.
header.namestringUI defaultSecondary name shown after the title. Set "" to remove it.
header.minimizeButtonIconType"close" | "minimize" | "side-panel-left" | "side-panel-right" | "side-panel-down"side-panel icon based on dock sideIcon for the close/minimize button.
header.hideMinimizeButtonbooleanfalseHides the close/minimize button.
header.showRestartButtonbooleanfalseShows the restart conversation button.
header.menuOptionsArray<{ text: string }>noneCustom menu options in the header menu.
header.showAiLabelbooleanfalseShows the AI label in the header. Disabled by default.
header.hideDefaultAiLabelContentbooleantrueHides the default AI label popover content.
header.hasContentMaxWidthbooleanfalseConstrains the header to the message content width.
header.actionsToolbarAction[]noneCustom header toolbar actions.

Launcher Options

PropertyTypeDefaultDescription
launcher.isOnbooleantrue for floating, false for docked/inlineShows the floating launcher button.
launcher.showUnreadIndicatorbooleanUI defaultShows the unread dot on the launcher.
launcher.mobile.avatarUrlOverridestringnoneCustom mobile launcher avatar/icon URL.
launcher.mobile.isOnbooleanfalseDeprecated expanded call-to-action launcher state.
launcher.mobile.titlestringtranslated defaultDeprecated expanded launcher title.
launcher.mobile.timeToExpandnumber15Deprecated delay before launcher expansion, in seconds.
launcher.desktop.avatarUrlOverridestringnoneCustom desktop launcher avatar/icon URL.
launcher.desktop.isOnbooleanfalseDeprecated expanded call-to-action launcher state.
launcher.desktop.titlestringtranslated defaultDeprecated expanded launcher title.
launcher.desktop.timeToExpandnumber15Deprecated delay before launcher expansion, in seconds.

History Options

PropertyTypeDefaultDescription
history.isOnbooleanfalseEnables the native history panel.
history.showMobileMenubooleantrueShows mobile header menu options for new chat and view chats.
history.startClosedbooleanfalseStarts history closed and preserves open/closed state across responsive mode changes.

Messaging Options

PropertyTypeDefaultDescription
messaging.skipWelcomebooleanUI defaultStarts new conversations without requesting a welcome message.
messaging.messageTimeoutSecsnumber150Message timeout in seconds. Use 0 to disable automatic timeout.
messaging.messageLoadingIndicatorTimeoutSecsnumber1Delay before the UI shows a loading indicator. Use 0 to prevent the UI from showing one automatically.
messaging.customSendMessagefunctionRapida bridgeReserved. Rapida overwrites this so text is sent through @rapidaai/react.
messaging.customLoadHistoryfunctionnoneOptional function that returns native history items for the UI.
messaging.showStopButtonImmediatelybooleanfalseShows the stop button as soon as a message request starts.

Input Options

PropertyTypeDefaultDescription
input.maxInputCharactersnumber10000Maximum characters allowed in the text input.
input.isVisiblebooleantrueShows or hides the main input surface.
input.isDisabledbooleanfalseDisables text input. Rapida also disables text input while audio mode is active.

Home Screen Options

PropertyTypeDefaultDescription
homescreen.isOnbooleanfalseEnables the native home screen before chat.
homescreen.greetingstringnoneGreeting text on the home screen.
homescreen.starters.isOnbooleanUI defaultShows starter buttons.
homescreen.starters.buttonsArray<{ label: string; isSelected?: boolean }>noneStarter utterances displayed as buttons.
homescreen.customContentOnlybooleanfalseHides the built-in greeting and starters so custom content can own the home screen.
homescreen.disableReturnbooleanfalsePrevents returning to the home screen after a user has sent a message.

Upload Options

File upload is experimental in the underlying UI.

PropertyTypeDefaultDescription
upload.is_onbooleanfalseEnables the attachment button. Requires upload.onFileUpload.
upload.acceptstringall file typesAccepted MIME types or extensions, same format as the HTML accept attribute.
upload.maxFileSizeBytesnumbernoneClient-side maximum file size.
upload.maxFilesnumbernoneMaximum number of pending files.
upload.onFileUploadfunctionnoneCalled once per selected file. Return structured data for the pending message.

Keyboard Shortcut Options

Keyboard shortcut configuration is experimental in the underlying UI.

PropertyTypeDefaultDescription
keyboardShortcuts.messageFocusToggle.is_onbooleantrueEnables the message/input focus toggle shortcut.
keyboardShortcuts.messageFocusToggle.keystring"F6"Primary shortcut key.
keyboardShortcuts.messageFocusToggle.modifiers.altbooleanfalseRequires Alt.
keyboardShortcuts.messageFocusToggle.modifiers.shiftbooleanfalseRequires Shift.
keyboardShortcuts.messageFocusToggle.modifiers.ctrlbooleanfalseRequires Control.
keyboardShortcuts.messageFocusToggle.modifiers.metabooleanfalseRequires Command/Meta.

Disclaimer Options

PropertyTypeDefaultDescription
disclaimer.isOnbooleanfalseShows a disclaimer screen before chat.
disclaimer.disclaimerHTMLstringrequired when enabledHTML content for the disclaimer. If this changes after acceptance, the user must accept again.

Service Desk Options

These are advanced native UI options for human-agent handoff integrations.

PropertyTypeDefaultDescription
serviceDeskFactoryfunctionnoneFactory that creates a service desk integration instance.
serviceDesk.availabilityTimeoutSecondsnumberUI defaultTimeout used while checking whether human agents are available.
serviceDesk.skipConnectHumanAgentCardbooleanfalseAuto-connects to an available agent after a connect-to-agent response while still showing the card.
serviceDesk.agentJoinTimeoutSecondsnumbernoneTimeout while waiting for an agent to join after one is requested.
serviceDesk.allowReconnectbooleantrueAttempts to reconnect the user to a prior human-agent conversation when supported.

Advanced UI Options

These are passed through to the native UI layer. Use them only when the host page needs lower-level control.

PropertyTypeDefaultDescription
aiEnabledbooleanfalseEnables AI visual styling. The widget disables this by default.
assistantNamestringname or deployment nameAssistant name used by the UI for accessibility, errors, and defaults.
assistantAvatarUrlstringlogo_urlAssistant avatar URL used by native messages.
localestringlanguageUI locale. Prefer language unless you need to override only the UI.
namespacestring"rapida-chat"Namespace for DOM IDs, storage keys, and multi-instance isolation. Must be 30 characters or fewer.
openChatByDefaultbooleantrue for docked/inline, false for floatingOpens the chat when it first renders.
shouldSanitizeHTMLbooleantrueSanitizes assistant HTML before rendering.
shouldTakeFocusIfOpensAutomaticallybooleanfalseMoves focus into the chat when it opens on page load.
disableCustomElementMobileEnhancementsbooleanfalseDisables mobile enhancements that can conflict with custom element embedding.
isReadonlybooleanfalsePuts the chat in read-only mode for viewing old conversations.
persistFeedbackbooleanfalseKeeps feedback controls visible beyond the latest message.
stringspartial language packUI defaultsOverrides built-in UI strings.
injectCarbonTheme"white" | "g10" | "g90" | "g100"derived from themeRaw UI prop. Prefer theme.injectTheme.
onErrorfunctionnoneCalled for catastrophic UI errors.

Render And Lifecycle Hooks

PropertyTypeDescription
onBeforeRender(instance)functionCalled before the UI renders. Rapida uses this internally, then calls your handler.
onAfterRender(instance)functionCalled after the UI renders.
onViewPreChange(event, instance)functionCalled before the chat opens or closes. Can return a promise to delay the view change.
onViewChange(event, instance)functionCalled after the chat opens or closes. Rapida uses this to track docked/inline shell state, then calls your handler.
renderUserDefinedResponsefunctionRenders custom user_defined response items.
renderCustomMessageFooterfunctionRenders custom message footers.
renderWriteableElementsobjectRenders writable slots. Rapida merges afterInputElement with its audio controls.

Legacy Shortcuts

These remain supported for old embeds. Prefer the sectioned config above for new usage.

PropertyReplacement
layout: "floating"layout: { mode: "floating" }
layout: "docked-right"layout: { mode: "docked-right" }
layout: "docked-left"layout: { mode: "docked-left" }
layout: "inline"layout: { mode: "inline" }
positionlayout.position
showLauncherlauncher.isOn

Layout Modes

Floating (default)

A fixed-position panel with a launcher FAB. Click the button to open/close the chat.

window.chatbotConfig={layout: {mode: "floating",position: "bottom-right",// or "bottom-left", "top-right", "top-left"},launcher: {isOn: true,},};

Docked

Panel fixed to the side of the viewport. Pushes page content to make room.

window.chatbotConfig={layout: {mode: "docked-right",// or "docked-left"},};

Inline

Flows with the page content. Place the <div id="rapida-chat-app"> where you want it.

window.chatbotConfig={layout: {mode: "inline",},};

Features

  • Text + Voice - type messages or speak with your assistant using WebRTC
  • Markdown rendering - assistant responses render as rich Markdown
  • Microphone device selector - choose input device during voice conversations
  • Dark mode - automatic or manual light/dark theme switching
  • Responsive - works on desktop and mobile browsers
  • Single file - one app.min.js bundle, no external dependencies to load
  • Versioned CDN - pin to a specific version or always use the latest

Development

Prerequisites

  • Node.js 20+
  • npm

Setup

npm install

Commands

npm start # Dev mode with watch (serves at webpack-dev-server)
npm run build # Production build -> dist/app.min.js
npm test# Run tests
npm run test:watch # Run tests in watch mode
npm run test:coverage # Run tests with coverage report

Project Structure

src/
├── index.tsx # Entry point, mounts React app
├── app/
│ ├── index.tsx # App root, creates VoiceAgent
│ └── pages/
│ ├── web-plugin-chat/ # Deployment loader
│ └── v3/
│ ├── index.tsx # Chat UI (messages, header, launcher)
│ └── input.tsx # Text/voice input + device selector
├── contexts/
│ ├── environment-context.tsx # Config from window.chatbotConfig
│ └── dark-mode-context.tsx # Theme management
├── hooks/
│ └── use-environment.ts # Environment context hook
├── configs/
│ └── index.ts # API base URL + constants
├── styles/
│ └── carbon.scss # Theme/component styles and widget style overrides
├── types/
│ ├── globals.d.ts # ChatbotConfig type definition
│ └── types.rapida.ts # Shared types
└── utils/
└── time.ts # Time formatting helpers

CI/CD

On push to main:

  1. Build - npm ci && npm run build
  2. CDN - uploads dist/app.min.js to S3 with CloudFront invalidation
  3. npm - publishes to npm as @rapidaai/web-widget
  4. Release - creates a GitHub release with a version tag

Pull requests run the CI pipeline (build + test) without deploying.

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages