0.1.3 • Published 8 months ago

@kieng/just-chat v0.1.3

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

Universal Chat Popup

A lightweight, customizable chat widget that can be easily embedded into any website. Built with Web Components for maximum compatibility and style isolation.

Features

  • šŸŽØ Customizable theme and appearance
  • šŸ’¾ Local chat history persistence
  • šŸ”Œ Simple webhook integration
  • šŸŽÆ Zero dependencies
  • šŸ›”ļø Style isolation via Shadow DOM
  • šŸ“± Responsive design
  • āŒØļø Keyboard accessible
  • šŸ”„ Message status indicators
  • āŒ Request cancellation support
  • šŸ”’ Secure by default
  • 🌐 Cross-browser compatible
  • šŸš€ Small bundle size (~4KB gzipped)

Installation

Via CDN (Recommended)

<!-- Latest version -->
<script src="https://cdn.jsdelivr.net/npm/@kieng/just-chat/dist/just-chat.umd.js"
        data-webhook-url="https://your-backend.com/chat"
        data-theme-color="#1E40AF"
        data-position="bottom-right"
        data-title="Chat with us"
        data-welcome-message="How can we help you today?"
        data-history-enabled="true"
        data-history-clear-button="true"
        defer>
</script>

<!-- Specific version -->
<script src="https://cdn.jsdelivr.net/npm/@kieng/just-chat@0.1.2/dist/just-chat.umd.js"
        data-webhook-url="https://your-backend.com/chat"
        defer>
</script>

Via NPM

# Using npm
npm install @kieng/just-chat

# Using pnpm
pnpm add @kieng/just-chat

# Using yarn
yarn add @kieng/just-chat
import { initChatPopup } from '@kieng/just-chat';

initChatPopup({
  webhookUrl: 'https://your-backend.com/chat',
  themeColor: '#1E40AF',
  position: 'bottom-right',
  title: 'Chat with us',
  welcomeMessage: 'How can we help you today?',
  history: {
    enabled: true,
    clearButton: true
  }
});

Configuration

OptionTypeDefaultDescription
webhookUrlstring-(Required) Backend endpoint URL for processing messages
themeColorstring'#1E40AF'Primary color for UI elements
position'bottom-right' | 'bottom-left''bottom-right'Widget position on screen
titlestring'Chat with us'Chat window title
welcomeMessagestring''Initial message shown when chat opens
history.enabledbooleantrueEnable/disable chat history persistence
history.clearButtonbooleantrueShow/hide the clear history button

Features in Detail

Message Status Indicators

Messages show their current status:

  • šŸ”„ Sending: Message is being sent to the webhook
  • āœ… Sent: Message was successfully delivered
  • āŒ Error: Failed to send message
  • ⚪ Cancelled: User cancelled the message

History Management

Chat history is stored in LocalStorage:

  • Persists across page reloads
  • Separate storage per webhook URL
  • Optional clear history button
  • Automatic loading of previous messages

Webhook Integration

The widget sends POST requests to your webhook URL with the following JSON payload:

{
  message: string;          // User's message
  timestamp: string;        // ISO8601 timestamp
  sessionId: string;        // Unique session identifier
  context: {
    url: string;           // Current page URL
  };
  history?: Array<{        // Last 10 messages (if any)
    id: string;
    text: string;
    sender: 'user' | 'backend' | 'system';
    timestamp: string;
  }>;
}

Expected response format:

{
  response: string;        // Text message to display to the user
}

Security Features

  • Content Security Policy (CSP) compatible
  • No eval() or inline scripts
  • XSS protection for message rendering
  • CORS support for webhook requests
  • Secure by default configuration

Browser Support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)
  • Mobile browsers

Accessibility

  • ARIA labels and roles
  • Keyboard navigation
  • Focus management
  • Screen reader support
  • High contrast support

Development

Prerequisites

  • Node.js 18+
  • pnpm (recommended) or npm

Setup

  1. Clone the repository
git clone https://github.com/draphonix/just-chat.git
cd just-chat
  1. Install dependencies
pnpm install
  1. Start development server
pnpm dev
  1. Build for production
pnpm build

Testing the Widget

  1. Start the mock server
pnpm start
  1. Open http://localhost:3000 in your browser
  2. Try the demo features:
    • Send messages
    • Cancel messages
    • Clear history
    • Change theme color
    • Test responsiveness

Project Structure

just-chat/
ā”œā”€ā”€ src/
│   ā”œā”€ā”€ components/        # Web Components
│   │   ā”œā”€ā”€ base-component.ts
│   │   ā”œā”€ā”€ chat-widget.ts
│   │   ā”œā”€ā”€ chat-launcher.ts
│   │   └── chat-window.ts
│   ā”œā”€ā”€ services/         # Core services
│   │   ā”œā”€ā”€ storage.ts
│   │   └── webhook.ts
│   └── main.ts          # Entry point
ā”œā”€ā”€ dist/                # Built files
ā”œā”€ā”€ mock-server.js      # Test server
└── package.json

Contributing

  1. Fork the repository
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. Create a Pull Request

License

MIT

Support

Credits

Built with:

  • TypeScript
  • Web Components
  • Vite
  • Express (mock server)# just-chat
0.1.3

8 months ago

0.1.2

8 months ago