Embeddable WebChat widget for MitraChat - built with Svelte 5, Vite, and Tailwind v4.
npm install @mitrachat/webchat-widget
# or
yarn add @mitrachat/webchat-widget
# or
bun add @mitrachat/webchat-widget
import { mountWebchat } from "@mitrachat/webchat-widget";
mountWebchat({
providerId: "your-provider-id",
apiUrl: "https://api.mitrachat.com",
theme: "auto",
position: "bottom-right",
});
<script src="https://cdn.mitrachat.com/widget/v1/webchat-widget.iife.js" async></script>
<script>
window.MitraChatWidget.init({
providerId: "your-provider-id",
apiUrl: "https://api.mitrachat.com",
});
</script>
<div
data-mitrachat-provider="your-provider-id"
data-mitrachat-api-url="https://api.mitrachat.com"
data-mitrachat-theme="auto"
data-mitrachat-position="bottom-right">
</div>
bun run dev:server (runs on http://localhost:3000)cd packages/webchat-widget
bun install
bun run dev
This will:
The demo page allows you to:
cd packages/webchat-widget
bun install
bun run build
Then open public/demo.html in a browser (requires a local server):
# Using Python 3
python3 -m http.server 8080
# Using Node.js
npx serve .
# Using Bun
bunx serve .
Visit http://localhost:8080/public/demo.html
You can also test the widget directly in the main web app:
bun run buildapps/web/src/pages/bun run dev:web| Prop | Type | Default | Description |
|---|---|---|---|
providerId |
string |
required | The webchat provider ID from MitraChat |
apiUrl |
string |
required | The API base URL (e.g., http://localhost:3000) |
theme |
'light' | 'dark' | 'auto' |
'auto' |
Widget theme |
position |
'bottom-right' | 'bottom-left' |
'bottom-right' |
Widget position |
Configure the widget appearance in the MitraChat dashboard:
widget_title - Chat window titlewidget_subtitle - Subtitle textwidget_color - Primary color (hex)widget_position - Position on screenallowed_domains - Allowed domains for securitywidget_welcome_message - Initial messagewidget_placeholder_text - Input placeholderwidget_logo_url - Custom logo URLThe widget uses Server-Sent Events (SSE) for real-time communication:
Widget <-- SSE Stream --> Server (oRPC eventIterator)
Widget -- HTTP POST --> Server (oRPC procedures)
Benefits:
POST /api/webchat.sendMessagepackages/webchat-widget/
├── src/
│ ├── components/ # Svelte components
│ ├── lib/ # Utilities (oRPC client, SSE, session)
│ ├── stores/ # Svelte stores
│ ├── types/ # TypeScript types
│ ├── styles/ # Tailwind CSS
│ ├── index.ts # NPM entry point
│ └── embed.ts # CDN entry point
├── public/
│ └── demo.html # Local test page
└── dist/ # Build output
bun run dev - Start dev server with HMRbun run build - Build for productionbun run preview - Preview production buildbun run typecheck - Run TypeScript checksdist/index.es.js - ESM build (for bundlers)dist/index.umd.js - UMD build (for legacy)dist/embed.iife.js - IIFE build (for CDN/script tag)dist/style.css - Compiled CSSallowed_domains (or leave empty)The widget uses credentials: "omit" for requests. Ensure your backend CORS settings allow the widget domain.
The widget has automatic reconnection with exponential backoff. Check:
MIT