Widget & API
JavaScript API
Create and control the chat from your own code.
For full control, create the chat yourself instead of using data-public-key. Load the script without the attribute and call CommerceOSChat.createChat, or import the ES module in a bundled app.
<script src="https://cdn.selfserve.cosmos.hub.nortq.com/v1/chat.js"></script>
<script>
const chat = CommerceOSChat.createChat({
publicKey: "pk_live_your_key",
apiUrl: "https://chat.selfserve.cosmos.hub.nortq.com",
});
</script>import { createChat } from "https://cdn.selfserve.cosmos.hub.nortq.com/v1/chat.esm.js";
const chat = createChat({
publicKey: "pk_live_your_key",
apiUrl: "https://chat.selfserve.cosmos.hub.nortq.com",
launcher: "hidden",
onUnreadChange: ({ count, teaser }) => updateBadge(count, teaser),
});
document.querySelector("#help").addEventListener("click", () => chat.toggle());Options
| Option | Type | Description |
|---|---|---|
publicKey | string | Required. Your key from Setup → Install. |
apiUrl | string | Required. https://chat.selfserve.cosmos.hub.nortq.com. |
mode | "window" | "fullscreen" | "inline" | Default window. |
target | string | CSS selector to mount into. Default: the page body. |
launcher | "default" | "hidden" | hidden shows no chat button — open it from your own. |
entryUrl | string | The page the visitor started on, if not the current one. |
trackPageViews | boolean | Record the pages a visitor views, shown beside their conversation. Default true. |
serviceWorker | string | Path of your reply-notification worker. See Visitor notifications. |
onUnreadChange | ({ count, teaser }) => void | Called when unread replies change. teaser is up to 140 characters of the newest one. |
onEvent | ({ type, data }) => void | Called for widget events. |
Controller
createChat returns a controller:
| Method | Description |
|---|---|
open() | Open the chat. |
close() | Close it. |
toggle() | Open if closed, close if open. |
isOpen() | Whether it's open. |
getUnread() | { count, teaser } — read once on load, then follow onUnreadChange. Unread survives page navigation. |
reset() | Start a fresh conversation for this visitor. |
destroy() | Remove the chat from the page. |