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 🙏

© 2025 – Pkg Stats / Ryan Hefner

newinstance-livechat-widget

v0.1.4

Published

A production-ready React chat widget with live agent support, bot integration, and standalone deployment capabilities

Readme

NewInstance Live Chat Widget

A production-ready React chat widget with live agent support, bot integration, and standalone deployment capabilities.

Features

  • React SDK: Easy integration into React applications
  • Standalone Script: Embeddable in any website without React
  • Live Agent Support: Real-time chat with human agents
  • Bot Integration: AI-powered conversation flows with seamless handoff
  • Session Persistence: Maintains conversation state across page reloads
  • Responsive Design: Mobile-first design with customizable themes
  • TypeScript: Full type safety and excellent developer experience
  • Production Ready: Optimized builds and comprehensive error handling

Quick Reference

Standalone Script (Most Common)

<div id="chat-container"></div>
<script src="https://live-chat.cinstance.com/dist/newinstance-widget.umd.js"></script>
<script>
const widget = new NewInstanceWidget.ChatWidgetVanilla({
    appId: 'your-app-id',
    apiKey: 'your-api-key'
});
widget.mount('chat-container');
</script>

React Component

import { ChatWidget } from 'newinstance-livechat-widget';
<ChatWidget config={{ appId: 'your-app', apiKey: 'your-key' }} />

Quick Start

React SDK Installation

npm install newinstance-livechat-widget

Basic React Usage

import React, { useState } from 'react';
import { ChatWidget } from 'newinstance-livechat-widget';

const config = {
  appId: 'your-app-id',
  apiKey: 'your-api-key',
  customerName: 'John Doe', // Optional - user will be prompted if not provided
  customerEmail: '[email protected]', // Optional
  autoOpen: false,
  theme: 'dark' as const // or custom theme object
};

function App() {
  const [error, setError] = useState<string | null>(null);

  const handleError = (error: Error) => {
    console.error('Widget error:', error);
    setError(error.message);
  };

  return (
    <div>
      <h1>My App</h1>
      <ChatWidget
        config={config}
        onError={handleError}
        onClose={() => {
          console.log('Widget closed');
        }}
        onMinimize={() => {
          console.log('Widget minimized');
        }}
      />
    </div>
  );
}

export default App;

Standalone Script Usage

For non-React websites, include the standalone script:

<!DOCTYPE html>
<html>
<head>
    <title>My Website</title>
</head>
<body>
    <h1>Welcome to my website</h1>

    <!-- Chat Widget Container -->
    <div id="chat-container"></div>

    <!-- Include the widget script -->
    <script src="https://live-chat.cinstance.com/dist/newinstance-widget.umd.js"></script>
    <script>
        // Initialize the widget
        const widget = new NewInstanceWidget.ChatWidgetVanilla({
            appId: 'your-app-id',
            apiKey: 'your-api-key',
            customerName: 'John Doe', // Optional - user will be prompted if not provided
            customerEmail: '[email protected]', // Optional
            autoOpen: false, // Optional - controls if widget opens automatically
            theme: 'dark' // or custom theme object
        });

        // Set event handlers (optional)
        widget.setEventHandlers({
            onError: (error) => {
                console.error('Widget error:', error);
            },
            onClose: () => {
                console.log('Widget closed');
            },
            onMinimize: () => {
                console.log('Widget minimized');
            }
        });

        // Mount the widget
        widget.mount('chat-container');
    </script>
</body>
</html>

Configuration Options

Widget Configuration

| Option | Type | Required | Default | Description | |--------|------|----------|---------|-------------| | appId | string | ✅ | - | Your application ID | | apiKey | string | ✅ | - | Your API key for authentication | | customerName | string | ❌ | - | Customer name (user will be prompted if not provided) | | customerEmail | string | ❌ | - | Customer email address | | customerId | string | ❌ | - | Optional identifier for the customer | | initialMessage | string | ❌ | - | Optional initial message to send | | theme | string | object | ❌ | 'light' | Theme configuration ('light', 'dark', or custom theme object) | | autoOpen | boolean | ❌ | false | Whether to automatically open the widget when customer info is provided |

React Component Props

For React usage, the ChatWidget component accepts these props:

| Prop | Type | Required | Description | |------|------|----------|-------------| | config | WidgetConfig | ✅ | Widget configuration object (see above) | | onClose | () => void | ❌ | Callback when widget is closed | | onMinimize | () => void | ❌ | Callback when widget is minimized | | onError | (error: Error) => void | ❌ | Callback for error handling | | className | string | ❌ | Additional CSS class name |

Widget Methods (Standalone Only)

After creating a standalone widget instance with new NewInstanceWidget.ChatWidgetVanilla(), you can use these methods:

// Mount the widget to a container
widget.mount('container-id');

// Unmount the widget
widget.unmount();

// Update widget configuration
widget.updateConfig({
    theme: 'dark',
    customerName: 'New Name'
});

// Set event handlers
widget.setEventHandlers({
    onError: (error) => console.error(error),
    onClose: () => console.log('Widget closed'),
    onMinimize: () => console.log('Widget minimized')
});

// Get widget mode (react or standalone)
const mode = widget.getMode();

Custom Theme Object

const customTheme = {
  primaryColor: '#007bff',
  secondaryColor: '#6c757d',
  bubbleColor: '#ffffff',
  iconColor: '#ffffff',
  backgroundColor: '#ffffff',
  textColor: '#333333'
};

// For React
<ChatWidget
  config={{
    appId: 'your-app-id',
    apiKey: 'your-api-key',
    theme: customTheme
  }}
/>

// For Standalone
const widget = new NewInstanceWidget.ChatWidgetVanilla({
    apiKey: 'your-api-key',
    appId: 'your-app-id',
    theme: customTheme
});

API Integration

Authentication

The widget uses API key authentication. Include your API key in the widget configuration:

React:

<ChatWidget
  config={{
    appId: 'your-app-id',
    apiKey: 'your-api-key-here'
  }}
/>

Standalone:

const widget = new NewInstanceWidget.ChatWidgetVanilla({
    apiKey: 'your-api-key-here',
    appId: 'your-app-id'
});

Bot Integration

The widget automatically integrates with your bot system. Configure bot flows in your NewInstance dashboard.

Live Agent Handoff

When a bot conversation needs human assistance, the widget seamlessly transitions to live agent chat with real-time messaging.

Customization

Styling

The widget includes all necessary styles internally. Customization is handled through the theme configuration object only - no external CSS imports are required.

All styling is controlled through the theme property in your widget configuration:

Event Handling

React:

const handleError = (error: Error) => {
  console.error('Widget error:', error);
  // Handle error (e.g., show notification)
};

<ChatWidget
  config={config}
  onError={handleError}
  onClose={() => {
    console.log('Widget closed');
  }}
  onMinimize={() => {
    console.log('Widget minimized');
  }}
/>

Standalone:

const widget = new NewInstanceWidget.ChatWidgetVanilla({
    apiKey: 'your-api-key',
    appId: 'your-app-id'
});

// Set event handlers after creating the widget
widget.setEventHandlers({
    onError: (error) => {
        console.error('Widget error:', error);
        // Handle error (e.g., show notification)
    },
    onClose: () => {
        console.log('Widget closed');
    },
    onMinimize: () => {
        console.log('Widget minimized');
    }
});

widget.mount('chat-container');

Troubleshooting

Common Issues

  1. Widget not loading:

    • Verify your API key is correct and active
    • Check browser console for JavaScript errors
    • Ensure the widget script is loaded properly
  2. Styling issues:

    • Verify theme configuration is properly formatted
    • Ensure theme colors are valid CSS color values
    • Check for z-index conflicts if the widget appears behind other elements
  3. React integration issues:

    • Ensure React and ReactDOM versions are compatible (16.8+)
    • Check for TypeScript errors if using TypeScript
    • Verify the component is properly imported
  4. Standalone script issues:

    • Ensure the script is loaded before creating new NewInstanceWidget.ChatWidgetVanilla()
    • Check that the configuration object is properly formatted
    • Verify the container element exists before calling widget.mount()
    • Make sure to use the correct constructor: NewInstanceWidget.ChatWidgetVanilla

Debug Tips

  • Open browser developer tools to check for console errors
  • Verify network requests are successful in the Network tab
  • Check that the widget configuration matches the expected format
  • Test with a minimal configuration first, then add customizations

Support

For widget integration help:

Examples

Check out example implementations in the /test-implementations directory:

Standalone HTML Example

See test-implementations/standalone.html for a complete working example with:

  • Theme customization controls
  • Event handling
  • Environment detection
  • Error handling
  • Dynamic configuration updates

React Integration

import React, { useState } from 'react';
import { ChatWidget } from 'newinstance-livechat-widget';

const DEMO_CONFIG = {
  appId: 'your-app-id',
  apiKey: 'your-api-key',
  customerName: 'Demo User',
  customerEmail: '[email protected]',
  autoOpen: false,
  theme: 'dark' as const
};

function App() {
  const [error, setError] = useState<string | null>(null);

  const handleError = (error: Error) => {
    console.error('Widget error:', error);
    setError(error.message);
  };

  return (
    <div>
      <h1>My App</h1>
      <ChatWidget
        config={DEMO_CONFIG}
        onError={handleError}
        onClose={() => {
          console.log('Widget closed');
        }}
        onMinimize={() => {
          console.log('Widget minimized');
        }}
      />
    </div>
  );
}