1.27.15 • Published 4 months ago

@waii-ai/widgets v1.27.15

Weekly downloads
-
License
UNLICENSED
Repository
-
Last release
4 months ago

Waii Widgets

A collection of React UI components featuring the WaiiChat widget, which provides embedded chat functionality powered by Waii's text-to-SQL API.

Features

  • 🚀 Easy to integrate with multiple implementation options
  • 💅 Customizable themes and styling
  • 📱 Mobile-responsive
  • 🔒 TypeScript support
  • ⚡ Lightweight
  • 🎯 Three integration methods: React Component, Standalone Script, or iFrame Embed

Installation

# Using npm
npm install @waii-ai/widgets

# Using yarn
yarn add @waii-ai/widgets

# Using pnpm
pnpm add @waii-ai/widgets

Integration Methods

1. React Component

import { WaiiChat } from '@waii-ai/widgets';

function App() {
  return (
    <WaiiChat 
      apiKey="your-api-key"
      databaseKey="your-database-key"
      theme="light"
      handleChatResponse={(response) => {
        console.log('Chat response:', response);
      }}
    />
  );
}

2. Standalone Script

<script src="https://unpkg.com/@waii-ai/widgets/dist/waii-widgets.js"></script>

<div id="waii-chat"></div>
<script>
  WaiiWidgets.WaiiChatLoader.init({
    containerId: 'waii-chat',
    apiKey: 'your-api-key',
    databaseKey: 'your-database-key',
    theme: 'light',
    onMessage: (message) => console.log('New message:', message)
  });
</script>

3. iFrame Embed

<script src="https://unpkg.com/@waii-ai/widgets/dist/embed.js"></script>

<div id="chat-container"></div>
<script>
  const chatWidget = new WaiiWidgets.WaiiChatEmbed('#chat-container', {
    apiKey: 'your-api-key',
    databaseKey: 'your-database-key',
    theme: 'light',
    onChatResponse: (response) => {
      console.log('Chat response:', response);
    }
  });
</script>

Configuration Options

Core Properties

PropertyTypeRequiredDescription
apiKeystringYesYour Waii API key
databaseKeystringYesYour database connection string
apiUrlstringNoCustom API endpoint (if different from default)
theme'light' \| 'dark'NoWidget theme (default: 'light')

Styling Options

PropertyTypeDescription
classNamestringCSS class for the container
styleReact.CSSPropertiesInline styles for the container
contentStyleReact.CSSPropertiesStyles for the content area
messageListStyleReact.CSSPropertiesStyles for the message list
inputStyleReact.CSSPropertiesStyles for the input area

Branding Options

PropertyTypeDescription
botNamestringCustom name for the chat bot
botAvatarUrlstringCustom avatar URL for the bot

AI Configuration

PropertyTypeDescription
useFewShotLearningbooleanEnable few-shot learning
useReflectionbooleanEnable reflection capabilities
useStrictHallucinationCheckbooleanEnable strict hallucination checking
modelstringSpecify the AI model to use

Callback Functions

PropertyTypeDescription
handleChatResponse(response: any) => voidCalled when a chat response is received
handleReset() => voidCalled when the chat is reset
handleEditChatFunctionCalled when a chat message is edited
onQueryProcessed() => voidCalled when a query is processed

State Management

PropertyTypeDescription
chatHistoryListany[]Pre-populate chat with history
selectedDBConnectoranySet the selected database connector
chatQueryEditedstring \| nullPre-set edited query
chatAskEditedstring \| nullPre-set edited question

Development

# Install dependencies
npm install

# Build for production
npm run build

# Run tests
npm run test

Support

For issues and feature requests, please contact Waii support.