npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

floating-chatbot-react

v1.0.2

Published

A lightweight, customizable floating chatbot React component designed to integrate easily into your application. It provides a simple UI for sending messages, handling PII detection, and delivering responses from a specified API endpoint.

Downloads

204

Readme

Floating Chatbot React Component

A lightweight, customizable floating chatbot React component designed to integrate easily into your application. It provides a simple UI for sending messages, handling PII detection, and delivering responses from a specified API endpoint.

Features

  • Floating UI: Displays a draggable, resizable chat window floating above your content. A clean interface that stays out of the way until needed.

  • PII Redaction: Automatically detects and redacts sensitive information (emails, phone numbers, SSN, etc.) in user input and responses, ensuring data privacy and security.

  • Customizable Appearance: Adjust theme (light/dark), position, z-index, and bot name to match your application's design and requirements.

  • Retry Logic & Error Handling: Automatically retries on non-4xx errors, handles 4xx errors gracefully, and displays user-friendly error messages to ensure reliable operation.

  • Easy Integration: Minimal setup required—just provide an API endpoint and initial configuration to get started.

Installation

npm install floating-chatbot-react

Basic Usage

1. Import and Use the Component

import React from 'react';
import { FloatingChatBot } from 'floating-chatbot-react';

const mockConfig = {
  apiEndpoint: 'https://api.example.com/chat',
  headers: { 'Authorization': 'Bearer YOUR_TOKEN' },
  retryConfig: { retries: 3, delayMs: 1000 },
  // Optionally include initialMessages: [{ sender: 'Assistant', text: 'Hello, how can I help?' }]
};

function App() {
  return (
    <div>
      <FloatingChatBot config={mockConfig} botName="AI Assistant" theme="light" />
      {/* Your app content */}
    </div>
  );
}

export default App;

2. Configuration Options

  • config.apiEndpoint: URL of your backend API handling chat messages
  • config.headers: Optional headers (e.g., authorization tokens)
  • config.retryConfig: Controls retry behavior (retries, delayMs)
  • botName: Customize the displayed assistant name
  • theme: Switch between "light" and "dark"
  • position: Set { bottom: number, right: number } for initial placement
  • zIndex: Adjust stacking order above other elements
  • initialMessages: Array of messages to display when the chatbot first opens

3. Backend Integration

The chatbot sends POST requests to config.apiEndpoint with:

{
  "message": "User typed message",
  "context": { "content": "...scraped page context..." }
}

Your server should respond with:

{
  "message": "Your response"
}

The component will handle retries, errors, and display the assistant's reply.

4. PII Redaction

The component automatically redacts sensitive info (emails, phone numbers, SSNs, etc.) before sending or displaying messages.

Customization and Theming

  • Theme: Pass theme="dark" or theme="light"
  • Position: Define position={{ bottom: 20, right: 20 }} to change initial placement
  • Styles & Dimensions: Modify maxHeight, width, and zIndex props for layout control

Running Tests

All functionality is thoroughly tested using Jest:

npm test

Run storybook

Test component options in storybook:

npm run storybook