0.1.6 • Published 8 months ago

@aplisay/react-widget v0.1.6

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

Aplisay Logo

@aplisay/react-widget

A React component for integrating Aplisay's conversational AI into your web applications.

Installation

npm install @aplisay/react-widget

Basic Usage

import React from 'react';
import '@aplisay/react-widget/dist/styles.css';
import { AplisayWidget } from '@aplisay/react-widget';

function App() {
  return (
    <AplisayWidget
      listenerId="YOUR_LISTENER_ID"
      url="YOUR_APLISAY_URL"
      roomKey="YOUR_ROOM_KEY"
      debug={true}
      showStatus={true}
      theme={{
        palette: {
          mode: 'light',
          primary: {
            main: '#f63bcb'
          },
          background: {
            default: '#ffffff'
          },
          text: {
            primary: '#374151'
          },
          error: {
            main: '#ef4444'
          }
        }
      }}
    />
  );
}

Props

PropTypeRequiredDescription
listenerIdstringYesYour unique listener identifier
urlstringYesThe Aplisay API endpoint URL
roomKeystringYesAuthentication key for the room
debugbooleanNoEnable detailed logging (default: false)
showStatusbooleanNoShow connection status (default: false)
themeTheme ObjectNoCustom theme configuration

Controlled Mode

If you wish, the widget can be controlled by the open prop. The setter, setOpen, will be called with the new state of the widget if it changes due to user interaction (pressing hangup, etc).

PropTypeRequiredDescription
openbooleanNoWhether the widget is active (default: true)
setOpen(open: boolean) => voidNoFunction to set the widget's open/active state

Theme Object

interface Theme {
  palette: {
    mode?: 'light' | 'dark';
    primary?: {
      main?: string; // Primary color
    };
    background?: {
      default?: string; // Background color
    };
    text?: {
      primary?: string; // Text color
    };
    error?: {
      main?: string; // Error color
    };
  };
}

Advanced Styling

This theme doesn't provide enough customization for your needs? Feel free to customize the appearance of the widget using your own CSS overrides. Note, however, that the CSS class names provided by @aplisay/react-widget are not considered stable and may change in future versions.

Room States

The widget can be in one of these states:

  • initial
  • parameter_error
  • join
  • connected
  • error

Additional Exports

import { useAplisayRoom } from '@aplisay/react-widget';

useAplisayRoom Hook

The useAplisayRoom hook provides a way to integrate Aplisay's conversational AI into your React application with more control over the room state and functionality.

Parameters

ParameterTypeRequiredDescription
urlstringNoThe Aplisay API endpoint URL
listenerIdstringNoYour unique listener identifier
roomKeystringNoAuthentication key for the room
joinCallback() => PromiseNoCustom function to handle room joining
clientFunctions{ key: string: Function }NoCustom functions to be registered with the session
closebooleanNoWhether to close the room connection

Either the url, listener and roomKey should be specified to allow the hook to call the server and instantiate a room OR a function passed in joinCallback which will be called to execute the room join.

Returns

PropertyTypeDescription
stateRoomStateCurrent state of the room ('initial', 'parameter_error', 'join', 'connected', 'error')
agentStatestringCurrent state of the AI agent
errorstringError message if any
transcriptTranscriptEntry[]Array of conversation transcript entries
roomRoomDataRoom connection data from join request. Primary useful property is callId which isn't otherwise obtainable

Example Usage

import { useAplisayRoom } from '@aplisay/react-widget';

function CustomWidget() {
  const { state, agentState, error, transcript, room } = useAplisayRoom({
    url: 'YOUR_APLISAY_URL',
    listenerId: 'YOUR_LISTENER_ID',
    roomKey: 'YOUR_ROOM_KEY',
    clientFunctions: {
      // Register custom functions here
      myCustomFunction: (args) => {
        // Handle custom function call
        return 'Result';
      }
    }
  });

  // Use the hook's return values to build your custom UI
  return (
    <div>
      {state === 'connected' && (
        <div>
          <p>Agent State: {agentState}</p>
          <div className="transcript">
            {transcript.map((entry, index) => (
              <p key={index}>{entry.speaker}: {entry.text}</p>
            ))}
          </div>
        </div>
      )}
      {error && <p className="error">{error}</p>}
    </div>
  );
}

Live Demo/Configurator

Configurator | Configurator Source Code

Support

For issues, feature requests, or questions, please just use this repo. Open An Issue in the first instance.

License

MIT License, for any code written by Aplisay for this widget.

0.1.6

8 months ago

0.1.5

8 months ago

0.1.4

10 months ago

0.1.3

10 months ago

0.1.2

10 months ago

0.1.1

10 months ago

0.1.1-alpha.3

10 months ago

0.1.1-alpha.2

10 months ago

0.1.1-alpha.1

10 months ago

0.1.0

11 months ago

0.0.1-beta.5

11 months ago

0.0.1-beta.4

11 months ago

0.0.1-beta.3

11 months ago

0.0.1-beta.2

11 months ago

0.0.1-beta.1

11 months ago

0.0.1-alpha.16

11 months ago

0.0.1-alpha.15

11 months ago

0.0.1-alpha.14

11 months ago

0.0.1-alpha.13

11 months ago

0.0.1-alpha.12

11 months ago

0.0.1-alpha.11

11 months ago

0.0.1-alpha.10

11 months ago

0.0.1-alpha.9

11 months ago

0.0.1-alpha.8

11 months ago

0.0.1-alpha.7

11 months ago

0.0.1-alpha.6

11 months ago

0.0.1-alpha.5

11 months ago

0.0.1-alpha.4

11 months ago

0.0.1-alpha.3

11 months ago

0.0.1-alpha.2

11 months ago

0.0.1-alpha.1

11 months ago