@chatmode/embed
v0.1.7
Published
A lightweight embeddable chat widget for Chatmode that can be added to any website.
Readme
@chatmode/embed
A lightweight embeddable chat widget for Chatmode that can be added to any website.
Installation
NPM
npm install @chatmode/embedCDN
You can also use the package directly from jsDelivr CDN:
<script type="module">
import Chatmode from "https://cdn.jsdelivr.net/npm/@chatmode/embed/+esm";
// Initialize the chat bubble
Chatmode.initBubble({
environmentId: "your-environment-id",
iconKey: "/environment/**",
/* Used to cache-bust your icon. Make sure to keep this updated */
updatedAt: 1743552265135,
/* "bottom-left" or "bottom-right" (default) */
position: "bottom-right",
});
</script>Usage
Initialize chat bubble
Add the following code to your website to display a chat bubble that opens a chat modal when clicked:
import Chatmode from "@chatmode/embed";
// Initialize the chat bubble
const chat = Chatmode.initBubble({
environmentId: "your-environment-id",
/* Optional: "light", "dark", or "automatic" (default) */
theme: "automatic",
iconKey: "/environment/**",
/* Used to cache-bust your icon. Make sure to keep this updated */
updatedAt: 1743552265135,
/* "bottom-left" or "bottom-right" (default) */
position: "bottom-right",
});
// Optional: Control the chat programmatically
// chat.open(); // Open the chat modal
// chat.close(); // Close the chat modalAPI Reference
Chatmode.initBubble(options)
Creates and initializes the chat bubble on your website.
Parameters:
options(object) - Configuration options:environmentId(string) - Your Chatmode environment IDposition("bottom-left" | "bottom-right") - Where the Chat Bubble is rendered attheme(string, optional) - Theme to use for the chat widget:"light"- Forces light theme"dark"- Forces dark theme"automatic"- Automatically detects theme based on user's system preferences or website settings (default)
Returns:
An object with methods to control the chat:
open()- Opens the chat modalclose()- Closes the chat modaltoggle()- Toggles the chat modal open/closedisOpen()- Returns true if the chat modal is openremove()- Unmounts the chat bubble and modal
Theme Detection
When theme is set to "automatic" or not provided, the widget will detect the appropriate theme in the following order:
- Check for
data-theme="dark"ordata-theme="light"attribute on the<html>element - Check for
darkorlightclass on the<html>element - Check the user's system preference using
prefers-color-schememedia query
The widget will automatically update if any of these values change.
