CommerceOS

Widget & API

Using your own chat button

Hide the built-in launcher and open the chat from your design.

The built-in button already shows an unread badge and a preview of new replies. If you'd rather use your own button, hide the built-in one and drive the chat with the JavaScript API.

<button id="help" aria-label="Chat with us">
  Help <span id="badge" hidden></span>
</button>
<p id="teaser" role="status" hidden></p>

<script src="https://cdn.selfserve.cosmos.hub.nortq.com/v1/chat.js"></script>
<script>
  const badge = document.getElementById("badge");
  const teaser = document.getElementById("teaser");

  function render({ count, teaser: text }) {
    badge.hidden = count === 0;
    badge.textContent = count > 9 ? "9+" : String(count);
    teaser.hidden = !text;
    teaser.textContent = text ?? "";
    document.getElementById("help").setAttribute(
      "aria-label",
      count ? `Chat with us, ${count} unread` : "Chat with us",
    );
  }

  const chat = CommerceOSChat.createChat({
    publicKey: "pk_live_your_key",
    apiUrl: "https://chat.selfserve.cosmos.hub.nortq.com",
    launcher: "hidden",
    onUnreadChange: render,
  });
  render(chat.getUnread());
  document.getElementById("help").addEventListener("click", () => chat.toggle());
</script>

Checklist

  • Show the unread count — replies from your team can arrive while the chat is closed.
  • Give the button an aria-label that includes the count, and announce the teaser with role="status".
  • Make the button at least 44×44 pixels on phones.
  • Respect prefers-reduced-motion if you animate the badge.